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