Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / PCA9544A / v1 / alld_PCA9544A_v1.c @ 78cc79d4

History | View | Annotate | Download (6.185 KB)

1 d6728c5b Thomas Schöpping
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3 f125ae07 Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 d6728c5b Thomas Schöpping

5
This program is free software: you can redistribute it and/or modify
6 f0ca400f Thomas Schöpping
it under the terms of the GNU Lesser General Public License as published by
7 d6728c5b Thomas Schöpping
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 f0ca400f Thomas Schöpping
GNU Lesser General Public License for more details.
14 d6728c5b Thomas Schöpping

15 f0ca400f Thomas Schöpping
You should have received a copy of the GNU Lesser General Public License
16 d6728c5b Thomas Schöpping
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 5e2f673b Marc Rothmann
/**
20 1d5bcc82 Thomas Schöpping
 * @file    alld_PCA9544A_v1.c
21 5e2f673b Marc Rothmann
 * @brief   I2C Multiplexer function implementations.
22
 *
23
 * @addtogroup lld_multi
24
 * @{
25
 */
26
27 1d5bcc82 Thomas Schöpping
#include <alld_PCA9544A.h>
28 d6728c5b Thomas Schöpping
29 1d5bcc82 Thomas Schöpping
#if (defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__)
30 d6728c5b Thomas Schöpping
31 ef078306 Thomas Schöpping
/******************************************************************************/
32
/* LOCAL DEFINITIONS                                                          */
33
/******************************************************************************/
34
35
/******************************************************************************/
36
/* EXPORTED VARIABLES                                                         */
37
/******************************************************************************/
38
39
/******************************************************************************/
40
/* LOCAL TYPES                                                                */
41
/******************************************************************************/
42
43
/******************************************************************************/
44
/* LOCAL VARIABLES                                                            */
45
/******************************************************************************/
46
47
/******************************************************************************/
48
/* LOCAL FUNCTIONS                                                            */
49
/******************************************************************************/
50
51
/******************************************************************************/
52
/* EXPORTED FUNCTIONS                                                         */
53
/******************************************************************************/
54
55 d6728c5b Thomas Schöpping
/**
56
 * @brief Read the control register of the PCA9544A.
57
 *
58
 * @param[in]   pca9544a  The PCA9544A driver object.
59
 * @param[out]  data      The data read from the PCA9544A.
60
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
61
 *
62
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
63
 */
64 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const  data, const apalTime_t timeout)
65 d6728c5b Thomas Schöpping
{
66
  apalDbgAssert(pca9544a != NULL);
67
  apalDbgAssert(data != NULL);
68
69
  return apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), data, 1, timeout);
70
}
71
72
/**
73
 * @brief Set the control register of the PCA9544A.
74
 *
75
 * @param[in] pca9544a  The PCA9544A driver object.
76
 * @param[in] data      The value to write to the PCA9544A.
77
 * @param[in] timeout   Timeout for the function to return (in microseconds)
78
 *
79
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
80
 */
81 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout)
82 d6728c5b Thomas Schöpping
{
83
  apalDbgAssert(pca9544a != NULL);
84
85
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &data, 1, NULL, 0, timeout);
86
}
87
88
/**
89
 * @brief Read the interrupt status.
90
 *
91
 * @param[in]   pca9544a  The PCA9544A driver object.
92
 * @param[out]  status    The status of the four interrupts.
93
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
94
 *
95
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
96
 */
97 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout)
98 d6728c5b Thomas Schöpping
{
99
  apalDbgAssert(pca9544a != NULL);
100
  apalDbgAssert(status != NULL);
101
102
  uint8_t buffer;
103
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
104
  *status = buffer >> 4;
105
  return stat;
106
}
107
108
/**
109
 * @brief Read which channel is currently set.
110
 *
111
 * @param[in]   pca9544a  The PCA9544A driver object.
112
 * @param[out]  channel   The identifier of the set channel.
113
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
114
 *
115
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
116
 */
117 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout)
118 d6728c5b Thomas Schöpping
{
119
  apalDbgAssert(pca9544a != NULL);
120
  apalDbgAssert(channel != NULL);
121
122
  uint8_t buffer;
123
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
124
  if (buffer & PCA9544A_LLD_CTRLREG_EN) {
125
    *channel = buffer & PCA9544A_LLD_CTRLREG_CH_MASK;
126
  } else {
127
    *channel = PCA9544A_LLD_CH_NONE;
128
  }
129
  return stat;
130
}
131
132
/**
133
 * @brief Set the channel for multiplexing.
134
 *
135
 * @param[in]   pca9544a  The PCA9544A driver object.
136
 * @param[in]   channel   The channel to set for multiplexing.
137
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
138
 *
139
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
140
 */
141 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout)
142 d6728c5b Thomas Schöpping
{
143
  apalDbgAssert(pca9544a != NULL);
144
145
  uint8_t buffer = (channel == PCA9544A_LLD_CH_NONE) ? 0x00u : (PCA9544A_LLD_CTRLREG_EN | channel);
146
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, NULL, 0, timeout);
147
}
148
149 1d5bcc82 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */
150 5e2f673b Marc Rothmann
151
/** @} */