1 /* --COPYRIGHT--,BSD\r
2 * Copyright (c) 2014, Texas Instruments Incorporated\r
3 * All rights reserved.\r
4 *\r
5 * Redistribution and use in source and binary forms, with or without\r
6 * modification, are permitted provided that the following conditions\r
7 * are met:\r
8 *\r
9 * * Redistributions of source code must retain the above copyright\r
10 * notice, this list of conditions and the following disclaimer.\r
11 *\r
12 * * Redistributions in binary form must reproduce the above copyright\r
13 * notice, this list of conditions and the following disclaimer in the\r
14 * documentation and/or other materials provided with the 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 "AS IS"\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 * --/COPYRIGHT--*/\r
32 //*****************************************************************************\r
33 //\r
34 // usci_i2c.h - Driver for the USCI_I2C Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 #ifndef __MSP430WARE_USCI_I2C_H__\r
39 #define __MSP430WARE_USCI_I2C_H__\r
40 \r
41 #include "inc/hw_memmap.h"\r
42 \r
43 #ifdef __MSP430_HAS_USCI_Bx__\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // If building with a C++ compiler, make all of the definitions in this header\r
48 // have a C binding.\r
49 //\r
50 //*****************************************************************************\r
51 #ifdef __cplusplus\r
52 extern "C"\r
53 {\r
54 #endif\r
55 \r
56 //******************************************************************************\r
57 //\r
58 // The following is a struct that is passed to USCI_I2C_initMaster()\r
59 //\r
60 //******************************************************************************\r
61 typedef struct USCI_I2C_initMasterParam {\r
62 uint8_t selectClockSource;\r
63 uint32_t i2cClk;\r
64 uint32_t dataRate;\r
65 } USCI_I2C_initMasterParam;\r
66 \r
67 //*****************************************************************************\r
68 //\r
69 // The following are values that can be passed to the selectClockSource\r
70 // parameter for functions: USCI_I2C_masterInit().\r
71 //\r
72 //*****************************************************************************\r
73 #define USCI_I2C_CLOCKSOURCE_ACLK UCSSEL__ACLK\r
74 #define USCI_I2C_CLOCKSOURCE_SMCLK UCSSEL__SMCLK\r
75 \r
76 //*****************************************************************************\r
77 //\r
78 // The following are values that can be passed to the dataRate parameter for\r
79 // functions: USCI_I2C_masterInit().\r
80 //\r
81 //*****************************************************************************\r
82 #define USCI_I2C_SET_DATA_RATE_400KBPS 400000\r
83 #define USCI_I2C_SET_DATA_RATE_100KBPS 100000\r
84 \r
85 //*****************************************************************************\r
86 //\r
87 // The following are values that can be passed to the mode parameter for\r
88 // functions: USCI_I2C_setMode().\r
89 //\r
90 //*****************************************************************************\r
91 #define USCI_I2C_TRANSMIT_MODE UCTR\r
92 #define USCI_I2C_RECEIVE_MODE 0x00\r
93 \r
94 //*****************************************************************************\r
95 //\r
96 // The following are values that can be passed to the mask parameter for\r
97 // functions: USCI_I2C_enableInterrupt(), USCI_I2C_disableInterrupt(),\r
98 // USCI_I2C_clearInterruptFlag(), and USCI_I2C_getInterruptStatus() as well as\r
99 // returned by the USCI_I2C_getInterruptStatus() function.\r
100 //\r
101 //*****************************************************************************\r
102 #define USCI_I2C_STOP_INTERRUPT UCSTPIE\r
103 #define USCI_I2C_START_INTERRUPT UCSTTIE\r
104 #define USCI_I2C_RECEIVE_INTERRUPT UCRXIE\r
105 #define USCI_I2C_TRANSMIT_INTERRUPT UCTXIE\r
106 #define USCI_I2C_NAK_INTERRUPT UCNACKIE\r
107 #define USCI_I2C_ARBITRATIONLOST_INTERRUPT UCALIE\r
108 \r
109 //*****************************************************************************\r
110 //\r
111 // The following are values that can be passed toThe following are values that\r
112 // can be returned by the USCI_I2C_isBusy() function and the\r
113 // USCI_I2C_isBusBusy() function.\r
114 //\r
115 //*****************************************************************************\r
116 #define USCI_I2C_BUS_BUSY UCBBUSY\r
117 #define USCI_I2C_BUS_NOT_BUSY 0x00\r
118 \r
119 //*****************************************************************************\r
120 //\r
121 // The following are values that can be passed toThe following are values that\r
122 // can be returned by the USCI_I2C_masterIsStartSent() function.\r
123 //\r
124 //*****************************************************************************\r
125 #define USCI_I2C_SENDING_START UCTXSTT\r
126 #define USCI_I2C_START_SEND_COMPLETE 0x00\r
127 \r
128 //*****************************************************************************\r
129 //\r
130 // The following are values that can be passed toThe following are values that\r
131 // can be returned by the USCI_I2C_masterIsStopSent() function.\r
132 //\r
133 //*****************************************************************************\r
134 #define USCI_I2C_SENDING_STOP UCTXSTP\r
135 #define USCI_I2C_STOP_SEND_COMPLETE 0x00\r
136 \r
137 //*****************************************************************************\r
138 //\r
139 // Prototypes for the APIs.\r
140 //\r
141 //*****************************************************************************\r
142 extern void USCI_I2C_initMaster(uint16_t baseAddress,\r
143 USCI_I2C_initMasterParam *param);\r
144 \r
145 extern void USCI_I2C_slaveInit(uint16_t baseAddress,\r
146 uint8_t slaveAddress);\r
147 \r
148 extern void USCI_I2C_enable(uint16_t baseAddress);\r
149 \r
150 extern void USCI_I2C_disable(uint16_t baseAddress);\r
151 \r
152 extern void USCI_I2C_setSlaveAddress(uint16_t baseAddress,\r
153 uint8_t slaveAddress);\r
154 \r
155 extern void USCI_I2C_setMode(uint16_t baseAddress,\r
156 uint8_t mode);\r
157 \r
158 extern void USCI_I2C_slaveDataPut(uint16_t baseAddress,\r
159 uint8_t transmitData);\r
160 \r
161 extern uint8_t USCI_I2C_slaveDataGet(uint16_t baseAddress);\r
162 \r
163 extern uint8_t USCI_I2C_isBusBusy(uint16_t baseAddress);\r
164 \r
165 extern uint8_t USCI_I2C_isBusy(uint16_t baseAddress);\r
166 \r
167 extern uint8_t USCI_I2C_masterIsStopSent(uint16_t baseAddress);\r
168 \r
169 extern uint8_t USCI_I2C_masterIsStartSent(uint16_t baseAddress);\r
170 \r
171 extern void USCI_I2C_masterSendStart(uint16_t baseAddress);\r
172 \r
173 extern void USCI_I2C_enableInterrupt(uint16_t baseAddress,\r
174 uint8_t mask);\r
175 \r
176 extern void USCI_I2C_disableInterrupt(uint16_t baseAddress,\r
177 uint8_t mask);\r
178 \r
179 extern void USCI_I2C_clearInterruptFlag(uint16_t baseAddress,\r
180 uint8_t mask);\r
181 \r
182 extern uint8_t USCI_I2C_getInterruptStatus(uint16_t baseAddress,\r
183 uint8_t mask);\r
184 \r
185 extern void USCI_I2C_masterSendSingleByte(uint16_t baseAddress,\r
186 uint8_t txData);\r
187 \r
188 extern bool USCI_I2C_masterSendSingleByteWithTimeout(uint16_t baseAddress,\r
189 uint8_t txData,\r
190 uint32_t timeout);\r
191 \r
192 extern void USCI_I2C_masterMultiByteSendStart(uint16_t baseAddress,\r
193 uint8_t txData);\r
194 \r
195 extern bool USCI_I2C_masterMultiByteSendStartWithTimeout(uint16_t baseAddress,\r
196 uint8_t txData,\r
197 uint32_t timeout);\r
198 \r
199 extern void USCI_I2C_masterMultiByteSendNext(uint16_t baseAddress,\r
200 uint8_t txData);\r
201 \r
202 extern bool USCI_I2C_masterMultiByteSendNextWithTimeout(uint16_t baseAddress,\r
203 uint8_t txData,\r
204 uint32_t timeout);\r
205 \r
206 extern void USCI_I2C_masterMultiByteSendFinish(uint16_t baseAddress,\r
207 uint8_t txData);\r
208 \r
209 extern bool USCI_I2C_masterMultiByteSendFinishWithTimeout(uint16_t baseAddress,\r
210 uint8_t txData,\r
211 uint32_t timeout);\r
212 \r
213 extern void USCI_I2C_masterMultiByteSendStop(uint16_t baseAddress);\r
214 \r
215 extern bool USCI_I2C_masterMultiByteSendStopWithTimeout(uint16_t baseAddress,\r
216 uint32_t timeout);\r
217 \r
218 extern void USCI_I2C_masterMultiByteReceiveStart(uint16_t baseAddress);\r
219 \r
220 extern uint8_t USCI_I2C_masterMultiByteReceiveNext(uint16_t baseAddress);\r
221 \r
222 extern uint8_t USCI_I2C_masterMultiByteReceiveFinish(uint16_t baseAddress);\r
223 \r
224 extern bool USCI_I2C_masterMultiByteReceiveFinishWithTimeout(uint16_t baseAddress,\r
225 uint8_t *rxData,\r
226 uint32_t timeout);\r
227 \r
228 extern void USCI_I2C_masterMultiByteReceiveStop(uint16_t baseAddress);\r
229 \r
230 extern void USCI_I2C_masterSingleReceiveStart(uint16_t baseAddress);\r
231 \r
232 extern bool USCI_I2C_masterSingleReceiveStartWithTimeout(uint16_t baseAddress,\r
233 uint32_t timeout);\r
234 \r
235 extern uint8_t USCI_I2C_masterSingleReceive(uint16_t baseAddress);\r
236 \r
237 extern uint32_t USCI_I2C_getReceiveBufferAddressForDMA(uint16_t baseAddress);\r
238 \r
239 extern uint32_t USCI_I2C_getTransmitBufferAddressForDMA(uint16_t baseAddress);\r
240 \r
241 //*****************************************************************************\r
242 //\r
243 // DEPRECATED APIS.\r
244 //\r
245 //*****************************************************************************\r
246 #define USCI_I2C_masterIsSTOPSent USCI_I2C_masterIsStopSent\r
247 \r
248 //*****************************************************************************\r
249 //\r
250 // The following are deprecated APIs.\r
251 //\r
252 //*****************************************************************************\r
253 extern void USCI_I2C_masterInit(uint16_t baseAddress,\r
254 uint8_t selectClockSource,\r
255 uint32_t i2cClk,\r
256 uint32_t dataRate);\r
257 \r
258 //*****************************************************************************\r
259 //\r
260 // Mark the end of the C bindings section for C++ compilers.\r
261 //\r
262 //*****************************************************************************\r
263 #ifdef __cplusplus\r
264 }\r
265 #endif\r
266 \r
267 #endif\r
268 #endif // __MSP430WARE_USCI_I2C_H__\r