mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Mar 21 11:45:09 2014 +0000
Revision:
130:1dec54e4aec3
Synchronized with git revision e5c9ff6781a4e277a5a454e5a0b037f76e31739d

Full URL: https://github.com/mbedmicro/mbed/commit/e5c9ff6781a4e277a5a454e5a0b037f76e31739d/

STM32F0-Discovery (STM32F051R8) initial port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 130:1dec54e4aec3 1 /**
mbed_official 130:1dec54e4aec3 2 ******************************************************************************
mbed_official 130:1dec54e4aec3 3 * @file stm32f0xx_i2c.h
mbed_official 130:1dec54e4aec3 4 * @author MCD Application Team
mbed_official 130:1dec54e4aec3 5 * @version V1.3.0
mbed_official 130:1dec54e4aec3 6 * @date 16-January-2014
mbed_official 130:1dec54e4aec3 7 * @brief This file contains all the functions prototypes for the I2C firmware
mbed_official 130:1dec54e4aec3 8 * library
mbed_official 130:1dec54e4aec3 9 ******************************************************************************
mbed_official 130:1dec54e4aec3 10 * @attention
mbed_official 130:1dec54e4aec3 11 *
mbed_official 130:1dec54e4aec3 12 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 130:1dec54e4aec3 13 *
mbed_official 130:1dec54e4aec3 14 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 130:1dec54e4aec3 15 * are permitted provided that the following conditions are met:
mbed_official 130:1dec54e4aec3 16 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 130:1dec54e4aec3 17 * this list of conditions and the following disclaimer.
mbed_official 130:1dec54e4aec3 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 130:1dec54e4aec3 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 130:1dec54e4aec3 20 * and/or other materials provided with the distribution.
mbed_official 130:1dec54e4aec3 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 130:1dec54e4aec3 22 * may be used to endorse or promote products derived from this software
mbed_official 130:1dec54e4aec3 23 * without specific prior written permission.
mbed_official 130:1dec54e4aec3 24 *
mbed_official 130:1dec54e4aec3 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 130:1dec54e4aec3 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 130:1dec54e4aec3 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 130:1dec54e4aec3 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 130:1dec54e4aec3 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 130:1dec54e4aec3 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 130:1dec54e4aec3 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 130:1dec54e4aec3 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 130:1dec54e4aec3 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 130:1dec54e4aec3 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 130:1dec54e4aec3 35 *
mbed_official 130:1dec54e4aec3 36 ******************************************************************************
mbed_official 130:1dec54e4aec3 37 */
mbed_official 130:1dec54e4aec3 38
mbed_official 130:1dec54e4aec3 39 /* Define to prevent recursive inclusion -------------------------------------*/
mbed_official 130:1dec54e4aec3 40 #ifndef __STM32F0XX_I2C_H
mbed_official 130:1dec54e4aec3 41 #define __STM32F0XX_I2C_H
mbed_official 130:1dec54e4aec3 42
mbed_official 130:1dec54e4aec3 43 #ifdef __cplusplus
mbed_official 130:1dec54e4aec3 44 extern "C" {
mbed_official 130:1dec54e4aec3 45 #endif
mbed_official 130:1dec54e4aec3 46
mbed_official 130:1dec54e4aec3 47 /* Includes ------------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 48 #include "stm32f0xx.h"
mbed_official 130:1dec54e4aec3 49
mbed_official 130:1dec54e4aec3 50 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 130:1dec54e4aec3 51 * @{
mbed_official 130:1dec54e4aec3 52 */
mbed_official 130:1dec54e4aec3 53
mbed_official 130:1dec54e4aec3 54 /** @addtogroup I2C
mbed_official 130:1dec54e4aec3 55 * @{
mbed_official 130:1dec54e4aec3 56 */
mbed_official 130:1dec54e4aec3 57
mbed_official 130:1dec54e4aec3 58 /* Exported types ------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 59
mbed_official 130:1dec54e4aec3 60 /**
mbed_official 130:1dec54e4aec3 61 * @brief I2C Init structure definition
mbed_official 130:1dec54e4aec3 62 */
mbed_official 130:1dec54e4aec3 63
mbed_official 130:1dec54e4aec3 64 typedef struct
mbed_official 130:1dec54e4aec3 65 {
mbed_official 130:1dec54e4aec3 66 uint32_t I2C_Timing; /*!< Specifies the I2C_TIMINGR_register value.
mbed_official 130:1dec54e4aec3 67 This parameter must be set by referring to I2C_Timing_Config_Tool*/
mbed_official 130:1dec54e4aec3 68
mbed_official 130:1dec54e4aec3 69 uint32_t I2C_AnalogFilter; /*!< Enables or disables analog noise filter.
mbed_official 130:1dec54e4aec3 70 This parameter can be a value of @ref I2C_Analog_Filter*/
mbed_official 130:1dec54e4aec3 71
mbed_official 130:1dec54e4aec3 72 uint32_t I2C_DigitalFilter; /*!< Configures the digital noise filter.
mbed_official 130:1dec54e4aec3 73 This parameter can be a number between 0x00 and 0x0F*/
mbed_official 130:1dec54e4aec3 74
mbed_official 130:1dec54e4aec3 75 uint32_t I2C_Mode; /*!< Specifies the I2C mode.
mbed_official 130:1dec54e4aec3 76 This parameter can be a value of @ref I2C_mode*/
mbed_official 130:1dec54e4aec3 77
mbed_official 130:1dec54e4aec3 78 uint32_t I2C_OwnAddress1; /*!< Specifies the device own address 1.
mbed_official 130:1dec54e4aec3 79 This parameter can be a 7-bit or 10-bit address*/
mbed_official 130:1dec54e4aec3 80
mbed_official 130:1dec54e4aec3 81 uint32_t I2C_Ack; /*!< Enables or disables the acknowledgement.
mbed_official 130:1dec54e4aec3 82 This parameter can be a value of @ref I2C_acknowledgement*/
mbed_official 130:1dec54e4aec3 83
mbed_official 130:1dec54e4aec3 84 uint32_t I2C_AcknowledgedAddress; /*!< Specifies if 7-bit or 10-bit address is acknowledged.
mbed_official 130:1dec54e4aec3 85 This parameter can be a value of @ref I2C_acknowledged_address*/
mbed_official 130:1dec54e4aec3 86 }I2C_InitTypeDef;
mbed_official 130:1dec54e4aec3 87
mbed_official 130:1dec54e4aec3 88 /* Exported constants --------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 89
mbed_official 130:1dec54e4aec3 90
mbed_official 130:1dec54e4aec3 91 /** @defgroup I2C_Exported_Constants
mbed_official 130:1dec54e4aec3 92 * @{
mbed_official 130:1dec54e4aec3 93 */
mbed_official 130:1dec54e4aec3 94
mbed_official 130:1dec54e4aec3 95 #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \
mbed_official 130:1dec54e4aec3 96 ((PERIPH) == I2C2))
mbed_official 130:1dec54e4aec3 97
mbed_official 130:1dec54e4aec3 98 #define IS_I2C_1_PERIPH(PERIPH) ((PERIPH) == I2C1)
mbed_official 130:1dec54e4aec3 99
mbed_official 130:1dec54e4aec3 100 /** @defgroup I2C_Analog_Filter
mbed_official 130:1dec54e4aec3 101 * @{
mbed_official 130:1dec54e4aec3 102 */
mbed_official 130:1dec54e4aec3 103
mbed_official 130:1dec54e4aec3 104 #define I2C_AnalogFilter_Enable ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 105 #define I2C_AnalogFilter_Disable I2C_CR1_ANFOFF
mbed_official 130:1dec54e4aec3 106
mbed_official 130:1dec54e4aec3 107 #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_AnalogFilter_Enable) || \
mbed_official 130:1dec54e4aec3 108 ((FILTER) == I2C_AnalogFilter_Disable))
mbed_official 130:1dec54e4aec3 109 /**
mbed_official 130:1dec54e4aec3 110 * @}
mbed_official 130:1dec54e4aec3 111 */
mbed_official 130:1dec54e4aec3 112
mbed_official 130:1dec54e4aec3 113 /** @defgroup I2C_Digital_Filter
mbed_official 130:1dec54e4aec3 114 * @{
mbed_official 130:1dec54e4aec3 115 */
mbed_official 130:1dec54e4aec3 116
mbed_official 130:1dec54e4aec3 117 #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000F)
mbed_official 130:1dec54e4aec3 118 /**
mbed_official 130:1dec54e4aec3 119 * @}
mbed_official 130:1dec54e4aec3 120 */
mbed_official 130:1dec54e4aec3 121
mbed_official 130:1dec54e4aec3 122 /** @defgroup I2C_mode
mbed_official 130:1dec54e4aec3 123 * @{
mbed_official 130:1dec54e4aec3 124 */
mbed_official 130:1dec54e4aec3 125
mbed_official 130:1dec54e4aec3 126 #define I2C_Mode_I2C ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 127 #define I2C_Mode_SMBusDevice I2C_CR1_SMBDEN
mbed_official 130:1dec54e4aec3 128 #define I2C_Mode_SMBusHost I2C_CR1_SMBHEN
mbed_official 130:1dec54e4aec3 129
mbed_official 130:1dec54e4aec3 130 #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \
mbed_official 130:1dec54e4aec3 131 ((MODE) == I2C_Mode_SMBusDevice) || \
mbed_official 130:1dec54e4aec3 132 ((MODE) == I2C_Mode_SMBusHost))
mbed_official 130:1dec54e4aec3 133 /**
mbed_official 130:1dec54e4aec3 134 * @}
mbed_official 130:1dec54e4aec3 135 */
mbed_official 130:1dec54e4aec3 136
mbed_official 130:1dec54e4aec3 137 /** @defgroup I2C_acknowledgement
mbed_official 130:1dec54e4aec3 138 * @{
mbed_official 130:1dec54e4aec3 139 */
mbed_official 130:1dec54e4aec3 140
mbed_official 130:1dec54e4aec3 141 #define I2C_Ack_Enable ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 142 #define I2C_Ack_Disable I2C_CR2_NACK
mbed_official 130:1dec54e4aec3 143
mbed_official 130:1dec54e4aec3 144 #define IS_I2C_ACK(ACK) (((ACK) == I2C_Ack_Enable) || \
mbed_official 130:1dec54e4aec3 145 ((ACK) == I2C_Ack_Disable))
mbed_official 130:1dec54e4aec3 146 /**
mbed_official 130:1dec54e4aec3 147 * @}
mbed_official 130:1dec54e4aec3 148 */
mbed_official 130:1dec54e4aec3 149
mbed_official 130:1dec54e4aec3 150 /** @defgroup I2C_acknowledged_address
mbed_official 130:1dec54e4aec3 151 * @{
mbed_official 130:1dec54e4aec3 152 */
mbed_official 130:1dec54e4aec3 153
mbed_official 130:1dec54e4aec3 154 #define I2C_AcknowledgedAddress_7bit ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 155 #define I2C_AcknowledgedAddress_10bit I2C_OAR1_OA1MODE
mbed_official 130:1dec54e4aec3 156
mbed_official 130:1dec54e4aec3 157 #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
mbed_official 130:1dec54e4aec3 158 ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
mbed_official 130:1dec54e4aec3 159 /**
mbed_official 130:1dec54e4aec3 160 * @}
mbed_official 130:1dec54e4aec3 161 */
mbed_official 130:1dec54e4aec3 162
mbed_official 130:1dec54e4aec3 163 /** @defgroup I2C_own_address1
mbed_official 130:1dec54e4aec3 164 * @{
mbed_official 130:1dec54e4aec3 165 */
mbed_official 130:1dec54e4aec3 166
mbed_official 130:1dec54e4aec3 167 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF)
mbed_official 130:1dec54e4aec3 168 /**
mbed_official 130:1dec54e4aec3 169 * @}
mbed_official 130:1dec54e4aec3 170 */
mbed_official 130:1dec54e4aec3 171
mbed_official 130:1dec54e4aec3 172 /** @defgroup I2C_transfer_direction
mbed_official 130:1dec54e4aec3 173 * @{
mbed_official 130:1dec54e4aec3 174 */
mbed_official 130:1dec54e4aec3 175
mbed_official 130:1dec54e4aec3 176 #define I2C_Direction_Transmitter ((uint16_t)0x0000)
mbed_official 130:1dec54e4aec3 177 #define I2C_Direction_Receiver ((uint16_t)0x0400)
mbed_official 130:1dec54e4aec3 178
mbed_official 130:1dec54e4aec3 179 #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
mbed_official 130:1dec54e4aec3 180 ((DIRECTION) == I2C_Direction_Receiver))
mbed_official 130:1dec54e4aec3 181 /**
mbed_official 130:1dec54e4aec3 182 * @}
mbed_official 130:1dec54e4aec3 183 */
mbed_official 130:1dec54e4aec3 184
mbed_official 130:1dec54e4aec3 185 /** @defgroup I2C_DMA_transfer_requests
mbed_official 130:1dec54e4aec3 186 * @{
mbed_official 130:1dec54e4aec3 187 */
mbed_official 130:1dec54e4aec3 188
mbed_official 130:1dec54e4aec3 189 #define I2C_DMAReq_Tx I2C_CR1_TXDMAEN
mbed_official 130:1dec54e4aec3 190 #define I2C_DMAReq_Rx I2C_CR1_RXDMAEN
mbed_official 130:1dec54e4aec3 191
mbed_official 130:1dec54e4aec3 192 #define IS_I2C_DMA_REQ(REQ) ((((REQ) & (uint32_t)0xFFFF3FFF) == 0x00) && ((REQ) != 0x00))
mbed_official 130:1dec54e4aec3 193 /**
mbed_official 130:1dec54e4aec3 194 * @}
mbed_official 130:1dec54e4aec3 195 */
mbed_official 130:1dec54e4aec3 196
mbed_official 130:1dec54e4aec3 197 /** @defgroup I2C_slave_address
mbed_official 130:1dec54e4aec3 198 * @{
mbed_official 130:1dec54e4aec3 199 */
mbed_official 130:1dec54e4aec3 200
mbed_official 130:1dec54e4aec3 201 #define IS_I2C_SLAVE_ADDRESS(ADDRESS) ((ADDRESS) <= (uint16_t)0x03FF)
mbed_official 130:1dec54e4aec3 202 /**
mbed_official 130:1dec54e4aec3 203 * @}
mbed_official 130:1dec54e4aec3 204 */
mbed_official 130:1dec54e4aec3 205
mbed_official 130:1dec54e4aec3 206
mbed_official 130:1dec54e4aec3 207 /** @defgroup I2C_own_address2
mbed_official 130:1dec54e4aec3 208 * @{
mbed_official 130:1dec54e4aec3 209 */
mbed_official 130:1dec54e4aec3 210
mbed_official 130:1dec54e4aec3 211 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF)
mbed_official 130:1dec54e4aec3 212
mbed_official 130:1dec54e4aec3 213 /**
mbed_official 130:1dec54e4aec3 214 * @}
mbed_official 130:1dec54e4aec3 215 */
mbed_official 130:1dec54e4aec3 216
mbed_official 130:1dec54e4aec3 217 /** @defgroup I2C_own_address2_mask
mbed_official 130:1dec54e4aec3 218 * @{
mbed_official 130:1dec54e4aec3 219 */
mbed_official 130:1dec54e4aec3 220
mbed_official 130:1dec54e4aec3 221 #define I2C_OA2_NoMask ((uint8_t)0x00)
mbed_official 130:1dec54e4aec3 222 #define I2C_OA2_Mask01 ((uint8_t)0x01)
mbed_official 130:1dec54e4aec3 223 #define I2C_OA2_Mask02 ((uint8_t)0x02)
mbed_official 130:1dec54e4aec3 224 #define I2C_OA2_Mask03 ((uint8_t)0x03)
mbed_official 130:1dec54e4aec3 225 #define I2C_OA2_Mask04 ((uint8_t)0x04)
mbed_official 130:1dec54e4aec3 226 #define I2C_OA2_Mask05 ((uint8_t)0x05)
mbed_official 130:1dec54e4aec3 227 #define I2C_OA2_Mask06 ((uint8_t)0x06)
mbed_official 130:1dec54e4aec3 228 #define I2C_OA2_Mask07 ((uint8_t)0x07)
mbed_official 130:1dec54e4aec3 229
mbed_official 130:1dec54e4aec3 230 #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NoMask) || \
mbed_official 130:1dec54e4aec3 231 ((MASK) == I2C_OA2_Mask01) || \
mbed_official 130:1dec54e4aec3 232 ((MASK) == I2C_OA2_Mask02) || \
mbed_official 130:1dec54e4aec3 233 ((MASK) == I2C_OA2_Mask03) || \
mbed_official 130:1dec54e4aec3 234 ((MASK) == I2C_OA2_Mask04) || \
mbed_official 130:1dec54e4aec3 235 ((MASK) == I2C_OA2_Mask05) || \
mbed_official 130:1dec54e4aec3 236 ((MASK) == I2C_OA2_Mask06) || \
mbed_official 130:1dec54e4aec3 237 ((MASK) == I2C_OA2_Mask07))
mbed_official 130:1dec54e4aec3 238
mbed_official 130:1dec54e4aec3 239 /**
mbed_official 130:1dec54e4aec3 240 * @}
mbed_official 130:1dec54e4aec3 241 */
mbed_official 130:1dec54e4aec3 242
mbed_official 130:1dec54e4aec3 243 /** @defgroup I2C_timeout
mbed_official 130:1dec54e4aec3 244 * @{
mbed_official 130:1dec54e4aec3 245 */
mbed_official 130:1dec54e4aec3 246
mbed_official 130:1dec54e4aec3 247 #define IS_I2C_TIMEOUT(TIMEOUT) ((TIMEOUT) <= (uint16_t)0x0FFF)
mbed_official 130:1dec54e4aec3 248
mbed_official 130:1dec54e4aec3 249 /**
mbed_official 130:1dec54e4aec3 250 * @}
mbed_official 130:1dec54e4aec3 251 */
mbed_official 130:1dec54e4aec3 252
mbed_official 130:1dec54e4aec3 253 /** @defgroup I2C_registers
mbed_official 130:1dec54e4aec3 254 * @{
mbed_official 130:1dec54e4aec3 255 */
mbed_official 130:1dec54e4aec3 256
mbed_official 130:1dec54e4aec3 257 #define I2C_Register_CR1 ((uint8_t)0x00)
mbed_official 130:1dec54e4aec3 258 #define I2C_Register_CR2 ((uint8_t)0x04)
mbed_official 130:1dec54e4aec3 259 #define I2C_Register_OAR1 ((uint8_t)0x08)
mbed_official 130:1dec54e4aec3 260 #define I2C_Register_OAR2 ((uint8_t)0x0C)
mbed_official 130:1dec54e4aec3 261 #define I2C_Register_TIMINGR ((uint8_t)0x10)
mbed_official 130:1dec54e4aec3 262 #define I2C_Register_TIMEOUTR ((uint8_t)0x14)
mbed_official 130:1dec54e4aec3 263 #define I2C_Register_ISR ((uint8_t)0x18)
mbed_official 130:1dec54e4aec3 264 #define I2C_Register_ICR ((uint8_t)0x1C)
mbed_official 130:1dec54e4aec3 265 #define I2C_Register_PECR ((uint8_t)0x20)
mbed_official 130:1dec54e4aec3 266 #define I2C_Register_RXDR ((uint8_t)0x24)
mbed_official 130:1dec54e4aec3 267 #define I2C_Register_TXDR ((uint8_t)0x28)
mbed_official 130:1dec54e4aec3 268
mbed_official 130:1dec54e4aec3 269 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
mbed_official 130:1dec54e4aec3 270 ((REGISTER) == I2C_Register_CR2) || \
mbed_official 130:1dec54e4aec3 271 ((REGISTER) == I2C_Register_OAR1) || \
mbed_official 130:1dec54e4aec3 272 ((REGISTER) == I2C_Register_OAR2) || \
mbed_official 130:1dec54e4aec3 273 ((REGISTER) == I2C_Register_TIMINGR) || \
mbed_official 130:1dec54e4aec3 274 ((REGISTER) == I2C_Register_TIMEOUTR) || \
mbed_official 130:1dec54e4aec3 275 ((REGISTER) == I2C_Register_ISR) || \
mbed_official 130:1dec54e4aec3 276 ((REGISTER) == I2C_Register_ICR) || \
mbed_official 130:1dec54e4aec3 277 ((REGISTER) == I2C_Register_PECR) || \
mbed_official 130:1dec54e4aec3 278 ((REGISTER) == I2C_Register_RXDR) || \
mbed_official 130:1dec54e4aec3 279 ((REGISTER) == I2C_Register_TXDR))
mbed_official 130:1dec54e4aec3 280 /**
mbed_official 130:1dec54e4aec3 281 * @}
mbed_official 130:1dec54e4aec3 282 */
mbed_official 130:1dec54e4aec3 283
mbed_official 130:1dec54e4aec3 284 /** @defgroup I2C_interrupts_definition
mbed_official 130:1dec54e4aec3 285 * @{
mbed_official 130:1dec54e4aec3 286 */
mbed_official 130:1dec54e4aec3 287
mbed_official 130:1dec54e4aec3 288 #define I2C_IT_ERRI I2C_CR1_ERRIE
mbed_official 130:1dec54e4aec3 289 #define I2C_IT_TCI I2C_CR1_TCIE
mbed_official 130:1dec54e4aec3 290 #define I2C_IT_STOPI I2C_CR1_STOPIE
mbed_official 130:1dec54e4aec3 291 #define I2C_IT_NACKI I2C_CR1_NACKIE
mbed_official 130:1dec54e4aec3 292 #define I2C_IT_ADDRI I2C_CR1_ADDRIE
mbed_official 130:1dec54e4aec3 293 #define I2C_IT_RXI I2C_CR1_RXIE
mbed_official 130:1dec54e4aec3 294 #define I2C_IT_TXI I2C_CR1_TXIE
mbed_official 130:1dec54e4aec3 295
mbed_official 130:1dec54e4aec3 296 #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint32_t)0xFFFFFF01) == 0x00) && ((IT) != 0x00))
mbed_official 130:1dec54e4aec3 297
mbed_official 130:1dec54e4aec3 298 /**
mbed_official 130:1dec54e4aec3 299 * @}
mbed_official 130:1dec54e4aec3 300 */
mbed_official 130:1dec54e4aec3 301
mbed_official 130:1dec54e4aec3 302 /** @defgroup I2C_flags_definition
mbed_official 130:1dec54e4aec3 303 * @{
mbed_official 130:1dec54e4aec3 304 */
mbed_official 130:1dec54e4aec3 305
mbed_official 130:1dec54e4aec3 306 #define I2C_FLAG_TXE I2C_ISR_TXE
mbed_official 130:1dec54e4aec3 307 #define I2C_FLAG_TXIS I2C_ISR_TXIS
mbed_official 130:1dec54e4aec3 308 #define I2C_FLAG_RXNE I2C_ISR_RXNE
mbed_official 130:1dec54e4aec3 309 #define I2C_FLAG_ADDR I2C_ISR_ADDR
mbed_official 130:1dec54e4aec3 310 #define I2C_FLAG_NACKF I2C_ISR_NACKF
mbed_official 130:1dec54e4aec3 311 #define I2C_FLAG_STOPF I2C_ISR_STOPF
mbed_official 130:1dec54e4aec3 312 #define I2C_FLAG_TC I2C_ISR_TC
mbed_official 130:1dec54e4aec3 313 #define I2C_FLAG_TCR I2C_ISR_TCR
mbed_official 130:1dec54e4aec3 314 #define I2C_FLAG_BERR I2C_ISR_BERR
mbed_official 130:1dec54e4aec3 315 #define I2C_FLAG_ARLO I2C_ISR_ARLO
mbed_official 130:1dec54e4aec3 316 #define I2C_FLAG_OVR I2C_ISR_OVR
mbed_official 130:1dec54e4aec3 317 #define I2C_FLAG_PECERR I2C_ISR_PECERR
mbed_official 130:1dec54e4aec3 318 #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT
mbed_official 130:1dec54e4aec3 319 #define I2C_FLAG_ALERT I2C_ISR_ALERT
mbed_official 130:1dec54e4aec3 320 #define I2C_FLAG_BUSY I2C_ISR_BUSY
mbed_official 130:1dec54e4aec3 321
mbed_official 130:1dec54e4aec3 322 #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFF4000) == 0x00) && ((FLAG) != 0x00))
mbed_official 130:1dec54e4aec3 323
mbed_official 130:1dec54e4aec3 324 #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_TXIS) || \
mbed_official 130:1dec54e4aec3 325 ((FLAG) == I2C_FLAG_RXNE) || ((FLAG) == I2C_FLAG_ADDR) || \
mbed_official 130:1dec54e4aec3 326 ((FLAG) == I2C_FLAG_NACKF) || ((FLAG) == I2C_FLAG_STOPF) || \
mbed_official 130:1dec54e4aec3 327 ((FLAG) == I2C_FLAG_TC) || ((FLAG) == I2C_FLAG_TCR) || \
mbed_official 130:1dec54e4aec3 328 ((FLAG) == I2C_FLAG_BERR) || ((FLAG) == I2C_FLAG_ARLO) || \
mbed_official 130:1dec54e4aec3 329 ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_PECERR) || \
mbed_official 130:1dec54e4aec3 330 ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_ALERT) || \
mbed_official 130:1dec54e4aec3 331 ((FLAG) == I2C_FLAG_BUSY))
mbed_official 130:1dec54e4aec3 332
mbed_official 130:1dec54e4aec3 333 /**
mbed_official 130:1dec54e4aec3 334 * @}
mbed_official 130:1dec54e4aec3 335 */
mbed_official 130:1dec54e4aec3 336
mbed_official 130:1dec54e4aec3 337
mbed_official 130:1dec54e4aec3 338 /** @defgroup I2C_interrupts_definition
mbed_official 130:1dec54e4aec3 339 * @{
mbed_official 130:1dec54e4aec3 340 */
mbed_official 130:1dec54e4aec3 341
mbed_official 130:1dec54e4aec3 342 #define I2C_IT_TXIS I2C_ISR_TXIS
mbed_official 130:1dec54e4aec3 343 #define I2C_IT_RXNE I2C_ISR_RXNE
mbed_official 130:1dec54e4aec3 344 #define I2C_IT_ADDR I2C_ISR_ADDR
mbed_official 130:1dec54e4aec3 345 #define I2C_IT_NACKF I2C_ISR_NACKF
mbed_official 130:1dec54e4aec3 346 #define I2C_IT_STOPF I2C_ISR_STOPF
mbed_official 130:1dec54e4aec3 347 #define I2C_IT_TC I2C_ISR_TC
mbed_official 130:1dec54e4aec3 348 #define I2C_IT_TCR I2C_ISR_TCR
mbed_official 130:1dec54e4aec3 349 #define I2C_IT_BERR I2C_ISR_BERR
mbed_official 130:1dec54e4aec3 350 #define I2C_IT_ARLO I2C_ISR_ARLO
mbed_official 130:1dec54e4aec3 351 #define I2C_IT_OVR I2C_ISR_OVR
mbed_official 130:1dec54e4aec3 352 #define I2C_IT_PECERR I2C_ISR_PECERR
mbed_official 130:1dec54e4aec3 353 #define I2C_IT_TIMEOUT I2C_ISR_TIMEOUT
mbed_official 130:1dec54e4aec3 354 #define I2C_IT_ALERT I2C_ISR_ALERT
mbed_official 130:1dec54e4aec3 355
mbed_official 130:1dec54e4aec3 356 #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint32_t)0xFFFFC001) == 0x00) && ((IT) != 0x00))
mbed_official 130:1dec54e4aec3 357
mbed_official 130:1dec54e4aec3 358 #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_TXIS) || ((IT) == I2C_IT_RXNE) || \
mbed_official 130:1dec54e4aec3 359 ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_NACKF) || \
mbed_official 130:1dec54e4aec3 360 ((IT) == I2C_IT_STOPF) || ((IT) == I2C_IT_TC) || \
mbed_official 130:1dec54e4aec3 361 ((IT) == I2C_IT_TCR) || ((IT) == I2C_IT_BERR) || \
mbed_official 130:1dec54e4aec3 362 ((IT) == I2C_IT_ARLO) || ((IT) == I2C_IT_OVR) || \
mbed_official 130:1dec54e4aec3 363 ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_TIMEOUT) || \
mbed_official 130:1dec54e4aec3 364 ((IT) == I2C_IT_ALERT))
mbed_official 130:1dec54e4aec3 365
mbed_official 130:1dec54e4aec3 366
mbed_official 130:1dec54e4aec3 367 /**
mbed_official 130:1dec54e4aec3 368 * @}
mbed_official 130:1dec54e4aec3 369 */
mbed_official 130:1dec54e4aec3 370
mbed_official 130:1dec54e4aec3 371 /** @defgroup I2C_ReloadEndMode_definition
mbed_official 130:1dec54e4aec3 372 * @{
mbed_official 130:1dec54e4aec3 373 */
mbed_official 130:1dec54e4aec3 374
mbed_official 130:1dec54e4aec3 375 #define I2C_Reload_Mode I2C_CR2_RELOAD
mbed_official 130:1dec54e4aec3 376 #define I2C_AutoEnd_Mode I2C_CR2_AUTOEND
mbed_official 130:1dec54e4aec3 377 #define I2C_SoftEnd_Mode ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 378
mbed_official 130:1dec54e4aec3 379
mbed_official 130:1dec54e4aec3 380 #define IS_RELOAD_END_MODE(MODE) (((MODE) == I2C_Reload_Mode) || \
mbed_official 130:1dec54e4aec3 381 ((MODE) == I2C_AutoEnd_Mode) || \
mbed_official 130:1dec54e4aec3 382 ((MODE) == I2C_SoftEnd_Mode))
mbed_official 130:1dec54e4aec3 383
mbed_official 130:1dec54e4aec3 384
mbed_official 130:1dec54e4aec3 385 /**
mbed_official 130:1dec54e4aec3 386 * @}
mbed_official 130:1dec54e4aec3 387 */
mbed_official 130:1dec54e4aec3 388
mbed_official 130:1dec54e4aec3 389 /** @defgroup I2C_StartStopMode_definition
mbed_official 130:1dec54e4aec3 390 * @{
mbed_official 130:1dec54e4aec3 391 */
mbed_official 130:1dec54e4aec3 392
mbed_official 130:1dec54e4aec3 393 #define I2C_No_StartStop ((uint32_t)0x00000000)
mbed_official 130:1dec54e4aec3 394 #define I2C_Generate_Stop I2C_CR2_STOP
mbed_official 130:1dec54e4aec3 395 #define I2C_Generate_Start_Read (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
mbed_official 130:1dec54e4aec3 396 #define I2C_Generate_Start_Write I2C_CR2_START
mbed_official 130:1dec54e4aec3 397
mbed_official 130:1dec54e4aec3 398
mbed_official 130:1dec54e4aec3 399 #define IS_START_STOP_MODE(MODE) (((MODE) == I2C_Generate_Stop) || \
mbed_official 130:1dec54e4aec3 400 ((MODE) == I2C_Generate_Start_Read) || \
mbed_official 130:1dec54e4aec3 401 ((MODE) == I2C_Generate_Start_Write) || \
mbed_official 130:1dec54e4aec3 402 ((MODE) == I2C_No_StartStop))
mbed_official 130:1dec54e4aec3 403
mbed_official 130:1dec54e4aec3 404
mbed_official 130:1dec54e4aec3 405 /**
mbed_official 130:1dec54e4aec3 406 * @}
mbed_official 130:1dec54e4aec3 407 */
mbed_official 130:1dec54e4aec3 408
mbed_official 130:1dec54e4aec3 409 /**
mbed_official 130:1dec54e4aec3 410 * @}
mbed_official 130:1dec54e4aec3 411 */
mbed_official 130:1dec54e4aec3 412
mbed_official 130:1dec54e4aec3 413 /* Exported macro ------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 414 /* Exported functions ------------------------------------------------------- */
mbed_official 130:1dec54e4aec3 415
mbed_official 130:1dec54e4aec3 416
mbed_official 130:1dec54e4aec3 417 /* Initialization and Configuration functions *********************************/
mbed_official 130:1dec54e4aec3 418 void I2C_DeInit(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 419 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
mbed_official 130:1dec54e4aec3 420 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
mbed_official 130:1dec54e4aec3 421 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 422 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 423 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint32_t I2C_IT, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 424 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 425 void I2C_StopModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState); /*!< not applicable for STM32F030 devices */
mbed_official 130:1dec54e4aec3 426 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 427 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Mask);
mbed_official 130:1dec54e4aec3 428 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 429 void I2C_SlaveByteControlCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 430 void I2C_SlaveAddressConfig(I2C_TypeDef* I2Cx, uint16_t Address);
mbed_official 130:1dec54e4aec3 431 void I2C_10BitAddressingModeCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 432
mbed_official 130:1dec54e4aec3 433 /* Communications handling functions ******************************************/
mbed_official 130:1dec54e4aec3 434 void I2C_AutoEndCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 435 void I2C_ReloadCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 436 void I2C_NumberOfBytesConfig(I2C_TypeDef* I2Cx, uint8_t Number_Bytes);
mbed_official 130:1dec54e4aec3 437 void I2C_MasterRequestConfig(I2C_TypeDef* I2Cx, uint16_t I2C_Direction);
mbed_official 130:1dec54e4aec3 438 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 439 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 440 void I2C_10BitAddressHeaderCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 441 void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 442 uint8_t I2C_GetAddressMatched(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 443 uint16_t I2C_GetTransferDirection(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 444 void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode);
mbed_official 130:1dec54e4aec3 445
mbed_official 130:1dec54e4aec3 446 /* SMBUS management functions ************************************************/
mbed_official 130:1dec54e4aec3 447 void I2C_SMBusAlertCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 448 void I2C_ClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 449 void I2C_ExtendedClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 450 void I2C_IdleClockTimeoutCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 451 void I2C_TimeoutAConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
mbed_official 130:1dec54e4aec3 452 void I2C_TimeoutBConfig(I2C_TypeDef* I2Cx, uint16_t Timeout);
mbed_official 130:1dec54e4aec3 453 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 454 void I2C_PECRequestCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 455 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 456
mbed_official 130:1dec54e4aec3 457 /* I2C registers management functions *****************************************/
mbed_official 130:1dec54e4aec3 458 uint32_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register);
mbed_official 130:1dec54e4aec3 459
mbed_official 130:1dec54e4aec3 460 /* Data transfers management functions ****************************************/
mbed_official 130:1dec54e4aec3 461 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
mbed_official 130:1dec54e4aec3 462 uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
mbed_official 130:1dec54e4aec3 463
mbed_official 130:1dec54e4aec3 464 /* DMA transfers management functions *****************************************/
mbed_official 130:1dec54e4aec3 465 void I2C_DMACmd(I2C_TypeDef* I2Cx, uint32_t I2C_DMAReq, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 466
mbed_official 130:1dec54e4aec3 467 /* Interrupts and flags management functions **********************************/
mbed_official 130:1dec54e4aec3 468 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
mbed_official 130:1dec54e4aec3 469 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
mbed_official 130:1dec54e4aec3 470 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
mbed_official 130:1dec54e4aec3 471 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
mbed_official 130:1dec54e4aec3 472
mbed_official 130:1dec54e4aec3 473
mbed_official 130:1dec54e4aec3 474 #ifdef __cplusplus
mbed_official 130:1dec54e4aec3 475 }
mbed_official 130:1dec54e4aec3 476 #endif
mbed_official 130:1dec54e4aec3 477
mbed_official 130:1dec54e4aec3 478 #endif /*__STM32F0XX_I2C_H */
mbed_official 130:1dec54e4aec3 479
mbed_official 130:1dec54e4aec3 480 /**
mbed_official 130:1dec54e4aec3 481 * @}
mbed_official 130:1dec54e4aec3 482 */
mbed_official 130:1dec54e4aec3 483
mbed_official 130:1dec54e4aec3 484 /**
mbed_official 130:1dec54e4aec3 485 * @}
mbed_official 130:1dec54e4aec3 486 */
mbed_official 130:1dec54e4aec3 487
mbed_official 130:1dec54e4aec3 488 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/