The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Tue Feb 14 11:24:20 2017 +0000
Revision:
136:ef9c61f8c49f
Parent:
135:176b8275d35d
Release 136 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3432: Target STM USBHOST support https://github.com/ARMmbed/mbed-os/pull/3432
3181: NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now https://github.com/ARMmbed/mbed-os/pull/3181
3626: NUCLEO_F412ZG : Add USB Device +Host https://github.com/ARMmbed/mbed-os/pull/3626
3628: Fix warnings https://github.com/ARMmbed/mbed-os/pull/3628
3629: STM32: L0 LL layer https://github.com/ARMmbed/mbed-os/pull/3629
3632: IDE Export support for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3632
3642: Missing IRQ pin fix for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3642
3664: Fix ncs36510 sleep definitions https://github.com/ARMmbed/mbed-os/pull/3664
3655: [STM32F4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3655
3657: [STM32L4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3657
3658: [STM32F3] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3658
3685: STM32: I2C: reset state machine https://github.com/ARMmbed/mbed-os/pull/3685
3692: uVisor: Standardize available legacy heap and stack https://github.com/ARMmbed/mbed-os/pull/3692
3621: Fix for #2884, LPC824: export to LPCXpresso, target running with wron https://github.com/ARMmbed/mbed-os/pull/3621
3649: [STM32F7] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3649
3695: Enforce device_name is valid in targets.json https://github.com/ARMmbed/mbed-os/pull/3695
3723: NCS36510: spi_format function bug fix https://github.com/ARMmbed/mbed-os/pull/3723

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 86:04dd9b1680ae 1 /**
bogdanm 86:04dd9b1680ae 2 ******************************************************************************
bogdanm 86:04dd9b1680ae 3 * @file stm32f3xx_hal_i2c.h
bogdanm 86:04dd9b1680ae 4 * @author MCD Application Team
<> 135:176b8275d35d 5 * @version V1.4.0
<> 135:176b8275d35d 6 * @date 16-December-2016
bogdanm 86:04dd9b1680ae 7 * @brief Header file of I2C HAL module.
bogdanm 86:04dd9b1680ae 8 ******************************************************************************
bogdanm 86:04dd9b1680ae 9 * @attention
bogdanm 86:04dd9b1680ae 10 *
Kojto 122:f9eeca106725 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
bogdanm 86:04dd9b1680ae 12 *
bogdanm 86:04dd9b1680ae 13 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 86:04dd9b1680ae 14 * are permitted provided that the following conditions are met:
bogdanm 86:04dd9b1680ae 15 * 1. Redistributions of source code must retain the above copyright notice,
bogdanm 86:04dd9b1680ae 16 * this list of conditions and the following disclaimer.
bogdanm 86:04dd9b1680ae 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
bogdanm 86:04dd9b1680ae 18 * this list of conditions and the following disclaimer in the documentation
bogdanm 86:04dd9b1680ae 19 * and/or other materials provided with the distribution.
bogdanm 86:04dd9b1680ae 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bogdanm 86:04dd9b1680ae 21 * may be used to endorse or promote products derived from this software
bogdanm 86:04dd9b1680ae 22 * without specific prior written permission.
bogdanm 86:04dd9b1680ae 23 *
bogdanm 86:04dd9b1680ae 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bogdanm 86:04dd9b1680ae 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bogdanm 86:04dd9b1680ae 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 86:04dd9b1680ae 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bogdanm 86:04dd9b1680ae 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bogdanm 86:04dd9b1680ae 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bogdanm 86:04dd9b1680ae 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bogdanm 86:04dd9b1680ae 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bogdanm 86:04dd9b1680ae 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bogdanm 86:04dd9b1680ae 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 86:04dd9b1680ae 34 *
bogdanm 86:04dd9b1680ae 35 ******************************************************************************
Kojto 122:f9eeca106725 36 */
bogdanm 86:04dd9b1680ae 37
bogdanm 86:04dd9b1680ae 38 /* Define to prevent recursive inclusion -------------------------------------*/
bogdanm 86:04dd9b1680ae 39 #ifndef __STM32F3xx_HAL_I2C_H
bogdanm 86:04dd9b1680ae 40 #define __STM32F3xx_HAL_I2C_H
bogdanm 86:04dd9b1680ae 41
bogdanm 86:04dd9b1680ae 42 #ifdef __cplusplus
bogdanm 86:04dd9b1680ae 43 extern "C" {
bogdanm 86:04dd9b1680ae 44 #endif
bogdanm 86:04dd9b1680ae 45
bogdanm 86:04dd9b1680ae 46 /* Includes ------------------------------------------------------------------*/
bogdanm 86:04dd9b1680ae 47 #include "stm32f3xx_hal_def.h"
bogdanm 86:04dd9b1680ae 48
bogdanm 86:04dd9b1680ae 49 /** @addtogroup STM32F3xx_HAL_Driver
bogdanm 86:04dd9b1680ae 50 * @{
bogdanm 86:04dd9b1680ae 51 */
bogdanm 86:04dd9b1680ae 52
bogdanm 86:04dd9b1680ae 53 /** @addtogroup I2C
bogdanm 86:04dd9b1680ae 54 * @{
bogdanm 86:04dd9b1680ae 55 */
bogdanm 86:04dd9b1680ae 56
Kojto 122:f9eeca106725 57 /* Exported types ------------------------------------------------------------*/
bogdanm 92:4fc01daae5a5 58 /** @defgroup I2C_Exported_Types I2C Exported Types
bogdanm 92:4fc01daae5a5 59 * @{
bogdanm 92:4fc01daae5a5 60 */
bogdanm 86:04dd9b1680ae 61
bogdanm 92:4fc01daae5a5 62 /** @defgroup I2C_Configuration_Structure_definition I2C Configuration Structure definition
bogdanm 86:04dd9b1680ae 63 * @brief I2C Configuration Structure definition
bogdanm 92:4fc01daae5a5 64 * @{
bogdanm 86:04dd9b1680ae 65 */
bogdanm 86:04dd9b1680ae 66 typedef struct
bogdanm 86:04dd9b1680ae 67 {
bogdanm 86:04dd9b1680ae 68 uint32_t Timing; /*!< Specifies the I2C_TIMINGR_register value.
bogdanm 86:04dd9b1680ae 69 This parameter calculated by referring to I2C initialization
bogdanm 86:04dd9b1680ae 70 section in Reference manual */
bogdanm 86:04dd9b1680ae 71
bogdanm 86:04dd9b1680ae 72 uint32_t OwnAddress1; /*!< Specifies the first device own address.
bogdanm 86:04dd9b1680ae 73 This parameter can be a 7-bit or 10-bit address. */
bogdanm 86:04dd9b1680ae 74
bogdanm 86:04dd9b1680ae 75 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
Kojto 122:f9eeca106725 76 This parameter can be a value of @ref I2C_ADDRESSING_MODE */
bogdanm 86:04dd9b1680ae 77
bogdanm 86:04dd9b1680ae 78 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
Kojto 122:f9eeca106725 79 This parameter can be a value of @ref I2C_DUAL_ADDRESSING_MODE */
bogdanm 86:04dd9b1680ae 80
bogdanm 86:04dd9b1680ae 81 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected
bogdanm 86:04dd9b1680ae 82 This parameter can be a 7-bit address. */
bogdanm 86:04dd9b1680ae 83
Kojto 122:f9eeca106725 84 uint32_t OwnAddress2Masks; /*!< Specifies the acknowledge mask address second device own address if dual addressing mode is selected
Kojto 122:f9eeca106725 85 This parameter can be a value of @ref I2C_OWN_ADDRESS2_MASKS */
bogdanm 86:04dd9b1680ae 86
bogdanm 86:04dd9b1680ae 87 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
Kojto 122:f9eeca106725 88 This parameter can be a value of @ref I2C_GENERAL_CALL_ADDRESSING_MODE */
bogdanm 86:04dd9b1680ae 89
bogdanm 86:04dd9b1680ae 90 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
Kojto 122:f9eeca106725 91 This parameter can be a value of @ref I2C_NOSTRETCH_MODE */
bogdanm 86:04dd9b1680ae 92
bogdanm 86:04dd9b1680ae 93 }I2C_InitTypeDef;
bogdanm 86:04dd9b1680ae 94
bogdanm 86:04dd9b1680ae 95 /**
bogdanm 92:4fc01daae5a5 96 * @}
bogdanm 92:4fc01daae5a5 97 */
bogdanm 92:4fc01daae5a5 98
bogdanm 92:4fc01daae5a5 99 /** @defgroup HAL_state_structure_definition HAL state structure definition
Kojto 122:f9eeca106725 100 * @brief HAL State structure definition
Kojto 122:f9eeca106725 101 * @note HAL I2C State value coding follow below described bitmap :\n
Kojto 122:f9eeca106725 102 * b7-b6 Error information\n
Kojto 122:f9eeca106725 103 * 00 : No Error\n
Kojto 122:f9eeca106725 104 * 01 : Abort (Abort user request on going)\n
Kojto 122:f9eeca106725 105 * 10 : Timeout\n
Kojto 122:f9eeca106725 106 * 11 : Error\n
Kojto 122:f9eeca106725 107 * b5 IP initilisation status\n
Kojto 122:f9eeca106725 108 * 0 : Reset (IP not initialized)\n
Kojto 122:f9eeca106725 109 * 1 : Init done (IP initialized and ready to use. HAL I2C Init function called)\n
Kojto 122:f9eeca106725 110 * b4 (not used)\n
Kojto 122:f9eeca106725 111 * x : Should be set to 0\n
Kojto 122:f9eeca106725 112 * b3\n
Kojto 122:f9eeca106725 113 * 0 : Ready or Busy (No Listen mode ongoing)\n
Kojto 122:f9eeca106725 114 * 1 : Listen (IP in Address Listen Mode)\n
Kojto 122:f9eeca106725 115 * b2 Intrinsic process state\n
Kojto 122:f9eeca106725 116 * 0 : Ready\n
Kojto 122:f9eeca106725 117 * 1 : Busy (IP busy with some configuration or internal operations)\n
Kojto 122:f9eeca106725 118 * b1 Rx state\n
Kojto 122:f9eeca106725 119 * 0 : Ready (no Rx operation ongoing)\n
Kojto 122:f9eeca106725 120 * 1 : Busy (Rx operation ongoing)\n
Kojto 122:f9eeca106725 121 * b0 Tx state\n
Kojto 122:f9eeca106725 122 * 0 : Ready (no Tx operation ongoing)\n
Kojto 122:f9eeca106725 123 * 1 : Busy (Tx operation ongoing)
bogdanm 92:4fc01daae5a5 124 * @{
bogdanm 86:04dd9b1680ae 125 */
bogdanm 86:04dd9b1680ae 126 typedef enum
bogdanm 86:04dd9b1680ae 127 {
Kojto 122:f9eeca106725 128 HAL_I2C_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
Kojto 122:f9eeca106725 129 HAL_I2C_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use */
Kojto 122:f9eeca106725 130 HAL_I2C_STATE_BUSY = 0x24U, /*!< An internal process is ongoing */
Kojto 122:f9eeca106725 131 HAL_I2C_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing */
Kojto 122:f9eeca106725 132 HAL_I2C_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
Kojto 122:f9eeca106725 133 HAL_I2C_STATE_LISTEN = 0x28U, /*!< Address Listen Mode is ongoing */
Kojto 122:f9eeca106725 134 HAL_I2C_STATE_BUSY_TX_LISTEN = 0x29U, /*!< Address Listen Mode and Data Transmission
Kojto 122:f9eeca106725 135 process is ongoing */
Kojto 122:f9eeca106725 136 HAL_I2C_STATE_BUSY_RX_LISTEN = 0x2AU, /*!< Address Listen Mode and Data Reception
Kojto 122:f9eeca106725 137 process is ongoing */
Kojto 122:f9eeca106725 138 HAL_I2C_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */
Kojto 122:f9eeca106725 139 HAL_I2C_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
Kojto 122:f9eeca106725 140 HAL_I2C_STATE_ERROR = 0xE0U /*!< Error */
Kojto 122:f9eeca106725 141
bogdanm 86:04dd9b1680ae 142 }HAL_I2C_StateTypeDef;
bogdanm 86:04dd9b1680ae 143
Kojto 122:f9eeca106725 144 /**
Kojto 122:f9eeca106725 145 * @}
Kojto 122:f9eeca106725 146 */
Kojto 122:f9eeca106725 147
Kojto 122:f9eeca106725 148 /** @defgroup HAL_mode_structure_definition HAL mode structure definition
Kojto 122:f9eeca106725 149 * @brief HAL Mode structure definition
Kojto 122:f9eeca106725 150 * @note HAL I2C Mode value coding follow below described bitmap :\n
Kojto 122:f9eeca106725 151 * b7 (not used)\n
Kojto 122:f9eeca106725 152 * x : Should be set to 0\n
Kojto 122:f9eeca106725 153 * b6\n
Kojto 122:f9eeca106725 154 * 0 : None\n
Kojto 122:f9eeca106725 155 * 1 : Memory (HAL I2C communication is in Memory Mode)\n
Kojto 122:f9eeca106725 156 * b5\n
Kojto 122:f9eeca106725 157 * 0 : None\n
Kojto 122:f9eeca106725 158 * 1 : Slave (HAL I2C communication is in Slave Mode)\n
Kojto 122:f9eeca106725 159 * b4\n
Kojto 122:f9eeca106725 160 * 0 : None\n
Kojto 122:f9eeca106725 161 * 1 : Master (HAL I2C communication is in Master Mode)\n
Kojto 122:f9eeca106725 162 * b3-b2-b1-b0 (not used)\n
Kojto 122:f9eeca106725 163 * xxxx : Should be set to 0000
Kojto 122:f9eeca106725 164 * @{
Kojto 122:f9eeca106725 165 */
Kojto 122:f9eeca106725 166 typedef enum
Kojto 122:f9eeca106725 167 {
Kojto 122:f9eeca106725 168 HAL_I2C_MODE_NONE = 0x00U, /*!< No I2C communication on going */
Kojto 122:f9eeca106725 169 HAL_I2C_MODE_MASTER = 0x10U, /*!< I2C communication is in Master Mode */
Kojto 122:f9eeca106725 170 HAL_I2C_MODE_SLAVE = 0x20U, /*!< I2C communication is in Slave Mode */
Kojto 122:f9eeca106725 171 HAL_I2C_MODE_MEM = 0x40U /*!< I2C communication is in Memory Mode */
Kojto 122:f9eeca106725 172
Kojto 122:f9eeca106725 173 }HAL_I2C_ModeTypeDef;
Kojto 122:f9eeca106725 174
bogdanm 86:04dd9b1680ae 175 /**
bogdanm 92:4fc01daae5a5 176 * @}
bogdanm 92:4fc01daae5a5 177 */
bogdanm 92:4fc01daae5a5 178
Kojto 122:f9eeca106725 179 /** @defgroup I2C_Error_Code_definition I2C Error Code definition
Kojto 122:f9eeca106725 180 * @brief I2C Error Code definition
bogdanm 92:4fc01daae5a5 181 * @{
Kojto 122:f9eeca106725 182 */
Kojto 122:f9eeca106725 183 #define HAL_I2C_ERROR_NONE (0x00000000U) /*!< No error */
Kojto 122:f9eeca106725 184 #define HAL_I2C_ERROR_BERR (0x00000001U) /*!< BERR error */
Kojto 122:f9eeca106725 185 #define HAL_I2C_ERROR_ARLO (0x00000002U) /*!< ARLO error */
Kojto 122:f9eeca106725 186 #define HAL_I2C_ERROR_AF (0x00000004U) /*!< ACKF error */
Kojto 122:f9eeca106725 187 #define HAL_I2C_ERROR_OVR (0x00000008U) /*!< OVR error */
Kojto 122:f9eeca106725 188 #define HAL_I2C_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
Kojto 122:f9eeca106725 189 #define HAL_I2C_ERROR_TIMEOUT (0x00000020U) /*!< Timeout error */
Kojto 122:f9eeca106725 190 #define HAL_I2C_ERROR_SIZE (0x00000040U) /*!< Size Management error */
Kojto 122:f9eeca106725 191 /**
bogdanm 92:4fc01daae5a5 192 * @}
bogdanm 92:4fc01daae5a5 193 */
bogdanm 92:4fc01daae5a5 194
Kojto 122:f9eeca106725 195 /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition
Kojto 122:f9eeca106725 196 * @brief I2C handle Structure definition
bogdanm 92:4fc01daae5a5 197 * @{
bogdanm 86:04dd9b1680ae 198 */
Kojto 122:f9eeca106725 199 typedef struct __I2C_HandleTypeDef
Kojto 122:f9eeca106725 200 {
Kojto 122:f9eeca106725 201 I2C_TypeDef *Instance; /*!< I2C registers base address */
bogdanm 92:4fc01daae5a5 202
Kojto 122:f9eeca106725 203 I2C_InitTypeDef Init; /*!< I2C communication parameters */
bogdanm 86:04dd9b1680ae 204
Kojto 122:f9eeca106725 205 uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */
Kojto 122:f9eeca106725 206
Kojto 122:f9eeca106725 207 uint16_t XferSize; /*!< I2C transfer size */
bogdanm 86:04dd9b1680ae 208
Kojto 122:f9eeca106725 209 __IO uint16_t XferCount; /*!< I2C transfer counter */
bogdanm 86:04dd9b1680ae 210
Kojto 122:f9eeca106725 211 __IO uint32_t XferOptions; /*!< I2C sequantial transfer options, this parameter can
Kojto 122:f9eeca106725 212 be a value of @ref I2C_XFEROPTIONS */
bogdanm 86:04dd9b1680ae 213
Kojto 122:f9eeca106725 214 __IO uint32_t PreviousState; /*!< I2C communication Previous state */
Kojto 122:f9eeca106725 215
Kojto 122:f9eeca106725 216 HAL_StatusTypeDef (*XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources); /*!< I2C transfer IRQ handler function pointer */
bogdanm 86:04dd9b1680ae 217
Kojto 122:f9eeca106725 218 DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */
bogdanm 86:04dd9b1680ae 219
Kojto 122:f9eeca106725 220 DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */
bogdanm 86:04dd9b1680ae 221
Kojto 122:f9eeca106725 222 HAL_LockTypeDef Lock; /*!< I2C locking object */
Kojto 122:f9eeca106725 223
Kojto 122:f9eeca106725 224 __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */
bogdanm 86:04dd9b1680ae 225
Kojto 122:f9eeca106725 226 __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */
bogdanm 86:04dd9b1680ae 227
Kojto 122:f9eeca106725 228 __IO uint32_t ErrorCode; /*!< I2C Error code */
bogdanm 86:04dd9b1680ae 229
Kojto 122:f9eeca106725 230 __IO uint32_t AddrEventCount; /*!< I2C Address Event counter */
bogdanm 86:04dd9b1680ae 231 }I2C_HandleTypeDef;
bogdanm 92:4fc01daae5a5 232 /**
bogdanm 92:4fc01daae5a5 233 * @}
bogdanm 92:4fc01daae5a5 234 */
bogdanm 86:04dd9b1680ae 235
bogdanm 92:4fc01daae5a5 236 /**
bogdanm 92:4fc01daae5a5 237 * @}
Kojto 122:f9eeca106725 238 */
bogdanm 86:04dd9b1680ae 239 /* Exported constants --------------------------------------------------------*/
bogdanm 86:04dd9b1680ae 240
bogdanm 92:4fc01daae5a5 241 /** @defgroup I2C_Exported_Constants I2C Exported Constants
bogdanm 86:04dd9b1680ae 242 * @{
bogdanm 86:04dd9b1680ae 243 */
bogdanm 86:04dd9b1680ae 244
Kojto 122:f9eeca106725 245 /** @defgroup I2C_XFEROPTIONS I2C Sequential Transfer Options
bogdanm 86:04dd9b1680ae 246 * @{
bogdanm 86:04dd9b1680ae 247 */
Kojto 122:f9eeca106725 248 #define I2C_FIRST_FRAME ((uint32_t)I2C_SOFTEND_MODE)
<> 135:176b8275d35d 249 #define I2C_FIRST_AND_NEXT_FRAME ((uint32_t)(I2C_RELOAD_MODE | I2C_SOFTEND_MODE))
Kojto 122:f9eeca106725 250 #define I2C_NEXT_FRAME ((uint32_t)(I2C_RELOAD_MODE | I2C_SOFTEND_MODE))
Kojto 122:f9eeca106725 251 #define I2C_FIRST_AND_LAST_FRAME ((uint32_t)I2C_AUTOEND_MODE)
Kojto 122:f9eeca106725 252 #define I2C_LAST_FRAME ((uint32_t)I2C_AUTOEND_MODE)
Kojto 122:f9eeca106725 253 /**
Kojto 122:f9eeca106725 254 * @}
Kojto 122:f9eeca106725 255 */
bogdanm 86:04dd9b1680ae 256
Kojto 122:f9eeca106725 257 /** @defgroup I2C_ADDRESSING_MODE I2C Addressing Mode
Kojto 122:f9eeca106725 258 * @{
Kojto 122:f9eeca106725 259 */
Kojto 122:f9eeca106725 260 #define I2C_ADDRESSINGMODE_7BIT (0x00000001U)
Kojto 122:f9eeca106725 261 #define I2C_ADDRESSINGMODE_10BIT (0x00000002U)
bogdanm 86:04dd9b1680ae 262 /**
bogdanm 86:04dd9b1680ae 263 * @}
bogdanm 86:04dd9b1680ae 264 */
bogdanm 86:04dd9b1680ae 265
Kojto 122:f9eeca106725 266 /** @defgroup I2C_DUAL_ADDRESSING_MODE I2C Dual Addressing Mode
bogdanm 86:04dd9b1680ae 267 * @{
bogdanm 86:04dd9b1680ae 268 */
Kojto 122:f9eeca106725 269 #define I2C_DUALADDRESS_DISABLE (0x00000000U)
Kojto 122:f9eeca106725 270 #define I2C_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
bogdanm 86:04dd9b1680ae 271 /**
bogdanm 86:04dd9b1680ae 272 * @}
bogdanm 86:04dd9b1680ae 273 */
bogdanm 86:04dd9b1680ae 274
Kojto 122:f9eeca106725 275 /** @defgroup I2C_OWN_ADDRESS2_MASKS I2C Own Address2 Masks
bogdanm 86:04dd9b1680ae 276 * @{
bogdanm 86:04dd9b1680ae 277 */
Kojto 122:f9eeca106725 278 #define I2C_OA2_NOMASK ((uint8_t)0x00U)
Kojto 122:f9eeca106725 279 #define I2C_OA2_MASK01 ((uint8_t)0x01U)
Kojto 122:f9eeca106725 280 #define I2C_OA2_MASK02 ((uint8_t)0x02U)
Kojto 122:f9eeca106725 281 #define I2C_OA2_MASK03 ((uint8_t)0x03U)
Kojto 122:f9eeca106725 282 #define I2C_OA2_MASK04 ((uint8_t)0x04U)
Kojto 122:f9eeca106725 283 #define I2C_OA2_MASK05 ((uint8_t)0x05U)
Kojto 122:f9eeca106725 284 #define I2C_OA2_MASK06 ((uint8_t)0x06U)
Kojto 122:f9eeca106725 285 #define I2C_OA2_MASK07 ((uint8_t)0x07U)
bogdanm 86:04dd9b1680ae 286 /**
bogdanm 86:04dd9b1680ae 287 * @}
bogdanm 86:04dd9b1680ae 288 */
bogdanm 86:04dd9b1680ae 289
Kojto 122:f9eeca106725 290 /** @defgroup I2C_GENERAL_CALL_ADDRESSING_MODE I2C General Call Addressing Mode
bogdanm 86:04dd9b1680ae 291 * @{
bogdanm 86:04dd9b1680ae 292 */
Kojto 122:f9eeca106725 293 #define I2C_GENERALCALL_DISABLE (0x00000000U)
Kojto 122:f9eeca106725 294 #define I2C_GENERALCALL_ENABLE I2C_CR1_GCEN
bogdanm 86:04dd9b1680ae 295 /**
bogdanm 86:04dd9b1680ae 296 * @}
bogdanm 86:04dd9b1680ae 297 */
bogdanm 86:04dd9b1680ae 298
Kojto 122:f9eeca106725 299 /** @defgroup I2C_NOSTRETCH_MODE I2C No-Stretch Mode
bogdanm 86:04dd9b1680ae 300 * @{
bogdanm 86:04dd9b1680ae 301 */
Kojto 122:f9eeca106725 302 #define I2C_NOSTRETCH_DISABLE (0x00000000U)
Kojto 122:f9eeca106725 303 #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
bogdanm 86:04dd9b1680ae 304 /**
bogdanm 86:04dd9b1680ae 305 * @}
bogdanm 86:04dd9b1680ae 306 */
bogdanm 86:04dd9b1680ae 307
Kojto 122:f9eeca106725 308 /** @defgroup I2C_MEMORY_ADDRESS_SIZE I2C Memory Address Size
bogdanm 86:04dd9b1680ae 309 * @{
bogdanm 86:04dd9b1680ae 310 */
Kojto 122:f9eeca106725 311 #define I2C_MEMADD_SIZE_8BIT (0x00000001U)
Kojto 122:f9eeca106725 312 #define I2C_MEMADD_SIZE_16BIT (0x00000002U)
bogdanm 86:04dd9b1680ae 313 /**
bogdanm 86:04dd9b1680ae 314 * @}
Kojto 122:f9eeca106725 315 */
bogdanm 86:04dd9b1680ae 316
Kojto 123:b0220dba8be7 317 /** @defgroup I2C_XFERDIRECTION I2C Transfer Direction Master Point of View
bogdanm 86:04dd9b1680ae 318 * @{
bogdanm 86:04dd9b1680ae 319 */
Kojto 122:f9eeca106725 320 #define I2C_DIRECTION_TRANSMIT (0x00000000U)
Kojto 122:f9eeca106725 321 #define I2C_DIRECTION_RECEIVE (0x00000001U)
bogdanm 86:04dd9b1680ae 322 /**
bogdanm 86:04dd9b1680ae 323 * @}
bogdanm 86:04dd9b1680ae 324 */
bogdanm 86:04dd9b1680ae 325
Kojto 122:f9eeca106725 326 /** @defgroup I2C_RELOAD_END_MODE I2C Reload End Mode
bogdanm 86:04dd9b1680ae 327 * @{
bogdanm 86:04dd9b1680ae 328 */
Kojto 122:f9eeca106725 329 #define I2C_RELOAD_MODE I2C_CR2_RELOAD
Kojto 122:f9eeca106725 330 #define I2C_AUTOEND_MODE I2C_CR2_AUTOEND
Kojto 122:f9eeca106725 331 #define I2C_SOFTEND_MODE (0x00000000U)
Kojto 122:f9eeca106725 332 /**
Kojto 122:f9eeca106725 333 * @}
Kojto 122:f9eeca106725 334 */
bogdanm 86:04dd9b1680ae 335
Kojto 122:f9eeca106725 336 /** @defgroup I2C_START_STOP_MODE I2C Start or Stop Mode
Kojto 122:f9eeca106725 337 * @{
Kojto 122:f9eeca106725 338 */
Kojto 122:f9eeca106725 339 #define I2C_NO_STARTSTOP (0x00000000U)
Kojto 122:f9eeca106725 340 #define I2C_GENERATE_STOP I2C_CR2_STOP
Kojto 122:f9eeca106725 341 #define I2C_GENERATE_START_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
Kojto 122:f9eeca106725 342 #define I2C_GENERATE_START_WRITE I2C_CR2_START
bogdanm 86:04dd9b1680ae 343 /**
bogdanm 86:04dd9b1680ae 344 * @}
bogdanm 86:04dd9b1680ae 345 */
bogdanm 86:04dd9b1680ae 346
bogdanm 92:4fc01daae5a5 347 /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
bogdanm 86:04dd9b1680ae 348 * @brief I2C Interrupt definition
bogdanm 86:04dd9b1680ae 349 * Elements values convention: 0xXXXXXXXX
bogdanm 86:04dd9b1680ae 350 * - XXXXXXXX : Interrupt control mask
bogdanm 86:04dd9b1680ae 351 * @{
bogdanm 86:04dd9b1680ae 352 */
Kojto 122:f9eeca106725 353 #define I2C_IT_ERRI I2C_CR1_ERRIE
Kojto 122:f9eeca106725 354 #define I2C_IT_TCI I2C_CR1_TCIE
Kojto 122:f9eeca106725 355 #define I2C_IT_STOPI I2C_CR1_STOPIE
Kojto 122:f9eeca106725 356 #define I2C_IT_NACKI I2C_CR1_NACKIE
Kojto 122:f9eeca106725 357 #define I2C_IT_ADDRI I2C_CR1_ADDRIE
Kojto 122:f9eeca106725 358 #define I2C_IT_RXI I2C_CR1_RXIE
Kojto 122:f9eeca106725 359 #define I2C_IT_TXI I2C_CR1_TXIE
bogdanm 86:04dd9b1680ae 360 /**
bogdanm 86:04dd9b1680ae 361 * @}
bogdanm 86:04dd9b1680ae 362 */
bogdanm 86:04dd9b1680ae 363
bogdanm 92:4fc01daae5a5 364 /** @defgroup I2C_Flag_definition I2C Flag definition
bogdanm 86:04dd9b1680ae 365 * @{
Kojto 122:f9eeca106725 366 */
Kojto 122:f9eeca106725 367 #define I2C_FLAG_TXE I2C_ISR_TXE
Kojto 122:f9eeca106725 368 #define I2C_FLAG_TXIS I2C_ISR_TXIS
Kojto 122:f9eeca106725 369 #define I2C_FLAG_RXNE I2C_ISR_RXNE
Kojto 122:f9eeca106725 370 #define I2C_FLAG_ADDR I2C_ISR_ADDR
Kojto 122:f9eeca106725 371 #define I2C_FLAG_AF I2C_ISR_NACKF
Kojto 122:f9eeca106725 372 #define I2C_FLAG_STOPF I2C_ISR_STOPF
Kojto 122:f9eeca106725 373 #define I2C_FLAG_TC I2C_ISR_TC
Kojto 122:f9eeca106725 374 #define I2C_FLAG_TCR I2C_ISR_TCR
Kojto 122:f9eeca106725 375 #define I2C_FLAG_BERR I2C_ISR_BERR
Kojto 122:f9eeca106725 376 #define I2C_FLAG_ARLO I2C_ISR_ARLO
Kojto 122:f9eeca106725 377 #define I2C_FLAG_OVR I2C_ISR_OVR
Kojto 122:f9eeca106725 378 #define I2C_FLAG_PECERR I2C_ISR_PECERR
Kojto 122:f9eeca106725 379 #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT
Kojto 122:f9eeca106725 380 #define I2C_FLAG_ALERT I2C_ISR_ALERT
Kojto 122:f9eeca106725 381 #define I2C_FLAG_BUSY I2C_ISR_BUSY
Kojto 122:f9eeca106725 382 #define I2C_FLAG_DIR I2C_ISR_DIR
bogdanm 86:04dd9b1680ae 383 /**
bogdanm 86:04dd9b1680ae 384 * @}
bogdanm 86:04dd9b1680ae 385 */
bogdanm 86:04dd9b1680ae 386
bogdanm 86:04dd9b1680ae 387 /**
bogdanm 86:04dd9b1680ae 388 * @}
Kojto 122:f9eeca106725 389 */
Kojto 122:f9eeca106725 390
bogdanm 86:04dd9b1680ae 391 /* Exported macros -----------------------------------------------------------*/
bogdanm 86:04dd9b1680ae 392
bogdanm 92:4fc01daae5a5 393 /** @defgroup I2C_Exported_Macros I2C Exported Macros
bogdanm 92:4fc01daae5a5 394 * @{
bogdanm 92:4fc01daae5a5 395 */
bogdanm 92:4fc01daae5a5 396
Kojto 122:f9eeca106725 397 /** @brief Reset I2C handle state.
Kojto 122:f9eeca106725 398 * @param __HANDLE__ specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 399 * @retval None
bogdanm 86:04dd9b1680ae 400 */
Kojto 122:f9eeca106725 401 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
bogdanm 86:04dd9b1680ae 402
Kojto 122:f9eeca106725 403 /** @brief Enable the specified I2C interrupt.
Kojto 122:f9eeca106725 404 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 405 * @param __INTERRUPT__ specifies the interrupt source to enable.
Kojto 122:f9eeca106725 406 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 407 * @arg @ref I2C_IT_ERRI Errors interrupt enable
Kojto 122:f9eeca106725 408 * @arg @ref I2C_IT_TCI Transfer complete interrupt enable
Kojto 122:f9eeca106725 409 * @arg @ref I2C_IT_STOPI STOP detection interrupt enable
Kojto 122:f9eeca106725 410 * @arg @ref I2C_IT_NACKI NACK received interrupt enable
Kojto 122:f9eeca106725 411 * @arg @ref I2C_IT_ADDRI Address match interrupt enable
Kojto 122:f9eeca106725 412 * @arg @ref I2C_IT_RXI RX interrupt enable
Kojto 122:f9eeca106725 413 * @arg @ref I2C_IT_TXI TX interrupt enable
Kojto 122:f9eeca106725 414 *
Kojto 122:f9eeca106725 415 * @retval None
Kojto 122:f9eeca106725 416 */
Kojto 122:f9eeca106725 417 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
Kojto 122:f9eeca106725 418
Kojto 122:f9eeca106725 419 /** @brief Disable the specified I2C interrupt.
Kojto 122:f9eeca106725 420 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 421 * @param __INTERRUPT__ specifies the interrupt source to disable.
Kojto 122:f9eeca106725 422 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 423 * @arg @ref I2C_IT_ERRI Errors interrupt enable
Kojto 122:f9eeca106725 424 * @arg @ref I2C_IT_TCI Transfer complete interrupt enable
Kojto 122:f9eeca106725 425 * @arg @ref I2C_IT_STOPI STOP detection interrupt enable
Kojto 122:f9eeca106725 426 * @arg @ref I2C_IT_NACKI NACK received interrupt enable
Kojto 122:f9eeca106725 427 * @arg @ref I2C_IT_ADDRI Address match interrupt enable
Kojto 122:f9eeca106725 428 * @arg @ref I2C_IT_RXI RX interrupt enable
Kojto 122:f9eeca106725 429 * @arg @ref I2C_IT_TXI TX interrupt enable
Kojto 122:f9eeca106725 430 *
bogdanm 86:04dd9b1680ae 431 * @retval None
bogdanm 86:04dd9b1680ae 432 */
Kojto 122:f9eeca106725 433 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
bogdanm 86:04dd9b1680ae 434
Kojto 122:f9eeca106725 435 /** @brief Check whether the specified I2C interrupt source is enabled or not.
Kojto 122:f9eeca106725 436 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 437 * @param __INTERRUPT__ specifies the I2C interrupt source to check.
Kojto 122:f9eeca106725 438 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 439 * @arg @ref I2C_IT_ERRI Errors interrupt enable
Kojto 122:f9eeca106725 440 * @arg @ref I2C_IT_TCI Transfer complete interrupt enable
Kojto 122:f9eeca106725 441 * @arg @ref I2C_IT_STOPI STOP detection interrupt enable
Kojto 122:f9eeca106725 442 * @arg @ref I2C_IT_NACKI NACK received interrupt enable
Kojto 122:f9eeca106725 443 * @arg @ref I2C_IT_ADDRI Address match interrupt enable
Kojto 122:f9eeca106725 444 * @arg @ref I2C_IT_RXI RX interrupt enable
Kojto 122:f9eeca106725 445 * @arg @ref I2C_IT_TXI TX interrupt enable
Kojto 122:f9eeca106725 446 *
Kojto 122:f9eeca106725 447 * @retval The new state of __INTERRUPT__ (SET or RESET).
bogdanm 86:04dd9b1680ae 448 */
Kojto 122:f9eeca106725 449 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
bogdanm 86:04dd9b1680ae 450
Kojto 122:f9eeca106725 451 /** @brief Check whether the specified I2C flag is set or not.
Kojto 122:f9eeca106725 452 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 453 * @param __FLAG__ specifies the flag to check.
Kojto 122:f9eeca106725 454 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 455 * @arg @ref I2C_FLAG_TXE Transmit data register empty
Kojto 122:f9eeca106725 456 * @arg @ref I2C_FLAG_TXIS Transmit interrupt status
Kojto 122:f9eeca106725 457 * @arg @ref I2C_FLAG_RXNE Receive data register not empty
Kojto 122:f9eeca106725 458 * @arg @ref I2C_FLAG_ADDR Address matched (slave mode)
Kojto 122:f9eeca106725 459 * @arg @ref I2C_FLAG_AF Acknowledge failure received flag
Kojto 122:f9eeca106725 460 * @arg @ref I2C_FLAG_STOPF STOP detection flag
Kojto 122:f9eeca106725 461 * @arg @ref I2C_FLAG_TC Transfer complete (master mode)
Kojto 122:f9eeca106725 462 * @arg @ref I2C_FLAG_TCR Transfer complete reload
Kojto 122:f9eeca106725 463 * @arg @ref I2C_FLAG_BERR Bus error
Kojto 122:f9eeca106725 464 * @arg @ref I2C_FLAG_ARLO Arbitration lost
Kojto 122:f9eeca106725 465 * @arg @ref I2C_FLAG_OVR Overrun/Underrun
Kojto 122:f9eeca106725 466 * @arg @ref I2C_FLAG_PECERR PEC error in reception
Kojto 122:f9eeca106725 467 * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow detection flag
Kojto 122:f9eeca106725 468 * @arg @ref I2C_FLAG_ALERT SMBus alert
Kojto 122:f9eeca106725 469 * @arg @ref I2C_FLAG_BUSY Bus busy
Kojto 122:f9eeca106725 470 * @arg @ref I2C_FLAG_DIR Transfer direction (slave mode)
Kojto 122:f9eeca106725 471 *
Kojto 122:f9eeca106725 472 * @retval The new state of __FLAG__ (SET or RESET).
bogdanm 86:04dd9b1680ae 473 */
Kojto 122:f9eeca106725 474 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
bogdanm 86:04dd9b1680ae 475
Kojto 122:f9eeca106725 476 /** @brief Clear the I2C pending flags which are cleared by writing 1 in a specific bit.
Kojto 122:f9eeca106725 477 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 478 * @param __FLAG__ specifies the flag to clear.
bogdanm 86:04dd9b1680ae 479 * This parameter can be any combination of the following values:
Kojto 122:f9eeca106725 480 * @arg @ref I2C_FLAG_TXE Transmit data register empty
Kojto 122:f9eeca106725 481 * @arg @ref I2C_FLAG_ADDR Address matched (slave mode)
Kojto 122:f9eeca106725 482 * @arg @ref I2C_FLAG_AF Acknowledge failure received flag
Kojto 122:f9eeca106725 483 * @arg @ref I2C_FLAG_STOPF STOP detection flag
Kojto 122:f9eeca106725 484 * @arg @ref I2C_FLAG_BERR Bus error
Kojto 122:f9eeca106725 485 * @arg @ref I2C_FLAG_ARLO Arbitration lost
Kojto 122:f9eeca106725 486 * @arg @ref I2C_FLAG_OVR Overrun/Underrun
Kojto 122:f9eeca106725 487 * @arg @ref I2C_FLAG_PECERR PEC error in reception
Kojto 122:f9eeca106725 488 * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow detection flag
Kojto 122:f9eeca106725 489 * @arg @ref I2C_FLAG_ALERT SMBus alert
Kojto 122:f9eeca106725 490 *
bogdanm 86:04dd9b1680ae 491 * @retval None
bogdanm 86:04dd9b1680ae 492 */
Kojto 122:f9eeca106725 493 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == I2C_FLAG_TXE) ? ((__HANDLE__)->Instance->ISR |= (__FLAG__)) \
Kojto 122:f9eeca106725 494 : ((__HANDLE__)->Instance->ICR = (__FLAG__)))
bogdanm 86:04dd9b1680ae 495
Kojto 122:f9eeca106725 496 /** @brief Enable the specified I2C peripheral.
Kojto 122:f9eeca106725 497 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 498 * @retval None
Kojto 122:f9eeca106725 499 */
Kojto 122:f9eeca106725 500 #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
bogdanm 86:04dd9b1680ae 501
Kojto 122:f9eeca106725 502 /** @brief Disable the specified I2C peripheral.
Kojto 122:f9eeca106725 503 * @param __HANDLE__ specifies the I2C Handle.
Kojto 122:f9eeca106725 504 * @retval None
Kojto 122:f9eeca106725 505 */
Kojto 122:f9eeca106725 506 #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
bogdanm 86:04dd9b1680ae 507
Kojto 122:f9eeca106725 508 /** @brief Generate a Non-Acknowledge I2C peripheral in Slave mode.
Kojto 122:f9eeca106725 509 * @param __HANDLE__: specifies the I2C Handle.
Kojto 122:f9eeca106725 510 * @retval None
Kojto 122:f9eeca106725 511 */
Kojto 122:f9eeca106725 512 #define __HAL_I2C_GENERATE_NACK(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR2, I2C_CR2_NACK))
bogdanm 92:4fc01daae5a5 513 /**
bogdanm 92:4fc01daae5a5 514 * @}
Kojto 122:f9eeca106725 515 */
bogdanm 86:04dd9b1680ae 516
bogdanm 92:4fc01daae5a5 517 /* Include I2C HAL Extended module */
bogdanm 86:04dd9b1680ae 518 #include "stm32f3xx_hal_i2c_ex.h"
bogdanm 86:04dd9b1680ae 519
bogdanm 86:04dd9b1680ae 520 /* Exported functions --------------------------------------------------------*/
bogdanm 92:4fc01daae5a5 521 /** @addtogroup I2C_Exported_Functions
bogdanm 92:4fc01daae5a5 522 * @{
bogdanm 92:4fc01daae5a5 523 */
bogdanm 92:4fc01daae5a5 524
bogdanm 92:4fc01daae5a5 525 /** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions
bogdanm 92:4fc01daae5a5 526 * @{
bogdanm 92:4fc01daae5a5 527 */
Kojto 122:f9eeca106725 528 /* Initialization and de-initialization functions******************************/
bogdanm 86:04dd9b1680ae 529 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 530 HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 531 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 532 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
bogdanm 92:4fc01daae5a5 533 /**
bogdanm 92:4fc01daae5a5 534 * @}
Kojto 122:f9eeca106725 535 */
bogdanm 92:4fc01daae5a5 536
bogdanm 92:4fc01daae5a5 537 /** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions
bogdanm 92:4fc01daae5a5 538 * @{
bogdanm 92:4fc01daae5a5 539 */
Kojto 122:f9eeca106725 540 /* IO operation functions ****************************************************/
bogdanm 86:04dd9b1680ae 541 /******* Blocking mode: Polling */
bogdanm 86:04dd9b1680ae 542 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 543 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 544 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 545 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 546 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);
bogdanm 86:04dd9b1680ae 547 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);
bogdanm 86:04dd9b1680ae 548 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 549
bogdanm 86:04dd9b1680ae 550 /******* Non-Blocking mode: Interrupt */
bogdanm 86:04dd9b1680ae 551 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 552 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 553 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 554 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 555 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);
bogdanm 86:04dd9b1680ae 556 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);
bogdanm 86:04dd9b1680ae 557
Kojto 122:f9eeca106725 558 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 559 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 560 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 561 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 562 HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 563 HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 564 HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
bogdanm 92:4fc01daae5a5 565
bogdanm 86:04dd9b1680ae 566 /******* Non-Blocking mode: DMA */
bogdanm 86:04dd9b1680ae 567 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 568 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 569 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 570 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 571 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);
bogdanm 86:04dd9b1680ae 572 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);
bogdanm 92:4fc01daae5a5 573 /**
bogdanm 92:4fc01daae5a5 574 * @}
Kojto 122:f9eeca106725 575 */
bogdanm 86:04dd9b1680ae 576
Kojto 122:f9eeca106725 577 /** @addtogroup I2C_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
bogdanm 92:4fc01daae5a5 578 * @{
Kojto 122:f9eeca106725 579 */
Kojto 122:f9eeca106725 580 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
bogdanm 86:04dd9b1680ae 581 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 582 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 583 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 584 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 585 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 586 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 587 void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode);
Kojto 122:f9eeca106725 588 void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 589 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 590 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 591 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 592 void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 92:4fc01daae5a5 593 /**
bogdanm 92:4fc01daae5a5 594 * @}
Kojto 122:f9eeca106725 595 */
Kojto 122:f9eeca106725 596
Kojto 122:f9eeca106725 597 /** @addtogroup I2C_Exported_Functions_Group3 Peripheral State, Mode and Error functions
bogdanm 92:4fc01daae5a5 598 * @{
bogdanm 92:4fc01daae5a5 599 */
Kojto 122:f9eeca106725 600 /* Peripheral State, Mode and Error functions *********************************/
bogdanm 86:04dd9b1680ae 601 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 602 HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 603 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 604
bogdanm 86:04dd9b1680ae 605 /**
bogdanm 86:04dd9b1680ae 606 * @}
bogdanm 86:04dd9b1680ae 607 */
bogdanm 86:04dd9b1680ae 608
bogdanm 86:04dd9b1680ae 609 /**
bogdanm 86:04dd9b1680ae 610 * @}
bogdanm 86:04dd9b1680ae 611 */
Kojto 122:f9eeca106725 612
Kojto 122:f9eeca106725 613 /* Private constants ---------------------------------------------------------*/
Kojto 122:f9eeca106725 614 /** @defgroup I2C_Private_Constants I2C Private Constants
Kojto 122:f9eeca106725 615 * @{
Kojto 122:f9eeca106725 616 */
Kojto 122:f9eeca106725 617
Kojto 122:f9eeca106725 618 /**
Kojto 122:f9eeca106725 619 * @}
Kojto 122:f9eeca106725 620 */
Kojto 122:f9eeca106725 621
Kojto 122:f9eeca106725 622 /* Private macros ------------------------------------------------------------*/
Kojto 122:f9eeca106725 623 /** @defgroup I2C_Private_Macro I2C Private Macros
Kojto 122:f9eeca106725 624 * @{
Kojto 122:f9eeca106725 625 */
Kojto 122:f9eeca106725 626
Kojto 122:f9eeca106725 627 #define IS_I2C_ADDRESSING_MODE(MODE) (((MODE) == I2C_ADDRESSINGMODE_7BIT) || \
Kojto 122:f9eeca106725 628 ((MODE) == I2C_ADDRESSINGMODE_10BIT))
Kojto 122:f9eeca106725 629
Kojto 122:f9eeca106725 630 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
Kojto 122:f9eeca106725 631 ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
Kojto 122:f9eeca106725 632
Kojto 122:f9eeca106725 633 #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NOMASK) || \
Kojto 122:f9eeca106725 634 ((MASK) == I2C_OA2_MASK01) || \
Kojto 122:f9eeca106725 635 ((MASK) == I2C_OA2_MASK02) || \
Kojto 122:f9eeca106725 636 ((MASK) == I2C_OA2_MASK03) || \
Kojto 122:f9eeca106725 637 ((MASK) == I2C_OA2_MASK04) || \
Kojto 122:f9eeca106725 638 ((MASK) == I2C_OA2_MASK05) || \
Kojto 122:f9eeca106725 639 ((MASK) == I2C_OA2_MASK06) || \
Kojto 122:f9eeca106725 640 ((MASK) == I2C_OA2_MASK07))
Kojto 122:f9eeca106725 641
Kojto 122:f9eeca106725 642 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
Kojto 122:f9eeca106725 643 ((CALL) == I2C_GENERALCALL_ENABLE))
Kojto 122:f9eeca106725 644
Kojto 122:f9eeca106725 645 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
Kojto 122:f9eeca106725 646 ((STRETCH) == I2C_NOSTRETCH_ENABLE))
Kojto 122:f9eeca106725 647
Kojto 122:f9eeca106725 648 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
Kojto 122:f9eeca106725 649 ((SIZE) == I2C_MEMADD_SIZE_16BIT))
Kojto 122:f9eeca106725 650
Kojto 122:f9eeca106725 651 #define IS_TRANSFER_MODE(MODE) (((MODE) == I2C_RELOAD_MODE) || \
Kojto 122:f9eeca106725 652 ((MODE) == I2C_AUTOEND_MODE) || \
Kojto 122:f9eeca106725 653 ((MODE) == I2C_SOFTEND_MODE))
Kojto 122:f9eeca106725 654
Kojto 122:f9eeca106725 655 #define IS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == I2C_GENERATE_STOP) || \
Kojto 122:f9eeca106725 656 ((REQUEST) == I2C_GENERATE_START_READ) || \
Kojto 122:f9eeca106725 657 ((REQUEST) == I2C_GENERATE_START_WRITE) || \
Kojto 122:f9eeca106725 658 ((REQUEST) == I2C_NO_STARTSTOP))
Kojto 122:f9eeca106725 659
Kojto 122:f9eeca106725 660 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_FIRST_FRAME) || \
<> 135:176b8275d35d 661 ((REQUEST) == I2C_FIRST_AND_NEXT_FRAME) || \
Kojto 122:f9eeca106725 662 ((REQUEST) == I2C_NEXT_FRAME) || \
Kojto 122:f9eeca106725 663 ((REQUEST) == I2C_FIRST_AND_LAST_FRAME) || \
Kojto 122:f9eeca106725 664 ((REQUEST) == I2C_LAST_FRAME))
Kojto 122:f9eeca106725 665
Kojto 122:f9eeca106725 666 #define 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)))
Kojto 122:f9eeca106725 667
Kojto 122:f9eeca106725 668 #define I2C_GET_ADDR_MATCH(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_ADDCODE) >> 16U)
Kojto 122:f9eeca106725 669 #define I2C_GET_DIR(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_DIR) >> 16U)
Kojto 122:f9eeca106725 670 #define I2C_GET_STOP_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_AUTOEND)
Kojto 122:f9eeca106725 671 #define I2C_GET_OWN_ADDRESS1(__HANDLE__) ((__HANDLE__)->Instance->OAR1 & I2C_OAR1_OA1)
Kojto 122:f9eeca106725 672 #define I2C_GET_OWN_ADDRESS2(__HANDLE__) ((__HANDLE__)->Instance->OAR2 & I2C_OAR2_OA2)
Kojto 122:f9eeca106725 673
Kojto 122:f9eeca106725 674 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x000003FFU)
Kojto 122:f9eeca106725 675 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FFU)
Kojto 122:f9eeca106725 676
Kojto 122:f9eeca106725 677 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
Kojto 122:f9eeca106725 678 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
Kojto 122:f9eeca106725 679
Kojto 122:f9eeca106725 680 #define 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)) : \
Kojto 122:f9eeca106725 681 (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
Kojto 122:f9eeca106725 682 /**
Kojto 122:f9eeca106725 683 * @}
Kojto 122:f9eeca106725 684 */
Kojto 122:f9eeca106725 685
Kojto 122:f9eeca106725 686 /* Private Functions ---------------------------------------------------------*/
Kojto 122:f9eeca106725 687 /** @defgroup I2C_Private_Functions I2C Private Functions
Kojto 122:f9eeca106725 688 * @{
Kojto 122:f9eeca106725 689 */
Kojto 122:f9eeca106725 690 /* Private functions are defined in stm32f3xx_hal_i2c.c file */
bogdanm 92:4fc01daae5a5 691 /**
bogdanm 92:4fc01daae5a5 692 * @}
bogdanm 92:4fc01daae5a5 693 */
bogdanm 92:4fc01daae5a5 694
bogdanm 92:4fc01daae5a5 695 /**
bogdanm 92:4fc01daae5a5 696 * @}
bogdanm 92:4fc01daae5a5 697 */
Kojto 122:f9eeca106725 698
Kojto 122:f9eeca106725 699 /**
Kojto 122:f9eeca106725 700 * @}
Kojto 122:f9eeca106725 701 */
Kojto 122:f9eeca106725 702
bogdanm 86:04dd9b1680ae 703 #ifdef __cplusplus
bogdanm 86:04dd9b1680ae 704 }
bogdanm 86:04dd9b1680ae 705 #endif
bogdanm 86:04dd9b1680ae 706
bogdanm 86:04dd9b1680ae 707
bogdanm 86:04dd9b1680ae 708 #endif /* __STM32F3xx_HAL_I2C_H */
bogdanm 86:04dd9b1680ae 709
bogdanm 86:04dd9b1680ae 710 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/