cc y / mbed

Fork of mbed by mbed official

Committer:
Kojto
Date:
Thu Jul 07 14:34:11 2016 +0100
Revision:
122:f9eeca106725
Parent:
90:cb3d968589d8
Release 122 of the mbed library

Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition

Who changed what in which revision?

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