Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / alld_pca9544a.c @ ef078306

History | View | Annotate | Download (6.16 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.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
/* 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
inline apalExitStatus_t
65
pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const  data, const apalTime_t timeout)
66
{
67
  apalDbgAssert(pca9544a != NULL);
68
  apalDbgAssert(data != NULL);
69

    
70
  return apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), data, 1, timeout);
71
}
72

    
73
/**
74
 * @brief Set the control register of the PCA9544A.
75
 *
76
 * @param[in] pca9544a  The PCA9544A driver object.
77
 * @param[in] data      The value to write to the PCA9544A.
78
 * @param[in] timeout   Timeout for the function to return (in microseconds)
79
 *
80
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
81
 */
82
inline apalExitStatus_t
83
pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout)
84
{
85
  apalDbgAssert(pca9544a != NULL);
86

    
87
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &data, 1, NULL, 0, timeout);
88
}
89

    
90
/**
91
 * @brief Read the interrupt status.
92
 *
93
 * @param[in]   pca9544a  The PCA9544A driver object.
94
 * @param[out]  status    The status of the four interrupts.
95
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
96
 *
97
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
98
 */
99
inline apalExitStatus_t
100
pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout)
101
{
102
  apalDbgAssert(pca9544a != NULL);
103
  apalDbgAssert(status != NULL);
104

    
105
  uint8_t buffer;
106
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
107
  *status = buffer >> 4;
108
  return stat;
109
}
110

    
111
/**
112
 * @brief Read which channel is currently set.
113
 *
114
 * @param[in]   pca9544a  The PCA9544A driver object.
115
 * @param[out]  channel   The identifier of the set channel.
116
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
117
 *
118
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
119
 */
120
inline apalExitStatus_t
121
pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout)
122
{
123
  apalDbgAssert(pca9544a != NULL);
124
  apalDbgAssert(channel != NULL);
125

    
126
  uint8_t buffer;
127
  apalExitStatus_t stat = apalI2CMasterReceive(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, timeout);
128
  if (buffer & PCA9544A_LLD_CTRLREG_EN) {
129
    *channel = buffer & PCA9544A_LLD_CTRLREG_CH_MASK;
130
  } else {
131
    *channel = PCA9544A_LLD_CH_NONE;
132
  }
133
  return stat;
134
}
135

    
136
/**
137
 * @brief Set the channel for multiplexing.
138
 *
139
 * @param[in]   pca9544a  The PCA9544A driver object.
140
 * @param[in]   channel   The channel to set for multiplexing.
141
 * @param[in]   timeout   Timeout for the function to return (in microseconds)
142
 *
143
 * @return  The return status indicates whether the function call was succesfull or a timeout occurred.
144
 */
145
inline apalExitStatus_t
146
pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout)
147
{
148
  apalDbgAssert(pca9544a != NULL);
149

    
150
  uint8_t buffer = (channel == PCA9544A_LLD_CH_NONE) ? 0x00u : (PCA9544A_LLD_CTRLREG_EN | channel);
151
  return apalI2CMasterTransmit(pca9544a->i2cd, (PCA9544A_LLD_I2C_ADDR_FIXED | pca9544a->addr), &buffer, 1, NULL, 0, timeout);
152
}
153

    
154
#endif /* defined(AMIROLLD_CFG_USE_PCA9544A) */
155

    
156
/** @} */