mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
237:f3da66175598
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_i2c.h
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 237:f3da66175598 5 * @version V1.0.1
mbed_official 237:f3da66175598 6 * @date 18-June-2014
mbed_official 237:f3da66175598 7 * @brief Header file of I2C HAL module.
mbed_official 237:f3da66175598 8 ******************************************************************************
mbed_official 237:f3da66175598 9 * @attention
mbed_official 237:f3da66175598 10 *
mbed_official 237:f3da66175598 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 12 *
mbed_official 237:f3da66175598 13 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 14 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 16 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 18 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 19 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 21 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 22 * without specific prior written permission.
mbed_official 237:f3da66175598 23 *
mbed_official 237:f3da66175598 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 34 *
mbed_official 237:f3da66175598 35 ******************************************************************************
mbed_official 237:f3da66175598 36 */
mbed_official 237:f3da66175598 37
mbed_official 237:f3da66175598 38 /* Define to prevent recursive inclusion -------------------------------------*/
mbed_official 237:f3da66175598 39 #ifndef __STM32F3xx_HAL_I2C_H
mbed_official 237:f3da66175598 40 #define __STM32F3xx_HAL_I2C_H
mbed_official 237:f3da66175598 41
mbed_official 237:f3da66175598 42 #ifdef __cplusplus
mbed_official 237:f3da66175598 43 extern "C" {
mbed_official 237:f3da66175598 44 #endif
mbed_official 237:f3da66175598 45
mbed_official 237:f3da66175598 46 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 47 #include "stm32f3xx_hal_def.h"
mbed_official 237:f3da66175598 48
mbed_official 237:f3da66175598 49 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 50 * @{
mbed_official 237:f3da66175598 51 */
mbed_official 237:f3da66175598 52
mbed_official 237:f3da66175598 53 /** @addtogroup I2C
mbed_official 237:f3da66175598 54 * @{
mbed_official 237:f3da66175598 55 */
mbed_official 237:f3da66175598 56
mbed_official 237:f3da66175598 57 /* Exported types ------------------------------------------------------------*/
mbed_official 237:f3da66175598 58
mbed_official 237:f3da66175598 59 /**
mbed_official 237:f3da66175598 60 * @brief I2C Configuration Structure definition
mbed_official 237:f3da66175598 61 */
mbed_official 237:f3da66175598 62 typedef struct
mbed_official 237:f3da66175598 63 {
mbed_official 237:f3da66175598 64 uint32_t Timing; /*!< Specifies the I2C_TIMINGR_register value.
mbed_official 237:f3da66175598 65 This parameter calculated by referring to I2C initialization
mbed_official 237:f3da66175598 66 section in Reference manual */
mbed_official 237:f3da66175598 67
mbed_official 237:f3da66175598 68 uint32_t OwnAddress1; /*!< Specifies the first device own address.
mbed_official 237:f3da66175598 69 This parameter can be a 7-bit or 10-bit address. */
mbed_official 237:f3da66175598 70
mbed_official 237:f3da66175598 71 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
mbed_official 237:f3da66175598 72 This parameter can be a value of @ref I2C_addressing_mode */
mbed_official 237:f3da66175598 73
mbed_official 237:f3da66175598 74 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
mbed_official 237:f3da66175598 75 This parameter can be a value of @ref I2C_dual_addressing_mode */
mbed_official 237:f3da66175598 76
mbed_official 237:f3da66175598 77 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected
mbed_official 237:f3da66175598 78 This parameter can be a 7-bit address. */
mbed_official 237:f3da66175598 79
mbed_official 237:f3da66175598 80 uint32_t OwnAddress2Masks; /*!< Specifies the acknoledge mask address second device own address if dual addressing mode is selected
mbed_official 237:f3da66175598 81 This parameter can be a value of @ref I2C_own_address2_masks. */
mbed_official 237:f3da66175598 82
mbed_official 237:f3da66175598 83 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
mbed_official 237:f3da66175598 84 This parameter can be a value of @ref I2C_general_call_addressing_mode. */
mbed_official 237:f3da66175598 85
mbed_official 237:f3da66175598 86 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
mbed_official 237:f3da66175598 87 This parameter can be a value of @ref I2C_nostretch_mode */
mbed_official 237:f3da66175598 88
mbed_official 237:f3da66175598 89 }I2C_InitTypeDef;
mbed_official 237:f3da66175598 90
mbed_official 237:f3da66175598 91 /**
mbed_official 237:f3da66175598 92 * @brief HAL State structures definition
mbed_official 237:f3da66175598 93 */
mbed_official 237:f3da66175598 94 typedef enum
mbed_official 237:f3da66175598 95 {
mbed_official 237:f3da66175598 96 HAL_I2C_STATE_RESET = 0x00, /*!< I2C not yet initialized or disabled */
mbed_official 237:f3da66175598 97 HAL_I2C_STATE_READY = 0x01, /*!< I2C initialized and ready for use */
mbed_official 237:f3da66175598 98 HAL_I2C_STATE_BUSY = 0x02, /*!< I2C internal process is ongoing */
mbed_official 237:f3da66175598 99 HAL_I2C_STATE_MASTER_BUSY_TX = 0x12, /*!< Master Data Transmission process is ongoing */
mbed_official 237:f3da66175598 100 HAL_I2C_STATE_MASTER_BUSY_RX = 0x22, /*!< Master Data Reception process is ongoing */
mbed_official 237:f3da66175598 101 HAL_I2C_STATE_SLAVE_BUSY_TX = 0x32, /*!< Slave Data Transmission process is ongoing */
mbed_official 237:f3da66175598 102 HAL_I2C_STATE_SLAVE_BUSY_RX = 0x42, /*!< Slave Data Reception process is ongoing */
mbed_official 237:f3da66175598 103 HAL_I2C_STATE_MEM_BUSY_TX = 0x52, /*!< Memory Data Transmission process is ongoing */
mbed_official 237:f3da66175598 104 HAL_I2C_STATE_MEM_BUSY_RX = 0x62, /*!< Memory Data Reception process is ongoing */
mbed_official 237:f3da66175598 105 HAL_I2C_STATE_TIMEOUT = 0x03, /*!< Timeout state */
mbed_official 237:f3da66175598 106 HAL_I2C_STATE_ERROR = 0x04 /*!< Reception process is ongoing */
mbed_official 237:f3da66175598 107
mbed_official 237:f3da66175598 108 }HAL_I2C_StateTypeDef;
mbed_official 237:f3da66175598 109
mbed_official 237:f3da66175598 110 /**
mbed_official 237:f3da66175598 111 * @brief HAL I2C Error Code structure definition
mbed_official 237:f3da66175598 112 */
mbed_official 237:f3da66175598 113 typedef enum
mbed_official 237:f3da66175598 114 {
mbed_official 237:f3da66175598 115 HAL_I2C_ERROR_NONE = 0x00, /*!< No error */
mbed_official 237:f3da66175598 116 HAL_I2C_ERROR_BERR = 0x01, /*!< BERR error */
mbed_official 237:f3da66175598 117 HAL_I2C_ERROR_ARLO = 0x02, /*!< ARLO error */
mbed_official 237:f3da66175598 118 HAL_I2C_ERROR_AF = 0x04, /*!< AF error */
mbed_official 237:f3da66175598 119 HAL_I2C_ERROR_OVR = 0x08, /*!< OVR error */
mbed_official 237:f3da66175598 120 HAL_I2C_ERROR_DMA = 0x10, /*!< DMA transfer error */
mbed_official 237:f3da66175598 121 HAL_I2C_ERROR_TIMEOUT = 0x20, /*!< Timeout error */
mbed_official 237:f3da66175598 122 HAL_I2C_ERROR_SIZE = 0x40 /*!< Size Management error */
mbed_official 237:f3da66175598 123 }HAL_I2C_ErrorTypeDef;
mbed_official 237:f3da66175598 124
mbed_official 237:f3da66175598 125 /**
mbed_official 237:f3da66175598 126 * @brief I2C handle Structure definition
mbed_official 237:f3da66175598 127 */
mbed_official 237:f3da66175598 128 typedef struct
mbed_official 237:f3da66175598 129 {
mbed_official 237:f3da66175598 130 I2C_TypeDef *Instance; /*!< I2C registers base address */
mbed_official 237:f3da66175598 131
mbed_official 237:f3da66175598 132 I2C_InitTypeDef Init; /*!< I2C communication parameters */
mbed_official 237:f3da66175598 133
mbed_official 237:f3da66175598 134 uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */
mbed_official 237:f3da66175598 135
mbed_official 237:f3da66175598 136 uint16_t XferSize; /*!< I2C transfer size */
mbed_official 237:f3da66175598 137
mbed_official 237:f3da66175598 138 __IO uint16_t XferCount; /*!< I2C transfer counter */
mbed_official 237:f3da66175598 139
mbed_official 237:f3da66175598 140 DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */
mbed_official 237:f3da66175598 141
mbed_official 237:f3da66175598 142 DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */
mbed_official 237:f3da66175598 143
mbed_official 237:f3da66175598 144 HAL_LockTypeDef Lock; /*!< I2C locking object */
mbed_official 237:f3da66175598 145
mbed_official 237:f3da66175598 146 __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */
mbed_official 237:f3da66175598 147
mbed_official 237:f3da66175598 148 __IO HAL_I2C_ErrorTypeDef ErrorCode; /* I2C Error code */
mbed_official 237:f3da66175598 149
mbed_official 237:f3da66175598 150 }I2C_HandleTypeDef;
mbed_official 237:f3da66175598 151
mbed_official 237:f3da66175598 152 /* Exported constants --------------------------------------------------------*/
mbed_official 237:f3da66175598 153
mbed_official 237:f3da66175598 154 /** @defgroup I2C_Exported_Constants
mbed_official 237:f3da66175598 155 * @{
mbed_official 237:f3da66175598 156 */
mbed_official 237:f3da66175598 157
mbed_official 237:f3da66175598 158 /** @defgroup I2C_addressing_mode
mbed_official 237:f3da66175598 159 * @{
mbed_official 237:f3da66175598 160 */
mbed_official 237:f3da66175598 161 #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00000001)
mbed_official 237:f3da66175598 162 #define I2C_ADDRESSINGMODE_10BIT ((uint32_t)0x00000002)
mbed_official 237:f3da66175598 163
mbed_official 237:f3da66175598 164 #define IS_I2C_ADDRESSING_MODE(MODE) (((MODE) == I2C_ADDRESSINGMODE_7BIT) || \
mbed_official 237:f3da66175598 165 ((MODE) == I2C_ADDRESSINGMODE_10BIT))
mbed_official 237:f3da66175598 166 /**
mbed_official 237:f3da66175598 167 * @}
mbed_official 237:f3da66175598 168 */
mbed_official 237:f3da66175598 169
mbed_official 237:f3da66175598 170 /** @defgroup I2C_dual_addressing_mode
mbed_official 237:f3da66175598 171 * @{
mbed_official 237:f3da66175598 172 */
mbed_official 237:f3da66175598 173
mbed_official 237:f3da66175598 174 #define I2C_DUALADDRESS_DISABLED ((uint32_t)0x00000000)
mbed_official 237:f3da66175598 175 #define I2C_DUALADDRESS_ENABLED I2C_OAR2_OA2EN
mbed_official 237:f3da66175598 176
mbed_official 237:f3da66175598 177 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLED) || \
mbed_official 237:f3da66175598 178 ((ADDRESS) == I2C_DUALADDRESS_ENABLED))
mbed_official 237:f3da66175598 179 /**
mbed_official 237:f3da66175598 180 * @}
mbed_official 237:f3da66175598 181 */
mbed_official 237:f3da66175598 182
mbed_official 237:f3da66175598 183 /** @defgroup I2C_own_address2_masks
mbed_official 237:f3da66175598 184 * @{
mbed_official 237:f3da66175598 185 */
mbed_official 237:f3da66175598 186
mbed_official 237:f3da66175598 187 #define I2C_OA2_NOMASK ((uint8_t)0x00)
mbed_official 237:f3da66175598 188 #define I2C_OA2_MASK01 ((uint8_t)0x01)
mbed_official 237:f3da66175598 189 #define I2C_OA2_MASK02 ((uint8_t)0x02)
mbed_official 237:f3da66175598 190 #define I2C_OA2_MASK03 ((uint8_t)0x03)
mbed_official 237:f3da66175598 191 #define I2C_OA2_MASK04 ((uint8_t)0x04)
mbed_official 237:f3da66175598 192 #define I2C_OA2_MASK05 ((uint8_t)0x05)
mbed_official 237:f3da66175598 193 #define I2C_OA2_MASK06 ((uint8_t)0x06)
mbed_official 237:f3da66175598 194 #define I2C_OA2_MASK07 ((uint8_t)0x07)
mbed_official 237:f3da66175598 195
mbed_official 237:f3da66175598 196 #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NOMASK) || \
mbed_official 237:f3da66175598 197 ((MASK) == I2C_OA2_MASK01) || \
mbed_official 237:f3da66175598 198 ((MASK) == I2C_OA2_MASK02) || \
mbed_official 237:f3da66175598 199 ((MASK) == I2C_OA2_MASK03) || \
mbed_official 237:f3da66175598 200 ((MASK) == I2C_OA2_MASK04) || \
mbed_official 237:f3da66175598 201 ((MASK) == I2C_OA2_MASK05) || \
mbed_official 237:f3da66175598 202 ((MASK) == I2C_OA2_MASK06) || \
mbed_official 237:f3da66175598 203 ((MASK) == I2C_OA2_MASK07))
mbed_official 237:f3da66175598 204 /**
mbed_official 237:f3da66175598 205 * @}
mbed_official 237:f3da66175598 206 */
mbed_official 237:f3da66175598 207
mbed_official 237:f3da66175598 208 /** @defgroup I2C_general_call_addressing_mode
mbed_official 237:f3da66175598 209 * @{
mbed_official 237:f3da66175598 210 */
mbed_official 237:f3da66175598 211 #define I2C_GENERALCALL_DISABLED ((uint32_t)0x00000000)
mbed_official 237:f3da66175598 212 #define I2C_GENERALCALL_ENABLED I2C_CR1_GCEN
mbed_official 237:f3da66175598 213
mbed_official 237:f3da66175598 214 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLED) || \
mbed_official 237:f3da66175598 215 ((CALL) == I2C_GENERALCALL_ENABLED))
mbed_official 237:f3da66175598 216 /**
mbed_official 237:f3da66175598 217 * @}
mbed_official 237:f3da66175598 218 */
mbed_official 237:f3da66175598 219
mbed_official 237:f3da66175598 220 /** @defgroup I2C_nostretch_mode
mbed_official 237:f3da66175598 221 * @{
mbed_official 237:f3da66175598 222 */
mbed_official 237:f3da66175598 223 #define I2C_NOSTRETCH_DISABLED ((uint32_t)0x00000000)
mbed_official 237:f3da66175598 224 #define I2C_NOSTRETCH_ENABLED I2C_CR1_NOSTRETCH
mbed_official 237:f3da66175598 225
mbed_official 237:f3da66175598 226 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLED) || \
mbed_official 237:f3da66175598 227 ((STRETCH) == I2C_NOSTRETCH_ENABLED))
mbed_official 237:f3da66175598 228 /**
mbed_official 237:f3da66175598 229 * @}
mbed_official 237:f3da66175598 230 */
mbed_official 237:f3da66175598 231
mbed_official 237:f3da66175598 232 /** @defgroup I2C_Memory_Address_Size
mbed_official 237:f3da66175598 233 * @{
mbed_official 237:f3da66175598 234 */
mbed_official 237:f3da66175598 235 #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001)
mbed_official 237:f3da66175598 236 #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000002)
mbed_official 237:f3da66175598 237
mbed_official 237:f3da66175598 238 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
mbed_official 237:f3da66175598 239 ((SIZE) == I2C_MEMADD_SIZE_16BIT))
mbed_official 237:f3da66175598 240 /**
mbed_official 237:f3da66175598 241 * @}
mbed_official 237:f3da66175598 242 */
mbed_official 237:f3da66175598 243
mbed_official 237:f3da66175598 244 /** @defgroup I2C_ReloadEndMode_definition
mbed_official 237:f3da66175598 245 * @{
mbed_official 237:f3da66175598 246 */
mbed_official 237:f3da66175598 247
mbed_official 237:f3da66175598 248 #define I2C_RELOAD_MODE I2C_CR2_RELOAD
mbed_official 237:f3da66175598 249 #define I2C_AUTOEND_MODE I2C_CR2_AUTOEND
mbed_official 237:f3da66175598 250 #define I2C_SOFTEND_MODE ((uint32_t)0x00000000)
mbed_official 237:f3da66175598 251
mbed_official 237:f3da66175598 252 #define IS_TRANSFER_MODE(MODE) (((MODE) == I2C_RELOAD_MODE) || \
mbed_official 237:f3da66175598 253 ((MODE) == I2C_AUTOEND_MODE) || \
mbed_official 237:f3da66175598 254 ((MODE) == I2C_SOFTEND_MODE))
mbed_official 237:f3da66175598 255 /**
mbed_official 237:f3da66175598 256 * @}
mbed_official 237:f3da66175598 257 */
mbed_official 237:f3da66175598 258
mbed_official 237:f3da66175598 259 /** @defgroup I2C_StartStopMode_definition
mbed_official 237:f3da66175598 260 * @{
mbed_official 237:f3da66175598 261 */
mbed_official 237:f3da66175598 262
mbed_official 237:f3da66175598 263 #define I2C_NO_STARTSTOP ((uint32_t)0x00000000)
mbed_official 237:f3da66175598 264 #define I2C_GENERATE_STOP I2C_CR2_STOP
mbed_official 237:f3da66175598 265 #define I2C_GENERATE_START_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
mbed_official 237:f3da66175598 266 #define I2C_GENERATE_START_WRITE I2C_CR2_START
mbed_official 237:f3da66175598 267
mbed_official 237:f3da66175598 268 #define IS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == I2C_GENERATE_STOP) || \
mbed_official 237:f3da66175598 269 ((REQUEST) == I2C_GENERATE_START_READ) || \
mbed_official 237:f3da66175598 270 ((REQUEST) == I2C_GENERATE_START_WRITE) || \
mbed_official 237:f3da66175598 271 ((REQUEST) == I2C_NO_STARTSTOP))
mbed_official 237:f3da66175598 272
mbed_official 237:f3da66175598 273 /**
mbed_official 237:f3da66175598 274 * @}
mbed_official 237:f3da66175598 275 */
mbed_official 237:f3da66175598 276
mbed_official 237:f3da66175598 277 /** @defgroup I2C_Interrupt_configuration_definition
mbed_official 237:f3da66175598 278 * @brief I2C Interrupt definition
mbed_official 237:f3da66175598 279 * Elements values convention: 0xXXXXXXXX
mbed_official 237:f3da66175598 280 * - XXXXXXXX : Interrupt control mask
mbed_official 237:f3da66175598 281 * @{
mbed_official 237:f3da66175598 282 */
mbed_official 237:f3da66175598 283 #define I2C_IT_ERRI I2C_CR1_ERRIE
mbed_official 237:f3da66175598 284 #define I2C_IT_TCI I2C_CR1_TCIE
mbed_official 237:f3da66175598 285 #define I2C_IT_STOPI I2C_CR1_STOPIE
mbed_official 237:f3da66175598 286 #define I2C_IT_NACKI I2C_CR1_NACKIE
mbed_official 237:f3da66175598 287 #define I2C_IT_ADDRI I2C_CR1_ADDRIE
mbed_official 237:f3da66175598 288 #define I2C_IT_RXI I2C_CR1_RXIE
mbed_official 237:f3da66175598 289 #define I2C_IT_TXI I2C_CR1_TXIE
mbed_official 237:f3da66175598 290
mbed_official 237:f3da66175598 291 /**
mbed_official 237:f3da66175598 292 * @}
mbed_official 237:f3da66175598 293 */
mbed_official 237:f3da66175598 294
mbed_official 237:f3da66175598 295
mbed_official 237:f3da66175598 296 /** @defgroup I2C_Flag_definition
mbed_official 237:f3da66175598 297 * @{
mbed_official 237:f3da66175598 298 */
mbed_official 237:f3da66175598 299
mbed_official 237:f3da66175598 300 #define I2C_FLAG_TXE I2C_ISR_TXE
mbed_official 237:f3da66175598 301 #define I2C_FLAG_TXIS I2C_ISR_TXIS
mbed_official 237:f3da66175598 302 #define I2C_FLAG_RXNE I2C_ISR_RXNE
mbed_official 237:f3da66175598 303 #define I2C_FLAG_ADDR I2C_ISR_ADDR
mbed_official 237:f3da66175598 304 #define I2C_FLAG_AF I2C_ISR_NACKF
mbed_official 237:f3da66175598 305 #define I2C_FLAG_STOPF I2C_ISR_STOPF
mbed_official 237:f3da66175598 306 #define I2C_FLAG_TC I2C_ISR_TC
mbed_official 237:f3da66175598 307 #define I2C_FLAG_TCR I2C_ISR_TCR
mbed_official 237:f3da66175598 308 #define I2C_FLAG_BERR I2C_ISR_BERR
mbed_official 237:f3da66175598 309 #define I2C_FLAG_ARLO I2C_ISR_ARLO
mbed_official 237:f3da66175598 310 #define I2C_FLAG_OVR I2C_ISR_OVR
mbed_official 237:f3da66175598 311 #define I2C_FLAG_PECERR I2C_ISR_PECERR
mbed_official 237:f3da66175598 312 #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT
mbed_official 237:f3da66175598 313 #define I2C_FLAG_ALERT I2C_ISR_ALERT
mbed_official 237:f3da66175598 314 #define I2C_FLAG_BUSY I2C_ISR_BUSY
mbed_official 237:f3da66175598 315 #define I2C_FLAG_DIR I2C_ISR_DIR
mbed_official 237:f3da66175598 316 /**
mbed_official 237:f3da66175598 317 * @}
mbed_official 237:f3da66175598 318 */
mbed_official 237:f3da66175598 319
mbed_official 237:f3da66175598 320 /**
mbed_official 237:f3da66175598 321 * @}
mbed_official 237:f3da66175598 322 */
mbed_official 237:f3da66175598 323
mbed_official 237:f3da66175598 324 /* Exported macros -----------------------------------------------------------*/
mbed_official 237:f3da66175598 325
mbed_official 237:f3da66175598 326 /** @brief Reset I2C handle state
mbed_official 237:f3da66175598 327 * @param __HANDLE__: I2C handle.
mbed_official 237:f3da66175598 328 * @retval None
mbed_official 237:f3da66175598 329 */
mbed_official 237:f3da66175598 330 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
mbed_official 237:f3da66175598 331
mbed_official 237:f3da66175598 332 /** @brief Enables or disables the specified I2C interrupts.
mbed_official 237:f3da66175598 333 * @param __HANDLE__: specifies the I2C Handle.
mbed_official 237:f3da66175598 334 * This parameter can be I2Cx where x: 1, 2, or 3 to select the I2C peripheral.
mbed_official 237:f3da66175598 335 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
mbed_official 237:f3da66175598 336 * This parameter can be one of the following values:
mbed_official 237:f3da66175598 337 * @arg I2C_IT_ERRI: Errors interrupt enable
mbed_official 237:f3da66175598 338 * @arg I2C_IT_TCI: Transfer complete interrupt enable
mbed_official 237:f3da66175598 339 * @arg I2C_IT_STOPI: STOP detection interrupt enable
mbed_official 237:f3da66175598 340 * @arg I2C_IT_NACKI: NACK received interrupt enable
mbed_official 237:f3da66175598 341 * @arg I2C_IT_ADDRI: Address match interrupt enable
mbed_official 237:f3da66175598 342 * @arg I2C_IT_RXI: RX interrupt enable
mbed_official 237:f3da66175598 343 * @arg I2C_IT_TXI: TX interrupt enable
mbed_official 237:f3da66175598 344 *
mbed_official 237:f3da66175598 345 * @retval None
mbed_official 237:f3da66175598 346 */
mbed_official 237:f3da66175598 347
mbed_official 237:f3da66175598 348 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
mbed_official 237:f3da66175598 349 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
mbed_official 237:f3da66175598 350
mbed_official 237:f3da66175598 351 /** @brief Checks if the specified I2C interrupt source is enabled or disabled.
mbed_official 237:f3da66175598 352 * @param __HANDLE__: specifies the I2C Handle.
mbed_official 237:f3da66175598 353 * This parameter can be I2Cx where x: 1, 2, or 3 to select the I2C peripheral.
mbed_official 237:f3da66175598 354 * @param __INTERRUPT__: specifies the I2C interrupt source to check.
mbed_official 237:f3da66175598 355 * This parameter can be one of the following values:
mbed_official 237:f3da66175598 356 * @arg I2C_IT_ERRI: Errors interrupt enable
mbed_official 237:f3da66175598 357 * @arg I2C_IT_TCI: Transfer complete interrupt enable
mbed_official 237:f3da66175598 358 * @arg I2C_IT_STOPI: STOP detection interrupt enable
mbed_official 237:f3da66175598 359 * @arg I2C_IT_NACKI: NACK received interrupt enable
mbed_official 237:f3da66175598 360 * @arg I2C_IT_ADDRI: Address match interrupt enable
mbed_official 237:f3da66175598 361 * @arg I2C_IT_RXI: RX interrupt enable
mbed_official 237:f3da66175598 362 * @arg I2C_IT_TXI: TX interrupt enable
mbed_official 237:f3da66175598 363 *
mbed_official 237:f3da66175598 364 * @retval The new state of __IT__ (TRUE or FALSE).
mbed_official 237:f3da66175598 365 */
mbed_official 237:f3da66175598 366 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
mbed_official 237:f3da66175598 367
mbed_official 237:f3da66175598 368 /** @brief Checks whether the specified I2C flag is set or not.
mbed_official 237:f3da66175598 369 * @param __HANDLE__: specifies the I2C Handle.
mbed_official 237:f3da66175598 370 * This parameter can be I2Cx where x: 1, 2, or 3 to select the I2C peripheral.
mbed_official 237:f3da66175598 371 * @param __FLAG__: specifies the flag to check.
mbed_official 237:f3da66175598 372 * This parameter can be one of the following values:
mbed_official 237:f3da66175598 373 * @arg I2C_FLAG_TXE: Transmit data register empty
mbed_official 237:f3da66175598 374 * @arg I2C_FLAG_TXIS: Transmit interrupt status
mbed_official 237:f3da66175598 375 * @arg I2C_FLAG_RXNE: Receive data register not empty
mbed_official 237:f3da66175598 376 * @arg I2C_FLAG_ADDR: Address matched (slave mode)
mbed_official 237:f3da66175598 377 * @arg I2C_FLAG_AF: Acknowledge failure received flag
mbed_official 237:f3da66175598 378 * @arg I2C_FLAG_STOPF: STOP detection flag
mbed_official 237:f3da66175598 379 * @arg I2C_FLAG_TC: Transfer complete (master mode)
mbed_official 237:f3da66175598 380 * @arg I2C_FLAG_TCR: Transfer complete reload
mbed_official 237:f3da66175598 381 * @arg I2C_FLAG_BERR: Bus error
mbed_official 237:f3da66175598 382 * @arg I2C_FLAG_ARLO: Arbitration lost
mbed_official 237:f3da66175598 383 * @arg I2C_FLAG_OVR: Overrun/Underrun
mbed_official 237:f3da66175598 384 * @arg I2C_FLAG_PECERR: PEC error in reception
mbed_official 237:f3da66175598 385 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
mbed_official 237:f3da66175598 386 * @arg I2C_FLAG_ALERT: SMBus alert
mbed_official 237:f3da66175598 387 * @arg I2C_FLAG_BUSY: Bus busy
mbed_official 237:f3da66175598 388 * @arg I2C_FLAG_DIR: Transfer direction (slave mode)
mbed_official 237:f3da66175598 389 *
mbed_official 237:f3da66175598 390 * @retval The new state of __FLAG__ (TRUE or FALSE).
mbed_official 237:f3da66175598 391 */
mbed_official 237:f3da66175598 392 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
mbed_official 237:f3da66175598 393
mbed_official 237:f3da66175598 394 /** @brief Clears the I2C pending flags which are cleared by writing 1 in a specific bit.
mbed_official 237:f3da66175598 395 * @param __HANDLE__: specifies the I2C Handle.
mbed_official 237:f3da66175598 396 * This parameter can be I2Cx where x: 1, 2, or 3 to select the I2C peripheral.
mbed_official 237:f3da66175598 397 * @param __FLAG__: specifies the flag to clear.
mbed_official 237:f3da66175598 398 * This parameter can be any combination of the following values:
mbed_official 237:f3da66175598 399 * @arg I2C_FLAG_ADDR: Address matched (slave mode)
mbed_official 237:f3da66175598 400 * @arg I2C_FLAG_AF: Acknowledge failure flag
mbed_official 237:f3da66175598 401 * @arg I2C_FLAG_STOPF: STOP detection flag
mbed_official 237:f3da66175598 402 * @arg I2C_FLAG_BERR: Bus error
mbed_official 237:f3da66175598 403 * @arg I2C_FLAG_ARLO: Arbitration lost
mbed_official 237:f3da66175598 404 * @arg I2C_FLAG_OVR: Overrun/Underrun
mbed_official 237:f3da66175598 405 * @arg I2C_FLAG_PECERR: PEC error in reception
mbed_official 237:f3da66175598 406 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
mbed_official 237:f3da66175598 407 * @arg I2C_FLAG_ALERT: SMBus alert
mbed_official 237:f3da66175598 408 *
mbed_official 237:f3da66175598 409 * @retval None
mbed_official 237:f3da66175598 410 */
mbed_official 237:f3da66175598 411 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
mbed_official 237:f3da66175598 412
mbed_official 237:f3da66175598 413
mbed_official 237:f3da66175598 414 #define __HAL_I2C_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
mbed_official 237:f3da66175598 415 #define __HAL_I2C_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
mbed_official 237:f3da66175598 416
mbed_official 237:f3da66175598 417 #define __HAL_I2C_RESET_CR2(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN)))
mbed_official 237:f3da66175598 418
mbed_official 237:f3da66175598 419 #define __HAL_I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00))) >> 8)))
mbed_official 237:f3da66175598 420 #define __HAL_I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF))))
mbed_official 237:f3da66175598 421
mbed_official 237:f3da66175598 422 #define __HAL_I2C_GENERATE_START(__ADDMODE__,__ADDRESS__) (((__ADDMODE__) == I2C_ADDRESSINGMODE_7BIT) ? (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_START) | (I2C_CR2_AUTOEND)) & (~I2C_CR2_RD_WRN)) : \
mbed_official 237:f3da66175598 423 (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
mbed_official 237:f3da66175598 424
mbed_official 237:f3da66175598 425 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF)
mbed_official 237:f3da66175598 426 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF)
mbed_official 237:f3da66175598 427
mbed_official 237:f3da66175598 428 /* Include I2C HAL Extension module */
mbed_official 237:f3da66175598 429 #include "stm32f3xx_hal_i2c_ex.h"
mbed_official 237:f3da66175598 430
mbed_official 237:f3da66175598 431 /* Exported functions --------------------------------------------------------*/
mbed_official 237:f3da66175598 432 /* Initialization/de-initialization functions **********************************/
mbed_official 237:f3da66175598 433 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 434 HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 435 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 436 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 437
mbed_official 237:f3da66175598 438 /* IO operation functions *****************************************************/
mbed_official 237:f3da66175598 439 /******* Blocking mode: Polling */
mbed_official 237:f3da66175598 440 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 237:f3da66175598 441 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 237:f3da66175598 442 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 237:f3da66175598 443 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 237:f3da66175598 444 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);
mbed_official 237:f3da66175598 445 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);
mbed_official 237:f3da66175598 446 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
mbed_official 237:f3da66175598 447
mbed_official 237:f3da66175598 448 /******* Non-Blocking mode: Interrupt */
mbed_official 237:f3da66175598 449 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 450 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 451 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 452 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 453 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);
mbed_official 237:f3da66175598 454 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);
mbed_official 237:f3da66175598 455
mbed_official 237:f3da66175598 456 /******* Non-Blocking mode: DMA */
mbed_official 237:f3da66175598 457 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 458 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 459 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 460 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
mbed_official 237:f3da66175598 461 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);
mbed_official 237:f3da66175598 462 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);
mbed_official 237:f3da66175598 463
mbed_official 237:f3da66175598 464 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
mbed_official 237:f3da66175598 465 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 466 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 467 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 468 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 469 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 470 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 471 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 472 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 473 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 474
mbed_official 237:f3da66175598 475 /* Peripheral State functions **************************************/
mbed_official 237:f3da66175598 476 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 477 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
mbed_official 237:f3da66175598 478
mbed_official 237:f3da66175598 479 /**
mbed_official 237:f3da66175598 480 * @}
mbed_official 237:f3da66175598 481 */
mbed_official 237:f3da66175598 482
mbed_official 237:f3da66175598 483 /**
mbed_official 237:f3da66175598 484 * @}
mbed_official 237:f3da66175598 485 */
mbed_official 237:f3da66175598 486
mbed_official 237:f3da66175598 487 #ifdef __cplusplus
mbed_official 237:f3da66175598 488 }
mbed_official 237:f3da66175598 489 #endif
mbed_official 237:f3da66175598 490
mbed_official 237:f3da66175598 491
mbed_official 237:f3da66175598 492 #endif /* __STM32F3xx_HAL_I2C_H */
mbed_official 237:f3da66175598 493
mbed_official 237:f3da66175598 494 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/