amiro-lld / include / PCA9544A / v1 / alld_PCA9544A_v1.h @ 7394be9e
History | View | Annotate | Download (6.064 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_v1.h
|
21 |
* @brief I2C Multiplexer macros and structures.
|
22 |
*
|
23 |
* @addtogroup lld_multi
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROLLD_PCA9544A_V1_H
|
28 |
#define AMIROLLD_PCA9544A_V1_H
|
29 |
|
30 |
#include <amiro-lld.h> |
31 |
|
32 |
#if (defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__) |
33 |
|
34 |
/******************************************************************************/
|
35 |
/* CONSTANTS */
|
36 |
/******************************************************************************/
|
37 |
|
38 |
/**
|
39 |
* @brief Maximum I2C frequency.
|
40 |
*/
|
41 |
#define PCA9544A_LLD_I2C_MAXFREQUENCY 400000 |
42 |
|
43 |
/******************************************************************************/
|
44 |
/* SETTINGS */
|
45 |
/******************************************************************************/
|
46 |
|
47 |
/******************************************************************************/
|
48 |
/* CHECKS */
|
49 |
/******************************************************************************/
|
50 |
|
51 |
/******************************************************************************/
|
52 |
/* DATA STRUCTURES AND TYPES */
|
53 |
/******************************************************************************/
|
54 |
|
55 |
/**
|
56 |
* @brief The PCA9544ADriver struct
|
57 |
*/
|
58 |
typedef struct { |
59 |
apalI2CDriver_t* i2cd; /**< @brief The I²C driver to use. */
|
60 |
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 |
} PCA9544ADriver; |
62 |
|
63 |
/**
|
64 |
* @brief The fixed address prefix of any PCA9544A.
|
65 |
*/
|
66 |
enum {
|
67 |
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 |
}; |
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 |
/**
|
112 |
* @brief Type holding a bit mask for the four channel interrupts.
|
113 |
*/
|
114 |
typedef uint8_t pca9544a_lld_intstatus_t;
|
115 |
|
116 |
/******************************************************************************/
|
117 |
/* MACROS */
|
118 |
/******************************************************************************/
|
119 |
|
120 |
/******************************************************************************/
|
121 |
/* EXTERN DECLARATIONS */
|
122 |
/******************************************************************************/
|
123 |
|
124 |
#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 |
/******************************************************************************/
|
137 |
/* INLINE FUNCTIONS */
|
138 |
/******************************************************************************/
|
139 |
|
140 |
#endif /* defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */ |
141 |
|
142 |
#endif /* AMIROLLD_PCA9544A_V1_H */ |
143 |
|
144 |
/** @} */
|