collab/mm20

git clone https://git.julia.blue/collab/mm20

Joseph RyanAdd starter files39a929c

master
18.3 KiB364 linesraw
1#include <stdbool.h>
2#include <stdint.h>
3//*****************************************************************************
4//
5// i2c.h - Prototypes for the I2C Driver.
6//
7// Copyright (c) 2005-2017 Texas Instruments Incorporated.  All rights reserved.
8// Software License Agreement
9// 
10//   Redistribution and use in source and binary forms, with or without
11//   modification, are permitted provided that the following conditions
12//   are met:
13// 
14//   Redistributions of source code must retain the above copyright
15//   notice, this list of conditions and the following disclaimer.
16// 
17//   Redistributions in binary form must reproduce the above copyright
18//   notice, this list of conditions and the following disclaimer in the
19//   documentation and/or other materials provided with the  
20//   distribution.
21// 
22//   Neither the name of Texas Instruments Incorporated nor the names of
23//   its contributors may be used to endorse or promote products derived
24//   from this software without specific prior written permission.
25// 
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37// 
38// This is part of revision 2.1.4.178 of the Tiva Peripheral Driver Library.
39//
40//*****************************************************************************
41
42#ifndef __DRIVERLIB_I2C_H__
43#define __DRIVERLIB_I2C_H__
44
45//*****************************************************************************
46//
47// If building with a C++ compiler, make all of the definitions in this header
48// have a C binding.
49//
50//*****************************************************************************
51#ifdef __cplusplus
52extern "C"
53{
54#endif
55
56//*****************************************************************************
57//
58// Defines for the API.
59//
60//*****************************************************************************
61
62//*****************************************************************************
63//
64// Interrupt defines.
65//
66//*****************************************************************************
67#define I2C_INT_MASTER          0x00000001
68#define I2C_INT_SLAVE           0x00000002
69
70//*****************************************************************************
71//
72// I2C Master commands.
73//
74//*****************************************************************************
75#define I2C_MASTER_CMD_SINGLE_SEND                                            \
76                                0x00000007
77#define I2C_MASTER_CMD_SINGLE_RECEIVE                                         \
78                                0x00000007
79#define I2C_MASTER_CMD_BURST_SEND_START                                       \
80                                0x00000003
81#define I2C_MASTER_CMD_BURST_SEND_CONT                                        \
82                                0x00000001
83#define I2C_MASTER_CMD_BURST_SEND_FINISH                                      \
84                                0x00000005
85#define I2C_MASTER_CMD_BURST_SEND_STOP                                        \
86                                0x00000004
87#define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP                                  \
88                                0x00000004
89#define I2C_MASTER_CMD_BURST_RECEIVE_START                                    \
90                                0x0000000b
91#define I2C_MASTER_CMD_BURST_RECEIVE_CONT                                     \
92                                0x00000009
93#define I2C_MASTER_CMD_BURST_RECEIVE_FINISH                                   \
94                                0x00000005
95#define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP                               \
96                                0x00000004
97#define I2C_MASTER_CMD_QUICK_COMMAND                                          \
98                                0x00000027
99#define I2C_MASTER_CMD_HS_MASTER_CODE_SEND                                    \
100                                0x00000013
101#define I2C_MASTER_CMD_FIFO_SINGLE_SEND                                       \
102                                0x00000046
103#define I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE                                    \
104                                0x00000046
105#define I2C_MASTER_CMD_FIFO_BURST_SEND_START                                  \
106                                0x00000042
107#define I2C_MASTER_CMD_FIFO_BURST_SEND_CONT                                   \
108                                0x00000040
109#define I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH                                 \
110                                0x00000044
111#define I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP                             \
112                                0x00000004
113#define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START                               \
114                                0x0000004a
115#define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT                                \
116                                0x00000048
117#define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH                              \
118                                0x00000044
119#define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP                          \
120                                0x00000004
121
122//*****************************************************************************
123//
124// I2C Master glitch filter configuration.
125//
126//*****************************************************************************
127#define I2C_MASTER_GLITCH_FILTER_DISABLED                                     \
128                                0
129#define I2C_MASTER_GLITCH_FILTER_1                                            \
130                                0x00010000
131#define I2C_MASTER_GLITCH_FILTER_2                                            \
132                                0x00020000
133#define I2C_MASTER_GLITCH_FILTER_3                                            \
134                                0x00030000
135#define I2C_MASTER_GLITCH_FILTER_4                                            \
136                                0x00040000
137#define I2C_MASTER_GLITCH_FILTER_8                                            \
138                                0x00050000
139#define I2C_MASTER_GLITCH_FILTER_16                                           \
140                                0x00060000
141#define I2C_MASTER_GLITCH_FILTER_32                                           \
142                                0x00070000
143
144//*****************************************************************************
145//
146// I2C Master error status.
147//
148//*****************************************************************************
149#define I2C_MASTER_ERR_NONE     0
150#define I2C_MASTER_ERR_ADDR_ACK 0x00000004
151#define I2C_MASTER_ERR_DATA_ACK 0x00000008
152#define I2C_MASTER_ERR_ARB_LOST 0x00000010
153#define I2C_MASTER_ERR_CLK_TOUT 0x00000080
154
155//*****************************************************************************
156//
157// I2C Slave action requests
158//
159//*****************************************************************************
160#define I2C_SLAVE_ACT_NONE      0
161#define I2C_SLAVE_ACT_RREQ      0x00000001  // Master has sent data
162#define I2C_SLAVE_ACT_TREQ      0x00000002  // Master has requested data
163#define I2C_SLAVE_ACT_RREQ_FBR  0x00000005  // Master has sent first byte
164#define I2C_SLAVE_ACT_OWN2SEL   0x00000008  // Master requested secondary slave
165#define I2C_SLAVE_ACT_QCMD      0x00000010  // Master has sent a Quick Command
166#define I2C_SLAVE_ACT_QCMD_DATA 0x00000020  // Master Quick Command value
167
168//*****************************************************************************
169//
170// Miscellaneous I2C driver definitions.
171//
172//*****************************************************************************
173#define I2C_MASTER_MAX_RETRIES  1000        // Number of retries
174
175//*****************************************************************************
176//
177// I2C Master interrupts.
178//
179//*****************************************************************************
180#define I2C_MASTER_INT_RX_FIFO_FULL                                           \
181                                0x00000800  // RX FIFO Full Interrupt
182#define I2C_MASTER_INT_TX_FIFO_EMPTY                                          \
183                                0x00000400  // TX FIFO Empty Interrupt
184#define I2C_MASTER_INT_RX_FIFO_REQ                                            \
185                                0x00000200  // RX FIFO Request Interrupt
186#define I2C_MASTER_INT_TX_FIFO_REQ                                            \
187                                0x00000100  // TX FIFO Request Interrupt
188#define I2C_MASTER_INT_ARB_LOST                                               \
189                                0x00000080  // Arb Lost Interrupt
190#define I2C_MASTER_INT_STOP     0x00000040  // Stop Condition Interrupt
191#define I2C_MASTER_INT_START    0x00000020  // Start Condition Interrupt
192#define I2C_MASTER_INT_NACK     0x00000010  // Addr/Data NACK Interrupt
193#define I2C_MASTER_INT_TX_DMA_DONE                                            \
194                                0x00000008  // TX DMA Complete Interrupt
195#define I2C_MASTER_INT_RX_DMA_DONE                                            \
196                                0x00000004  // RX DMA Complete Interrupt
197#define I2C_MASTER_INT_TIMEOUT  0x00000002  // Clock Timeout Interrupt
198#define I2C_MASTER_INT_DATA     0x00000001  // Data Interrupt
199
200//*****************************************************************************
201//
202// I2C Slave interrupts.
203//
204//*****************************************************************************
205#define I2C_SLAVE_INT_RX_FIFO_FULL                                            \
206                                0x00000100  // RX FIFO Full Interrupt
207#define I2C_SLAVE_INT_TX_FIFO_EMPTY                                           \
208                                0x00000080  // TX FIFO Empty Interrupt
209#define I2C_SLAVE_INT_RX_FIFO_REQ                                             \
210                                0x00000040  // RX FIFO Request Interrupt
211#define I2C_SLAVE_INT_TX_FIFO_REQ                                             \
212                                0x00000020  // TX FIFO Request Interrupt
213#define I2C_SLAVE_INT_TX_DMA_DONE                                             \
214                                0x00000010  // TX DMA Complete Interrupt
215#define I2C_SLAVE_INT_RX_DMA_DONE                                             \
216                                0x00000008  // RX DMA Complete Interrupt
217#define I2C_SLAVE_INT_STOP      0x00000004  // Stop Condition Interrupt
218#define I2C_SLAVE_INT_START     0x00000002  // Start Condition Interrupt
219#define I2C_SLAVE_INT_DATA      0x00000001  // Data Interrupt
220
221//*****************************************************************************
222//
223// I2C Slave FIFO configuration macros.
224//
225//*****************************************************************************
226#define I2C_SLAVE_TX_FIFO_ENABLE                                              \
227                                0x00000002
228#define I2C_SLAVE_RX_FIFO_ENABLE                                              \
229                                0x00000004
230
231//*****************************************************************************
232//
233// I2C FIFO configuration macros.
234//
235//*****************************************************************************
236#define I2C_FIFO_CFG_TX_MASTER  0x00000000
237#define I2C_FIFO_CFG_TX_SLAVE   0x00008000
238#define I2C_FIFO_CFG_RX_MASTER  0x00000000
239#define I2C_FIFO_CFG_RX_SLAVE   0x80000000
240#define I2C_FIFO_CFG_TX_MASTER_DMA                                            \
241                                0x00002000
242#define I2C_FIFO_CFG_TX_SLAVE_DMA                                             \
243                                0x0000a000
244#define I2C_FIFO_CFG_RX_MASTER_DMA                                            \
245                                0x20000000
246#define I2C_FIFO_CFG_RX_SLAVE_DMA                                             \
247                                0xa0000000
248#define I2C_FIFO_CFG_TX_NO_TRIG 0x00000000
249#define I2C_FIFO_CFG_TX_TRIG_1  0x00000001
250#define I2C_FIFO_CFG_TX_TRIG_2  0x00000002
251#define I2C_FIFO_CFG_TX_TRIG_3  0x00000003
252#define I2C_FIFO_CFG_TX_TRIG_4  0x00000004
253#define I2C_FIFO_CFG_TX_TRIG_5  0x00000005
254#define I2C_FIFO_CFG_TX_TRIG_6  0x00000006
255#define I2C_FIFO_CFG_TX_TRIG_7  0x00000007
256#define I2C_FIFO_CFG_TX_TRIG_8  0x00000008
257#define I2C_FIFO_CFG_RX_NO_TRIG 0x00000000
258#define I2C_FIFO_CFG_RX_TRIG_1  0x00010000
259#define I2C_FIFO_CFG_RX_TRIG_2  0x00020000
260#define I2C_FIFO_CFG_RX_TRIG_3  0x00030000
261#define I2C_FIFO_CFG_RX_TRIG_4  0x00040000
262#define I2C_FIFO_CFG_RX_TRIG_5  0x00050000
263#define I2C_FIFO_CFG_RX_TRIG_6  0x00060000
264#define I2C_FIFO_CFG_RX_TRIG_7  0x00070000
265#define I2C_FIFO_CFG_RX_TRIG_8  0x00080000
266
267//*****************************************************************************
268//
269// I2C FIFO status.
270//
271//*****************************************************************************
272#define I2C_FIFO_RX_BELOW_TRIG_LEVEL                                          \
273                                0x00040000
274#define I2C_FIFO_RX_FULL        0x00020000
275#define I2C_FIFO_RX_EMPTY       0x00010000
276#define I2C_FIFO_TX_BELOW_TRIG_LEVEL                                          \
277                                0x00000004
278#define I2C_FIFO_TX_FULL        0x00000002
279#define I2C_FIFO_TX_EMPTY       0x00000001
280
281//*****************************************************************************
282//
283// Prototypes for the APIs.
284//
285//*****************************************************************************
286extern void I2CIntRegister(uint32_t ui32Base, void(*pfnHandler)(void));
287extern void I2CIntUnregister(uint32_t ui32Base);
288extern void I2CTxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config);
289extern void I2CTxFIFOFlush(uint32_t ui32Base);
290extern void I2CRxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config);
291extern void I2CRxFIFOFlush(uint32_t ui32Base);
292extern uint32_t I2CFIFOStatus(uint32_t ui32Base);
293extern void I2CFIFODataPut(uint32_t ui32Base, uint8_t ui8Data);
294extern uint32_t I2CFIFODataPutNonBlocking(uint32_t ui32Base,
295                                          uint8_t ui8Data);
296extern uint32_t I2CFIFODataGet(uint32_t ui32Base);
297extern uint32_t I2CFIFODataGetNonBlocking(uint32_t ui32Base,
298                                          uint8_t *pui8Data);
299extern void I2CMasterBurstLengthSet(uint32_t ui32Base,
300                                    uint8_t ui8Length);
301extern uint32_t I2CMasterBurstCountGet(uint32_t ui32Base);
302extern void I2CMasterGlitchFilterConfigSet(uint32_t ui32Base,
303                                           uint32_t ui32Config);
304extern void I2CSlaveFIFOEnable(uint32_t ui32Base, uint32_t ui32Config);
305extern void I2CSlaveFIFODisable(uint32_t ui32Base);
306extern bool I2CMasterBusBusy(uint32_t ui32Base);
307extern bool I2CMasterBusy(uint32_t ui32Base);
308extern void I2CMasterControl(uint32_t ui32Base, uint32_t ui32Cmd);
309extern uint32_t I2CMasterDataGet(uint32_t ui32Base);
310extern void I2CMasterDataPut(uint32_t ui32Base, uint8_t ui8Data);
311extern void I2CMasterDisable(uint32_t ui32Base);
312extern void I2CMasterEnable(uint32_t ui32Base);
313extern uint32_t I2CMasterErr(uint32_t ui32Base);
314extern void I2CMasterInitExpClk(uint32_t ui32Base, uint32_t ui32I2CClk,
315                                bool bFast);
316extern void I2CMasterIntClear(uint32_t ui32Base);
317extern void I2CMasterIntDisable(uint32_t ui32Base);
318extern void I2CMasterIntEnable(uint32_t ui32Base);
319extern bool I2CMasterIntStatus(uint32_t ui32Base, bool bMasked);
320extern void I2CMasterIntEnableEx(uint32_t ui32Base,
321                                 uint32_t ui32IntFlags);
322extern void I2CMasterIntDisableEx(uint32_t ui32Base,
323                                  uint32_t ui32IntFlags);
324extern uint32_t I2CMasterIntStatusEx(uint32_t ui32Base,
325                                       bool bMasked);
326extern void I2CMasterIntClearEx(uint32_t ui32Base,
327                                uint32_t ui32IntFlags);
328extern void I2CMasterTimeoutSet(uint32_t ui32Base, uint32_t ui32Value);
329extern void I2CSlaveACKOverride(uint32_t ui32Base, bool bEnable);
330extern void I2CSlaveACKValueSet(uint32_t ui32Base, bool bACK);
331extern uint32_t I2CMasterLineStateGet(uint32_t ui32Base);
332extern void I2CMasterSlaveAddrSet(uint32_t ui32Base,
333                                  uint8_t ui8SlaveAddr,
334                                  bool bReceive);
335extern uint32_t I2CSlaveDataGet(uint32_t ui32Base);
336extern void I2CSlaveDataPut(uint32_t ui32Base, uint8_t ui8Data);
337extern void I2CSlaveDisable(uint32_t ui32Base);
338extern void I2CSlaveEnable(uint32_t ui32Base);
339extern void I2CSlaveInit(uint32_t ui32Base, uint8_t ui8SlaveAddr);
340extern void I2CSlaveAddressSet(uint32_t ui32Base, uint8_t ui8AddrNum,
341                                 uint8_t ui8SlaveAddr);
342extern void I2CSlaveIntClear(uint32_t ui32Base);
343extern void I2CSlaveIntDisable(uint32_t ui32Base);
344extern void I2CSlaveIntEnable(uint32_t ui32Base);
345extern void I2CSlaveIntClearEx(uint32_t ui32Base, uint32_t ui32IntFlags);
346extern void I2CSlaveIntDisableEx(uint32_t ui32Base,
347                                 uint32_t ui32IntFlags);
348extern void I2CSlaveIntEnableEx(uint32_t ui32Base, uint32_t ui32IntFlags);
349extern bool I2CSlaveIntStatus(uint32_t ui32Base, bool bMasked);
350extern uint32_t I2CSlaveIntStatusEx(uint32_t ui32Base,
351                                      bool bMasked);
352extern uint32_t I2CSlaveStatus(uint32_t ui32Base);
353extern void I2CLoopbackEnable(uint32_t ui32Base);
354
355//*****************************************************************************
356//
357// Mark the end of the C bindings section for C++ compilers.
358//
359//*****************************************************************************
360#ifdef __cplusplus
361}
362#endif
363
364#endif // __DRIVERLIB_I2C_H__