SimpleLink MCU SDK Driver APIs  tidrivers_msp43x_3_01_01_03
I2CMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
50 #ifndef ti_drivers_i2c_I2CMSP432__include
51 #define ti_drivers_i2c_I2CMSP432__include
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 #include <stdint.h>
58 #include <stdbool.h>
59 
60 #include <ti/drivers/I2C.h>
61 #include <ti/drivers/dpl/HwiP.h>
62 #include <ti/drivers/dpl/SemaphoreP.h>
63 #include <ti/drivers/Power.h>
64 
65 /*
66  * I2C port/pin defines for pin configuration. Ports P2, P3, and P7 are
67  * configurable through the port mapping controller.
68  * Value specifies the pin function and ranges from 0 to 31
69  * pin range: 0 - 7, port range: 0 - 15
70  *
71  *
72  * 15 - 10 9 8 7 - 4 3 - 0
73  * -------------------------------
74  * | VALUE | X | X | PORT | PIN |
75  * -------------------------------
76  *
77  * value = pinConfig >> 10
78  * port = (pinConfig >> 4) & 0xf
79  * pin = pinConfig & 0x7
80  *
81  * pmap = port * 0x8; // 2 -> 0x10, 3 -> 0x18, 7 -> 0x38
82  * portMapReconfigure = PMAP_ENABLE_RECONFIGURATION;
83  *
84  * Code from pmap.c:
85  * //Get write-access to port mapping registers:
86  * PMAP->KEYID = PMAP_KEYID_VAL;
87  *
88  * //Enable/Disable reconfiguration during runtime
89  * PMAP->CTL = (PMAP->CTL & ~PMAP_CTL_PRECFG) | portMapReconfigure;
90  * HWREG8(PMAP_BASE + pin + pmap) = value;
91  *
92  * For non-configurable ports (bits 20 - 12 will be 0).
93  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
94  * TERTIALRY).
95  *
96  * 9 8 7 - 4 3 - 0
97  * -----------------------------------
98  * | PnSEL1.x | PnSEL0.x | PORT | PIN |
99  * -----------------------------------
100  *
101  * moduleFunction = (pinConfig >> 8) & 0x3
102  * port = (pinConfig >> 4) & 0xf
103  * pin = 1 << (pinConfig & 0xf)
104  *
105  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
106  * pin, moduleFunction);
107  * or:
108  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
109  * pin, moduleFunction);
110  *
111  */
112 
113 #define I2CMSP432_P1_6_UCB0SDA 0x00000116
114 
115 #define I2CMSP432_P1_7_UCB0SCL 0x00000117
116 
118 #define I2CMSP432_P2_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x20)
119 
120 #define I2CMSP432_P2_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x20)
121 
122 #define I2CMSP432_P2_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x20)
123 
124 #define I2CMSP432_P2_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x20)
125 
127 #define I2CMSP432_P2_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x21)
128 
129 #define I2CMSP432_P2_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x21)
130 
131 #define I2CMSP432_P2_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x21)
132 
133 #define I2CMSP432_P2_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x21)
134 
136 #define I2CMSP432_P2_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x22)
137 
138 #define I2CMSP432_P2_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x22)
139 
140 #define I2CMSP432_P2_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x22)
141 
142 #define I2CMSP432_P2_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x22)
143 
145 #define I2CMSP432_P2_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x23)
146 
147 #define I2CMSP432_P2_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x23)
148 
149 #define I2CMSP432_P2_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x23)
150 
151 #define I2CMSP432_P2_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x23)
152 
154 #define I2CMSP432_P2_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x24)
155 
156 #define I2CMSP432_P2_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x24)
157 
158 #define I2CMSP432_P2_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x24)
159 
160 #define I2CMSP432_P2_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x24)
161 
163 #define I2CMSP432_P2_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x25)
164 
165 #define I2CMSP432_P2_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x25)
166 
167 #define I2CMSP432_P2_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x25)
168 
169 #define I2CMSP432_P2_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x25)
170 
172 #define I2CMSP432_P2_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x26)
173 
174 #define I2CMSP432_P2_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x26)
175 
176 #define I2CMSP432_P2_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x26)
177 
178 #define I2CMSP432_P2_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x26)
179 
181 #define I2CMSP432_P2_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x27)
182 
183 #define I2CMSP432_P2_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x27)
184 
185 #define I2CMSP432_P2_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x27)
186 
187 #define I2CMSP432_P2_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x27)
188 
190 #define I2CMSP432_P3_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x30)
191 
192 #define I2CMSP432_P3_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x30)
193 
194 #define I2CMSP432_P3_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x30)
195 
196 #define I2CMSP432_P3_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x30)
197 
199 #define I2CMSP432_P3_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x31)
200 
201 #define I2CMSP432_P3_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x31)
202 
203 #define I2CMSP432_P3_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x31)
204 
205 #define I2CMSP432_P3_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x31)
206 
208 #define I2CMSP432_P3_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x32)
209 
210 #define I2CMSP432_P3_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x32)
211 
212 #define I2CMSP432_P3_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x32)
213 
214 #define I2CMSP432_P3_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x32)
215 
217 #define I2CMSP432_P3_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x33)
218 
219 #define I2CMSP432_P3_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x33)
220 
221 #define I2CMSP432_P3_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x33)
222 
223 #define I2CMSP432_P3_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x33)
224 
226 #define I2CMSP432_P3_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x34)
227 
228 #define I2CMSP432_P3_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x34)
229 
230 #define I2CMSP432_P3_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x34)
231 
232 #define I2CMSP432_P3_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x34)
233 
235 #define I2CMSP432_P3_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x35)
236 
237 #define I2CMSP432_P3_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x35)
238 
239 #define I2CMSP432_P3_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x35)
240 
241 #define I2CMSP432_P3_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x35)
242 
244 #define I2CMSP432_P3_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x36)
245 
246 #define I2CMSP432_P3_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x36)
247 
248 #define I2CMSP432_P3_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x36)
249 
250 #define I2CMSP432_P3_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x36)
251 
253 #define I2CMSP432_P3_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x37)
254 
255 #define I2CMSP432_P3_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x37)
256 
257 #define I2CMSP432_P3_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x37)
258 
259 #define I2CMSP432_P3_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x37)
260 
262 #define I2CMSP432_P6_4_UCB1SDA 0x00000164
263 
264 #define I2CMSP432_P6_5_UCB1SCL 0x00000165
265 
266 #define I2CMSP432_P6_6_UCB3SDA 0x00000266
267 
268 #define I2CMSP432_P6_7_UCB3SCL 0x00000267
269 
271 #define I2CMSP432_P7_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x70)
272 
273 #define I2CMSP432_P7_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x70)
274 
275 #define I2CMSP432_P7_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x70)
276 
277 #define I2CMSP432_P7_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x70)
278 
280 #define I2CMSP432_P7_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x71)
281 
282 #define I2CMSP432_P7_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x71)
283 
284 #define I2CMSP432_P7_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x71)
285 
286 #define I2CMSP432_P7_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x71)
287 
289 #define I2CMSP432_P7_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x72)
290 
291 #define I2CMSP432_P7_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x72)
292 
293 #define I2CMSP432_P7_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x72)
294 
295 #define I2CMSP432_P7_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x72)
296 
298 #define I2CMSP432_P7_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x73)
299 
300 #define I2CMSP432_P7_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x73)
301 
302 #define I2CMSP432_P7_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x73)
303 
304 #define I2CMSP432_P7_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x73)
305 
307 #define I2CMSP432_P7_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x74)
308 
309 #define I2CMSP432_P7_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x74)
310 
311 #define I2CMSP432_P7_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x74)
312 
313 #define I2CMSP432_P7_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x74)
314 
316 #define I2CMSP432_P7_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x75)
317 
318 #define I2CMSP432_P7_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x75)
319 
320 #define I2CMSP432_P7_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x75)
321 
322 #define I2CMSP432_P7_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x75)
323 
325 #define I2CMSP432_P7_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x76)
326 
327 #define I2CMSP432_P7_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x76)
328 
329 #define I2CMSP432_P7_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x76)
330 
331 #define I2CMSP432_P7_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x76)
332 
334 #define I2CMSP432_P7_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x77)
335 
336 #define I2CMSP432_P7_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x77)
337 
338 #define I2CMSP432_P7_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x77)
339 
340 #define I2CMSP432_P7_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x77)
341 
343 #define I2CMSP432_P10_2_UCB3SDA 0x000001A2
344 
345 #define I2CMSP432_P10_3_UCB3SCL 0x000001A3
346 
358 /* Add I2CMSP432_STATUS_* macros here */
359 
372 /* Add I2CMSP432_CMD_* macros here */
373 
376 /* I2C function table pointer */
377 extern const I2C_FxnTable I2CMSP432_fxnTable;
378 
385 typedef enum I2CMSP432_Mode {
386  I2CMSP432_IDLE_MODE = 0, /* I2C is not performing a transaction */
387  I2CMSP432_WRITE_MODE, /* I2C is currently performing write operations */
388  I2CMSP432_READ_MODE, /* I2C is currently performing read operations */
389  I2CMSP432_ERROR = 0xFF /* I2C error has occurred, exit gracefully */
390 } I2CMSP432_Mode;
430 typedef struct I2CMSP432_HWAttrsV1 {
432  uint32_t baseAddr;
434  uint32_t intNum;
436  uint32_t intPriority;
438  uint8_t clockSource;
440  uint16_t clkPin;
442  uint16_t dataPin;
444 
450 typedef struct I2CMSP432_Object {
451  SemaphoreP_Handle mutex; /* Grants exclusive access to I2C */
452  SemaphoreP_Handle transferComplete; /* Notify finished I2C transfer */
453 
454  HwiP_Handle hwiHandle;
455 
456  I2C_Transaction *currentTransaction; /* Ptr to current I2C transaction */
457  I2C_CallbackFxn transferCallbackFxn; /* Callback function pointer */
458 
459  /* I2C transaction pointers for I2C_MODE_CALLBACK */
460  I2C_Transaction *headPtr; /* Head ptr for queued transactions */
461  I2C_Transaction *tailPtr; /* Tail ptr for queued transactions */
462 
463  uint8_t *writeBufIdx; /* Internal inc. writeBuf index */
464  size_t writeCountIdx; /* Internal dec. writeCounter */
465 
466  uint8_t *readBufIdx; /* Internal inc. readBuf index */
467  size_t readCountIdx; /* Internal dec. readCounter */
468 
469  Power_NotifyObj perfChangeNotify;
470  uint32_t perfConstraintMask;
471 
472  volatile I2CMSP432_Mode mode; /* Stores the I2C state */
473  I2C_TransferMode transferMode; /* Blocking or Callback mode */
474  I2C_BitRate bitRate; /* SPI bit rate in Hz */
475  bool isOpen; /* To determine if the SPI is open */
476 } I2CMSP432_Object;
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 #endif /* ti_drivers_i2c_I2CMSP432__include */
uint16_t clkPin
Definition: I2CMSP432.h:440
I2C transaction.
Definition: I2C.h:465
struct I2CMSP432_HWAttrsV1 I2CMSP432_HWAttrsV1
I2CMSP432 Hardware attributes.
Power manager interface.
const I2C_FxnTable I2CMSP432_fxnTable
Power notify object structure.
Definition: Power.h:113
uint32_t intNum
Definition: I2CMSP432.h:434
enum I2C_TransferMode_ I2C_TransferMode
I2C transfer mode.
The definition of an I2C function table that contains the required set of functions to control a spec...
Definition: I2C.h:594
enum I2C_BitRate_ I2C_BitRate
I2C bitRate.
uint16_t dataPin
Definition: I2CMSP432.h:442
uint32_t intPriority
Definition: I2CMSP432.h:436
uint8_t clockSource
Definition: I2CMSP432.h:438
void(* I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction *transaction, bool transferStatus)
I2C callback function.
Definition: I2C.h:507
uint32_t baseAddr
Definition: I2CMSP432.h:432
I2CMSP432 Hardware attributes.
Definition: I2CMSP432.h:430
I2C driver interface.
Copyright 2016, Texas Instruments Incorporated