1 /** @file I2C.h
2 *   @brief I2C Driver Definition File
3 *   @date 29.May.2013
4 *   @version 03.05.02
5 *
6 */
7 
8 /* (c) Texas Instruments 2009-2013, All rights reserved. */
9 
10 #ifndef __I2C_H__
11 #define __I2C_H__
12 
13 #include "reg_i2c.h"
14 
15 
16 
17 /** @enum i2cMode
18 *   @brief Alias names for i2c modes
19 *   This enumeration is used to provide alias names for I2C modes:
20 */
21 
22 enum i2cMode
23 {
24     I2C_FD_FORMAT   = 0x0008U,  /* Free Data Format    */
25     I2C_START_BYTE  = 0x0010U,
26     I2C_RESET_OUT   = 0x0020U,  I2C_RESET_IN   = 0x0000U,
27     I2C_DLOOPBACK   = 0x0040U,
28     I2C_REPEATMODE  = 0x0080U,  /* In Master Mode only */
29     I2C_10BIT_AMODE = 0x0100U,  I2C_7BIT_AMODE = 0x0000U,
30     I2C_TRANSMITTER = 0x0200U,  I2C_RECEIVER   = 0x0000U,
31     I2C_MASTER      = 0x0400U,  I2C_SLAVE      = 0x0000U,
32     I2C_STOP_COND   = 0x0800U,  /* In Master Mode only */
33     I2C_START_COND  = 0x2000U,  /* In Master Mode only */
34     I2C_FREE_RUN    = 0x4000U,
35     I2C_NACK_MODE   = 0x8000U
36 };
37 
38 
39 /** @enum i2cBitCount
40 *   @brief Alias names for i2c bit count
41 *   This enumeration is used to provide alias names for I2C bit count:
42 */
43 
44 enum i2cBitCount
45 {
46     I2C_2_BIT   = 0x2U,
47     I2C_3_BIT   = 0x3U,
48     I2C_4_BIT   = 0x4U,
49     I2C_5_BIT   = 0x5U,
50     I2C_6_BIT   = 0x6U,
51     I2C_7_BIT   = 0x7U,
52     I2C_8_BIT   = 0x0U
53 };
54 
55 
56 
57 /** @enum i2cIntFlags
58 *   @brief Interrupt Flag Definitions
59 *
60 *   Used with I2CEnableNotification, I2CDisableNotification
61 */
62 enum i2cIntFlags
63 {
64     I2C_AL_INT     = 0x0001U,  /* arbitration lost      */
65     I2C_NACK_INT   = 0x0002U,  /* no acknowledgment    */
66     I2C_ARDY_INT   = 0x0004U,  /* access ready          */
67     I2C_RX_INT     = 0x0008U,  /* receive data ready    */
68     I2C_TX_INT     = 0x0010U,  /* transmit data ready   */
69     I2C_SCD_INT    = 0x0020U,  /* stop condition detect */
70     I2C_AAS_INT    = 0x0040U   /* address as slave      */
71 };
72 
73 
74 /** @enum i2cStatFlags
75 *   @brief Interrupt Status Definitions
76 *
77 */
78 enum i2cStatFlags
79 {
80     I2C_AL         = 0x0001U,  /* arbitration lost          */
81     I2C_NACK       = 0x0002U,  /* no acknowledgement        */
82     I2C_ARDY       = 0x0004U,  /* access ready              */
83     I2C_RX         = 0x0008U,  /* receive data ready        */
84     I2C_TX         = 0x0010U,  /* transmit data ready       */
85     I2C_SCD        = 0x0020U,  /* stop condition detect     */
86     I2C_AD0        = 0x0100U,  /* address Zero Status       */
87     I2C_AAS        = 0x0200U,  /* address as slave          */
88     I2C_XSMT       = 0x0400U,  /* Transmit shift empty not  */
89     I2C_RXFULL     = 0x0800U,  /* receive full              */
90     I2C_BUSBUSY    = 0x1000U,  /* bus busy                  */
91     I2C_NACKSNT    = 0x2000U,  /* No Ack Sent               */
92     I2C_SDIR       = 0x4000U   /* Slave Direction           */
93 };
94 
95 
96 /** @enum i2cDMA
97 *   @brief I2C DMA definitions
98 *
99 *   Used before i2c transfer
100 */
101 enum i2cDMA
102 {
103     I2C_TXDMA   = 0x20U,
104     I2C_RXDMA   = 0x10U
105 };
106 
107 /**
108  *  @defgroup I2C I2C
109  *  @brief Inter-Integrated Circuit Module.
110  *
111  *  The I2C is a multi-master communication module providing an interface between the Texas Instruments (TI) microcontroller
112  *  and devices compliant with Philips Semiconductor I2C-bus specification version 2.1 and connected by an I2Cbus.
113  *  This module will support any slave or master I2C compatible device.
114  *
115  *	Related Files
116  *   - reg_i2c.h
117  *   - i2c.h
118  *   - i2c.c
119  *  @addtogroup I2C
120  *  @{
121  */
122 
123 /* I2C Interface Functions */
124 void i2cInit(void);
125 void i2cSetOwnAdd(i2cBASE_t *i2c, uint32 oadd);
126 void i2cSetSlaveAdd(i2cBASE_t *i2c, uint32 sadd);
127 void i2cSetBaudrate(i2cBASE_t *i2c, uint32 baud);
128 uint32  i2cIsTxReady(i2cBASE_t *i2c);
129 void i2cSendByte(i2cBASE_t *i2c, uint8 byte);
130 void i2cSend(i2cBASE_t *i2c, uint32 length, uint8 * data);
131 uint32  i2cIsRxReady(i2cBASE_t *i2c);
132 void i2cClearSCD(i2cBASE_t *i2c);
133 uint32  i2cRxError(i2cBASE_t *i2c);
134 uint32  i2cReceiveByte(i2cBASE_t *i2c);
135 void i2cReceive(i2cBASE_t *i2c, uint32 length, uint8 * data);
136 void i2cEnableNotification(i2cBASE_t *i2c, uint32 flags);
137 void i2cDisableNotification(i2cBASE_t *i2c, uint32 flags);
138 void i2cSetStart(i2cBASE_t *i2c);
139 void i2cSetStop(i2cBASE_t *i2c);
140 void i2cSetCount(i2cBASE_t *i2c ,uint32 cnt);
141 void i2cEnableLoopback(i2cBASE_t *i2c);
142 void i2cDisableLoopback(i2cBASE_t *i2c);
143 
144 /** @fn void i2cNotification(i2cBASE_t *i2c, uint32 flags)
145 *   @brief Interrupt callback
146 *   @param[in] i2c   - I2C module base address
147 *   @param[in] flags - copy of error interrupt flags
148 *
149 * This is a callback that is provided by the application and is called apon
150 * an interrupt.  The parameter passed to the callback is a copy of the
151 * interrupt flag register.
152 */
153 void i2cNotification(i2cBASE_t *i2c, uint32 flags);
154 
155 /**@}*/
156 #endif
157