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