I2CMSP432E4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019, 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  */
32 /*!****************************************************************************
33  * @file I2CMSP432E4.h
34  *
35  * @brief I2C driver implementation for a MSP432E4 I2C controller.
36  *
37  * The I2C header file should be included in an application as follows:
38  * @code
39  * #include <ti/drivers/I2C.h>
40  * #include <ti/drivers/i2c/I2CMSP432E4.h>
41  * @endcode
42  *
43  * Refer to @ref I2C.h for a complete description of APIs & example of use.
44  *
45  * ## Supported Bit Rates ##
46  * - #I2C_100kHz
47  * - #I2C_400kHz
48  * - #I2C_1000kHz
49  * - #I2C_3330kHz
50  *
51  * ## Using High Speed Mode (#I2C_3330kHz) ##
52  * When operating at #I2C_3330kHz, the #I2CMSP432E4_HWAttrs.masterCode must
53  * be provided. If the master code is not provided, I2C_open() will fail.
54  * This driver assumes that the system clock is 120MHz. If the system clock
55  * is not 120MHz, I2C_open() will fail.
56  *
57  ******************************************************************************
58  */
59 
60 #ifndef ti_drivers_i2c_I2CMSP432E4__include
61 #define ti_drivers_i2c_I2CMSP432E4__include
62 
63 #include <stdbool.h>
64 #include <stddef.h>
65 #include <stdint.h>
66 
67 #include <ti/devices/msp432e4/inc/msp432.h>
68 
69 #include <ti/devices/msp432e4/driverlib/gpio.h>
70 #include <ti/devices/msp432e4/driverlib/pin_map.h>
71 
72 #include <ti/drivers/dpl/SemaphoreP.h>
73 #include <ti/drivers/dpl/HwiP.h>
75 #include <ti/drivers/I2C.h>
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
91 /* Add I2CMSP432E4_STATUS_* macros here */
92 
105 /* Add I2CMSP432E4_CMD_* macros here */
106 
112 #define I2CMSP432E4_PB2_I2C0SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 2, GPIO_PB2_I2C0SCL)
113 
117 #define I2CMSP432E4_PB3_I2C0SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 3, GPIO_PB3_I2C0SDA)
118 
122 #define I2CMSP432E4_PG0_I2C1SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 0, GPIO_PG0_I2C1SCL)
123 
127 #define I2CMSP432E4_PR0_I2C1SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 0, GPIO_PR0_I2C1SCL)
128 
132 #define I2CMSP432E4_PG1_I2C1SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 1, GPIO_PG1_I2C1SDA)
133 
137 #define I2CMSP432E4_PR1_I2C1SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 1, GPIO_PR1_I2C1SDA)
138 
142 #define I2CMSP432E4_PL1_I2C2SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTL, 1, GPIO_PL1_I2C2SCL)
143 
147 #define I2CMSP432E4_PP5_I2C2SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 5, GPIO_PP5_I2C2SCL)
148 
152 #define I2CMSP432E4_PN5_I2C2SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 5, GPIO_PN5_I2C2SCL)
153 
157 #define I2CMSP432E4_PG2_I2C2SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 2, GPIO_PG2_I2C2SCL)
158 
162 #define I2CMSP432E4_PR2_I2C2SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 2, GPIO_PR2_I2C2SCL)
163 
167 #define I2CMSP432E4_PL0_I2C2SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTL, 0, GPIO_PL0_I2C2SDA)
168 
172 #define I2CMSP432E4_PN4_I2C2SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTN, 4, GPIO_PN4_I2C2SDA)
173 
177 #define I2CMSP432E4_PP6_I2C2SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTP, 6, GPIO_PP6_I2C2SDA)
178 
182 #define I2CMSP432E4_PG3_I2C2SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 3, GPIO_PG3_I2C2SDA)
183 
187 #define I2CMSP432E4_PR3_I2C2SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 3, GPIO_PR3_I2C2SDA)
188 
192 #define I2CMSP432E4_PK4_I2C3SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 4, GPIO_PK4_I2C3SCL)
193 
197 #define I2CMSP432E4_PG4_I2C3SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 4, GPIO_PG4_I2C3SCL)
198 
202 #define I2CMSP432E4_PR4_I2C3SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 4, GPIO_PR4_I2C3SCL)
203 
207 #define I2CMSP432E4_PK5_I2C3SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 5, GPIO_PK5_I2C3SDA)
208 
212 #define I2CMSP432E4_PG5_I2C3SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 5, GPIO_PG5_I2C3SDA)
213 
217 #define I2CMSP432E4_PR5_I2C3SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 5, GPIO_PR5_I2C3SDA)
218 
222 #define I2CMSP432E4_PK6_I2C4SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 6, GPIO_PK6_I2C4SCL)
223 
227 #define I2CMSP432E4_PG6_I2C4SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 6, GPIO_PG6_I2C4SCL)
228 
232 #define I2CMSP432E4_PR6_I2C4SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 6, GPIO_PR6_I2C4SCL)
233 
237 #define I2CMSP432E4_PK7_I2C4SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTK, 7, GPIO_PK7_I2C4SDA)
238 
242 #define I2CMSP432E4_PG7_I2C4SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTG, 7, GPIO_PG7_I2C4SDA)
243 
247 #define I2CMSP432E4_PR7_I2C4SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTR, 7, GPIO_PR7_I2C4SDA)
248 
252 #define I2CMSP432E4_PB0_I2C5SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 0, GPIO_PB0_I2C5SCL)
253 
257 #define I2CMSP432E4_PB4_I2C5SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 4, GPIO_PB4_I2C5SCL)
258 
262 #define I2CMSP432E4_PB1_I2C5SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 1, GPIO_PB1_I2C5SDA)
263 
267 #define I2CMSP432E4_PB5_I2C5SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 5, GPIO_PB5_I2C5SDA)
268 
272 #define I2CMSP432E4_PA6_I2C6SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 6, GPIO_PA6_I2C6SCL)
273 
277 #define I2CMSP432E4_PB6_I2C6SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 6, GPIO_PB6_I2C6SCL)
278 
282 #define I2CMSP432E4_PA7_I2C6SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 7, GPIO_PA7_I2C6SDA)
283 
287 #define I2CMSP432E4_PB7_I2C6SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTB, 7, GPIO_PB7_I2C6SDA)
288 
292 #define I2CMSP432E4_PD0_I2C7SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 0, GPIO_PD0_I2C7SCL)
293 
297 #define I2CMSP432E4_PA4_I2C7SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 4, GPIO_PA4_I2C7SCL)
298 
302 #define I2CMSP432E4_PD1_I2C7SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 1, GPIO_PD1_I2C7SDA)
303 
307 #define I2CMSP432E4_PA5_I2C7SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 5, GPIO_PA5_I2C7SDA)
308 
312 #define I2CMSP432E4_PD2_I2C8SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 2, GPIO_PD2_I2C8SCL)
313 
317 #define I2CMSP432E4_PA2_I2C8SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 2, GPIO_PA2_I2C8SCL)
318 
322 #define I2CMSP432E4_PD3_I2C8SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTD, 3, GPIO_PD3_I2C8SDA)
323 
327 #define I2CMSP432E4_PA3_I2C8SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 3, GPIO_PA3_I2C8SDA)
328 
332 #define I2CMSP432E4_PA0_I2C9SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 0, GPIO_PA0_I2C9SCL)
333 
337 #define I2CMSP432E4_PE6_I2C9SCL GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 6, GPIO_PE6_I2C9SCL)
338 
342 #define I2CMSP432E4_PA1_I2C9SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTA, 1, GPIO_PA1_I2C9SDA)
343 
347 #define I2CMSP432E4_PE7_I2C9SDA GPIOMSP432E4_pinConfigMask(GPIOMSP432E4_PORTE, 7, GPIO_PE7_I2C9SDA)
348 
349 
350 /* I2C function table pointer */
352 
359 typedef enum {
360  I2CMSP432E4_IDLE_MODE = 0, /* I2C is not performing a transaction */
361  I2CMSP432E4_WRITE_MODE, /* I2C is currently performing write operations */
362  I2CMSP432E4_READ_MODE, /* I2C is currently performing read operations */
363  I2CMSP432E4_TIMEOUT, /* I2C transaction timed-out */
364  I2CMSP432E4_ERROR = 0xFF /* I2C error has occurred, exit gracefully */
366 
407 typedef struct {
409  uint32_t baseAddr;
411  uint32_t intNum;
413  uint32_t intPriority;
415  uint32_t sclPin;
417  uint32_t sdaPin;
424  uint8_t masterCode;
426 
432 typedef struct {
433  /* Grants exclusive access to I2C */
434  SemaphoreP_Handle mutex;
435 
436  /* Notify finished I2C transfer */
437  SemaphoreP_Handle transferComplete;
438 
439  /* Hardware interrupt handle */
440  HwiP_Handle hwiHandle;
441 
442  /* Blocking or Callback mode */
444 
445  /* Application callback function pointer */
447 
448  /* Stores the I2C object state */
450 
451  /* Pointer to current I2C transaction */
453 
454  /* Head and tail pointers for queued transactions in I2C_MODE_CALLBACK */
457 
458  /* Enumerated bit rate */
459  uint8_t bitRate;
460 
461  uint8_t *writeBufIdx; /* Internal increment writeBuf index */
462  size_t totalWriteCountIdx; /* Internal decrement totalWriteCounter */
463  size_t burstWriteCountIdx; /* Internal writeCounter for transfer burst */
464  uint8_t *readBufIdx; /* Internal increment readBuf index */
465  size_t totalReadCountIdx; /* Internal decrement totalReadCounter */
466  size_t burstReadCountIdx; /* Internal readCounter for transfer burst */
467  bool isOpen; /* Flag to indicate module is open */
469 
470 #ifdef __cplusplus
471 }
472 #endif
473 
474 #endif /* ti_drivers_i2c_I2CMSP432E4__include */
size_t burstReadCountIdx
Definition: I2CMSP432E4.h:466
I2CMSP432E4 Object.
Definition: I2CMSP432E4.h:432
I2C_Transaction * currentTransaction
Definition: I2CMSP432E4.h:452
size_t burstWriteCountIdx
Definition: I2CMSP432E4.h:463
Definition: I2CMSP432E4.h:363
I2CMSP432E4 Hardware attributes.
Definition: I2CMSP432E4.h:407
uint8_t * writeBufIdx
Definition: I2CMSP432E4.h:461
uint8_t * readBufIdx
Definition: I2CMSP432E4.h:464
I2C_TransferMode transferMode
Definition: I2CMSP432E4.h:443
size_t totalWriteCountIdx
Definition: I2CMSP432E4.h:462
I2C_TransferMode
Return behavior of I2C_Transfer() specified in the I2C_Params.
Definition: I2C.h:458
I2CMSP432E4_Mode
I2CMSP432E4 mode.
Definition: I2CMSP432E4.h:359
The definition of an I2C function table that contains the required set of functions to control a spec...
Definition: I2C.h:604
Definition: I2CMSP432E4.h:364
Definition: I2CMSP432E4.h:362
I2C_Transaction * headPtr
Definition: I2CMSP432E4.h:455
I2C_CallbackFxn transferCallbackFxn
Definition: I2CMSP432E4.h:446
const I2C_FxnTable I2CMSP432E4_fxnTable
HwiP_Handle hwiHandle
Definition: I2CMSP432E4.h:440
uint32_t intPriority
Definition: I2CMSP432E4.h:413
volatile I2CMSP432E4_Mode mode
Definition: I2CMSP432E4.h:449
MSP432E4 GPIO driver.
uint32_t intNum
Definition: I2CMSP432E4.h:411
size_t totalReadCountIdx
Definition: I2CMSP432E4.h:465
SemaphoreP_Handle mutex
Definition: I2CMSP432E4.h:434
uint32_t sdaPin
Definition: I2CMSP432E4.h:417
void(* I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction *transaction, bool transferStatus)
The definition of a callback function.
Definition: I2C.h:508
uint8_t masterCode
Definition: I2CMSP432E4.h:424
Defines a transaction to be used with I2C_transfer()
Definition: I2C.h:381
SemaphoreP_Handle transferComplete
Definition: I2CMSP432E4.h:437
Inter-Integrated Circuit (I2C) Driver.
uint32_t sclPin
Definition: I2CMSP432E4.h:415
Definition: I2CMSP432E4.h:361
bool isOpen
Definition: I2CMSP432E4.h:467
uint32_t baseAddr
Definition: I2CMSP432E4.h:409
Definition: I2CMSP432E4.h:360
I2C_Transaction * tailPtr
Definition: I2CMSP432E4.h:456
uint8_t bitRate
Definition: I2CMSP432E4.h:459
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale