Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / PCA9544A / v1 / alld_PCA9544A.c @ 9466e34d

History | View | Annotate | Download (6.016 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
/******************************************************************************/
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
/**
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
apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const  data, const apalTime_t timeout)
63
{
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
apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout)
80
{
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
apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout)
96
{
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
apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout)
116
{
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
apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout)
140
{
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
/** @} */
148