amiro-lld / source / alld_pca9544a.c @ 11500ad8
History | View | Annotate | Download (4.729 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
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 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file alld_pca9544a.c
|
21 |
* @brief I2C Multiplexer function implementations.
|
22 |
*
|
23 |
* @addtogroup lld_multi
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <alld_pca9544a.h> |
28 |
|
29 |
#if defined(AMIROLLD_CFG_USE_PCA9544A) || defined(__DOXYGEN__)
|
30 |
|
31 |
/**
|
32 |
* @brief Read the control register of the PCA9544A.
|
33 |
*
|
34 |
* @param[in] pca9544a The PCA9544A driver object.
|
35 |
* @param[out] data The data read from the PCA9544A.
|
36 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
37 |
*
|
38 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
39 |
*/
|
40 |
inline apalExitStatus_t
|
41 |
pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout) |
42 |
{ |
43 |
apalDbgAssert(pca9544a != NULL);
|
44 |
apalDbgAssert(data != NULL);
|
45 |
|
46 |
return apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), data, 1, timeout); |
47 |
} |
48 |
|
49 |
/**
|
50 |
* @brief Set the control register of the PCA9544A.
|
51 |
*
|
52 |
* @param[in] pca9544a The PCA9544A driver object.
|
53 |
* @param[in] data The value to write to the PCA9544A.
|
54 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
55 |
*
|
56 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
57 |
*/
|
58 |
inline apalExitStatus_t
|
59 |
pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout) |
60 |
{ |
61 |
apalDbgAssert(pca9544a != NULL);
|
62 |
|
63 |
return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &data, 1, NULL, 0, timeout); |
64 |
} |
65 |
|
66 |
/**
|
67 |
* @brief Read the interrupt status.
|
68 |
*
|
69 |
* @param[in] pca9544a The PCA9544A driver object.
|
70 |
* @param[out] status The status of the four interrupts.
|
71 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
72 |
*
|
73 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
74 |
*/
|
75 |
inline apalExitStatus_t
|
76 |
pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout) |
77 |
{ |
78 |
apalDbgAssert(pca9544a != NULL);
|
79 |
apalDbgAssert(status != NULL);
|
80 |
|
81 |
uint8_t buffer; |
82 |
apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
|
83 |
*status = buffer >> 4;
|
84 |
return stat;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* @brief Read which channel is currently set.
|
89 |
*
|
90 |
* @param[in] pca9544a The PCA9544A driver object.
|
91 |
* @param[out] channel The identifier of the set channel.
|
92 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
93 |
*
|
94 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
95 |
*/
|
96 |
inline apalExitStatus_t
|
97 |
pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout) |
98 |
{ |
99 |
apalDbgAssert(pca9544a != NULL);
|
100 |
apalDbgAssert(channel != NULL);
|
101 |
|
102 |
uint8_t buffer; |
103 |
apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
|
104 |
if (buffer & PCA9544A_LLD_CTRLREG_EN) {
|
105 |
*channel = buffer & PCA9544A_LLD_CTRLREG_CH_MASK; |
106 |
} else {
|
107 |
*channel = PCA9544A_LLD_CH_NONE; |
108 |
} |
109 |
return stat;
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* @brief Set the channel for multiplexing.
|
114 |
*
|
115 |
* @param[in] pca9544a The PCA9544A driver object.
|
116 |
* @param[in] channel The channel to set for multiplexing.
|
117 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
118 |
*
|
119 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
120 |
*/
|
121 |
inline apalExitStatus_t
|
122 |
pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout) |
123 |
{ |
124 |
apalDbgAssert(pca9544a != NULL);
|
125 |
|
126 |
uint8_t buffer = (channel == PCA9544A_LLD_CH_NONE) ? 0x00u : (PCA9544A_LLD_CTRLREG_EN | channel);
|
127 |
return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, NULL, 0, timeout); |
128 |
} |
129 |
|
130 |
#endif /* defined(AMIROLLD_CFG_USE_PCA9544A) */ |
131 |
|
132 |
/** @} */
|