I2CSlaveMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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  */
49 #ifndef ti_drivers_i2cslave_I2CSlaveMSP432__include
50 #define ti_drivers_i2cslave_I2CSlaveMSP432__include
51 
52 #include <stdint.h>
53 #include <stdbool.h>
54 
55 #include <ti/drivers/I2CSlave.h>
56 
57 #include <ti/drivers/dpl/HwiP.h>
58 #include <ti/drivers/dpl/SemaphoreP.h>
59 #include <ti/drivers/Power.h>
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /*
66  * I2CSlave 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 /* Port 1 EUSCI B I2CSLAVE defines */
114 #define I2CSLAVEMSP432_P1_6_UCB0SDA 0x00000116 /* Primary, port 1, pin 6 */
115 #define I2CSLAVEMSP432_P1_7_UCB0SCL 0x00000117 /* Primary, port 1, pin 7 */
116 
117 /* Port 2, pin 0 defines */
118 #define I2CSLAVEMSP432_P2_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x20)
119 #define I2CSLAVEMSP432_P2_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x20)
120 #define I2CSLAVEMSP432_P2_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x20)
121 #define I2CSLAVEMSP432_P2_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x20)
122 
123 /* Port 2, pin 1 defines */
124 #define I2CSLAVEMSP432_P2_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x21)
125 #define I2CSLAVEMSP432_P2_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x21)
126 #define I2CSLAVEMSP432_P2_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x21)
127 #define I2CSLAVEMSP432_P2_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x21)
128 
129 /* Port 2, pin 2 defines */
130 #define I2CSLAVEMSP432_P2_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x22)
131 #define I2CSLAVEMSP432_P2_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x22)
132 #define I2CSLAVEMSP432_P2_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x22)
133 #define I2CSLAVEMSP432_P2_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x22)
134 
135 /* Port 2, pin 3 defines */
136 #define I2CSLAVEMSP432_P2_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x23)
137 #define I2CSLAVEMSP432_P2_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x23)
138 #define I2CSLAVEMSP432_P2_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x23)
139 #define I2CSLAVEMSP432_P2_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x23)
140 
141 /* Port 2, pin 4 defines */
142 #define I2CSLAVEMSP432_P2_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x24)
143 #define I2CSLAVEMSP432_P2_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x24)
144 #define I2CSLAVEMSP432_P2_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x24)
145 #define I2CSLAVEMSP432_P2_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x24)
146 
147 /* Port 2, pin 5 defines */
148 #define I2CSLAVEMSP432_P2_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x25)
149 #define I2CSLAVEMSP432_P2_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x25)
150 #define I2CSLAVEMSP432_P2_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x25)
151 #define I2CSLAVEMSP432_P2_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x25)
152 
153 /* Port 2, pin 6 defines */
154 #define I2CSLAVEMSP432_P2_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x26)
155 #define I2CSLAVEMSP432_P2_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x26)
156 #define I2CSLAVEMSP432_P2_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x26)
157 #define I2CSLAVEMSP432_P2_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x26)
158 
159 /* Port 2, pin 7 defines */
160 #define I2CSLAVEMSP432_P2_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x27)
161 #define I2CSLAVEMSP432_P2_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x27)
162 #define I2CSLAVEMSP432_P2_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x27)
163 #define I2CSLAVEMSP432_P2_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x27)
164 
165 /* Port 3, pin 0 defines */
166 #define I2CSLAVEMSP432_P3_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x30)
167 #define I2CSLAVEMSP432_P3_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x30)
168 #define I2CSLAVEMSP432_P3_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x30)
169 #define I2CSLAVEMSP432_P3_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x30)
170 
171 /* Port 3, pin 1 defines */
172 #define I2CSLAVEMSP432_P3_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x31)
173 #define I2CSLAVEMSP432_P3_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x31)
174 #define I2CSLAVEMSP432_P3_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x31)
175 #define I2CSLAVEMSP432_P3_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x31)
176 
177 /* Port 3, pin 2 defines */
178 #define I2CSLAVEMSP432_P3_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x32)
179 #define I2CSLAVEMSP432_P3_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x32)
180 #define I2CSLAVEMSP432_P3_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x32)
181 #define I2CSLAVEMSP432_P3_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x32)
182 
183 /* Port 3, pin 3 defines */
184 #define I2CSLAVEMSP432_P3_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x33)
185 #define I2CSLAVEMSP432_P3_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x33)
186 #define I2CSLAVEMSP432_P3_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x33)
187 #define I2CSLAVEMSP432_P3_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x33)
188 
189 /* Port 3, pin 4 defines */
190 #define I2CSLAVEMSP432_P3_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x34)
191 #define I2CSLAVEMSP432_P3_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x34)
192 #define I2CSLAVEMSP432_P3_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x34)
193 #define I2CSLAVEMSP432_P3_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x34)
194 
195 /* Port 3, pin 5 defines */
196 #define I2CSLAVEMSP432_P3_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x35)
197 #define I2CSLAVEMSP432_P3_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x35)
198 #define I2CSLAVEMSP432_P3_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x35)
199 #define I2CSLAVEMSP432_P3_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x35)
200 
201 /* Port 3, pin 6 defines */
202 #define I2CSLAVEMSP432_P3_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x36)
203 #define I2CSLAVEMSP432_P3_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x36)
204 #define I2CSLAVEMSP432_P3_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x36)
205 #define I2CSLAVEMSP432_P3_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x36)
206 
207 /* Port 3, pin 7 defines */
208 #define I2CSLAVEMSP432_P3_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x37)
209 #define I2CSLAVEMSP432_P3_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x37)
210 #define I2CSLAVEMSP432_P3_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x37)
211 #define I2CSLAVEMSP432_P3_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x37)
212 
213 /* Port 6 EUSCI B I2CSLAVE defines */
214 #define I2CSLAVEMSP432_P6_4_UCB1SDA 0x00000164 /* Primary, port 6, pin 4 */
215 #define I2CSLAVEMSP432_P6_5_UCB1SCL 0x00000165 /* Primary, port 6, pin 5 */
216 #define I2CSLAVEMSP432_P6_6_UCB3SDA 0x00000266 /* Secondary, port 6, pin 6 */
217 #define I2CSLAVEMSP432_P6_7_UCB3SCL 0x00000267 /* Secondary, port 6, pin 7 */
218 
219 /* Port 7, pin 0 defines */
220 #define I2CSLAVEMSP432_P7_0_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x70)
221 #define I2CSLAVEMSP432_P7_0_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x70)
222 #define I2CSLAVEMSP432_P7_0_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x70)
223 #define I2CSLAVEMSP432_P7_0_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x70)
224 
225 /* Port 7, pin 1 defines */
226 #define I2CSLAVEMSP432_P7_1_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x71)
227 #define I2CSLAVEMSP432_P7_1_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x71)
228 #define I2CSLAVEMSP432_P7_1_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x71)
229 #define I2CSLAVEMSP432_P7_1_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x71)
230 
231 /* Port 7, pin 2 defines */
232 #define I2CSLAVEMSP432_P7_2_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x72)
233 #define I2CSLAVEMSP432_P7_2_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x72)
234 #define I2CSLAVEMSP432_P7_2_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x72)
235 #define I2CSLAVEMSP432_P7_2_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x72)
236 
237 /* Port 7, pin 3 defines */
238 #define I2CSLAVEMSP432_P7_3_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x73)
239 #define I2CSLAVEMSP432_P7_3_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x73)
240 #define I2CSLAVEMSP432_P7_3_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x73)
241 #define I2CSLAVEMSP432_P7_3_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x73)
242 
243 /* Port 7, pin 4 defines */
244 #define I2CSLAVEMSP432_P7_4_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x74)
245 #define I2CSLAVEMSP432_P7_4_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x74)
246 #define I2CSLAVEMSP432_P7_4_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x74)
247 #define I2CSLAVEMSP432_P7_4_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x74)
248 
249 /* Port 7, pin 5 defines */
250 #define I2CSLAVEMSP432_P7_5_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x75)
251 #define I2CSLAVEMSP432_P7_5_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x75)
252 #define I2CSLAVEMSP432_P7_5_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x75)
253 #define I2CSLAVEMSP432_P7_5_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x75)
254 
255 /* Port 7, pin 6 defines */
256 #define I2CSLAVEMSP432_P7_6_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x76)
257 #define I2CSLAVEMSP432_P7_6_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x76)
258 #define I2CSLAVEMSP432_P7_6_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x76)
259 #define I2CSLAVEMSP432_P7_6_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x76)
260 
261 /* Port 7, pin 7 defines */
262 #define I2CSLAVEMSP432_P7_7_UCB0SDA ((PMAP_UCB0SDA << 10) | 0x77)
263 #define I2CSLAVEMSP432_P7_7_UCB0SCL ((PMAP_UCB0SCL << 10) | 0x77)
264 #define I2CSLAVEMSP432_P7_7_UCB2SDA ((PMAP_UCB2SDA << 10) | 0x77)
265 #define I2CSLAVEMSP432_P7_7_UCB2SCL ((PMAP_UCB2SCL << 10) | 0x77)
266 
267 /* Port 10 EUSCI B I2CSLAVE defines */
268 #define I2CSLAVEMSP432_P10_2_UCB3SDA 0x000001A2 /* Primary, port 10, pin 2 */
269 #define I2CSLAVEMSP432_P10_3_UCB3SCL 0x000001A3 /* Primary, port 10, pin 3 */
270 
281 /* Add I2CSLAVEMSP432_STATUS_* macros here */
282 
295 /* Add I2CSLAVEMSP432_CMD_* macros here */
296 
299 /* I2CSlave function table pointer */
301 
322  typedef struct {
323  uint32_t baseAddr;
324  uint32_t intNum;
325  uint32_t intPriority;
326  uint32_t slaveAddress;
327  uint16_t clkPin;
328  uint16_t dataPin;
331 
337 typedef struct {
338  SemaphoreP_Handle mutex; /* Grants exclusive access */
339  /* Notify finished I2C transfer */
340  SemaphoreP_Handle transferComplete;
341 
342  HwiP_Handle hwiHandle;
343 
344  I2CSlave_CallbackFxn transferCallbackFxn; /* Callback function pointer */
345  /* Internal inc. writeBuf index */
346  const uint8_t *writeBufferIdx;
347  /* Internal inc. readBuf index */
348  uint8_t *readBufferIdx;
349  size_t countIdx; /* Internal dec. writeCounter */
350 
351  volatile I2CSlave_Mode mode; /* Stores the I2CSlave state */
352  I2CSlave_TransferMode transferMode; /* Blocking or Callback mode */
353 
354  /* To determine if the I2CSlave is open */
355  bool isOpen;
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 
363 #endif /* ti_drivers_i2cslave_I2CMSP432__include */
uint16_t dataPin
Definition: I2CSlaveMSP432.h:328
uint16_t clkPin
Definition: I2CSlaveMSP432.h:327
SemaphoreP_Handle transferComplete
Definition: I2CSlaveMSP432.h:340
I2CSlave_TransferMode
Return behavior of I2CSlave_write() and I2CSlave_read() specified in the I2CSlave_Params.
Definition: I2CSlave.h:253
volatile I2CSlave_Mode mode
Definition: I2CSlaveMSP432.h:351
Power Manager.
SemaphoreP_Handle mutex
Definition: I2CSlaveMSP432.h:338
I2CSlaveMSP432 Object.
Definition: I2CSlaveMSP432.h:337
uint8_t * readBufferIdx
Definition: I2CSlaveMSP432.h:348
uint32_t intNum
Definition: I2CSlaveMSP432.h:324
HwiP_Handle hwiHandle
Definition: I2CSlaveMSP432.h:342
I2CSlaveMSP432 Hardware attributes These fields are used by driverlib APIs and therefore must be popu...
Definition: I2CSlaveMSP432.h:322
Inter-Integrated Circuit (I2C) Slave Driver.
uint32_t slaveAddress
Definition: I2CSlaveMSP432.h:326
const I2CSlave_FxnTable I2CSlaveMSP432_fxnTable
I2CSlave_TransferMode transferMode
Definition: I2CSlaveMSP432.h:352
void(* I2CSlave_CallbackFxn)(I2CSlave_Handle handle, bool status)
The definition of a callback function.
Definition: I2CSlave.h:295
uint32_t baseAddr
Definition: I2CSlaveMSP432.h:323
bool transferInProgress
Definition: I2CSlaveMSP432.h:356
uint32_t intPriority
Definition: I2CSlaveMSP432.h:325
bool isOpen
Definition: I2CSlaveMSP432.h:355
const uint8_t * writeBufferIdx
Definition: I2CSlaveMSP432.h:346
I2CSlave_CallbackFxn transferCallbackFxn
Definition: I2CSlaveMSP432.h:344
The definition of a I2CSlave function table that contains the required set of functions to control a ...
Definition: I2CSlave.h:371
size_t countIdx
Definition: I2CSlaveMSP432.h:349
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale