Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / PCA9544A / v1 / alld_PCA9544A.c @ 4dba9195

History | View | Annotate | Download (6.016 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 9466e34d Thomas Schöpping
 * @file    alld_PCA9544A.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 ef078306 Thomas Schöpping
/******************************************************************************/
30
/* LOCAL DEFINITIONS                                                          */
31
/******************************************************************************/
32
33
/******************************************************************************/
34
/* EXPORTED VARIABLES                                                         */
35
/******************************************************************************/
36
37
/******************************************************************************/
38
/* LOCAL TYPES                                                                */
39
/******************************************************************************/
40
41
/******************************************************************************/
42
/* LOCAL VARIABLES                                                            */
43
/******************************************************************************/
44
45
/******************************************************************************/
46
/* LOCAL FUNCTIONS                                                            */
47
/******************************************************************************/
48
49
/******************************************************************************/
50
/* EXPORTED FUNCTIONS                                                         */
51
/******************************************************************************/
52
53 d6728c5b Thomas Schöpping
/**
54
 * @brief Read the control register of the PCA9544A.
55
 *
56
 * @param[in]   pca9544a  The PCA9544A driver object.
57
 * @param[out]  data      The data read from the PCA9544A.
58
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
59
 *
60
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
61
 */
62 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const  data, const apalTime_t timeout)
63 d6728c5b Thomas Schöpping
{
64
  apalDbgAssert(pca9544a != NULL);
65
  apalDbgAssert(data != NULL);
66
67
  return apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), data, 1, timeout);
68
}
69
70
/**
71
 * @brief Set the control register of the PCA9544A.
72
 *
73
 * @param[in] pca9544a  The PCA9544A driver object.
74
 * @param[in] data      The value to write to the PCA9544A.
75
 * @param[in] timeout   Timeout for the function to return (in microseconds)
76
 *
77
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
78
 */
79 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout)
80 d6728c5b Thomas Schöpping
{
81
  apalDbgAssert(pca9544a != NULL);
82
83
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &data, 1, NULL, 0, timeout);
84
}
85
86
/**
87
 * @brief Read the interrupt status.
88
 *
89
 * @param[in]   pca9544a  The PCA9544A driver object.
90
 * @param[out]  status    The status of the four interrupts.
91
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
92
 *
93
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
94
 */
95 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout)
96 d6728c5b Thomas Schöpping
{
97
  apalDbgAssert(pca9544a != NULL);
98
  apalDbgAssert(status != NULL);
99
100
  uint8_t buffer;
101
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
102
  *status = buffer >> 4;
103
  return stat;
104
}
105
106
/**
107
 * @brief Read which channel is currently set.
108
 *
109
 * @param[in]   pca9544a  The PCA9544A driver object.
110
 * @param[out]  channel   The identifier of the set channel.
111
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
112
 *
113
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
114
 */
115 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout)
116 d6728c5b Thomas Schöpping
{
117
  apalDbgAssert(pca9544a != NULL);
118
  apalDbgAssert(channel != NULL);
119
120
  uint8_t buffer;
121
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
122
  if (buffer & PCA9544A_LLD_CTRLREG_EN) {
123
    *channel = buffer & PCA9544A_LLD_CTRLREG_CH_MASK;
124
  } else {
125
    *channel = PCA9544A_LLD_CH_NONE;
126
  }
127
  return stat;
128
}
129
130
/**
131
 * @brief Set the channel for multiplexing.
132
 *
133
 * @param[in]   pca9544a  The PCA9544A driver object.
134
 * @param[in]   channel   The channel to set for multiplexing.
135
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
136
 *
137
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
138
 */
139 21076167 Thomas Schöpping
apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout)
140 d6728c5b Thomas Schöpping
{
141
  apalDbgAssert(pca9544a != NULL);
142
143
  uint8_t buffer = (channel == PCA9544A_LLD_CH_NONE) ? 0x00u : (PCA9544A_LLD_CTRLREG_EN | channel);
144
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, NULL, 0, timeout);
145
}
146
147 5e2f673b Marc Rothmann
/** @} */