1 /* 2 * Copyright (c) 2015-2020, 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 /*!< PIN 1 is used for I2C_SCL */ 80 #define I2CCC32XX_PIN_02_I2C_SDA 0x101 /*!< PIN 2 is used for I2C_SDA */ 81 #define I2CCC32XX_PIN_03_I2C_SCL 0x502 /*!< PIN 3 is used for I2C_SCL */ 82 #define I2CCC32XX_PIN_04_I2C_SDA 0x503 /*!< PIN 4 is used for I2C_SDA */ 83 #define I2CCC32XX_PIN_05_I2C_SCL 0x504 /*!< PIN 5 is used for I2C_SCL */ 84 #define I2CCC32XX_PIN_06_I2C_SDA 0x505 /*!< PIN 6 is used for I2C_SDA */ 85 #define I2CCC32XX_PIN_16_I2C_SCL 0x90F /*!< PIN 16 is used for I2C_SCL */ 86 #define I2CCC32XX_PIN_17_I2C_SDA 0x910 /*!< PIN 17 is used for I2C_SDA */ 87 88 /** 89 * @addtogroup I2C_STATUS 90 * I2CCC32XX_STATUS_* macros are command codes only defined in the 91 * I2CCC32XX.h driver implementation and need to: 92 * @code 93 * #include <ti/drivers/i2c/I2CCC32XX.h> 94 * @endcode 95 * @{ 96 */ 97 98 /* Add I2CCC32XX_STATUS_* macros here */ 99 100 /** @}*/ 101 102 /** 103 * @addtogroup I2C_CMD 104 * I2CCC32XX_CMD_* macros are command codes only defined in the 105 * I2CCC32XX.h driver implementation and need to: 106 * @code 107 * #include <ti/drivers/i2c/I2CCC32XX.h> 108 * @endcode 109 * @{ 110 */ 111 112 /* Add I2CCC32XX_CMD_* macros here */ 113 114 /** @}*/ 115 116 /* I2C function table pointer */ 117 extern const I2C_FxnTable I2CCC32XX_fxnTable; 118 119 /*! 120 * @brief I2CCC32XX Hardware attributes 121 * 122 * The baseAddr and intNum fields define the base address and interrupt number 123 * of the I2C peripheral. These values are used by driverlib APIs and 124 * therefore must be populated by driverlib macro definitions. These 125 * definitions are found in the header files: 126 * - inc/hw_memmap.h 127 * - inc/hw_ints.h 128 * 129 * intPriority is the I2C peripheral's interrupt priority. 130 * This driver uses the ti.dpl interface instead of making OS calls directly, 131 * and the corresponding HwiP port handles the interrupt priority in an 132 * OS-specific way. For example, in the case of the TI-RTOS kernel port, 133 * the intPriority is passed unmodified to Hwi_create() provided by the 134 * ti.sysbios.family.arm.m3.Hwi module; so the documentation for the 135 * ti.sysbios.family.arm.m3.Hwi module should be referenced for a description 136 * of usage of priority. 137 * 138 * clkPin and dataPin define the pin multiplexing to be used for the SCL and 139 * SDA pins, respectively. Macro values defined in this header file should 140 * be used for these fields. 141 * 142 * A sample structure is shown below: 143 * @code 144 * const I2CCC32XX_HWAttrsV1 i2cCC32XXHWAttrs[] = { 145 * { 146 * .baseAddr = I2CA0_BASE, 147 * .intNum = INT_I2CA0, 148 * .intPriority = (~0), 149 * .clkPin = I2CCC32XX_PIN_01_I2C_SCL, 150 * .dataPin = I2CCC32XX_PIN_02_I2C_SDA, 151 * } 152 * }; 153 * @endcode 154 */ 155 typedef struct { 156 /*! I2C Peripheral's base address */ 157 unsigned int baseAddr; 158 /*! I2C Peripheral's interrupt vector */ 159 unsigned int intNum; 160 /*! I2C Peripheral's interrupt priority */ 161 unsigned int intPriority; 162 /*! I2C clock pin configuration */ 163 uint16_t clkPin; 164 /*! I2C data pin configuration */ 165 uint16_t dataPin; 166 } I2CCC32XX_HWAttrsV1; 167 168 /*! 169 * @cond NODOC 170 * I2CCC32XX Object. Applications must not access any member variables of 171 * this structure! 172 */ 173 typedef struct { 174 /* Grants exclusive access to I2C */ 175 SemaphoreP_Handle mutex; 176 177 /* Notify finished I2C transfer */ 178 SemaphoreP_Handle transferComplete; 179 180 /* Hardware interrupt handle */ 181 HwiP_Handle hwiHandle; 182 183 /* Blocking or Callback mode */ 184 I2C_TransferMode transferMode; 185 186 /* Application callback function pointer */ 187 I2C_CallbackFxn transferCallbackFxn; 188 189 /* Pointer to current I2C transaction */ 190 I2C_Transaction *currentTransaction; 191 192 /* Head and tail pointers for queued transactions */ 193 I2C_Transaction * volatile headPtr; 194 I2C_Transaction *tailPtr; 195 196 /* Pointers to transaction buffers */ 197 const uint8_t * writeBuf; 198 uint8_t *readBuf; 199 200 /* Read, write, and burst counters */ 201 size_t writeCount; 202 size_t readCount; 203 uint16_t burstCount; 204 bool burstStarted; 205 206 /* Flag to indicate module is open */ 207 bool isOpen; 208 209 /* Enumerated bit rate */ 210 I2C_BitRate bitRate; 211 212 /* For notification of wake from LPDS */ 213 Power_NotifyObj notifyObj; 214 } I2CCC32XX_Object; 215 /*! @endcond */ 216 217 #ifdef __cplusplus 218 } 219 #endif 220 221 #endif /* ti_drivers_i2c_I2CCC32XX__include */ 222