I2CCC32XX.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  */
32 /*!****************************************************************************
33  * @file I2CCC32XX.h
34  *
35  * @brief I2C driver implementation for a CC32XX I2C controller.
36  *
37  * The I2C header file should be included in an application as follows:
38  * @code
39  * #include <ti/drivers/I2C.h>
40  * #include <ti/drivers/i2c/I2CCC32XX.h>
41  * @endcode
42  *
43  * Refer to @ref I2C.h for a complete description of APIs and usage.
44  *
45  * ## Supported Bit Rates ##
46  * - #I2C_100kHz
47  * - #I2C_400kHz
48  *
49  ******************************************************************************
50  */
51 
52 #ifndef ti_drivers_i2c_I2CCC32XX__include
53 #define ti_drivers_i2c_I2CCC32XX__include
54 
55 #include <stdint.h>
56 #include <stdbool.h>
57 
58 #include <ti/drivers/I2C.h>
59 #include <ti/drivers/dpl/HwiP.h>
60 #include <ti/drivers/dpl/SemaphoreP.h>
61 #include <ti/drivers/Power.h>
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 /*
68  * Macros defining possible I2C signal pin mux options
69  *
70  * The bits in the pin mode macros are as follows:
71  * The lower 8 bits of the macro refer to the pin, offset by 1, to match
72  * driverlib pin defines. For example, I2CCC32XX_PIN_01_I2C_SCL & 0xff = 0,
73  * which equals PIN_01 in driverlib pin.h. By matching the PIN_xx defines in
74  * driverlib pin.h, we can pass the pin directly to the driverlib functions.
75  * The upper 8 bits of the macro correspond to the pin mux confg mode
76  * value for the pin to operate in the I2C mode. For example, pin 1 is
77  * configured with mode 1 to operate as I2C_SCL.
78  */
79 #define I2CCC32XX_PIN_01_I2C_SCL 0x100
80 #define I2CCC32XX_PIN_02_I2C_SDA 0x101
81 #define I2CCC32XX_PIN_03_I2C_SCL 0x502
82 #define I2CCC32XX_PIN_04_I2C_SDA 0x503
83 #define I2CCC32XX_PIN_05_I2C_SCL 0x504
84 #define I2CCC32XX_PIN_06_I2C_SDA 0x505
85 #define I2CCC32XX_PIN_16_I2C_SCL 0x90F
86 #define I2CCC32XX_PIN_17_I2C_SDA 0x910
98 /* Add I2CCC32XX_STATUS_* macros here */
99 
112 /* Add I2CCC32XX_CMD_* macros here */
113 
116 /* I2C function table pointer */
117 extern const I2C_FxnTable I2CCC32XX_fxnTable;
118 
125 typedef enum {
127  I2CCC32XX_IDLE_MODE = 0,
129  I2CCC32XX_WRITE_MODE,
131  I2CCC32XX_READ_MODE,
133  I2CCC32XX_TIMEOUT,
135  I2CCC32XX_ERROR = 0xFF
136 } I2CCC32XX_Mode;
175 typedef struct {
177  unsigned int baseAddr;
179  unsigned int intNum;
181  unsigned int intPriority;
183  uint16_t clkPin;
185  uint16_t dataPin;
187 
193 typedef struct {
194  SemaphoreP_Handle mutex; /* Grants exclusive access to I2C */
195  SemaphoreP_Handle transferComplete; /* Signals I2C transfer completion */
196 
197  HwiP_Handle hwiHandle;
198 
199  I2C_TransferMode transferMode; /* Blocking or Callback mode */
200  I2C_CallbackFxn transferCallbackFxn; /* Callback function pointer */
201 
202  volatile I2CCC32XX_Mode mode; /* Stores the I2C state */
203 
204  I2C_Transaction *currentTransaction; /* Pointer to current transaction */
205 
206  uint8_t *writeBufIdx; /* Internal inc. writeBuf index */
207  size_t totalWriteCountIdx; /* Internal dec. writeCounter */
208  size_t burstWriteCountIdx; /* Internal dec. writeCounter */
209 
210  uint8_t *readBufIdx; /* Internal inc. readBuf index */
211  size_t totalReadCountIdx; /* Internal dec. readCounter */
212  size_t burstReadCountIdx; /* Internal dec. readCounter */
213 
214  /* I2C transaction pointers for I2C_MODE_CALLBACK */
215  I2C_Transaction *headPtr; /* Head ptr for queued transactions */
216  I2C_Transaction *tailPtr; /* Tail ptr for queued transactions */
217 
218  bool isOpen; /* Flag to indicate module is open */
219 
220  Power_NotifyObj notifyObj; /* For notification of wake from LPDS */
221  I2C_BitRate bitRate; /* I2C bus bit rate */
222 } I2CCC32XX_Object;
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* ti_drivers_i2c_I2CCC32XX__include */
unsigned int intNum
Definition: I2CCC32XX.h:179
I2C_BitRate
Bit rate for an I2C driver instance specified in the I2C_Params.
Definition: I2C.h:519
uint16_t dataPin
Definition: I2CCC32XX.h:185
Power Manager.
unsigned int intPriority
Definition: I2CCC32XX.h:181
I2C_TransferMode
Return behavior of I2C_Transfer() specified in the I2C_Params.
Definition: I2C.h:458
The definition of an I2C function table that contains the required set of functions to control a spec...
Definition: I2C.h:604
Power notify object structure.
Definition: Power.h:443
I2CCC32XX Hardware attributes.
Definition: I2CCC32XX.h:175
unsigned int baseAddr
Definition: I2CCC32XX.h:177
uint16_t clkPin
Definition: I2CCC32XX.h:183
const I2C_FxnTable I2CCC32XX_fxnTable
void(* I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction *transaction, bool transferStatus)
The definition of a callback function.
Definition: I2C.h:508
Defines a transaction to be used with I2C_transfer()
Definition: I2C.h:381
Inter-Integrated Circuit (I2C) Driver.
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale