Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.
Dependents: 1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB
Fork of mbed by
TARGET_NUCLEO_F103RB/stm32f1xx_hal_i2c.h@121:672067c3ada4, 2016-04-14 (annotated)
- Committer:
- elijahorr
- Date:
- Thu Apr 14 07:28:54 2016 +0000
- Revision:
- 121:672067c3ada4
- Parent:
- 96:487b796308b0
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 96:487b796308b0 | 1 | /** |
Kojto | 96:487b796308b0 | 2 | ****************************************************************************** |
Kojto | 96:487b796308b0 | 3 | * @file stm32f1xx_hal_i2c.h |
Kojto | 96:487b796308b0 | 4 | * @author MCD Application Team |
Kojto | 96:487b796308b0 | 5 | * @version V1.0.0 |
Kojto | 96:487b796308b0 | 6 | * @date 15-December-2014 |
Kojto | 96:487b796308b0 | 7 | * @brief Header file of I2C HAL module. |
Kojto | 96:487b796308b0 | 8 | ****************************************************************************** |
Kojto | 96:487b796308b0 | 9 | * @attention |
Kojto | 96:487b796308b0 | 10 | * |
Kojto | 96:487b796308b0 | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
Kojto | 96:487b796308b0 | 12 | * |
Kojto | 96:487b796308b0 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 96:487b796308b0 | 14 | * are permitted provided that the following conditions are met: |
Kojto | 96:487b796308b0 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
Kojto | 96:487b796308b0 | 16 | * this list of conditions and the following disclaimer. |
Kojto | 96:487b796308b0 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Kojto | 96:487b796308b0 | 18 | * this list of conditions and the following disclaimer in the documentation |
Kojto | 96:487b796308b0 | 19 | * and/or other materials provided with the distribution. |
Kojto | 96:487b796308b0 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Kojto | 96:487b796308b0 | 21 | * may be used to endorse or promote products derived from this software |
Kojto | 96:487b796308b0 | 22 | * without specific prior written permission. |
Kojto | 96:487b796308b0 | 23 | * |
Kojto | 96:487b796308b0 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Kojto | 96:487b796308b0 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Kojto | 96:487b796308b0 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 96:487b796308b0 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Kojto | 96:487b796308b0 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Kojto | 96:487b796308b0 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Kojto | 96:487b796308b0 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Kojto | 96:487b796308b0 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Kojto | 96:487b796308b0 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Kojto | 96:487b796308b0 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 96:487b796308b0 | 34 | * |
Kojto | 96:487b796308b0 | 35 | ****************************************************************************** |
Kojto | 96:487b796308b0 | 36 | */ |
Kojto | 96:487b796308b0 | 37 | |
Kojto | 96:487b796308b0 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Kojto | 96:487b796308b0 | 39 | #ifndef __STM32F1xx_HAL_I2C_H |
Kojto | 96:487b796308b0 | 40 | #define __STM32F1xx_HAL_I2C_H |
Kojto | 96:487b796308b0 | 41 | |
Kojto | 96:487b796308b0 | 42 | #ifdef __cplusplus |
Kojto | 96:487b796308b0 | 43 | extern "C" { |
Kojto | 96:487b796308b0 | 44 | #endif |
Kojto | 96:487b796308b0 | 45 | |
Kojto | 96:487b796308b0 | 46 | /* Includes ------------------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 47 | #include "stm32f1xx_hal_def.h" |
Kojto | 96:487b796308b0 | 48 | |
Kojto | 96:487b796308b0 | 49 | /** @addtogroup STM32F1xx_HAL_Driver |
Kojto | 96:487b796308b0 | 50 | * @{ |
Kojto | 96:487b796308b0 | 51 | */ |
Kojto | 96:487b796308b0 | 52 | |
Kojto | 96:487b796308b0 | 53 | /** @addtogroup I2C |
Kojto | 96:487b796308b0 | 54 | * @{ |
Kojto | 96:487b796308b0 | 55 | */ |
Kojto | 96:487b796308b0 | 56 | |
Kojto | 96:487b796308b0 | 57 | /* Exported types ------------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 58 | /** @defgroup I2C_Exported_Types I2C Exported Types |
Kojto | 96:487b796308b0 | 59 | * @{ |
Kojto | 96:487b796308b0 | 60 | */ |
Kojto | 96:487b796308b0 | 61 | |
Kojto | 96:487b796308b0 | 62 | /** @defgroup I2C_Configuration_Structure_definition I2C Configuration Structure definition |
Kojto | 96:487b796308b0 | 63 | * @brief I2C Configuration Structure definition |
Kojto | 96:487b796308b0 | 64 | * @{ |
Kojto | 96:487b796308b0 | 65 | */ |
Kojto | 96:487b796308b0 | 66 | typedef struct |
Kojto | 96:487b796308b0 | 67 | { |
Kojto | 96:487b796308b0 | 68 | uint32_t ClockSpeed; /*!< Specifies the clock frequency. |
Kojto | 96:487b796308b0 | 69 | This parameter must be set to a value lower than 400kHz */ |
Kojto | 96:487b796308b0 | 70 | |
Kojto | 96:487b796308b0 | 71 | uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle. |
Kojto | 96:487b796308b0 | 72 | This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */ |
Kojto | 96:487b796308b0 | 73 | |
Kojto | 96:487b796308b0 | 74 | uint32_t OwnAddress1; /*!< Specifies the first device own address. |
Kojto | 96:487b796308b0 | 75 | This parameter can be a 7-bit or 10-bit address. */ |
Kojto | 96:487b796308b0 | 76 | |
Kojto | 96:487b796308b0 | 77 | uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected. |
Kojto | 96:487b796308b0 | 78 | This parameter can be a value of @ref I2C_addressing_mode */ |
Kojto | 96:487b796308b0 | 79 | |
Kojto | 96:487b796308b0 | 80 | uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected. |
Kojto | 96:487b796308b0 | 81 | This parameter can be a value of @ref I2C_dual_addressing_mode */ |
Kojto | 96:487b796308b0 | 82 | |
Kojto | 96:487b796308b0 | 83 | uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected |
Kojto | 96:487b796308b0 | 84 | This parameter can be a 7-bit address. */ |
Kojto | 96:487b796308b0 | 85 | |
Kojto | 96:487b796308b0 | 86 | uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected. |
Kojto | 96:487b796308b0 | 87 | This parameter can be a value of @ref I2C_general_call_addressing_mode */ |
Kojto | 96:487b796308b0 | 88 | |
Kojto | 96:487b796308b0 | 89 | uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected. |
Kojto | 96:487b796308b0 | 90 | This parameter can be a value of @ref I2C_nostretch_mode */ |
Kojto | 96:487b796308b0 | 91 | |
Kojto | 96:487b796308b0 | 92 | }I2C_InitTypeDef; |
Kojto | 96:487b796308b0 | 93 | |
Kojto | 96:487b796308b0 | 94 | /** |
Kojto | 96:487b796308b0 | 95 | * @} |
Kojto | 96:487b796308b0 | 96 | */ |
Kojto | 96:487b796308b0 | 97 | |
Kojto | 96:487b796308b0 | 98 | /** @defgroup HAL_state_structure_definition HAL state structure definition |
Kojto | 96:487b796308b0 | 99 | * @brief HAL State structure definition |
Kojto | 96:487b796308b0 | 100 | * @{ |
Kojto | 96:487b796308b0 | 101 | */ |
Kojto | 96:487b796308b0 | 102 | |
Kojto | 96:487b796308b0 | 103 | typedef enum |
Kojto | 96:487b796308b0 | 104 | { |
Kojto | 96:487b796308b0 | 105 | HAL_I2C_STATE_RESET = 0x00, /*!< I2C not yet initialized or disabled */ |
Kojto | 96:487b796308b0 | 106 | HAL_I2C_STATE_READY = 0x01, /*!< I2C initialized and ready for use */ |
Kojto | 96:487b796308b0 | 107 | HAL_I2C_STATE_BUSY = 0x02, /*!< I2C internal process is ongoing */ |
Kojto | 96:487b796308b0 | 108 | HAL_I2C_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */ |
Kojto | 96:487b796308b0 | 109 | HAL_I2C_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ |
Kojto | 96:487b796308b0 | 110 | HAL_I2C_STATE_MEM_BUSY_TX = 0x32, /*!< Memory Data Transmission process is ongoing */ |
Kojto | 96:487b796308b0 | 111 | HAL_I2C_STATE_MEM_BUSY_RX = 0x42, /*!< Memory Data Reception process is ongoing */ |
Kojto | 96:487b796308b0 | 112 | HAL_I2C_STATE_TIMEOUT = 0x03, /*!< I2C timeout state */ |
Kojto | 96:487b796308b0 | 113 | HAL_I2C_STATE_ERROR = 0x04 /*!< I2C error state */ |
Kojto | 96:487b796308b0 | 114 | |
Kojto | 96:487b796308b0 | 115 | }HAL_I2C_StateTypeDef; |
Kojto | 96:487b796308b0 | 116 | |
Kojto | 96:487b796308b0 | 117 | /** |
Kojto | 96:487b796308b0 | 118 | * @} |
Kojto | 96:487b796308b0 | 119 | */ |
Kojto | 96:487b796308b0 | 120 | |
Kojto | 96:487b796308b0 | 121 | /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition |
Kojto | 96:487b796308b0 | 122 | * @brief I2C handle Structure definition |
Kojto | 96:487b796308b0 | 123 | * @{ |
Kojto | 96:487b796308b0 | 124 | */ |
Kojto | 96:487b796308b0 | 125 | typedef struct |
Kojto | 96:487b796308b0 | 126 | { |
Kojto | 96:487b796308b0 | 127 | I2C_TypeDef *Instance; /*!< I2C registers base address */ |
Kojto | 96:487b796308b0 | 128 | |
Kojto | 96:487b796308b0 | 129 | I2C_InitTypeDef Init; /*!< I2C communication parameters */ |
Kojto | 96:487b796308b0 | 130 | |
Kojto | 96:487b796308b0 | 131 | uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */ |
Kojto | 96:487b796308b0 | 132 | |
Kojto | 96:487b796308b0 | 133 | uint16_t XferSize; /*!< I2C transfer size */ |
Kojto | 96:487b796308b0 | 134 | |
Kojto | 96:487b796308b0 | 135 | __IO uint16_t XferCount; /*!< I2C transfer counter */ |
Kojto | 96:487b796308b0 | 136 | |
Kojto | 96:487b796308b0 | 137 | DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */ |
Kojto | 96:487b796308b0 | 138 | |
Kojto | 96:487b796308b0 | 139 | DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */ |
Kojto | 96:487b796308b0 | 140 | |
Kojto | 96:487b796308b0 | 141 | HAL_LockTypeDef Lock; /*!< I2C locking object */ |
Kojto | 96:487b796308b0 | 142 | |
Kojto | 96:487b796308b0 | 143 | __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ |
Kojto | 96:487b796308b0 | 144 | |
Kojto | 96:487b796308b0 | 145 | __IO uint32_t ErrorCode; /* I2C Error code */ |
Kojto | 96:487b796308b0 | 146 | |
Kojto | 96:487b796308b0 | 147 | }I2C_HandleTypeDef; |
Kojto | 96:487b796308b0 | 148 | /** |
Kojto | 96:487b796308b0 | 149 | * @} |
Kojto | 96:487b796308b0 | 150 | */ |
Kojto | 96:487b796308b0 | 151 | |
Kojto | 96:487b796308b0 | 152 | /** |
Kojto | 96:487b796308b0 | 153 | * @} |
Kojto | 96:487b796308b0 | 154 | */ |
Kojto | 96:487b796308b0 | 155 | /* Exported constants --------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 156 | |
Kojto | 96:487b796308b0 | 157 | /** @defgroup I2C_Exported_Constants I2C Exported Constants |
Kojto | 96:487b796308b0 | 158 | * @{ |
Kojto | 96:487b796308b0 | 159 | */ |
Kojto | 96:487b796308b0 | 160 | |
Kojto | 96:487b796308b0 | 161 | /** @defgroup I2C_Error_Codes I2C Error Codes |
Kojto | 96:487b796308b0 | 162 | * @{ |
Kojto | 96:487b796308b0 | 163 | */ |
Kojto | 96:487b796308b0 | 164 | |
Kojto | 96:487b796308b0 | 165 | #define HAL_I2C_ERROR_NONE ((uint32_t)0x00) /*!< No error */ |
Kojto | 96:487b796308b0 | 166 | #define HAL_I2C_ERROR_BERR ((uint32_t)0x01) /*!< BERR error */ |
Kojto | 96:487b796308b0 | 167 | #define HAL_I2C_ERROR_ARLO ((uint32_t)0x02) /*!< ARLO error */ |
Kojto | 96:487b796308b0 | 168 | #define HAL_I2C_ERROR_AF ((uint32_t)0x04) /*!< AF error */ |
Kojto | 96:487b796308b0 | 169 | #define HAL_I2C_ERROR_OVR ((uint32_t)0x08) /*!< OVR error */ |
Kojto | 96:487b796308b0 | 170 | #define HAL_I2C_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */ |
Kojto | 96:487b796308b0 | 171 | #define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x20) /*!< Timeout error */ |
Kojto | 96:487b796308b0 | 172 | |
Kojto | 96:487b796308b0 | 173 | /** |
Kojto | 96:487b796308b0 | 174 | * @} |
Kojto | 96:487b796308b0 | 175 | */ |
Kojto | 96:487b796308b0 | 176 | |
Kojto | 96:487b796308b0 | 177 | |
Kojto | 96:487b796308b0 | 178 | |
Kojto | 96:487b796308b0 | 179 | /** @defgroup I2C_duty_cycle_in_fast_mode I2C Duty Cycle |
Kojto | 96:487b796308b0 | 180 | * @{ |
Kojto | 96:487b796308b0 | 181 | */ |
Kojto | 96:487b796308b0 | 182 | #define I2C_DUTYCYCLE_2 ((uint32_t)0x00000000) |
Kojto | 96:487b796308b0 | 183 | #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY |
Kojto | 96:487b796308b0 | 184 | /** |
Kojto | 96:487b796308b0 | 185 | * @} |
Kojto | 96:487b796308b0 | 186 | */ |
Kojto | 96:487b796308b0 | 187 | |
Kojto | 96:487b796308b0 | 188 | /** @defgroup I2C_addressing_mode I2C addressing mode |
Kojto | 96:487b796308b0 | 189 | * @{ |
Kojto | 96:487b796308b0 | 190 | */ |
Kojto | 96:487b796308b0 | 191 | #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00004000) |
Kojto | 96:487b796308b0 | 192 | #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | ((uint32_t)0x00004000)) |
Kojto | 96:487b796308b0 | 193 | /** |
Kojto | 96:487b796308b0 | 194 | * @} |
Kojto | 96:487b796308b0 | 195 | */ |
Kojto | 96:487b796308b0 | 196 | |
Kojto | 96:487b796308b0 | 197 | /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode |
Kojto | 96:487b796308b0 | 198 | * @{ |
Kojto | 96:487b796308b0 | 199 | */ |
Kojto | 96:487b796308b0 | 200 | #define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000) |
Kojto | 96:487b796308b0 | 201 | #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL |
Kojto | 96:487b796308b0 | 202 | /** |
Kojto | 96:487b796308b0 | 203 | * @} |
Kojto | 96:487b796308b0 | 204 | */ |
Kojto | 96:487b796308b0 | 205 | |
Kojto | 96:487b796308b0 | 206 | /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode |
Kojto | 96:487b796308b0 | 207 | * @{ |
Kojto | 96:487b796308b0 | 208 | */ |
Kojto | 96:487b796308b0 | 209 | #define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000) |
Kojto | 96:487b796308b0 | 210 | #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC |
Kojto | 96:487b796308b0 | 211 | /** |
Kojto | 96:487b796308b0 | 212 | * @} |
Kojto | 96:487b796308b0 | 213 | */ |
Kojto | 96:487b796308b0 | 214 | |
Kojto | 96:487b796308b0 | 215 | /** @defgroup I2C_nostretch_mode I2C nostretch mode |
Kojto | 96:487b796308b0 | 216 | * @{ |
Kojto | 96:487b796308b0 | 217 | */ |
Kojto | 96:487b796308b0 | 218 | #define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000) |
Kojto | 96:487b796308b0 | 219 | #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH |
Kojto | 96:487b796308b0 | 220 | /** |
Kojto | 96:487b796308b0 | 221 | * @} |
Kojto | 96:487b796308b0 | 222 | */ |
Kojto | 96:487b796308b0 | 223 | |
Kojto | 96:487b796308b0 | 224 | /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size |
Kojto | 96:487b796308b0 | 225 | * @{ |
Kojto | 96:487b796308b0 | 226 | */ |
Kojto | 96:487b796308b0 | 227 | #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001) |
Kojto | 96:487b796308b0 | 228 | #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000010) |
Kojto | 96:487b796308b0 | 229 | /** |
Kojto | 96:487b796308b0 | 230 | * @} |
Kojto | 96:487b796308b0 | 231 | */ |
Kojto | 96:487b796308b0 | 232 | |
Kojto | 96:487b796308b0 | 233 | /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition |
Kojto | 96:487b796308b0 | 234 | * @{ |
Kojto | 96:487b796308b0 | 235 | */ |
Kojto | 96:487b796308b0 | 236 | #define I2C_IT_BUF I2C_CR2_ITBUFEN |
Kojto | 96:487b796308b0 | 237 | #define I2C_IT_EVT I2C_CR2_ITEVTEN |
Kojto | 96:487b796308b0 | 238 | #define I2C_IT_ERR I2C_CR2_ITERREN |
Kojto | 96:487b796308b0 | 239 | /** |
Kojto | 96:487b796308b0 | 240 | * @} |
Kojto | 96:487b796308b0 | 241 | */ |
Kojto | 96:487b796308b0 | 242 | |
Kojto | 96:487b796308b0 | 243 | /** @defgroup I2C_Flag_definition I2C Flag definition |
Kojto | 96:487b796308b0 | 244 | * @brief I2C Interrupt definition |
Kojto | 96:487b796308b0 | 245 | * - 0001XXXX : Flag control mask for SR1 Register |
Kojto | 96:487b796308b0 | 246 | * - 0010XXXX : Flag control mask for SR2 Register |
Kojto | 96:487b796308b0 | 247 | * @{ |
Kojto | 96:487b796308b0 | 248 | */ |
Kojto | 96:487b796308b0 | 249 | #define I2C_FLAG_SMBALERT ((uint32_t)0x00018000) |
Kojto | 96:487b796308b0 | 250 | #define I2C_FLAG_TIMEOUT ((uint32_t)0x00014000) |
Kojto | 96:487b796308b0 | 251 | #define I2C_FLAG_PECERR ((uint32_t)0x00011000) |
Kojto | 96:487b796308b0 | 252 | #define I2C_FLAG_OVR ((uint32_t)0x00010800) |
Kojto | 96:487b796308b0 | 253 | #define I2C_FLAG_AF ((uint32_t)0x00010400) |
Kojto | 96:487b796308b0 | 254 | #define I2C_FLAG_ARLO ((uint32_t)0x00010200) |
Kojto | 96:487b796308b0 | 255 | #define I2C_FLAG_BERR ((uint32_t)0x00010100) |
Kojto | 96:487b796308b0 | 256 | #define I2C_FLAG_TXE ((uint32_t)0x00010080) |
Kojto | 96:487b796308b0 | 257 | #define I2C_FLAG_RXNE ((uint32_t)0x00010040) |
Kojto | 96:487b796308b0 | 258 | #define I2C_FLAG_STOPF ((uint32_t)0x00010010) |
Kojto | 96:487b796308b0 | 259 | #define I2C_FLAG_ADD10 ((uint32_t)0x00010008) |
Kojto | 96:487b796308b0 | 260 | #define I2C_FLAG_BTF ((uint32_t)0x00010004) |
Kojto | 96:487b796308b0 | 261 | #define I2C_FLAG_ADDR ((uint32_t)0x00010002) |
Kojto | 96:487b796308b0 | 262 | #define I2C_FLAG_SB ((uint32_t)0x00010001) |
Kojto | 96:487b796308b0 | 263 | #define I2C_FLAG_DUALF ((uint32_t)0x00100080) |
Kojto | 96:487b796308b0 | 264 | #define I2C_FLAG_SMBHOST ((uint32_t)0x00100040) |
Kojto | 96:487b796308b0 | 265 | #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00100020) |
Kojto | 96:487b796308b0 | 266 | #define I2C_FLAG_GENCALL ((uint32_t)0x00100010) |
Kojto | 96:487b796308b0 | 267 | #define I2C_FLAG_TRA ((uint32_t)0x00100004) |
Kojto | 96:487b796308b0 | 268 | #define I2C_FLAG_BUSY ((uint32_t)0x00100002) |
Kojto | 96:487b796308b0 | 269 | #define I2C_FLAG_MSL ((uint32_t)0x00100001) |
Kojto | 96:487b796308b0 | 270 | #define I2C_FLAG_MASK ((uint32_t)0x0000FFFF) |
Kojto | 96:487b796308b0 | 271 | /** |
Kojto | 96:487b796308b0 | 272 | * @} |
Kojto | 96:487b796308b0 | 273 | */ |
Kojto | 96:487b796308b0 | 274 | |
Kojto | 96:487b796308b0 | 275 | /** |
Kojto | 96:487b796308b0 | 276 | * @} |
Kojto | 96:487b796308b0 | 277 | */ |
Kojto | 96:487b796308b0 | 278 | |
Kojto | 96:487b796308b0 | 279 | /* Exported macros -----------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 280 | |
Kojto | 96:487b796308b0 | 281 | /** @defgroup I2C_Exported_Macros I2C Exported Macros |
Kojto | 96:487b796308b0 | 282 | * @{ |
Kojto | 96:487b796308b0 | 283 | */ |
Kojto | 96:487b796308b0 | 284 | |
Kojto | 96:487b796308b0 | 285 | /** @brief Reset I2C handle state |
Kojto | 96:487b796308b0 | 286 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 287 | * @retval None |
Kojto | 96:487b796308b0 | 288 | */ |
Kojto | 96:487b796308b0 | 289 | #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) |
Kojto | 96:487b796308b0 | 290 | |
Kojto | 96:487b796308b0 | 291 | /** @brief Enable the specified I2C interrupts. |
Kojto | 96:487b796308b0 | 292 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 293 | * @param __INTERRUPT__: specifies the interrupt source to enable. |
Kojto | 96:487b796308b0 | 294 | * This parameter can be one of the following values: |
Kojto | 96:487b796308b0 | 295 | * @arg I2C_IT_BUF: Buffer interrupt enable |
Kojto | 96:487b796308b0 | 296 | * @arg I2C_IT_EVT: Event interrupt enable |
Kojto | 96:487b796308b0 | 297 | * @arg I2C_IT_ERR: Error interrupt enable |
Kojto | 96:487b796308b0 | 298 | * @retval None |
Kojto | 96:487b796308b0 | 299 | */ |
Kojto | 96:487b796308b0 | 300 | #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
Kojto | 96:487b796308b0 | 301 | |
Kojto | 96:487b796308b0 | 302 | /** @brief Disable the specified I2C interrupts. |
Kojto | 96:487b796308b0 | 303 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 304 | * @param __INTERRUPT__: specifies the interrupt source to disable. |
Kojto | 96:487b796308b0 | 305 | * This parameter can be one of the following values: |
Kojto | 96:487b796308b0 | 306 | * @arg I2C_IT_BUF: Buffer interrupt enable |
Kojto | 96:487b796308b0 | 307 | * @arg I2C_IT_EVT: Event interrupt enable |
Kojto | 96:487b796308b0 | 308 | * @arg I2C_IT_ERR: Error interrupt enable |
Kojto | 96:487b796308b0 | 309 | * @retval None |
Kojto | 96:487b796308b0 | 310 | */ |
Kojto | 96:487b796308b0 | 311 | #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
Kojto | 96:487b796308b0 | 312 | |
Kojto | 96:487b796308b0 | 313 | /** @brief Checks if the specified I2C interrupt source is enabled or disabled. |
Kojto | 96:487b796308b0 | 314 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 315 | * @param __INTERRUPT__: specifies the I2C interrupt source to check. |
Kojto | 96:487b796308b0 | 316 | * This parameter can be one of the following values: |
Kojto | 96:487b796308b0 | 317 | * @arg I2C_IT_BUF: Buffer interrupt enable |
Kojto | 96:487b796308b0 | 318 | * @arg I2C_IT_EVT: Event interrupt enable |
Kojto | 96:487b796308b0 | 319 | * @arg I2C_IT_ERR: Error interrupt enable |
Kojto | 96:487b796308b0 | 320 | * @retval The new state of __INTERRUPT__ (TRUE or FALSE). |
Kojto | 96:487b796308b0 | 321 | */ |
Kojto | 96:487b796308b0 | 322 | #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) |
Kojto | 96:487b796308b0 | 323 | |
Kojto | 96:487b796308b0 | 324 | /** @brief Checks whether the specified I2C flag is set or not. |
Kojto | 96:487b796308b0 | 325 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 326 | * @param __FLAG__: specifies the flag to check. |
Kojto | 96:487b796308b0 | 327 | * This parameter can be one of the following values: |
Kojto | 96:487b796308b0 | 328 | * @arg I2C_FLAG_SMBALERT: SMBus Alert flag |
Kojto | 96:487b796308b0 | 329 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag |
Kojto | 96:487b796308b0 | 330 | * @arg I2C_FLAG_PECERR: PEC error in reception flag |
Kojto | 96:487b796308b0 | 331 | * @arg I2C_FLAG_OVR: Overrun/Underrun flag |
Kojto | 96:487b796308b0 | 332 | * @arg I2C_FLAG_AF: Acknowledge failure flag |
Kojto | 96:487b796308b0 | 333 | * @arg I2C_FLAG_ARLO: Arbitration lost flag |
Kojto | 96:487b796308b0 | 334 | * @arg I2C_FLAG_BERR: Bus error flag |
Kojto | 96:487b796308b0 | 335 | * @arg I2C_FLAG_TXE: Data register empty flag |
Kojto | 96:487b796308b0 | 336 | * @arg I2C_FLAG_RXNE: Data register not empty flag |
Kojto | 96:487b796308b0 | 337 | * @arg I2C_FLAG_STOPF: Stop detection flag |
Kojto | 96:487b796308b0 | 338 | * @arg I2C_FLAG_ADD10: 10-bit header sent flag |
Kojto | 96:487b796308b0 | 339 | * @arg I2C_FLAG_BTF: Byte transfer finished flag |
Kojto | 96:487b796308b0 | 340 | * @arg I2C_FLAG_ADDR: Address sent flag |
Kojto | 96:487b796308b0 | 341 | * Address matched flag |
Kojto | 96:487b796308b0 | 342 | * @arg I2C_FLAG_SB: Start bit flag |
Kojto | 96:487b796308b0 | 343 | * @arg I2C_FLAG_DUALF: Dual flag |
Kojto | 96:487b796308b0 | 344 | * @arg I2C_FLAG_SMBHOST: SMBus host header |
Kojto | 96:487b796308b0 | 345 | * @arg I2C_FLAG_SMBDEFAULT: SMBus default header |
Kojto | 96:487b796308b0 | 346 | * @arg I2C_FLAG_GENCALL: General call header flag |
Kojto | 96:487b796308b0 | 347 | * @arg I2C_FLAG_TRA: Transmitter/Receiver flag |
Kojto | 96:487b796308b0 | 348 | * @arg I2C_FLAG_BUSY: Bus busy flag |
Kojto | 96:487b796308b0 | 349 | * @arg I2C_FLAG_MSL: Master/Slave flag |
Kojto | 96:487b796308b0 | 350 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
Kojto | 96:487b796308b0 | 351 | */ |
Kojto | 96:487b796308b0 | 352 | #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16)) == 0x01)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \ |
Kojto | 96:487b796308b0 | 353 | ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) |
Kojto | 96:487b796308b0 | 354 | |
Kojto | 96:487b796308b0 | 355 | /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit. |
Kojto | 96:487b796308b0 | 356 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 357 | * @param __FLAG__: specifies the flag to clear. |
Kojto | 96:487b796308b0 | 358 | * This parameter can be any combination of the following values: |
Kojto | 96:487b796308b0 | 359 | * @arg I2C_FLAG_SMBALERT: SMBus Alert flag |
Kojto | 96:487b796308b0 | 360 | * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag |
Kojto | 96:487b796308b0 | 361 | * @arg I2C_FLAG_PECERR: PEC error in reception flag |
Kojto | 96:487b796308b0 | 362 | * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode) |
Kojto | 96:487b796308b0 | 363 | * @arg I2C_FLAG_AF: Acknowledge failure flag |
Kojto | 96:487b796308b0 | 364 | * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode) |
Kojto | 96:487b796308b0 | 365 | * @arg I2C_FLAG_BERR: Bus error flag |
Kojto | 96:487b796308b0 | 366 | * @retval None |
Kojto | 96:487b796308b0 | 367 | */ |
Kojto | 96:487b796308b0 | 368 | #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HANDLE__)->Instance->SR1 = (((__HANDLE__)->Instance->SR1) & (~((__FLAG__) & I2C_FLAG_MASK))) |
Kojto | 96:487b796308b0 | 369 | |
Kojto | 96:487b796308b0 | 370 | /** @brief Clears the I2C ADDR pending flag. |
Kojto | 96:487b796308b0 | 371 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 372 | * @retval None |
Kojto | 96:487b796308b0 | 373 | */ |
Kojto | 96:487b796308b0 | 374 | #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \ |
Kojto | 96:487b796308b0 | 375 | do{ \ |
Kojto | 96:487b796308b0 | 376 | __IO uint32_t tmpreg; \ |
Kojto | 96:487b796308b0 | 377 | tmpreg = (__HANDLE__)->Instance->SR1; \ |
Kojto | 96:487b796308b0 | 378 | tmpreg = (__HANDLE__)->Instance->SR2; \ |
Kojto | 96:487b796308b0 | 379 | UNUSED(tmpreg); \ |
Kojto | 96:487b796308b0 | 380 | }while(0) |
Kojto | 96:487b796308b0 | 381 | |
Kojto | 96:487b796308b0 | 382 | /** @brief Clears the I2C STOPF pending flag. |
Kojto | 96:487b796308b0 | 383 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 384 | * @retval None |
Kojto | 96:487b796308b0 | 385 | */ |
Kojto | 96:487b796308b0 | 386 | #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \ |
Kojto | 96:487b796308b0 | 387 | do{ \ |
Kojto | 96:487b796308b0 | 388 | __IO uint32_t tmpreg; \ |
Kojto | 96:487b796308b0 | 389 | tmpreg = (__HANDLE__)->Instance->SR1; \ |
Kojto | 96:487b796308b0 | 390 | tmpreg = (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \ |
Kojto | 96:487b796308b0 | 391 | UNUSED(tmpreg); \ |
Kojto | 96:487b796308b0 | 392 | }while(0) |
Kojto | 96:487b796308b0 | 393 | |
Kojto | 96:487b796308b0 | 394 | /** @brief Enable the specified I2C peripheral. |
Kojto | 96:487b796308b0 | 395 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 396 | * @retval None |
Kojto | 96:487b796308b0 | 397 | */ |
Kojto | 96:487b796308b0 | 398 | #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
Kojto | 96:487b796308b0 | 399 | |
Kojto | 96:487b796308b0 | 400 | /** @brief Disable the specified I2C peripheral. |
Kojto | 96:487b796308b0 | 401 | * @param __HANDLE__: specifies the I2C Handle. |
Kojto | 96:487b796308b0 | 402 | * @retval None |
Kojto | 96:487b796308b0 | 403 | */ |
Kojto | 96:487b796308b0 | 404 | #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
Kojto | 96:487b796308b0 | 405 | |
Kojto | 96:487b796308b0 | 406 | /** |
Kojto | 96:487b796308b0 | 407 | * @} |
Kojto | 96:487b796308b0 | 408 | */ |
Kojto | 96:487b796308b0 | 409 | |
Kojto | 96:487b796308b0 | 410 | /* Exported functions --------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 411 | /** @addtogroup I2C_Exported_Functions |
Kojto | 96:487b796308b0 | 412 | * @{ |
Kojto | 96:487b796308b0 | 413 | */ |
Kojto | 96:487b796308b0 | 414 | |
Kojto | 96:487b796308b0 | 415 | /** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions |
Kojto | 96:487b796308b0 | 416 | * @{ |
Kojto | 96:487b796308b0 | 417 | */ |
Kojto | 96:487b796308b0 | 418 | |
Kojto | 96:487b796308b0 | 419 | /* Initialization/de-initialization functions ********************************/ |
Kojto | 96:487b796308b0 | 420 | HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 421 | HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 422 | void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 423 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 424 | |
Kojto | 96:487b796308b0 | 425 | /** |
Kojto | 96:487b796308b0 | 426 | * @} |
Kojto | 96:487b796308b0 | 427 | */ |
Kojto | 96:487b796308b0 | 428 | |
Kojto | 96:487b796308b0 | 429 | /** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions |
Kojto | 96:487b796308b0 | 430 | * @{ |
Kojto | 96:487b796308b0 | 431 | */ |
Kojto | 96:487b796308b0 | 432 | |
Kojto | 96:487b796308b0 | 433 | /* IO operation functions ****************************************************/ |
Kojto | 96:487b796308b0 | 434 | |
Kojto | 96:487b796308b0 | 435 | /******* Blocking mode: Polling */ |
Kojto | 96:487b796308b0 | 436 | HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
Kojto | 96:487b796308b0 | 437 | HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
Kojto | 96:487b796308b0 | 438 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
Kojto | 96:487b796308b0 | 439 | HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
Kojto | 96:487b796308b0 | 440 | 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); |
Kojto | 96:487b796308b0 | 441 | 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); |
Kojto | 96:487b796308b0 | 442 | HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout); |
Kojto | 96:487b796308b0 | 443 | |
Kojto | 96:487b796308b0 | 444 | /******* Non-Blocking mode: Interrupt */ |
Kojto | 96:487b796308b0 | 445 | HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 446 | HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 447 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 448 | HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 449 | 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); |
Kojto | 96:487b796308b0 | 450 | 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); |
Kojto | 96:487b796308b0 | 451 | |
Kojto | 96:487b796308b0 | 452 | /******* Non-Blocking mode: DMA */ |
Kojto | 96:487b796308b0 | 453 | HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 454 | HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 455 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 456 | HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
Kojto | 96:487b796308b0 | 457 | 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); |
Kojto | 96:487b796308b0 | 458 | 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); |
Kojto | 96:487b796308b0 | 459 | /** |
Kojto | 96:487b796308b0 | 460 | * @} |
Kojto | 96:487b796308b0 | 461 | */ |
Kojto | 96:487b796308b0 | 462 | |
Kojto | 96:487b796308b0 | 463 | /** @addtogroup IRQ_Handler_and_Callbacks IRQ Handler and Callbacks |
Kojto | 96:487b796308b0 | 464 | * @{ |
Kojto | 96:487b796308b0 | 465 | */ |
Kojto | 96:487b796308b0 | 466 | /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */ |
Kojto | 96:487b796308b0 | 467 | void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 468 | void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 469 | void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 470 | void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 471 | void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 472 | void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 473 | void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 474 | void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 475 | void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 476 | |
Kojto | 96:487b796308b0 | 477 | /** |
Kojto | 96:487b796308b0 | 478 | * @} |
Kojto | 96:487b796308b0 | 479 | */ |
Kojto | 96:487b796308b0 | 480 | |
Kojto | 96:487b796308b0 | 481 | |
Kojto | 96:487b796308b0 | 482 | /** @addtogroup I2C_Exported_Functions_Group3 Peripheral State and Errors functions |
Kojto | 96:487b796308b0 | 483 | * @{ |
Kojto | 96:487b796308b0 | 484 | */ |
Kojto | 96:487b796308b0 | 485 | |
Kojto | 96:487b796308b0 | 486 | /* Peripheral State and Errors functions *************************************/ |
Kojto | 96:487b796308b0 | 487 | HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 488 | uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c); |
Kojto | 96:487b796308b0 | 489 | |
Kojto | 96:487b796308b0 | 490 | /** |
Kojto | 96:487b796308b0 | 491 | * @} |
Kojto | 96:487b796308b0 | 492 | */ |
Kojto | 96:487b796308b0 | 493 | |
Kojto | 96:487b796308b0 | 494 | /** |
Kojto | 96:487b796308b0 | 495 | * @} |
Kojto | 96:487b796308b0 | 496 | */ |
Kojto | 96:487b796308b0 | 497 | |
Kojto | 96:487b796308b0 | 498 | /* Private constants ---------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 499 | /** @defgroup I2C_Private_Constants I2C Private Constants |
Kojto | 96:487b796308b0 | 500 | * @{ |
Kojto | 96:487b796308b0 | 501 | */ |
Kojto | 96:487b796308b0 | 502 | #define I2C_STANDARD_MODE_MAX_CLK ((uint32_t)100000) /* Standard Clock Up to 100kHz */ |
Kojto | 96:487b796308b0 | 503 | #define I2C_FAST_MODE_MAX_CLK ((uint32_t)400000) /* Fast Clock up to 400kHz */ |
Kojto | 96:487b796308b0 | 504 | /** |
Kojto | 96:487b796308b0 | 505 | * @} |
Kojto | 96:487b796308b0 | 506 | */ |
Kojto | 96:487b796308b0 | 507 | |
Kojto | 96:487b796308b0 | 508 | /* Private macros ------------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 509 | /** @defgroup I2C_Private_Macro I2C Private Macros |
Kojto | 96:487b796308b0 | 510 | * @{ |
Kojto | 96:487b796308b0 | 511 | */ |
Kojto | 96:487b796308b0 | 512 | #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \ |
Kojto | 96:487b796308b0 | 513 | ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT)) |
Kojto | 96:487b796308b0 | 514 | |
Kojto | 96:487b796308b0 | 515 | #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \ |
Kojto | 96:487b796308b0 | 516 | ((ADDRESS) == I2C_DUALADDRESS_ENABLE)) |
Kojto | 96:487b796308b0 | 517 | |
Kojto | 96:487b796308b0 | 518 | #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \ |
Kojto | 96:487b796308b0 | 519 | ((CALL) == I2C_GENERALCALL_ENABLE)) |
Kojto | 96:487b796308b0 | 520 | |
Kojto | 96:487b796308b0 | 521 | #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \ |
Kojto | 96:487b796308b0 | 522 | ((SIZE) == I2C_MEMADD_SIZE_16BIT)) |
Kojto | 96:487b796308b0 | 523 | |
Kojto | 96:487b796308b0 | 524 | #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \ |
Kojto | 96:487b796308b0 | 525 | ((STRETCH) == I2C_NOSTRETCH_ENABLE)) |
Kojto | 96:487b796308b0 | 526 | |
Kojto | 96:487b796308b0 | 527 | #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00)) == 0) |
Kojto | 96:487b796308b0 | 528 | |
Kojto | 96:487b796308b0 | 529 | #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01)) == 0) |
Kojto | 96:487b796308b0 | 530 | |
Kojto | 96:487b796308b0 | 531 | #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0) && ((SPEED) <= I2C_FAST_MODE_MAX_CLK)) |
Kojto | 96:487b796308b0 | 532 | |
Kojto | 96:487b796308b0 | 533 | #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \ |
Kojto | 96:487b796308b0 | 534 | ((CYCLE) == I2C_DUTYCYCLE_16_9)) |
Kojto | 96:487b796308b0 | 535 | |
Kojto | 96:487b796308b0 | 536 | #define I2C_FREQ_RANGE(__PCLK__) ((__PCLK__)/1000000) |
Kojto | 96:487b796308b0 | 537 | #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= I2C_STANDARD_MODE_MAX_CLK) ? ((__FREQRANGE__) + 1) : ((((__FREQRANGE__) * 300) / 1000) + 1)) |
Kojto | 96:487b796308b0 | 538 | |
Kojto | 96:487b796308b0 | 539 | #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1)) & I2C_CCR_CCR) < 4)? 4:((__PCLK__) / ((__SPEED__) << 1))) |
Kojto | 96:487b796308b0 | 540 | #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3)) : (((__PCLK__) / ((__SPEED__) * 25)) | I2C_DUTYCYCLE_16_9)) |
Kojto | 96:487b796308b0 | 541 | #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \ |
Kojto | 96:487b796308b0 | 542 | ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0)? 1 : \ |
Kojto | 96:487b796308b0 | 543 | ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS)) |
Kojto | 96:487b796308b0 | 544 | |
Kojto | 96:487b796308b0 | 545 | #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00))) >> 8))) |
Kojto | 96:487b796308b0 | 546 | #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) |
Kojto | 96:487b796308b0 | 547 | |
Kojto | 96:487b796308b0 | 548 | #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0))) |
Kojto | 96:487b796308b0 | 549 | #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0)) |
Kojto | 96:487b796308b0 | 550 | |
Kojto | 96:487b796308b0 | 551 | #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) |
Kojto | 96:487b796308b0 | 552 | #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF0)))) |
Kojto | 96:487b796308b0 | 553 | #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF1)))) |
Kojto | 96:487b796308b0 | 554 | /** |
Kojto | 96:487b796308b0 | 555 | * @} |
Kojto | 96:487b796308b0 | 556 | */ |
Kojto | 96:487b796308b0 | 557 | |
Kojto | 96:487b796308b0 | 558 | /* Private Fonctions ---------------------------------------------------------*/ |
Kojto | 96:487b796308b0 | 559 | /** @defgroup I2C_Private_Functions I2C Private Functions |
Kojto | 96:487b796308b0 | 560 | * @{ |
Kojto | 96:487b796308b0 | 561 | */ |
Kojto | 96:487b796308b0 | 562 | /* Private functions are defined in stm32f1xx_hal_i2c.c file */ |
Kojto | 96:487b796308b0 | 563 | /** |
Kojto | 96:487b796308b0 | 564 | * @} |
Kojto | 96:487b796308b0 | 565 | */ |
Kojto | 96:487b796308b0 | 566 | |
Kojto | 96:487b796308b0 | 567 | /** |
Kojto | 96:487b796308b0 | 568 | * @} |
Kojto | 96:487b796308b0 | 569 | */ |
Kojto | 96:487b796308b0 | 570 | |
Kojto | 96:487b796308b0 | 571 | /** |
Kojto | 96:487b796308b0 | 572 | * @} |
Kojto | 96:487b796308b0 | 573 | */ |
Kojto | 96:487b796308b0 | 574 | |
Kojto | 96:487b796308b0 | 575 | #ifdef __cplusplus |
Kojto | 96:487b796308b0 | 576 | } |
Kojto | 96:487b796308b0 | 577 | #endif |
Kojto | 96:487b796308b0 | 578 | |
Kojto | 96:487b796308b0 | 579 | |
Kojto | 96:487b796308b0 | 580 | #endif /* __STM32F1xx_HAL_I2C_H */ |
Kojto | 96:487b796308b0 | 581 | |
Kojto | 96:487b796308b0 | 582 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |