amiro-lld / include / PCA9544A / v1 / alld_PCA9544A_v1.h @ 2344a771
History | View | Annotate | Download (6.064 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 | 1d5bcc82 | Thomas Schöpping | * @file alld_PCA9544A_v1.h
|
21 | 5e2f673b | Marc Rothmann | * @brief I2C Multiplexer macros and structures.
|
22 | *
|
||
23 | * @addtogroup lld_multi
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | 1d5bcc82 | Thomas Schöpping | #ifndef AMIROLLD_PCA9544A_V1_H
|
28 | #define AMIROLLD_PCA9544A_V1_H
|
||
29 | d6728c5b | Thomas Schöpping | |
30 | #include <amiro-lld.h> |
||
31 | |||
32 | 1d5bcc82 | Thomas Schöpping | #if (defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__) |
33 | d6728c5b | Thomas Schöpping | |
34 | ef078306 | Thomas Schöpping | /******************************************************************************/
|
35 | /* CONSTANTS */
|
||
36 | /******************************************************************************/
|
||
37 | |||
38 | d6728c5b | Thomas Schöpping | /**
|
39 | * @brief Maximum I2C frequency.
|
||
40 | */
|
||
41 | #define PCA9544A_LLD_I2C_MAXFREQUENCY 400000 |
||
42 | |||
43 | ef078306 | Thomas Schöpping | /******************************************************************************/
|
44 | /* SETTINGS */
|
||
45 | /******************************************************************************/
|
||
46 | |||
47 | /******************************************************************************/
|
||
48 | /* CHECKS */
|
||
49 | /******************************************************************************/
|
||
50 | |||
51 | /******************************************************************************/
|
||
52 | /* DATA STRUCTURES AND TYPES */
|
||
53 | /******************************************************************************/
|
||
54 | |||
55 | d6728c5b | Thomas Schöpping | /**
|
56 | * @brief The PCA9544ADriver struct
|
||
57 | */
|
||
58 | typedef struct { |
||
59 | apalI2CDriver_t* i2cd; /**< @brief The I²C driver to use. */
|
||
60 | cf1f756b | Thomas Schöpping | apalI2Caddr_t addr; /**< @brief The address of the PCA9544A for I2C communication, which is defined by the wiring of the A0, A1, A2 pins */
|
61 | d6728c5b | Thomas Schöpping | } PCA9544ADriver; |
62 | |||
63 | /**
|
||
64 | * @brief The fixed address prefix of any PCA9544A.
|
||
65 | */
|
||
66 | enum {
|
||
67 | cf1f756b | Thomas Schöpping | PCA9544A_LLD_I2C_ADDR_FIXED = 0x0070u,
|
68 | PCA9544A_LLD_I2C_ADDR_A0 = 0x0001u,
|
||
69 | PCA9544A_LLD_I2C_ADDR_A1 = 0x0002u,
|
||
70 | PCA9544A_LLD_I2C_ADDR_A2 = 0x0004u,
|
||
71 | d6728c5b | Thomas Schöpping | }; |
72 | |||
73 | /**
|
||
74 | * @brief The control register of the PCA9544A.
|
||
75 | */
|
||
76 | typedef enum { |
||
77 | PCA9544A_LLD_CTRLREG_INT3 = 0x80u, /**< interrupt 3 flag (1 = active) */ |
||
78 | PCA9544A_LLD_CTRLREG_INT2 = 0x40u, /**< interrupt 2 flag (1 = active) */ |
||
79 | PCA9544A_LLD_CTRLREG_INT1 = 0x20u, /**< interrupt 1 flag (1 = active) */ |
||
80 | PCA9544A_LLD_CTRLREG_INT0 = 0x10u, /**< interrupt 0 flag (1 = active) */ |
||
81 | PCA9544A_LLD_CTRLREG_EN = 0x04u, /**< multiplexing enable flag (1 = enabled) */ |
||
82 | PCA9544A_LLD_CTRLREG_CH_MASK = 0x03u, /**< bitmask for all channel selection bits */ |
||
83 | PCA9544A_LLD_CTRLREG_CH0 = 0x00u, /**< channel 0 selection mask */ |
||
84 | PCA9544A_LLD_CTRLREG_CH1 = 0x01u, /**< channel 1 selection mask */ |
||
85 | PCA9544A_LLD_CTRLREG_CH2 = 0x02u, /**< channel 2 selection mask */ |
||
86 | PCA9544A_LLD_CTRLREG_CH3 = 0x03u, /**< channel 3 selection mask */ |
||
87 | PCA9544A_LLD_CTRLREG_DEFAULT = 0x00u, /**< default register value after power-up */ |
||
88 | } pca9544a_lld_ctrlreg_t; |
||
89 | |||
90 | /**
|
||
91 | * @brief Interrupt identifiers for external use.
|
||
92 | */
|
||
93 | typedef enum { |
||
94 | PCA9544A_LLD_INT0 = 0x01u, /**< interrupt 0 identifier */ |
||
95 | PCA9544A_LLD_INT1 = 0x02u, /**< interrupt 1 identifier */ |
||
96 | PCA9544A_LLD_INT2 = 0x04u, /**< interrupt 2 identifier */ |
||
97 | PCA9544A_LLD_INT3 = 0x08u, /**< interrupt 3 identifier */ |
||
98 | } pca9544a_lld_intid_t; |
||
99 | |||
100 | /**
|
||
101 | * @brief Channel selection identifier for external use.
|
||
102 | */
|
||
103 | typedef enum { |
||
104 | PCA9544A_LLD_CH0 = 0x00u, /**< identifier to select channel 0 */ |
||
105 | PCA9544A_LLD_CH1 = 0x01u, /**< identifier to select channel 1*/ |
||
106 | PCA9544A_LLD_CH2 = 0x02u, /**< identifier to select channel 2 */ |
||
107 | PCA9544A_LLD_CH3 = 0x03u, /**< identifier to select channel 3 */ |
||
108 | PCA9544A_LLD_CH_NONE = 0xFFu, /**< identifier to select no channel */ |
||
109 | } pca9544a_lld_chid_t; |
||
110 | |||
111 | 21076167 | Thomas Schöpping | /**
|
112 | * @brief Type holding a bit mask for the four channel interrupts.
|
||
113 | */
|
||
114 | d6728c5b | Thomas Schöpping | typedef uint8_t pca9544a_lld_intstatus_t;
|
115 | |||
116 | ef078306 | Thomas Schöpping | /******************************************************************************/
|
117 | /* MACROS */
|
||
118 | /******************************************************************************/
|
||
119 | |||
120 | /******************************************************************************/
|
||
121 | /* EXTERN DECLARATIONS */
|
||
122 | /******************************************************************************/
|
||
123 | |||
124 | d6728c5b | Thomas Schöpping | #ifdef __cplusplus
|
125 | extern "C" { |
||
126 | #endif
|
||
127 | apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout); |
||
128 | apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout); |
||
129 | apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const status, const apalTime_t timeout); |
||
130 | apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout); |
||
131 | apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout); |
||
132 | #ifdef __cplusplus
|
||
133 | } |
||
134 | #endif
|
||
135 | |||
136 | ef078306 | Thomas Schöpping | /******************************************************************************/
|
137 | /* INLINE FUNCTIONS */
|
||
138 | /******************************************************************************/
|
||
139 | |||
140 | 1d5bcc82 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */ |
141 | d6728c5b | Thomas Schöpping | |
142 | 1d5bcc82 | Thomas Schöpping | #endif /* AMIROLLD_PCA9544A_V1_H */ |
143 | 5e2f673b | Marc Rothmann | |
144 | /** @} */ |