I2CMSP432E4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018, 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 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 #include <stdbool.h>
68 #include <stddef.h>
69 #include <stdint.h>
70 
71 #include <ti/devices/msp432e4/inc/msp432.h>
72 
73 #include <ti/devices/msp432e4/driverlib/gpio.h>
74 #include <ti/devices/msp432e4/driverlib/pin_map.h>
75 
76 #include <ti/drivers/dpl/SemaphoreP.h>
77 #include <ti/drivers/dpl/HwiP.h>
79 #include <ti/drivers/I2C.h>
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 I2CMSP432E4_Mode {
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_ERROR = 0xFF /* I2C error has occurred, exit gracefully */
365 
406 typedef struct I2CMSP432E4_HWAttrs_ {
408  uint32_t baseAddr;
410  uint32_t intNum;
412  uint32_t intPriority;
414  uint32_t sclPin;
416  uint32_t sdaPin;
423  uint8_t masterCode;
425 
431 typedef struct I2CMSP432E4_Object_ {
432  /* Grants exclusive access to I2C */
433  SemaphoreP_Handle mutex;
434 
435  /* Notify finished I2C transfer */
436  SemaphoreP_Handle transferComplete;
437 
438  /* Hardware interrupt handle */
439  HwiP_Handle hwiHandle;
440 
441  /* Blocking or Callback mode */
443 
444  /* Application callback function pointer */
446 
447  /* Stores the I2C object state */
449 
450  /* Pointer to current I2C transaction */
452 
453  /* Head and tail pointers for queued transactions in I2C_MODE_CALLBACK */
456 
457  /* Enumerated bit rate */
458  uint8_t bitRate;
459 
460  uint8_t *writeBufIdx; /* Internal increment writeBuf index */
461  size_t writeCountIdx; /* Internal decrement writeCounter */
462  uint8_t *readBufIdx; /* Internal increment readBuf index */
463  size_t readCountIdx; /* Internal decrement readCounter */
464  bool isOpen; /* Flag to indicate module is open */
466 
467 #ifdef __cplusplus
468 }
469 #endif
470 
471 #endif /* ti_drivers_i2c_I2CMSP432E4__include */
size_t writeCountIdx
Definition: I2CMSP432E4.h:461
I2CMSP432E4 Hardware attributes.
Definition: I2CMSP432E4.h:406
volatile I2CMSP432E4_Mode mode
Definition: I2CMSP432E4.h:448
I2CMSP432E4 Object.
Definition: I2CMSP432E4.h:431
Structure used to perform I2C bus transfers.
Definition: I2C.h:431
uint32_t intNum
Definition: I2CMSP432E4.h:410
I2C_Transaction * tailPtr
Definition: I2CMSP432E4.h:455
uint32_t intPriority
Definition: I2CMSP432E4.h:412
I2C_TransferMode transferMode
Definition: I2CMSP432E4.h:442
uint32_t sdaPin
Definition: I2CMSP432E4.h:416
enum I2C_TransferMode_ I2C_TransferMode
Specifies the behavior of I2C_Transfer().
uint8_t masterCode
Definition: I2CMSP432E4.h:423
uint8_t bitRate
Definition: I2CMSP432E4.h:458
I2CMSP432E4_Mode
I2CMSP432E4 mode.
Definition: I2CMSP432E4.h:359
Definition: I2CMSP432E4.h:363
Definition: I2CMSP432E4.h:362
bool isOpen
Definition: I2CMSP432E4.h:464
const I2C_FxnTable I2CMSP432E4_fxnTable
The definition of an I2C function table that contains the required set of functions to control a spec...
Definition: I2C.h:589
uint32_t baseAddr
Definition: I2CMSP432E4.h:408
struct I2CMSP432E4_Object_ I2CMSP432E4_Object
I2CMSP432E4 Object.
MSP432E4 GPIO driver.
uint8_t * writeBufIdx
Definition: I2CMSP432E4.h:460
SemaphoreP_Handle mutex
Definition: I2CMSP432E4.h:433
I2C_CallbackFxn transferCallbackFxn
Definition: I2CMSP432E4.h:445
uint8_t * readBufIdx
Definition: I2CMSP432E4.h:462
struct I2CMSP432E4_HWAttrs_ I2CMSP432E4_HWAttrs
I2CMSP432E4 Hardware attributes.
size_t readCountIdx
Definition: I2CMSP432E4.h:463
SemaphoreP_Handle transferComplete
Definition: I2CMSP432E4.h:436
void(* I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction *transaction, bool transferStatus)
I2C callback function prototype.
Definition: I2C.h:502
HwiP_Handle hwiHandle
Definition: I2CMSP432E4.h:439
I2C_Transaction * currentTransaction
Definition: I2CMSP432E4.h:451
uint32_t sclPin
Definition: I2CMSP432E4.h:414
I2C_Transaction * headPtr
Definition: I2CMSP432E4.h:454
Inter-Integrated Circuit driver interface.
Definition: I2CMSP432E4.h:361
Definition: I2CMSP432E4.h:360
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale