amiro-lld / source / PCA9544A / v1 / alld_PCA9544A_v1.c @ c4db2363
History | View | Annotate | Download (6.185 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 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_v1.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_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__) |
30 |
|
31 |
/******************************************************************************/
|
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 |
/**
|
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 |
apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout) |
65 |
{ |
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 |
apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout) |
82 |
{ |
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 |
apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout) |
98 |
{ |
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 |
apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout) |
118 |
{ |
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 |
apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout) |
142 |
{ |
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 |
#endif /* defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */ |
150 |
|
151 |
/** @} */
|