Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /**
sahilmgandhi 18:6a4db94011d3 2 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 3 * @file stm32f2xx_hal_i2c.h
sahilmgandhi 18:6a4db94011d3 4 * @author MCD Application Team
sahilmgandhi 18:6a4db94011d3 5 * @version V1.1.3
sahilmgandhi 18:6a4db94011d3 6 * @date 29-June-2016
sahilmgandhi 18:6a4db94011d3 7 * @brief Header file of I2C HAL module.
sahilmgandhi 18:6a4db94011d3 8 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 9 * @attention
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
sahilmgandhi 18:6a4db94011d3 12 *
sahilmgandhi 18:6a4db94011d3 13 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 14 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 15 * 1. Redistributions of source code must retain the above copyright notice,
sahilmgandhi 18:6a4db94011d3 16 * this list of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
sahilmgandhi 18:6a4db94011d3 18 * this list of conditions and the following disclaimer in the documentation
sahilmgandhi 18:6a4db94011d3 19 * and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
sahilmgandhi 18:6a4db94011d3 21 * may be used to endorse or promote products derived from this software
sahilmgandhi 18:6a4db94011d3 22 * without specific prior written permission.
sahilmgandhi 18:6a4db94011d3 23 *
sahilmgandhi 18:6a4db94011d3 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sahilmgandhi 18:6a4db94011d3 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sahilmgandhi 18:6a4db94011d3 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
sahilmgandhi 18:6a4db94011d3 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sahilmgandhi 18:6a4db94011d3 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sahilmgandhi 18:6a4db94011d3 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
sahilmgandhi 18:6a4db94011d3 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
sahilmgandhi 18:6a4db94011d3 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
sahilmgandhi 18:6a4db94011d3 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 34 *
sahilmgandhi 18:6a4db94011d3 35 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 36 */
sahilmgandhi 18:6a4db94011d3 37
sahilmgandhi 18:6a4db94011d3 38 /* Define to prevent recursive inclusion -------------------------------------*/
sahilmgandhi 18:6a4db94011d3 39 #ifndef __STM32F2xx_HAL_I2C_H
sahilmgandhi 18:6a4db94011d3 40 #define __STM32F2xx_HAL_I2C_H
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 43 extern "C" {
sahilmgandhi 18:6a4db94011d3 44 #endif
sahilmgandhi 18:6a4db94011d3 45
sahilmgandhi 18:6a4db94011d3 46 /* Includes ------------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 47 #include "stm32f2xx_hal_def.h"
sahilmgandhi 18:6a4db94011d3 48
sahilmgandhi 18:6a4db94011d3 49 /** @addtogroup STM32F2xx_HAL_Driver
sahilmgandhi 18:6a4db94011d3 50 * @{
sahilmgandhi 18:6a4db94011d3 51 */
sahilmgandhi 18:6a4db94011d3 52
sahilmgandhi 18:6a4db94011d3 53 /** @addtogroup I2C
sahilmgandhi 18:6a4db94011d3 54 * @{
sahilmgandhi 18:6a4db94011d3 55 */
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57 /* Exported types ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 58 /** @defgroup I2C_Exported_Types I2C Exported Types
sahilmgandhi 18:6a4db94011d3 59 * @{
sahilmgandhi 18:6a4db94011d3 60 */
sahilmgandhi 18:6a4db94011d3 61
sahilmgandhi 18:6a4db94011d3 62 /**
sahilmgandhi 18:6a4db94011d3 63 * @brief I2C Configuration Structure definition
sahilmgandhi 18:6a4db94011d3 64 */
sahilmgandhi 18:6a4db94011d3 65 typedef struct
sahilmgandhi 18:6a4db94011d3 66 {
sahilmgandhi 18:6a4db94011d3 67 uint32_t ClockSpeed; /*!< Specifies the clock frequency.
sahilmgandhi 18:6a4db94011d3 68 This parameter must be set to a value lower than 400kHz */
sahilmgandhi 18:6a4db94011d3 69
sahilmgandhi 18:6a4db94011d3 70 uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
sahilmgandhi 18:6a4db94011d3 71 This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
sahilmgandhi 18:6a4db94011d3 72
sahilmgandhi 18:6a4db94011d3 73 uint32_t OwnAddress1; /*!< Specifies the first device own address.
sahilmgandhi 18:6a4db94011d3 74 This parameter can be a 7-bit or 10-bit address. */
sahilmgandhi 18:6a4db94011d3 75
sahilmgandhi 18:6a4db94011d3 76 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
sahilmgandhi 18:6a4db94011d3 77 This parameter can be a value of @ref I2C_addressing_mode */
sahilmgandhi 18:6a4db94011d3 78
sahilmgandhi 18:6a4db94011d3 79 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
sahilmgandhi 18:6a4db94011d3 80 This parameter can be a value of @ref I2C_dual_addressing_mode */
sahilmgandhi 18:6a4db94011d3 81
sahilmgandhi 18:6a4db94011d3 82 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected
sahilmgandhi 18:6a4db94011d3 83 This parameter can be a 7-bit address. */
sahilmgandhi 18:6a4db94011d3 84
sahilmgandhi 18:6a4db94011d3 85 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
sahilmgandhi 18:6a4db94011d3 86 This parameter can be a value of @ref I2C_general_call_addressing_mode */
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
sahilmgandhi 18:6a4db94011d3 89 This parameter can be a value of @ref I2C_nostretch_mode */
sahilmgandhi 18:6a4db94011d3 90
sahilmgandhi 18:6a4db94011d3 91 }I2C_InitTypeDef;
sahilmgandhi 18:6a4db94011d3 92
sahilmgandhi 18:6a4db94011d3 93 /**
sahilmgandhi 18:6a4db94011d3 94 * @brief HAL State structure definition
sahilmgandhi 18:6a4db94011d3 95 * @note HAL I2C State value coding follow below described bitmap :
sahilmgandhi 18:6a4db94011d3 96 * b7-b6 Error information
sahilmgandhi 18:6a4db94011d3 97 * 00 : No Error
sahilmgandhi 18:6a4db94011d3 98 * 01 : Abort (Abort user request on going)
sahilmgandhi 18:6a4db94011d3 99 * 10 : Timeout
sahilmgandhi 18:6a4db94011d3 100 * 11 : Error
sahilmgandhi 18:6a4db94011d3 101 * b5 IP initilisation status
sahilmgandhi 18:6a4db94011d3 102 * 0 : Reset (IP not initialized)
sahilmgandhi 18:6a4db94011d3 103 * 1 : Init done (IP initialized and ready to use. HAL I2C Init function called)
sahilmgandhi 18:6a4db94011d3 104 * b4 (not used)
sahilmgandhi 18:6a4db94011d3 105 * x : Should be set to 0
sahilmgandhi 18:6a4db94011d3 106 * b3
sahilmgandhi 18:6a4db94011d3 107 * 0 : Ready or Busy (No Listen mode ongoing)
sahilmgandhi 18:6a4db94011d3 108 * 1 : Listen (IP in Address Listen Mode)
sahilmgandhi 18:6a4db94011d3 109 * b2 Intrinsic process state
sahilmgandhi 18:6a4db94011d3 110 * 0 : Ready
sahilmgandhi 18:6a4db94011d3 111 * 1 : Busy (IP busy with some configuration or internal operations)
sahilmgandhi 18:6a4db94011d3 112 * b1 Rx state
sahilmgandhi 18:6a4db94011d3 113 * 0 : Ready (no Rx operation ongoing)
sahilmgandhi 18:6a4db94011d3 114 * 1 : Busy (Rx operation ongoing)
sahilmgandhi 18:6a4db94011d3 115 * b0 Tx state
sahilmgandhi 18:6a4db94011d3 116 * 0 : Ready (no Tx operation ongoing)
sahilmgandhi 18:6a4db94011d3 117 * 1 : Busy (Tx operation ongoing)
sahilmgandhi 18:6a4db94011d3 118 */
sahilmgandhi 18:6a4db94011d3 119 typedef enum
sahilmgandhi 18:6a4db94011d3 120 {
sahilmgandhi 18:6a4db94011d3 121 HAL_I2C_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
sahilmgandhi 18:6a4db94011d3 122 HAL_I2C_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use */
sahilmgandhi 18:6a4db94011d3 123 HAL_I2C_STATE_BUSY = 0x24U, /*!< An internal process is ongoing */
sahilmgandhi 18:6a4db94011d3 124 HAL_I2C_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing */
sahilmgandhi 18:6a4db94011d3 125 HAL_I2C_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
sahilmgandhi 18:6a4db94011d3 126 HAL_I2C_STATE_LISTEN = 0x28U, /*!< Address Listen Mode is ongoing */
sahilmgandhi 18:6a4db94011d3 127 HAL_I2C_STATE_BUSY_TX_LISTEN = 0x29U, /*!< Address Listen Mode and Data Transmission
sahilmgandhi 18:6a4db94011d3 128 process is ongoing */
sahilmgandhi 18:6a4db94011d3 129 HAL_I2C_STATE_BUSY_RX_LISTEN = 0x2AU, /*!< Address Listen Mode and Data Reception
sahilmgandhi 18:6a4db94011d3 130 process is ongoing */
sahilmgandhi 18:6a4db94011d3 131 HAL_I2C_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */
sahilmgandhi 18:6a4db94011d3 132 HAL_I2C_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
sahilmgandhi 18:6a4db94011d3 133 HAL_I2C_STATE_ERROR = 0xE0U /*!< Error */
sahilmgandhi 18:6a4db94011d3 134
sahilmgandhi 18:6a4db94011d3 135 }HAL_I2C_StateTypeDef;
sahilmgandhi 18:6a4db94011d3 136
sahilmgandhi 18:6a4db94011d3 137 /**
sahilmgandhi 18:6a4db94011d3 138 * @brief HAL Mode structure definition
sahilmgandhi 18:6a4db94011d3 139 * @note HAL I2C Mode value coding follow below described bitmap :
sahilmgandhi 18:6a4db94011d3 140 * b7 (not used)
sahilmgandhi 18:6a4db94011d3 141 * x : Should be set to 0
sahilmgandhi 18:6a4db94011d3 142 * b6
sahilmgandhi 18:6a4db94011d3 143 * 0 : None
sahilmgandhi 18:6a4db94011d3 144 * 1 : Memory (HAL I2C communication is in Memory Mode)
sahilmgandhi 18:6a4db94011d3 145 * b5
sahilmgandhi 18:6a4db94011d3 146 * 0 : None
sahilmgandhi 18:6a4db94011d3 147 * 1 : Slave (HAL I2C communication is in Slave Mode)
sahilmgandhi 18:6a4db94011d3 148 * b4
sahilmgandhi 18:6a4db94011d3 149 * 0 : None
sahilmgandhi 18:6a4db94011d3 150 * 1 : Master (HAL I2C communication is in Master Mode)
sahilmgandhi 18:6a4db94011d3 151 * b3-b2-b1-b0 (not used)
sahilmgandhi 18:6a4db94011d3 152 * xxxx : Should be set to 0000
sahilmgandhi 18:6a4db94011d3 153 */
sahilmgandhi 18:6a4db94011d3 154 typedef enum
sahilmgandhi 18:6a4db94011d3 155 {
sahilmgandhi 18:6a4db94011d3 156 HAL_I2C_MODE_NONE = 0x00U, /*!< No I2C communication on going */
sahilmgandhi 18:6a4db94011d3 157 HAL_I2C_MODE_MASTER = 0x10U, /*!< I2C communication is in Master Mode */
sahilmgandhi 18:6a4db94011d3 158 HAL_I2C_MODE_SLAVE = 0x20U, /*!< I2C communication is in Slave Mode */
sahilmgandhi 18:6a4db94011d3 159 HAL_I2C_MODE_MEM = 0x40U /*!< I2C communication is in Memory Mode */
sahilmgandhi 18:6a4db94011d3 160
sahilmgandhi 18:6a4db94011d3 161 }HAL_I2C_ModeTypeDef;
sahilmgandhi 18:6a4db94011d3 162
sahilmgandhi 18:6a4db94011d3 163 /**
sahilmgandhi 18:6a4db94011d3 164 * @brief I2C handle Structure definition
sahilmgandhi 18:6a4db94011d3 165 */
sahilmgandhi 18:6a4db94011d3 166 typedef struct
sahilmgandhi 18:6a4db94011d3 167 {
sahilmgandhi 18:6a4db94011d3 168 I2C_TypeDef *Instance; /*!< I2C registers base address */
sahilmgandhi 18:6a4db94011d3 169
sahilmgandhi 18:6a4db94011d3 170 I2C_InitTypeDef Init; /*!< I2C communication parameters */
sahilmgandhi 18:6a4db94011d3 171
sahilmgandhi 18:6a4db94011d3 172 uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */
sahilmgandhi 18:6a4db94011d3 173
sahilmgandhi 18:6a4db94011d3 174 uint16_t XferSize; /*!< I2C transfer size */
sahilmgandhi 18:6a4db94011d3 175
sahilmgandhi 18:6a4db94011d3 176 __IO uint16_t XferCount; /*!< I2C transfer counter */
sahilmgandhi 18:6a4db94011d3 177
sahilmgandhi 18:6a4db94011d3 178 __IO uint32_t XferOptions; /*!< I2C transfer options */
sahilmgandhi 18:6a4db94011d3 179
sahilmgandhi 18:6a4db94011d3 180 __IO uint32_t PreviousState; /*!< I2C communication Previous state and mode
sahilmgandhi 18:6a4db94011d3 181 context for internal usage */
sahilmgandhi 18:6a4db94011d3 182
sahilmgandhi 18:6a4db94011d3 183 DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */
sahilmgandhi 18:6a4db94011d3 184
sahilmgandhi 18:6a4db94011d3 185 DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */
sahilmgandhi 18:6a4db94011d3 186
sahilmgandhi 18:6a4db94011d3 187 HAL_LockTypeDef Lock; /*!< I2C locking object */
sahilmgandhi 18:6a4db94011d3 188
sahilmgandhi 18:6a4db94011d3 189 __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */
sahilmgandhi 18:6a4db94011d3 190
sahilmgandhi 18:6a4db94011d3 191 __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */
sahilmgandhi 18:6a4db94011d3 192
sahilmgandhi 18:6a4db94011d3 193 __IO uint32_t ErrorCode; /*!< I2C Error code */
sahilmgandhi 18:6a4db94011d3 194
sahilmgandhi 18:6a4db94011d3 195 __IO uint32_t Devaddress; /*!< I2C Target device address */
sahilmgandhi 18:6a4db94011d3 196
sahilmgandhi 18:6a4db94011d3 197 __IO uint32_t Memaddress; /*!< I2C Target memory address */
sahilmgandhi 18:6a4db94011d3 198
sahilmgandhi 18:6a4db94011d3 199 __IO uint32_t MemaddSize; /*!< I2C Target memory address size */
sahilmgandhi 18:6a4db94011d3 200
sahilmgandhi 18:6a4db94011d3 201 __IO uint32_t EventCount; /*!< I2C Event counter */
sahilmgandhi 18:6a4db94011d3 202
sahilmgandhi 18:6a4db94011d3 203 }I2C_HandleTypeDef;
sahilmgandhi 18:6a4db94011d3 204 /**
sahilmgandhi 18:6a4db94011d3 205 * @}
sahilmgandhi 18:6a4db94011d3 206 */
sahilmgandhi 18:6a4db94011d3 207
sahilmgandhi 18:6a4db94011d3 208 /* Exported constants --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 209 /** @defgroup I2C_Exported_Constants I2C Exported Constants
sahilmgandhi 18:6a4db94011d3 210 * @{
sahilmgandhi 18:6a4db94011d3 211 */
sahilmgandhi 18:6a4db94011d3 212
sahilmgandhi 18:6a4db94011d3 213 /** @defgroup I2C_Error_Code I2C Error Code
sahilmgandhi 18:6a4db94011d3 214 * @brief I2C Error Code
sahilmgandhi 18:6a4db94011d3 215 * @{
sahilmgandhi 18:6a4db94011d3 216 */
sahilmgandhi 18:6a4db94011d3 217 #define HAL_I2C_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
sahilmgandhi 18:6a4db94011d3 218 #define HAL_I2C_ERROR_BERR ((uint32_t)0x00000001U) /*!< BERR error */
sahilmgandhi 18:6a4db94011d3 219 #define HAL_I2C_ERROR_ARLO ((uint32_t)0x00000002U) /*!< ARLO error */
sahilmgandhi 18:6a4db94011d3 220 #define HAL_I2C_ERROR_AF ((uint32_t)0x00000004U) /*!< AF error */
sahilmgandhi 18:6a4db94011d3 221 #define HAL_I2C_ERROR_OVR ((uint32_t)0x00000008U) /*!< OVR error */
sahilmgandhi 18:6a4db94011d3 222 #define HAL_I2C_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
sahilmgandhi 18:6a4db94011d3 223 #define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x00000020U) /*!< Timeout Error */
sahilmgandhi 18:6a4db94011d3 224 /**
sahilmgandhi 18:6a4db94011d3 225 * @}
sahilmgandhi 18:6a4db94011d3 226 */
sahilmgandhi 18:6a4db94011d3 227
sahilmgandhi 18:6a4db94011d3 228 /** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
sahilmgandhi 18:6a4db94011d3 229 * @{
sahilmgandhi 18:6a4db94011d3 230 */
sahilmgandhi 18:6a4db94011d3 231 #define I2C_DUTYCYCLE_2 ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 232 #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY
sahilmgandhi 18:6a4db94011d3 233 /**
sahilmgandhi 18:6a4db94011d3 234 * @}
sahilmgandhi 18:6a4db94011d3 235 */
sahilmgandhi 18:6a4db94011d3 236
sahilmgandhi 18:6a4db94011d3 237 /** @defgroup I2C_addressing_mode I2C addressing mode
sahilmgandhi 18:6a4db94011d3 238 * @{
sahilmgandhi 18:6a4db94011d3 239 */
sahilmgandhi 18:6a4db94011d3 240 #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00004000U)
sahilmgandhi 18:6a4db94011d3 241 #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | ((uint32_t)0x00004000U))
sahilmgandhi 18:6a4db94011d3 242 /**
sahilmgandhi 18:6a4db94011d3 243 * @}
sahilmgandhi 18:6a4db94011d3 244 */
sahilmgandhi 18:6a4db94011d3 245
sahilmgandhi 18:6a4db94011d3 246 /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode
sahilmgandhi 18:6a4db94011d3 247 * @{
sahilmgandhi 18:6a4db94011d3 248 */
sahilmgandhi 18:6a4db94011d3 249 #define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 250 #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL
sahilmgandhi 18:6a4db94011d3 251 /**
sahilmgandhi 18:6a4db94011d3 252 * @}
sahilmgandhi 18:6a4db94011d3 253 */
sahilmgandhi 18:6a4db94011d3 254
sahilmgandhi 18:6a4db94011d3 255 /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode
sahilmgandhi 18:6a4db94011d3 256 * @{
sahilmgandhi 18:6a4db94011d3 257 */
sahilmgandhi 18:6a4db94011d3 258 #define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 259 #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC
sahilmgandhi 18:6a4db94011d3 260 /**
sahilmgandhi 18:6a4db94011d3 261 * @}
sahilmgandhi 18:6a4db94011d3 262 */
sahilmgandhi 18:6a4db94011d3 263
sahilmgandhi 18:6a4db94011d3 264 /** @defgroup I2C_nostretch_mode I2C nostretch mode
sahilmgandhi 18:6a4db94011d3 265 * @{
sahilmgandhi 18:6a4db94011d3 266 */
sahilmgandhi 18:6a4db94011d3 267 #define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 268 #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
sahilmgandhi 18:6a4db94011d3 269 /**
sahilmgandhi 18:6a4db94011d3 270 * @}
sahilmgandhi 18:6a4db94011d3 271 */
sahilmgandhi 18:6a4db94011d3 272
sahilmgandhi 18:6a4db94011d3 273 /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size
sahilmgandhi 18:6a4db94011d3 274 * @{
sahilmgandhi 18:6a4db94011d3 275 */
sahilmgandhi 18:6a4db94011d3 276 #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001U)
sahilmgandhi 18:6a4db94011d3 277 #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000010U)
sahilmgandhi 18:6a4db94011d3 278 /**
sahilmgandhi 18:6a4db94011d3 279 * @}
sahilmgandhi 18:6a4db94011d3 280 */
sahilmgandhi 18:6a4db94011d3 281
sahilmgandhi 18:6a4db94011d3 282 /** @defgroup I2C_XferDirection_definition I2C XferDirection definition
sahilmgandhi 18:6a4db94011d3 283 * @{
sahilmgandhi 18:6a4db94011d3 284 */
sahilmgandhi 18:6a4db94011d3 285 #define I2C_DIRECTION_RECEIVE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 286 #define I2C_DIRECTION_TRANSMIT ((uint32_t)0x00000001U)
sahilmgandhi 18:6a4db94011d3 287 /**
sahilmgandhi 18:6a4db94011d3 288 * @}
sahilmgandhi 18:6a4db94011d3 289 */
sahilmgandhi 18:6a4db94011d3 290
sahilmgandhi 18:6a4db94011d3 291 /** @defgroup I2C_XferOptions_definition I2C XferOptions definition
sahilmgandhi 18:6a4db94011d3 292 * @{
sahilmgandhi 18:6a4db94011d3 293 */
sahilmgandhi 18:6a4db94011d3 294 #define I2C_FIRST_FRAME ((uint32_t)0x00000001U)
sahilmgandhi 18:6a4db94011d3 295 #define I2C_NEXT_FRAME ((uint32_t)0x00000002U)
sahilmgandhi 18:6a4db94011d3 296 #define I2C_FIRST_AND_LAST_FRAME ((uint32_t)0x00000004U)
sahilmgandhi 18:6a4db94011d3 297 #define I2C_LAST_FRAME ((uint32_t)0x00000008U)
sahilmgandhi 18:6a4db94011d3 298 /**
sahilmgandhi 18:6a4db94011d3 299 * @}
sahilmgandhi 18:6a4db94011d3 300 */
sahilmgandhi 18:6a4db94011d3 301
sahilmgandhi 18:6a4db94011d3 302
sahilmgandhi 18:6a4db94011d3 303 /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
sahilmgandhi 18:6a4db94011d3 304 * @{
sahilmgandhi 18:6a4db94011d3 305 */
sahilmgandhi 18:6a4db94011d3 306 #define I2C_IT_BUF I2C_CR2_ITBUFEN
sahilmgandhi 18:6a4db94011d3 307 #define I2C_IT_EVT I2C_CR2_ITEVTEN
sahilmgandhi 18:6a4db94011d3 308 #define I2C_IT_ERR I2C_CR2_ITERREN
sahilmgandhi 18:6a4db94011d3 309 /**
sahilmgandhi 18:6a4db94011d3 310 * @}
sahilmgandhi 18:6a4db94011d3 311 */
sahilmgandhi 18:6a4db94011d3 312
sahilmgandhi 18:6a4db94011d3 313 /** @defgroup I2C_Flag_definition I2C Flag definition
sahilmgandhi 18:6a4db94011d3 314 * @{
sahilmgandhi 18:6a4db94011d3 315 */
sahilmgandhi 18:6a4db94011d3 316 #define I2C_FLAG_SMBALERT ((uint32_t)0x00018000U)
sahilmgandhi 18:6a4db94011d3 317 #define I2C_FLAG_TIMEOUT ((uint32_t)0x00014000U)
sahilmgandhi 18:6a4db94011d3 318 #define I2C_FLAG_PECERR ((uint32_t)0x00011000U)
sahilmgandhi 18:6a4db94011d3 319 #define I2C_FLAG_OVR ((uint32_t)0x00010800U)
sahilmgandhi 18:6a4db94011d3 320 #define I2C_FLAG_AF ((uint32_t)0x00010400U)
sahilmgandhi 18:6a4db94011d3 321 #define I2C_FLAG_ARLO ((uint32_t)0x00010200U)
sahilmgandhi 18:6a4db94011d3 322 #define I2C_FLAG_BERR ((uint32_t)0x00010100U)
sahilmgandhi 18:6a4db94011d3 323 #define I2C_FLAG_TXE ((uint32_t)0x00010080U)
sahilmgandhi 18:6a4db94011d3 324 #define I2C_FLAG_RXNE ((uint32_t)0x00010040U)
sahilmgandhi 18:6a4db94011d3 325 #define I2C_FLAG_STOPF ((uint32_t)0x00010010U)
sahilmgandhi 18:6a4db94011d3 326 #define I2C_FLAG_ADD10 ((uint32_t)0x00010008U)
sahilmgandhi 18:6a4db94011d3 327 #define I2C_FLAG_BTF ((uint32_t)0x00010004U)
sahilmgandhi 18:6a4db94011d3 328 #define I2C_FLAG_ADDR ((uint32_t)0x00010002U)
sahilmgandhi 18:6a4db94011d3 329 #define I2C_FLAG_SB ((uint32_t)0x00010001U)
sahilmgandhi 18:6a4db94011d3 330 #define I2C_FLAG_DUALF ((uint32_t)0x00100080U)
sahilmgandhi 18:6a4db94011d3 331 #define I2C_FLAG_SMBHOST ((uint32_t)0x00100040U)
sahilmgandhi 18:6a4db94011d3 332 #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00100020U)
sahilmgandhi 18:6a4db94011d3 333 #define I2C_FLAG_GENCALL ((uint32_t)0x00100010U)
sahilmgandhi 18:6a4db94011d3 334 #define I2C_FLAG_TRA ((uint32_t)0x00100004U)
sahilmgandhi 18:6a4db94011d3 335 #define I2C_FLAG_BUSY ((uint32_t)0x00100002U)
sahilmgandhi 18:6a4db94011d3 336 #define I2C_FLAG_MSL ((uint32_t)0x00100001U)
sahilmgandhi 18:6a4db94011d3 337 /**
sahilmgandhi 18:6a4db94011d3 338 * @}
sahilmgandhi 18:6a4db94011d3 339 */
sahilmgandhi 18:6a4db94011d3 340
sahilmgandhi 18:6a4db94011d3 341 /**
sahilmgandhi 18:6a4db94011d3 342 * @}
sahilmgandhi 18:6a4db94011d3 343 */
sahilmgandhi 18:6a4db94011d3 344
sahilmgandhi 18:6a4db94011d3 345 /* Exported macro ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 346 /** @defgroup I2C_Exported_Macros I2C Exported Macros
sahilmgandhi 18:6a4db94011d3 347 * @{
sahilmgandhi 18:6a4db94011d3 348 */
sahilmgandhi 18:6a4db94011d3 349
sahilmgandhi 18:6a4db94011d3 350 /** @brief Reset I2C handle state
sahilmgandhi 18:6a4db94011d3 351 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 352 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 353 * @retval None
sahilmgandhi 18:6a4db94011d3 354 */
sahilmgandhi 18:6a4db94011d3 355 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
sahilmgandhi 18:6a4db94011d3 356
sahilmgandhi 18:6a4db94011d3 357 /** @brief Enable or disable the specified I2C interrupts.
sahilmgandhi 18:6a4db94011d3 358 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 359 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 360 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
sahilmgandhi 18:6a4db94011d3 361 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 362 * @arg I2C_IT_BUF: Buffer interrupt enable
sahilmgandhi 18:6a4db94011d3 363 * @arg I2C_IT_EVT: Event interrupt enable
sahilmgandhi 18:6a4db94011d3 364 * @arg I2C_IT_ERR: Error interrupt enable
sahilmgandhi 18:6a4db94011d3 365 * @retval None
sahilmgandhi 18:6a4db94011d3 366 */
sahilmgandhi 18:6a4db94011d3 367 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
sahilmgandhi 18:6a4db94011d3 368 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
sahilmgandhi 18:6a4db94011d3 369
sahilmgandhi 18:6a4db94011d3 370 /** @brief Checks if the specified I2C interrupt source is enabled or disabled.
sahilmgandhi 18:6a4db94011d3 371 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 372 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 373 * @param __INTERRUPT__: specifies the I2C interrupt source to check.
sahilmgandhi 18:6a4db94011d3 374 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 375 * @arg I2C_IT_BUF: Buffer interrupt enable
sahilmgandhi 18:6a4db94011d3 376 * @arg I2C_IT_EVT: Event interrupt enable
sahilmgandhi 18:6a4db94011d3 377 * @arg I2C_IT_ERR: Error interrupt enable
sahilmgandhi 18:6a4db94011d3 378 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
sahilmgandhi 18:6a4db94011d3 379 */
sahilmgandhi 18:6a4db94011d3 380 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
sahilmgandhi 18:6a4db94011d3 381
sahilmgandhi 18:6a4db94011d3 382 /** @brief Checks whether the specified I2C flag is set or not.
sahilmgandhi 18:6a4db94011d3 383 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 384 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 385 * @param __FLAG__: specifies the flag to check.
sahilmgandhi 18:6a4db94011d3 386 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 387 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
sahilmgandhi 18:6a4db94011d3 388 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
sahilmgandhi 18:6a4db94011d3 389 * @arg I2C_FLAG_PECERR: PEC error in reception flag
sahilmgandhi 18:6a4db94011d3 390 * @arg I2C_FLAG_OVR: Overrun/Underrun flag
sahilmgandhi 18:6a4db94011d3 391 * @arg I2C_FLAG_AF: Acknowledge failure flag
sahilmgandhi 18:6a4db94011d3 392 * @arg I2C_FLAG_ARLO: Arbitration lost flag
sahilmgandhi 18:6a4db94011d3 393 * @arg I2C_FLAG_BERR: Bus error flag
sahilmgandhi 18:6a4db94011d3 394 * @arg I2C_FLAG_TXE: Data register empty flag
sahilmgandhi 18:6a4db94011d3 395 * @arg I2C_FLAG_RXNE: Data register not empty flag
sahilmgandhi 18:6a4db94011d3 396 * @arg I2C_FLAG_STOPF: Stop detection flag
sahilmgandhi 18:6a4db94011d3 397 * @arg I2C_FLAG_ADD10: 10-bit header sent flag
sahilmgandhi 18:6a4db94011d3 398 * @arg I2C_FLAG_BTF: Byte transfer finished flag
sahilmgandhi 18:6a4db94011d3 399 * @arg I2C_FLAG_ADDR: Address sent flag
sahilmgandhi 18:6a4db94011d3 400 * Address matched flag
sahilmgandhi 18:6a4db94011d3 401 * @arg I2C_FLAG_SB: Start bit flag
sahilmgandhi 18:6a4db94011d3 402 * @arg I2C_FLAG_DUALF: Dual flag
sahilmgandhi 18:6a4db94011d3 403 * @arg I2C_FLAG_SMBHOST: SMBus host header
sahilmgandhi 18:6a4db94011d3 404 * @arg I2C_FLAG_SMBDEFAULT: SMBus default header
sahilmgandhi 18:6a4db94011d3 405 * @arg I2C_FLAG_GENCALL: General call header flag
sahilmgandhi 18:6a4db94011d3 406 * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
sahilmgandhi 18:6a4db94011d3 407 * @arg I2C_FLAG_BUSY: Bus busy flag
sahilmgandhi 18:6a4db94011d3 408 * @arg I2C_FLAG_MSL: Master/Slave flag
sahilmgandhi 18:6a4db94011d3 409 * @retval The new state of __FLAG__ (TRUE or FALSE).
sahilmgandhi 18:6a4db94011d3 410 */
sahilmgandhi 18:6a4db94011d3 411 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \
sahilmgandhi 18:6a4db94011d3 412 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
sahilmgandhi 18:6a4db94011d3 413
sahilmgandhi 18:6a4db94011d3 414 /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
sahilmgandhi 18:6a4db94011d3 415 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 416 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 417 * @param __FLAG__: specifies the flag to clear.
sahilmgandhi 18:6a4db94011d3 418 * This parameter can be any combination of the following values:
sahilmgandhi 18:6a4db94011d3 419 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
sahilmgandhi 18:6a4db94011d3 420 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
sahilmgandhi 18:6a4db94011d3 421 * @arg I2C_FLAG_PECERR: PEC error in reception flag
sahilmgandhi 18:6a4db94011d3 422 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
sahilmgandhi 18:6a4db94011d3 423 * @arg I2C_FLAG_AF: Acknowledge failure flag
sahilmgandhi 18:6a4db94011d3 424 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
sahilmgandhi 18:6a4db94011d3 425 * @arg I2C_FLAG_BERR: Bus error flag
sahilmgandhi 18:6a4db94011d3 426 * @retval None
sahilmgandhi 18:6a4db94011d3 427 */
sahilmgandhi 18:6a4db94011d3 428 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
sahilmgandhi 18:6a4db94011d3 429
sahilmgandhi 18:6a4db94011d3 430 /** @brief Clears the I2C ADDR pending flag.
sahilmgandhi 18:6a4db94011d3 431 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 432 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 433 * @retval None
sahilmgandhi 18:6a4db94011d3 434 */
sahilmgandhi 18:6a4db94011d3 435 #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \
sahilmgandhi 18:6a4db94011d3 436 do{ \
sahilmgandhi 18:6a4db94011d3 437 __IO uint32_t tmpreg_addr = 0x00U; \
sahilmgandhi 18:6a4db94011d3 438 tmpreg_addr = (__HANDLE__)->Instance->SR1; \
sahilmgandhi 18:6a4db94011d3 439 tmpreg_addr = (__HANDLE__)->Instance->SR2; \
sahilmgandhi 18:6a4db94011d3 440 UNUSED(tmpreg_addr); \
sahilmgandhi 18:6a4db94011d3 441 } while(0)
sahilmgandhi 18:6a4db94011d3 442
sahilmgandhi 18:6a4db94011d3 443 /** @brief Clears the I2C STOPF pending flag.
sahilmgandhi 18:6a4db94011d3 444 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 445 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 446 * @retval None
sahilmgandhi 18:6a4db94011d3 447 */
sahilmgandhi 18:6a4db94011d3 448 #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \
sahilmgandhi 18:6a4db94011d3 449 do{ \
sahilmgandhi 18:6a4db94011d3 450 __IO uint32_t tmpreg_stop = 0x00U; \
sahilmgandhi 18:6a4db94011d3 451 tmpreg_stop = (__HANDLE__)->Instance->SR1; \
sahilmgandhi 18:6a4db94011d3 452 (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \
sahilmgandhi 18:6a4db94011d3 453 UNUSED(tmpreg_stop); \
sahilmgandhi 18:6a4db94011d3 454 } while(0)
sahilmgandhi 18:6a4db94011d3 455
sahilmgandhi 18:6a4db94011d3 456 /** @brief Enable the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 457 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 458 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 459 * @retval None
sahilmgandhi 18:6a4db94011d3 460 */
sahilmgandhi 18:6a4db94011d3 461 #define __HAL_I2C_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
sahilmgandhi 18:6a4db94011d3 462
sahilmgandhi 18:6a4db94011d3 463 /** @brief Disable the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 464 * @param __HANDLE__: specifies the I2C Handle.
sahilmgandhi 18:6a4db94011d3 465 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
sahilmgandhi 18:6a4db94011d3 466 * @retval None
sahilmgandhi 18:6a4db94011d3 467 */
sahilmgandhi 18:6a4db94011d3 468 #define __HAL_I2C_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
sahilmgandhi 18:6a4db94011d3 469
sahilmgandhi 18:6a4db94011d3 470 /**
sahilmgandhi 18:6a4db94011d3 471 * @}
sahilmgandhi 18:6a4db94011d3 472 */
sahilmgandhi 18:6a4db94011d3 473
sahilmgandhi 18:6a4db94011d3 474 /* Exported functions --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 475 /** @addtogroup I2C_Exported_Functions
sahilmgandhi 18:6a4db94011d3 476 * @{
sahilmgandhi 18:6a4db94011d3 477 */
sahilmgandhi 18:6a4db94011d3 478
sahilmgandhi 18:6a4db94011d3 479 /** @addtogroup I2C_Exported_Functions_Group1
sahilmgandhi 18:6a4db94011d3 480 * @{
sahilmgandhi 18:6a4db94011d3 481 */
sahilmgandhi 18:6a4db94011d3 482 /* Initialization/de-initialization functions **********************************/
sahilmgandhi 18:6a4db94011d3 483 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 484 HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 485 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 486 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 487 /**
sahilmgandhi 18:6a4db94011d3 488 * @}
sahilmgandhi 18:6a4db94011d3 489 */
sahilmgandhi 18:6a4db94011d3 490
sahilmgandhi 18:6a4db94011d3 491 /** @addtogroup I2C_Exported_Functions_Group2
sahilmgandhi 18:6a4db94011d3 492 * @{
sahilmgandhi 18:6a4db94011d3 493 */
sahilmgandhi 18:6a4db94011d3 494 /* I/O operation functions *****************************************************/
sahilmgandhi 18:6a4db94011d3 495 /******* Blocking mode: Polling */
sahilmgandhi 18:6a4db94011d3 496 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 497 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 498 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 499 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 500 HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 501 HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 502 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 503
sahilmgandhi 18:6a4db94011d3 504 /******* Non-Blocking mode: Interrupt */
sahilmgandhi 18:6a4db94011d3 505 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 506 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 507 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 508 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 509 HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 510 HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 511
sahilmgandhi 18:6a4db94011d3 512 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
sahilmgandhi 18:6a4db94011d3 513 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
sahilmgandhi 18:6a4db94011d3 514 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
sahilmgandhi 18:6a4db94011d3 515 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
sahilmgandhi 18:6a4db94011d3 516 HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
sahilmgandhi 18:6a4db94011d3 517 HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 518 HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 519
sahilmgandhi 18:6a4db94011d3 520 /******* Non-Blocking mode: DMA */
sahilmgandhi 18:6a4db94011d3 521 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 522 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 523 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 524 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 525 HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 526 HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 527
sahilmgandhi 18:6a4db94011d3 528 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
sahilmgandhi 18:6a4db94011d3 529 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 530 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 531 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 532 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 533 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 534 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 535 void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode);
sahilmgandhi 18:6a4db94011d3 536 void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 537 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 538 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 539 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 540 void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 541 /**
sahilmgandhi 18:6a4db94011d3 542 * @}
sahilmgandhi 18:6a4db94011d3 543 */
sahilmgandhi 18:6a4db94011d3 544
sahilmgandhi 18:6a4db94011d3 545 /** @addtogroup I2C_Exported_Functions_Group3
sahilmgandhi 18:6a4db94011d3 546 * @{
sahilmgandhi 18:6a4db94011d3 547 */
sahilmgandhi 18:6a4db94011d3 548 /* Peripheral State, Mode and Errors functions *********************************/
sahilmgandhi 18:6a4db94011d3 549 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 550 HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 551 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
sahilmgandhi 18:6a4db94011d3 552
sahilmgandhi 18:6a4db94011d3 553 /**
sahilmgandhi 18:6a4db94011d3 554 * @}
sahilmgandhi 18:6a4db94011d3 555 */
sahilmgandhi 18:6a4db94011d3 556
sahilmgandhi 18:6a4db94011d3 557 /**
sahilmgandhi 18:6a4db94011d3 558 * @}
sahilmgandhi 18:6a4db94011d3 559 */
sahilmgandhi 18:6a4db94011d3 560 /* Private types -------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 561 /* Private variables ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 562 /* Private constants ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 563 /** @defgroup I2C_Private_Constants I2C Private Constants
sahilmgandhi 18:6a4db94011d3 564 * @{
sahilmgandhi 18:6a4db94011d3 565 */
sahilmgandhi 18:6a4db94011d3 566 #define I2C_FLAG_MASK ((uint32_t)0x0000FFFFU)
sahilmgandhi 18:6a4db94011d3 567 /**
sahilmgandhi 18:6a4db94011d3 568 * @}
sahilmgandhi 18:6a4db94011d3 569 */
sahilmgandhi 18:6a4db94011d3 570
sahilmgandhi 18:6a4db94011d3 571 /* Private macros ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 572 /** @defgroup I2C_Private_Macros I2C Private Macros
sahilmgandhi 18:6a4db94011d3 573 * @{
sahilmgandhi 18:6a4db94011d3 574 */
sahilmgandhi 18:6a4db94011d3 575
sahilmgandhi 18:6a4db94011d3 576 #define I2C_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U)
sahilmgandhi 18:6a4db94011d3 577 #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= 100000U) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
sahilmgandhi 18:6a4db94011d3 578 #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
sahilmgandhi 18:6a4db94011d3 579 #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3U)) : (((__PCLK__) / ((__SPEED__) * 25U)) | I2C_DUTYCYCLE_16_9))
sahilmgandhi 18:6a4db94011d3 580 #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
sahilmgandhi 18:6a4db94011d3 581 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
sahilmgandhi 18:6a4db94011d3 582 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
sahilmgandhi 18:6a4db94011d3 583
sahilmgandhi 18:6a4db94011d3 584 #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
sahilmgandhi 18:6a4db94011d3 585 #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
sahilmgandhi 18:6a4db94011d3 586
sahilmgandhi 18:6a4db94011d3 587 #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
sahilmgandhi 18:6a4db94011d3 588 #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0xF0U))))
sahilmgandhi 18:6a4db94011d3 589 #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0xF1U))))
sahilmgandhi 18:6a4db94011d3 590
sahilmgandhi 18:6a4db94011d3 591 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
sahilmgandhi 18:6a4db94011d3 592 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
sahilmgandhi 18:6a4db94011d3 593
sahilmgandhi 18:6a4db94011d3 594 /** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
sahilmgandhi 18:6a4db94011d3 595 * @{
sahilmgandhi 18:6a4db94011d3 596 */
sahilmgandhi 18:6a4db94011d3 597 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
sahilmgandhi 18:6a4db94011d3 598 ((CYCLE) == I2C_DUTYCYCLE_16_9))
sahilmgandhi 18:6a4db94011d3 599 #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \
sahilmgandhi 18:6a4db94011d3 600 ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT))
sahilmgandhi 18:6a4db94011d3 601 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
sahilmgandhi 18:6a4db94011d3 602 ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
sahilmgandhi 18:6a4db94011d3 603 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
sahilmgandhi 18:6a4db94011d3 604 ((CALL) == I2C_GENERALCALL_ENABLE))
sahilmgandhi 18:6a4db94011d3 605 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
sahilmgandhi 18:6a4db94011d3 606 ((STRETCH) == I2C_NOSTRETCH_ENABLE))
sahilmgandhi 18:6a4db94011d3 607 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
sahilmgandhi 18:6a4db94011d3 608 ((SIZE) == I2C_MEMADD_SIZE_16BIT))
sahilmgandhi 18:6a4db94011d3 609 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 400000U))
sahilmgandhi 18:6a4db94011d3 610 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00U)) == 0U)
sahilmgandhi 18:6a4db94011d3 611 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01U)) == 0U)
sahilmgandhi 18:6a4db94011d3 612 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_FIRST_FRAME) || \
sahilmgandhi 18:6a4db94011d3 613 ((REQUEST) == I2C_NEXT_FRAME) || \
sahilmgandhi 18:6a4db94011d3 614 ((REQUEST) == I2C_FIRST_AND_LAST_FRAME) || \
sahilmgandhi 18:6a4db94011d3 615 ((REQUEST) == I2C_LAST_FRAME))
sahilmgandhi 18:6a4db94011d3 616 /**
sahilmgandhi 18:6a4db94011d3 617 * @}
sahilmgandhi 18:6a4db94011d3 618 */
sahilmgandhi 18:6a4db94011d3 619
sahilmgandhi 18:6a4db94011d3 620 /**
sahilmgandhi 18:6a4db94011d3 621 * @}
sahilmgandhi 18:6a4db94011d3 622 */
sahilmgandhi 18:6a4db94011d3 623
sahilmgandhi 18:6a4db94011d3 624 /* Private functions ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 625 /** @defgroup I2C_Private_Functions I2C Private Functions
sahilmgandhi 18:6a4db94011d3 626 * @{
sahilmgandhi 18:6a4db94011d3 627 */
sahilmgandhi 18:6a4db94011d3 628
sahilmgandhi 18:6a4db94011d3 629 /**
sahilmgandhi 18:6a4db94011d3 630 * @}
sahilmgandhi 18:6a4db94011d3 631 */
sahilmgandhi 18:6a4db94011d3 632
sahilmgandhi 18:6a4db94011d3 633 /**
sahilmgandhi 18:6a4db94011d3 634 * @}
sahilmgandhi 18:6a4db94011d3 635 */
sahilmgandhi 18:6a4db94011d3 636
sahilmgandhi 18:6a4db94011d3 637 /**
sahilmgandhi 18:6a4db94011d3 638 * @}
sahilmgandhi 18:6a4db94011d3 639 */
sahilmgandhi 18:6a4db94011d3 640
sahilmgandhi 18:6a4db94011d3 641 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 642 }
sahilmgandhi 18:6a4db94011d3 643 #endif
sahilmgandhi 18:6a4db94011d3 644
sahilmgandhi 18:6a4db94011d3 645
sahilmgandhi 18:6a4db94011d3 646 #endif /* __STM32F2xx_HAL_I2C_H */
sahilmgandhi 18:6a4db94011d3 647
sahilmgandhi 18:6a4db94011d3 648 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/