72df7edfb17460d2f78c3d7802ca60645f11f283
1 /******************************************************************************\r
2 * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com\r
3 *\r
4 * Redistribution and use in source and binary forms, with or without\r
5 * modification, are permitted provided that the following conditions\r
6 * are met:\r
7 *\r
8 * Redistributions of source code must retain the above copyright\r
9 * notice, this list of conditions and the following disclaimer.\r
10 *\r
11 * Redistributions in binary form must reproduce the above copyright\r
12 * notice, this list of conditions and the following disclaimer in the\r
13 * documentation and/or other materials provided with the\r
14 * distribution.\r
15 *\r
16 * Neither the name of Texas Instruments Incorporated nor the names of\r
17 * its contributors may be used to endorse or promote products derived\r
18 * from this software without specific prior written permission.\r
19 *\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 *\r
32 *****************************************************************************/\r
33 \r
34 /**\r
35 * \file board_i2c_io_exp.h\r
36 *\r
37 * \brief I2C IO Expander configurations header file\r
38 *\r
39 * This file includes the structures, enums and register offsets\r
40 * for configuring the slave devices connected to I2C IO expander.\r
41 *\r
42 */\r
43 \r
44 #ifndef _BOARD_I2C_IO_EXP_H_\r
45 #define _BOARD_I2C_IO_EXP_H_\r
46 \r
47 #include "board_internal.h"\r
48 \r
49 #ifdef __cplusplus\r
50 extern "C" {\r
51 #endif\r
52 \r
53 #include <stdio.h>\r
54 #include <stdint.h>\r
55 #include <stdlib.h>\r
56 #include <string.h>\r
57 \r
58 /* Input command for single port IO expander */\r
59 #define BOARD_1PORT_IOEXP_INPUT_CMD (0x00U)\r
60 \r
61 /* Output command for single port IO expander */\r
62 #define BOARD_1PORT_IOEXP_OUTPUT_CMD (0x01U)\r
63 \r
64 /* Polarity inversion command for single port IO expander */\r
65 #define BOARD_1PORT_IOEXP_POLARITY_CMD (0x02U)\r
66 \r
67 /* Configuration command for single port IO expander */\r
68 #define BOARD_1PORT_IOEXP_CONFIGURATION_CMD (0x03U)\r
69 \r
70 /* Input commands for two port IO expander */\r
71 #define BOARD_2PORT_IOEXP_PORT0_INPUT_CMD (0x00U)\r
72 #define BOARD_2PORT_IOEXP_PORT1_INPUT_CMD (0x01U)\r
73 \r
74 /* Output commands for two port IO expander */\r
75 #define BOARD_2PORT_IOEXP_PORT0_OUTPUT_CMD (0x02U)\r
76 #define BOARD_2PORT_IOEXP_PORT1_OUTPUT_CMD (0x03U)\r
77 \r
78 /* Polarity inversion commands for two port IO expander */\r
79 #define BOARD_2PORT_IOEXP_PORT0_POLARITY_CMD (0x04U)\r
80 #define BOARD_2PORT_IOEXP_PORT1_POLARITY_CMD (0x05U)\r
81 \r
82 /* Configuration commands for two port IO expander */\r
83 #define BOARD_2PORT_IOEXP_PORT0_CONFIGURATION_CMD (0x06U)\r
84 #define BOARD_2PORT_IOEXP_PORT1_CONFIGURATION_CMD (0x07U)\r
85 \r
86 /* Input commands for three port IO expander */\r
87 #define BOARD_3PORT_IOEXP_PORT0_INPUT_CMD (0x00U)\r
88 #define BOARD_3PORT_IOEXP_PORT1_INPUT_CMD (0x01U)\r
89 #define BOARD_3PORT_IOEXP_PORT2_INPUT_CMD (0x02U)\r
90 \r
91 /* Output commands for three port IO expander */\r
92 #define BOARD_3PORT_IOEXP_PORT0_OUTPUT_CMD (0x04U)\r
93 #define BOARD_3PORT_IOEXP_PORT1_OUTPUT_CMD (0x05U)\r
94 #define BOARD_3PORT_IOEXP_PORT2_OUTPUT_CMD (0x06U)\r
95 \r
96 /* Polarity inversion commands for three port IO expander */\r
97 #define BOARD_3PORT_IOEXP_PORT0_POLARITY_CMD (0x08U)\r
98 #define BOARD_3PORT_IOEXP_PORT1_POLARITY_CMD (0x09U)\r
99 #define BOARD_3PORT_IOEXP_PORT2_POLARITY_CMD (0x0AU)\r
100 \r
101 /* Configuration commands for two port IO expander */\r
102 #define BOARD_3PORT_IOEXP_PORT0_CONFIGURATION_CMD (0x0CU)\r
103 #define BOARD_3PORT_IOEXP_PORT1_CONFIGURATION_CMD (0x0DU)\r
104 #define BOARD_3PORT_IOEXP_PORT2_CONFIGURATION_CMD (0x0EU)\r
105 \r
106 /**\r
107 * \enum i2cIoExpType_t\r
108 *\r
109 * \brief specifies the available types of IO expander.\r
110 */\r
111 typedef enum\r
112 {\r
113 ONE_PORT_IOEXP = 0,\r
114 TWO_PORT_IOEXP,\r
115 THREE_PORT_IOEXP\r
116 }i2cIoExpType_t;\r
117 \r
118 /**\r
119 * \enum i2cIoExpPortNumber_t\r
120 *\r
121 * \brief specifies the available port types.\r
122 */\r
123 typedef enum\r
124 {\r
125 PORTNUM_0 = 0,\r
126 PORTNUM_1,\r
127 PORTNUM_2\r
128 }i2cIoExpPortNumber_t;\r
129 \r
130 /**\r
131 * \enum i2cIoExpPinNumber_t\r
132 *\r
133 * \brief specifies the available pin numbers.\r
134 */\r
135 typedef enum\r
136 {\r
137 PIN_NUM_0 = 0,\r
138 PIN_NUM_1,\r
139 PIN_NUM_2,\r
140 PIN_NUM_3,\r
141 PIN_NUM_4,\r
142 PIN_NUM_5,\r
143 PIN_NUM_6,\r
144 PIN_NUM_7\r
145 }i2cIoExpPinNumber_t;\r
146 \r
147 /**\r
148 * \enum i2cIoExpPinDirection_t\r
149 *\r
150 * \brief specifies the available direction types.\r
151 */\r
152 typedef enum\r
153 {\r
154 PIN_DIRECTION_OUTPUT = 0,\r
155 PIN_DIRECTION_INPUT\r
156 }i2cIoExpPinDirection_t;\r
157 \r
158 /**\r
159 * \enum i2cIoExpPinDirection_t\r
160 *\r
161 * \brief specifies the available signal levels.\r
162 */\r
163 typedef enum\r
164 {\r
165 GPIO_SIGNAL_LEVEL_LOW = 0,\r
166 GPIO_SIGNAL_LEVEL_HIGH\r
167 }i2cIoExpSignalLevel_t;\r
168 \r
169 /**\r
170 * \brief Reads the current configuration of direction port.\r
171 *\r
172 * \param slaveAddr [IN] I2C Slave Address.\r
173 * \param ioExpType [IN] IO expander type.\r
174 * X_PORT_IOEXP - Total number of ports\r
175 * in slave device.\r
176 * \param portNum [IN] Port number of the i2c slave device\r
177 * PORTNUM_X - Port number of a slave\r
178 * device.\r
179 * \param data [IN/OUT] Pointer to the data buffer to store\r
180 * the pin level data of a specified port.\r
181 *\r
182 * \return Board_STATUS in case of success or appropriate error code.\r
183 *\r
184 */\r
185 Board_STATUS Board_i2cIoExpReadDirPort(uint8_t slaveAddr,\r
186 i2cIoExpType_t ioExpType,\r
187 i2cIoExpPortNumber_t portNum,\r
188 uint8_t *data);\r
189 \r
190 /**\r
191 * \brief Reads the current configuration of output port.\r
192 *\r
193 * \param slaveAddr [IN] I2C Slave Address.\r
194 * \param ioExpType [IN] IO expander type.\r
195 * X_PORT_IOEXP - Total number of ports\r
196 * in slave device.\r
197 * \param portNum [IN] Port number of the i2c slave device\r
198 * PORTNUM_X - Port number of a slave\r
199 * device.\r
200 * \param data [IN/OUT] Pointer to the data buffer to store\r
201 * the pin level data of a specified port.\r
202 *\r
203 * \return Board_STATUS in case of success or appropriate error code.\r
204 *\r
205 */\r
206 Board_STATUS Board_i2cIoExpReadOutputPort(uint8_t slaveAddr,\r
207 i2cIoExpType_t ioExpType,\r
208 i2cIoExpPortNumber_t portNum,\r
209 uint8_t *data);\r
210 \r
211 /**\r
212 * \brief Reads the signal level of all the pins of the specified port.\r
213 *\r
214 * \param slaveAddr [IN] I2C Slave Address.\r
215 * \param ioExpType [IN] IO expander type.\r
216 * X_PORT_IOEXP - Total number of ports\r
217 * in slave device.\r
218 * \param portNum [IN] Port number of the i2c slave device\r
219 * PORTNUM_X - Port number of a slave\r
220 * device.\r
221 * \param data [IN/OUT] Pointer to the data buffer to store\r
222 * the pin level data of a specified port.\r
223 *\r
224 * \return Board_STATUS in case of success or appropriate error code.\r
225 *\r
226 */\r
227 Board_STATUS Board_i2cIoExpReadInputPort(uint8_t slaveAddr,\r
228 i2cIoExpType_t ioExpType,\r
229 i2cIoExpPortNumber_t portNum,\r
230 uint8_t *data);\r
231 \r
232 /**\r
233 * \brief Sets the direction of all the pins of the specified Port.\r
234 *\r
235 * \param slaveAddr [IN] I2C Slave Address.\r
236 * \param ioExpType [IN] IO expander type.\r
237 * X_PORT_IOEXP - Total number of ports\r
238 * in that slave device.\r
239 * \param portNum [IN] Port number of the i2c slave device\r
240 * PORTNUM_X - Port number of a\r
241 * slave device.\r
242 * \param data [IN] Register data to be configured.\r
243 *\r
244 * \return Board_STATUS in case of success or appropriate error code.\r
245 *\r
246 */\r
247 Board_STATUS Board_i2cIoExpSetPortDirection(uint8_t slaveAddr,\r
248 i2cIoExpType_t ioExpType,\r
249 i2cIoExpPortNumber_t portNum,\r
250 uint8_t data);\r
251 \r
252 /**\r
253 * \brief Sets the direction of the specified pin of the specified port.\r
254 *\r
255 * \param slaveAddr [IN] I2C Slave Address.\r
256 * \param ioExpType [IN] IO expander type.\r
257 * X_PORT_IOEXP - Total number of ports\r
258 * in slave device.\r
259 * \param portNum [IN] Port number of the i2c slave device\r
260 * PORTNUM_X - Port number of a slave\r
261 * device.\r
262 * \param pinNum [IN] Pin with in the specified port of\r
263 * the i2c slave device.\r
264 * PIN_NUM_X - Pin number.\r
265 * \param direction [IN] Direction of the pin to be configured.\r
266 *\r
267 * \return Board_STATUS in case of success or appropriate error code.\r
268 *\r
269 */\r
270 Board_STATUS Board_i2cIoExpSetPinDirection(uint8_t slaveAddr,\r
271 i2cIoExpType_t ioExpType,\r
272 i2cIoExpPortNumber_t portNum,\r
273 i2cIoExpPinNumber_t pinNum,\r
274 i2cIoExpPinDirection_t direction);\r
275 \r
276 /**\r
277 * \brief Sets the signal level of all the pins of the specified port.\r
278 *\r
279 * \param slaveAddr [IN] I2C Slave Address.\r
280 * \param ioExpType [IN] IO expander type.\r
281 * X_PORT_IOEXP - Total number of ports\r
282 * in slave device.\r
283 * \param portNum [IN] Port number of the i2c slave device\r
284 * PORTNUM_X - Port number of a slave\r
285 * device.\r
286 * \param data [IN] Signal level data of the pins to be\r
287 * configured.\r
288 *\r
289 * \return Board_STATUS in case of success or appropriate error code.\r
290 *\r
291 */\r
292 Board_STATUS Board_i2cIoExpWritePort(uint8_t slaveAddr,\r
293 i2cIoExpType_t ioExpType,\r
294 i2cIoExpPortNumber_t portNum,\r
295 uint8_t data);\r
296 \r
297 /**\r
298 * \brief Sets the signal level of the specified pin of the specified port.\r
299 *\r
300 * \param slaveAddr [IN] I2C Slave Address.\r
301 * \param ioExpType [IN] IO expander type.\r
302 * X_PORT_IOEXP - Total number of ports\r
303 * in slave device.\r
304 * \param portNum [IN] Port number of the i2c slave device\r
305 * PORTNUM_X - Port number of a slave\r
306 * device.\r
307 * \param pinNum [IN] Pin with in the specified port of\r
308 * the i2c slave device.\r
309 * PIN_NUM_X - Pin number.\r
310 * \param signalLevel [IN] Signal level data of the pin to be\r
311 * configured.\r
312 *\r
313 * \return Board_STATUS in case of success or appropriate error code.\r
314 *\r
315 */\r
316 Board_STATUS Board_i2cIoExpPinLevelSet(uint8_t slaveAddr,\r
317 i2cIoExpType_t ioExpType,\r
318 i2cIoExpPortNumber_t portNum,\r
319 i2cIoExpPinNumber_t pinNum,\r
320 i2cIoExpSignalLevel_t signalLevel);\r
321 \r
322 \r
323 /**\r
324 * \brief Reads the signal level of specified pin of the specified port.\r
325 *\r
326 * \param slaveAddr [IN] I2C Slave Address.\r
327 * \param ioExpType [IN] IO expander type.\r
328 * X_PORT_IOEXP - Total number of ports\r
329 * in slave device.\r
330 * \param portNum [IN] Port number of the i2c slave device.\r
331 * PORTNUM_X - Port number of a slave\r
332 * device.\r
333 * \param pinNum [IN] Pin number of the specified port.\r
334 * PIN_NUM_X - Pin number.\r
335 * \param signalLevel [IN/OUT] Data buffer to store specified pin\r
336 * level of a specified port.\r
337 *\r
338 * \return Board_STATUS in case of success or appropriate error code.\r
339 *\r
340 */\r
341 Board_STATUS Board_i2cIoExpPinLevelGet(uint8_t slaveAddr,\r
342 i2cIoExpType_t ioExpType,\r
343 i2cIoExpPortNumber_t portNum,\r
344 i2cIoExpPinNumber_t pinNum,\r
345 uint8_t *signalLevel);\r
346 \r
347 /**\r
348 * \brief Initializes the i2c instance connected to the i2c IO Expander.\r
349 *\r
350 * \return Board_STATUS in case of success or appropriate error code.\r
351 *\r
352 */\r
353 Board_STATUS Board_i2cIoExpInit(void);\r
354 \r
355 /**\r
356 * \brief de-initializes the i2c instance connected to the i2c IO Expander.\r
357 *\r
358 */\r
359 void Board_i2cIoExpDeInit(void);\r
360 \r
361 #ifdef __cplusplus\r
362 }\r
363 #endif /* __cplusplus */\r
364 \r
365 #endif /* _BOARD_I2C_IO_EXP_H_ */\r