1 //###########################################################################
2 //
3 // FILE:     F2837xD_I2c_defines.h
4 //
5 // TITLE:    F2837xD I2C Common Definitions.
6 //
7 //###########################################################################
8 // $TI Release: F2837xD Support Library v3.05.00.00 $
9 // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
10 // $Copyright:
11 // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
12 //
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions
15 // are met:
16 //
17 //   Redistributions of source code must retain the above copyright
18 //   notice, this list of conditions and the following disclaimer.
19 //
20 //   Redistributions in binary form must reproduce the above copyright
21 //   notice, this list of conditions and the following disclaimer in the
22 //   documentation and/or other materials provided with the
23 //   distribution.
24 //
25 //   Neither the name of Texas Instruments Incorporated nor the names of
26 //   its contributors may be used to endorse or promote products derived
27 //   from this software without specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 // $
41 //###########################################################################
42 
43 #ifndef F2837xD_I2C_DEFINES_H
44 #define F2837xD_I2C_DEFINES_H
45 
46 //
47 // Defines
48 //
49 
50 //
51 // Error Messages
52 //
53 #define I2C_ERROR               0xFFFF
54 #define I2C_ARB_LOST_ERROR      0x0001
55 #define I2C_NACK_ERROR          0x0002
56 #define I2C_BUS_BUSY_ERROR      0x1000
57 #define I2C_STP_NOT_READY_ERROR 0x5555
58 #define I2C_NO_FLAGS            0xAAAA
59 #define I2C_SUCCESS             0x0000
60 
61 //
62 // Clear Status Flags
63 //
64 #define I2C_CLR_AL_BIT          0x0001
65 #define I2C_CLR_NACK_BIT        0x0002
66 #define I2C_CLR_ARDY_BIT        0x0004
67 #define I2C_CLR_RRDY_BIT        0x0008
68 #define I2C_CLR_SCD_BIT         0x0020
69 
70 //
71 // Interrupt Source Messages
72 //
73 #define I2C_NO_ISRC             0x0000
74 #define I2C_ARB_ISRC            0x0001
75 #define I2C_NACK_ISRC           0x0002
76 #define I2C_ARDY_ISRC           0x0003
77 #define I2C_RX_ISRC             0x0004
78 #define I2C_TX_ISRC             0x0005
79 #define I2C_SCD_ISRC            0x0006
80 #define I2C_AAS_ISRC            0x0007
81 
82 //
83 // I2CMSG structure defines
84 //
85 #define I2C_NO_STOP             0
86 #define I2C_YES_STOP            1
87 #define I2C_RECEIVE             0
88 #define I2C_TRANSMIT            1
89 #define I2C_MAX_BUFFER_SIZE     16
90 
91 //
92 // I2C Slave State defines
93 //
94 #define I2C_NOTSLAVE            0
95 #define I2C_ADDR_AS_SLAVE       1
96 #define I2C_ST_MSG_READY        2
97 
98 //
99 // I2C Slave Receiver messages defines
100 //
101 #define I2C_SND_MSG1            1
102 #define I2C_SND_MSG2            2
103 
104 //
105 // I2C State defines
106 //
107 #define I2C_IDLE                0
108 #define I2C_SLAVE_RECEIVER      1
109 #define I2C_SLAVE_TRANSMITTER   2
110 #define I2C_MASTER_RECEIVER     3
111 #define I2C_MASTER_TRANSMITTER  4
112 
113 //
114 // I2C  Message Commands for I2CMSG struct
115 //
116 #define I2C_MSGSTAT_INACTIVE          0x0000
117 #define I2C_MSGSTAT_SEND_WITHSTOP     0x0010
118 #define I2C_MSGSTAT_WRITE_BUSY        0x0011
119 #define I2C_MSGSTAT_SEND_NOSTOP       0x0020
120 #define I2C_MSGSTAT_SEND_NOSTOP_BUSY  0x0021
121 #define I2C_MSGSTAT_RESTART           0x0022
122 #define I2C_MSGSTAT_READ_BUSY         0x0023
123 
124 //
125 // Generic defines
126 //
127 #define I2C_TRUE  1
128 #define I2C_FALSE 0
129 #define I2C_YES   1
130 #define I2C_NO    0
131 #define I2C_DUMMY_BYTE 0
132 
133 
134 //
135 //  These are the Defines to select I2C pin muxing when calling the functions
136 //  I2cAGpioConfig() & I2cBGpioConfig() in F2837xD_I2C.c
137 //
138 #define I2C_A_GPIO0_GPIO1            1    //switch case 1
139 #define I2C_A_GPIO32_GPIO33          2    //switch case 2
140 #define I2C_A_GPIO42_GPIO43          3    //switch case 3
141 #define I2C_A_GPIO91_GPIO92          4    //switch case 4
142 #define I2C_A_GPIO63104_GPIO105      5    //switch case 5
143 
144 #define I2C_B_GPIO2_GPIO3            1    //switch case 1
145 #define I2C_B_GPIO134_GPIO35         2    //switch case 2
146 #define I2C_B_GPIO40_GPIO41          3    //switch case 3
147 #define I2C_B_GPIO66_GPIO69          4    //switch case 4
148 
149 //
150 // Globals
151 //
152 
153 //
154 // I2C Message Structure
155 //
156 struct I2CMSG {
157   Uint16 MsgStatus;             // Word stating what state msg is in:
158                                 //  I2C_MSGCMD_INACTIVE = do not send msg
159                                 //  I2C_MSGCMD_BUSY = msg start has been sent,
160                                 //                    awaiting stop
161                                 //  I2C_MSGCMD_SEND_WITHSTOP = command to send
162                                 //    master trans msg complete with a stop bit
163                                 //  I2C_MSGCMD_SEND_NOSTOP = command to send
164                                 //    master trans msg without the stop bit
165                                 //  I2C_MSGCMD_RESTART = command to send a
166                                 //    restart as a master receiver with a
167                                 //    stop bit
168   Uint16 SlaveAddress;          // I2C address of slave msg is intended for
169   Uint16 NumOfBytes;            // Num of valid bytes in (or to be put
170                                 // in MsgBuffer)
171   Uint16 MemoryHighAddr;        // EEPROM address of data associated with
172                                 // msg (high byte)
173   Uint16 MemoryLowAddr;         // EEPROM address of data associated with
174                                 // msg (low byte)
175   Uint16 MsgBuffer[I2C_MAX_BUFFER_SIZE];  // Array holding msg data - max that
176                                           // MAX_BUFFER_SIZE can be is 16 due
177                                           // to the FIFO's
178 };
179 
180 #endif  // end of F2837xD_I2C_DEFINES_H definition
181 
182 //
183 // End of file
184 //
185