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:
<>
Date:
Mon Jan 16 12:05:23 2017 +0000
Revision:
134:ad3be0349dc5
Parent:
128:9bcdf88f62b0
Child:
145:64910690c574
Release 134 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3488: Dev stm i2c v2 unitary functions https://github.com/ARMmbed/mbed-os/pull/3488
3492: Fix #3463 CAN read() return value https://github.com/ARMmbed/mbed-os/pull/3492
3503: [LPC15xx] Ensure that PWM=1 is resolved correctly https://github.com/ARMmbed/mbed-os/pull/3503
3504: [LPC15xx] CAN implementation improvements https://github.com/ARMmbed/mbed-os/pull/3504
3539: NUCLEO_F412ZG - Add support of TRNG peripheral https://github.com/ARMmbed/mbed-os/pull/3539
3540: STM: SPI: Initialize Rx in spi_master_write https://github.com/ARMmbed/mbed-os/pull/3540
3438: K64F: Add support for SERIAL ASYNCH API https://github.com/ARMmbed/mbed-os/pull/3438
3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set https://github.com/ARMmbed/mbed-os/pull/3519
3544: STM32L4 deepsleep improvement https://github.com/ARMmbed/mbed-os/pull/3544
3546: NUCLEO-F412ZG - Add CAN peripheral https://github.com/ARMmbed/mbed-os/pull/3546
3551: Fix I2C driver for RZ/A1H https://github.com/ARMmbed/mbed-os/pull/3551
3558: K64F UART Asynch API: Fix synchronization issue https://github.com/ARMmbed/mbed-os/pull/3558
3563: LPC4088 - Fix vector checksum https://github.com/ARMmbed/mbed-os/pull/3563
3567: Dev stm32 F0 v1.7.0 https://github.com/ARMmbed/mbed-os/pull/3567
3577: Fixes linking errors when building with debug profile https://github.com/ARMmbed/mbed-os/pull/3577

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 86:04dd9b1680ae 1 /**
bogdanm 86:04dd9b1680ae 2 ******************************************************************************
bogdanm 86:04dd9b1680ae 3 * @file stm32f4xx_hal_i2c.h
bogdanm 86:04dd9b1680ae 4 * @author MCD Application Team
Kojto 122:f9eeca106725 5 * @version V1.5.0
Kojto 122:f9eeca106725 6 * @date 06-May-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 ******************************************************************************
bogdanm 86:04dd9b1680ae 36 */
bogdanm 86:04dd9b1680ae 37
bogdanm 86:04dd9b1680ae 38 /* Define to prevent recursive inclusion -------------------------------------*/
bogdanm 86:04dd9b1680ae 39 #ifndef __STM32F4xx_HAL_I2C_H
bogdanm 86:04dd9b1680ae 40 #define __STM32F4xx_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 "stm32f4xx_hal_def.h"
bogdanm 86:04dd9b1680ae 48
bogdanm 86:04dd9b1680ae 49 /** @addtogroup STM32F4xx_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
bogdanm 86:04dd9b1680ae 57 /* Exported types ------------------------------------------------------------*/
Kojto 99:dbbf35b96557 58 /** @defgroup I2C_Exported_Types I2C Exported Types
Kojto 99:dbbf35b96557 59 * @{
Kojto 99:dbbf35b96557 60 */
Kojto 99:dbbf35b96557 61
bogdanm 86:04dd9b1680ae 62 /**
bogdanm 86:04dd9b1680ae 63 * @brief I2C Configuration Structure definition
bogdanm 86:04dd9b1680ae 64 */
bogdanm 86:04dd9b1680ae 65 typedef struct
bogdanm 86:04dd9b1680ae 66 {
bogdanm 86:04dd9b1680ae 67 uint32_t ClockSpeed; /*!< Specifies the clock frequency.
bogdanm 86:04dd9b1680ae 68 This parameter must be set to a value lower than 400kHz */
bogdanm 86:04dd9b1680ae 69
bogdanm 86:04dd9b1680ae 70 uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
bogdanm 86:04dd9b1680ae 71 This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
bogdanm 86:04dd9b1680ae 72
bogdanm 86:04dd9b1680ae 73 uint32_t OwnAddress1; /*!< Specifies the first device own address.
bogdanm 86:04dd9b1680ae 74 This parameter can be a 7-bit or 10-bit address. */
bogdanm 86:04dd9b1680ae 75
bogdanm 86:04dd9b1680ae 76 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
bogdanm 86:04dd9b1680ae 77 This parameter can be a value of @ref I2C_addressing_mode */
bogdanm 86:04dd9b1680ae 78
bogdanm 86:04dd9b1680ae 79 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
bogdanm 86:04dd9b1680ae 80 This parameter can be a value of @ref I2C_dual_addressing_mode */
bogdanm 86:04dd9b1680ae 81
bogdanm 86:04dd9b1680ae 82 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected
bogdanm 86:04dd9b1680ae 83 This parameter can be a 7-bit address. */
bogdanm 86:04dd9b1680ae 84
bogdanm 86:04dd9b1680ae 85 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
bogdanm 86:04dd9b1680ae 86 This parameter can be a value of @ref I2C_general_call_addressing_mode */
bogdanm 86:04dd9b1680ae 87
bogdanm 86:04dd9b1680ae 88 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
bogdanm 86:04dd9b1680ae 89 This parameter can be a value of @ref I2C_nostretch_mode */
bogdanm 86:04dd9b1680ae 90
bogdanm 86:04dd9b1680ae 91 }I2C_InitTypeDef;
bogdanm 86:04dd9b1680ae 92
bogdanm 86:04dd9b1680ae 93 /**
Kojto 122:f9eeca106725 94 * @brief HAL State structure definition
Kojto 122:f9eeca106725 95 * @note HAL I2C State value coding follow below described bitmap :
Kojto 122:f9eeca106725 96 * b7-b6 Error information
Kojto 122:f9eeca106725 97 * 00 : No Error
Kojto 122:f9eeca106725 98 * 01 : Abort (Abort user request on going)
Kojto 122:f9eeca106725 99 * 10 : Timeout
Kojto 122:f9eeca106725 100 * 11 : Error
Kojto 122:f9eeca106725 101 * b5 IP initilisation status
Kojto 122:f9eeca106725 102 * 0 : Reset (IP not initialized)
Kojto 122:f9eeca106725 103 * 1 : Init done (IP initialized and ready to use. HAL I2C Init function called)
Kojto 122:f9eeca106725 104 * b4 (not used)
Kojto 122:f9eeca106725 105 * x : Should be set to 0
Kojto 122:f9eeca106725 106 * b3
Kojto 122:f9eeca106725 107 * 0 : Ready or Busy (No Listen mode ongoing)
Kojto 122:f9eeca106725 108 * 1 : Listen (IP in Address Listen Mode)
Kojto 122:f9eeca106725 109 * b2 Intrinsic process state
Kojto 122:f9eeca106725 110 * 0 : Ready
Kojto 122:f9eeca106725 111 * 1 : Busy (IP busy with some configuration or internal operations)
Kojto 122:f9eeca106725 112 * b1 Rx state
Kojto 122:f9eeca106725 113 * 0 : Ready (no Rx operation ongoing)
Kojto 122:f9eeca106725 114 * 1 : Busy (Rx operation ongoing)
Kojto 122:f9eeca106725 115 * b0 Tx state
Kojto 122:f9eeca106725 116 * 0 : Ready (no Tx operation ongoing)
Kojto 122:f9eeca106725 117 * 1 : Busy (Tx operation ongoing)
bogdanm 86:04dd9b1680ae 118 */
bogdanm 86:04dd9b1680ae 119 typedef enum
bogdanm 86:04dd9b1680ae 120 {
Kojto 122:f9eeca106725 121 HAL_I2C_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
Kojto 122:f9eeca106725 122 HAL_I2C_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use */
Kojto 122:f9eeca106725 123 HAL_I2C_STATE_BUSY = 0x24U, /*!< An internal process is ongoing */
Kojto 122:f9eeca106725 124 HAL_I2C_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing */
Kojto 122:f9eeca106725 125 HAL_I2C_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
Kojto 122:f9eeca106725 126 HAL_I2C_STATE_LISTEN = 0x28U, /*!< Address Listen Mode is ongoing */
Kojto 122:f9eeca106725 127 HAL_I2C_STATE_BUSY_TX_LISTEN = 0x29U, /*!< Address Listen Mode and Data Transmission
Kojto 122:f9eeca106725 128 process is ongoing */
Kojto 122:f9eeca106725 129 HAL_I2C_STATE_BUSY_RX_LISTEN = 0x2AU, /*!< Address Listen Mode and Data Reception
Kojto 122:f9eeca106725 130 process is ongoing */
Kojto 122:f9eeca106725 131 HAL_I2C_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */
Kojto 122:f9eeca106725 132 HAL_I2C_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
Kojto 122:f9eeca106725 133 HAL_I2C_STATE_ERROR = 0xE0U /*!< Error */
bogdanm 86:04dd9b1680ae 134
bogdanm 86:04dd9b1680ae 135 }HAL_I2C_StateTypeDef;
bogdanm 86:04dd9b1680ae 136
bogdanm 86:04dd9b1680ae 137 /**
Kojto 122:f9eeca106725 138 * @brief HAL Mode structure definition
Kojto 122:f9eeca106725 139 * @note HAL I2C Mode value coding follow below described bitmap :
Kojto 122:f9eeca106725 140 * b7 (not used)
Kojto 122:f9eeca106725 141 * x : Should be set to 0
Kojto 122:f9eeca106725 142 * b6
Kojto 122:f9eeca106725 143 * 0 : None
Kojto 122:f9eeca106725 144 * 1 : Memory (HAL I2C communication is in Memory Mode)
Kojto 122:f9eeca106725 145 * b5
Kojto 122:f9eeca106725 146 * 0 : None
Kojto 122:f9eeca106725 147 * 1 : Slave (HAL I2C communication is in Slave Mode)
Kojto 122:f9eeca106725 148 * b4
Kojto 122:f9eeca106725 149 * 0 : None
Kojto 122:f9eeca106725 150 * 1 : Master (HAL I2C communication is in Master Mode)
Kojto 122:f9eeca106725 151 * b3-b2-b1-b0 (not used)
Kojto 122:f9eeca106725 152 * xxxx : Should be set to 0000
Kojto 122:f9eeca106725 153 */
Kojto 122:f9eeca106725 154 typedef enum
Kojto 122:f9eeca106725 155 {
Kojto 122:f9eeca106725 156 HAL_I2C_MODE_NONE = 0x00U, /*!< No I2C communication on going */
Kojto 122:f9eeca106725 157 HAL_I2C_MODE_MASTER = 0x10U, /*!< I2C communication is in Master Mode */
Kojto 122:f9eeca106725 158 HAL_I2C_MODE_SLAVE = 0x20U, /*!< I2C communication is in Slave Mode */
Kojto 122:f9eeca106725 159 HAL_I2C_MODE_MEM = 0x40U /*!< I2C communication is in Memory Mode */
Kojto 122:f9eeca106725 160
Kojto 122:f9eeca106725 161 }HAL_I2C_ModeTypeDef;
Kojto 122:f9eeca106725 162
Kojto 122:f9eeca106725 163 /**
bogdanm 86:04dd9b1680ae 164 * @brief I2C handle Structure definition
bogdanm 86:04dd9b1680ae 165 */
bogdanm 86:04dd9b1680ae 166 typedef struct
bogdanm 86:04dd9b1680ae 167 {
Kojto 122:f9eeca106725 168 I2C_TypeDef *Instance; /*!< I2C registers base address */
Kojto 122:f9eeca106725 169
Kojto 122:f9eeca106725 170 I2C_InitTypeDef Init; /*!< I2C communication parameters */
Kojto 122:f9eeca106725 171
Kojto 122:f9eeca106725 172 uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */
Kojto 122:f9eeca106725 173
Kojto 122:f9eeca106725 174 uint16_t XferSize; /*!< I2C transfer size */
Kojto 122:f9eeca106725 175
Kojto 122:f9eeca106725 176 __IO uint16_t XferCount; /*!< I2C transfer counter */
Kojto 122:f9eeca106725 177
Kojto 122:f9eeca106725 178 __IO uint32_t XferOptions; /*!< I2C transfer options */
Kojto 122:f9eeca106725 179
Kojto 122:f9eeca106725 180 __IO uint32_t PreviousState; /*!< I2C communication Previous state and mode
Kojto 122:f9eeca106725 181 context for internal usage */
Kojto 122:f9eeca106725 182
Kojto 122:f9eeca106725 183 DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */
Kojto 122:f9eeca106725 184
Kojto 122:f9eeca106725 185 DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */
Kojto 122:f9eeca106725 186
Kojto 122:f9eeca106725 187 HAL_LockTypeDef Lock; /*!< I2C locking object */
Kojto 122:f9eeca106725 188
Kojto 122:f9eeca106725 189 __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */
Kojto 122:f9eeca106725 190
Kojto 122:f9eeca106725 191 __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */
Kojto 122:f9eeca106725 192
Kojto 122:f9eeca106725 193 __IO uint32_t ErrorCode; /*!< I2C Error code */
bogdanm 86:04dd9b1680ae 194
Kojto 122:f9eeca106725 195 __IO uint32_t Devaddress; /*!< I2C Target device address */
bogdanm 86:04dd9b1680ae 196
Kojto 122:f9eeca106725 197 __IO uint32_t Memaddress; /*!< I2C Target memory address */
bogdanm 86:04dd9b1680ae 198
Kojto 122:f9eeca106725 199 __IO uint32_t MemaddSize; /*!< I2C Target memory address size */
bogdanm 86:04dd9b1680ae 200
Kojto 122:f9eeca106725 201 __IO uint32_t EventCount; /*!< I2C Event counter */
Kojto 122:f9eeca106725 202
Kojto 122:f9eeca106725 203 }I2C_HandleTypeDef;
bogdanm 86:04dd9b1680ae 204
Kojto 99:dbbf35b96557 205 /**
Kojto 99:dbbf35b96557 206 * @}
Kojto 99:dbbf35b96557 207 */
bogdanm 86:04dd9b1680ae 208
bogdanm 86:04dd9b1680ae 209 /* Exported constants --------------------------------------------------------*/
Kojto 99:dbbf35b96557 210 /** @defgroup I2C_Exported_Constants I2C Exported Constants
bogdanm 86:04dd9b1680ae 211 * @{
bogdanm 86:04dd9b1680ae 212 */
bogdanm 86:04dd9b1680ae 213
Kojto 99:dbbf35b96557 214 /** @defgroup I2C_Error_Code I2C Error Code
Kojto 99:dbbf35b96557 215 * @brief I2C Error Code
Kojto 99:dbbf35b96557 216 * @{
Kojto 99:dbbf35b96557 217 */
Kojto 122:f9eeca106725 218 #define HAL_I2C_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
Kojto 122:f9eeca106725 219 #define HAL_I2C_ERROR_BERR ((uint32_t)0x00000001U) /*!< BERR error */
Kojto 122:f9eeca106725 220 #define HAL_I2C_ERROR_ARLO ((uint32_t)0x00000002U) /*!< ARLO error */
Kojto 122:f9eeca106725 221 #define HAL_I2C_ERROR_AF ((uint32_t)0x00000004U) /*!< AF error */
Kojto 122:f9eeca106725 222 #define HAL_I2C_ERROR_OVR ((uint32_t)0x00000008U) /*!< OVR error */
Kojto 122:f9eeca106725 223 #define HAL_I2C_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
Kojto 122:f9eeca106725 224 #define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x00000020U) /*!< Timeout Error */
Kojto 99:dbbf35b96557 225 /**
Kojto 99:dbbf35b96557 226 * @}
Kojto 99:dbbf35b96557 227 */
Kojto 99:dbbf35b96557 228
Kojto 99:dbbf35b96557 229 /** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
bogdanm 86:04dd9b1680ae 230 * @{
bogdanm 86:04dd9b1680ae 231 */
Kojto 122:f9eeca106725 232 #define I2C_DUTYCYCLE_2 ((uint32_t)0x00000000U)
bogdanm 86:04dd9b1680ae 233 #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY
bogdanm 86:04dd9b1680ae 234 /**
bogdanm 86:04dd9b1680ae 235 * @}
bogdanm 86:04dd9b1680ae 236 */
bogdanm 86:04dd9b1680ae 237
Kojto 99:dbbf35b96557 238 /** @defgroup I2C_addressing_mode I2C addressing mode
bogdanm 86:04dd9b1680ae 239 * @{
bogdanm 86:04dd9b1680ae 240 */
Kojto 122:f9eeca106725 241 #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00004000U)
Kojto 122:f9eeca106725 242 #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | ((uint32_t)0x00004000U))
bogdanm 86:04dd9b1680ae 243 /**
bogdanm 86:04dd9b1680ae 244 * @}
bogdanm 86:04dd9b1680ae 245 */
bogdanm 86:04dd9b1680ae 246
Kojto 99:dbbf35b96557 247 /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode
bogdanm 86:04dd9b1680ae 248 * @{
bogdanm 86:04dd9b1680ae 249 */
Kojto 122:f9eeca106725 250 #define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000U)
Kojto 99:dbbf35b96557 251 #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL
bogdanm 86:04dd9b1680ae 252 /**
bogdanm 86:04dd9b1680ae 253 * @}
bogdanm 86:04dd9b1680ae 254 */
bogdanm 86:04dd9b1680ae 255
Kojto 99:dbbf35b96557 256 /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode
bogdanm 86:04dd9b1680ae 257 * @{
bogdanm 86:04dd9b1680ae 258 */
Kojto 122:f9eeca106725 259 #define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000U)
Kojto 99:dbbf35b96557 260 #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC
bogdanm 86:04dd9b1680ae 261 /**
bogdanm 86:04dd9b1680ae 262 * @}
bogdanm 86:04dd9b1680ae 263 */
bogdanm 86:04dd9b1680ae 264
Kojto 99:dbbf35b96557 265 /** @defgroup I2C_nostretch_mode I2C nostretch mode
Kojto 99:dbbf35b96557 266 * @{
Kojto 99:dbbf35b96557 267 */
Kojto 122:f9eeca106725 268 #define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000U)
Kojto 99:dbbf35b96557 269 #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
Kojto 99:dbbf35b96557 270 /**
Kojto 99:dbbf35b96557 271 * @}
Kojto 99:dbbf35b96557 272 */
Kojto 99:dbbf35b96557 273
Kojto 99:dbbf35b96557 274 /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size
bogdanm 86:04dd9b1680ae 275 * @{
bogdanm 86:04dd9b1680ae 276 */
Kojto 122:f9eeca106725 277 #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001U)
Kojto 122:f9eeca106725 278 #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000010U)
Kojto 122:f9eeca106725 279 /**
Kojto 122:f9eeca106725 280 * @}
Kojto 122:f9eeca106725 281 */
Kojto 122:f9eeca106725 282
Kojto 122:f9eeca106725 283 /** @defgroup I2C_XferDirection_definition I2C XferDirection definition
Kojto 122:f9eeca106725 284 * @{
Kojto 122:f9eeca106725 285 */
Kojto 122:f9eeca106725 286 #define I2C_DIRECTION_RECEIVE ((uint32_t)0x00000000U)
Kojto 122:f9eeca106725 287 #define I2C_DIRECTION_TRANSMIT ((uint32_t)0x00000001U)
Kojto 122:f9eeca106725 288 /**
Kojto 122:f9eeca106725 289 * @}
Kojto 122:f9eeca106725 290 */
Kojto 122:f9eeca106725 291
Kojto 122:f9eeca106725 292 /** @defgroup I2C_XferOptions_definition I2C XferOptions definition
Kojto 122:f9eeca106725 293 * @{
Kojto 122:f9eeca106725 294 */
Kojto 122:f9eeca106725 295 #define I2C_FIRST_FRAME ((uint32_t)0x00000001U)
Kojto 122:f9eeca106725 296 #define I2C_NEXT_FRAME ((uint32_t)0x00000002U)
Kojto 122:f9eeca106725 297 #define I2C_FIRST_AND_LAST_FRAME ((uint32_t)0x00000004U)
Kojto 122:f9eeca106725 298 #define I2C_LAST_FRAME ((uint32_t)0x00000008U)
bogdanm 86:04dd9b1680ae 299 /**
bogdanm 86:04dd9b1680ae 300 * @}
bogdanm 86:04dd9b1680ae 301 */
bogdanm 86:04dd9b1680ae 302
Kojto 99:dbbf35b96557 303 /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
bogdanm 86:04dd9b1680ae 304 * @{
bogdanm 86:04dd9b1680ae 305 */
bogdanm 86:04dd9b1680ae 306 #define I2C_IT_BUF I2C_CR2_ITBUFEN
bogdanm 86:04dd9b1680ae 307 #define I2C_IT_EVT I2C_CR2_ITEVTEN
bogdanm 86:04dd9b1680ae 308 #define I2C_IT_ERR I2C_CR2_ITERREN
bogdanm 86:04dd9b1680ae 309 /**
bogdanm 86:04dd9b1680ae 310 * @}
bogdanm 86:04dd9b1680ae 311 */
bogdanm 86:04dd9b1680ae 312
Kojto 99:dbbf35b96557 313 /** @defgroup I2C_Flag_definition I2C Flag definition
bogdanm 86:04dd9b1680ae 314 * @{
bogdanm 86:04dd9b1680ae 315 */
Kojto 122:f9eeca106725 316 #define I2C_FLAG_SMBALERT ((uint32_t)0x00018000U)
Kojto 122:f9eeca106725 317 #define I2C_FLAG_TIMEOUT ((uint32_t)0x00014000U)
Kojto 122:f9eeca106725 318 #define I2C_FLAG_PECERR ((uint32_t)0x00011000U)
Kojto 122:f9eeca106725 319 #define I2C_FLAG_OVR ((uint32_t)0x00010800U)
Kojto 122:f9eeca106725 320 #define I2C_FLAG_AF ((uint32_t)0x00010400U)
Kojto 122:f9eeca106725 321 #define I2C_FLAG_ARLO ((uint32_t)0x00010200U)
Kojto 122:f9eeca106725 322 #define I2C_FLAG_BERR ((uint32_t)0x00010100U)
Kojto 122:f9eeca106725 323 #define I2C_FLAG_TXE ((uint32_t)0x00010080U)
Kojto 122:f9eeca106725 324 #define I2C_FLAG_RXNE ((uint32_t)0x00010040U)
Kojto 122:f9eeca106725 325 #define I2C_FLAG_STOPF ((uint32_t)0x00010010U)
Kojto 122:f9eeca106725 326 #define I2C_FLAG_ADD10 ((uint32_t)0x00010008U)
Kojto 122:f9eeca106725 327 #define I2C_FLAG_BTF ((uint32_t)0x00010004U)
Kojto 122:f9eeca106725 328 #define I2C_FLAG_ADDR ((uint32_t)0x00010002U)
Kojto 122:f9eeca106725 329 #define I2C_FLAG_SB ((uint32_t)0x00010001U)
Kojto 122:f9eeca106725 330 #define I2C_FLAG_DUALF ((uint32_t)0x00100080U)
Kojto 122:f9eeca106725 331 #define I2C_FLAG_SMBHOST ((uint32_t)0x00100040U)
Kojto 122:f9eeca106725 332 #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00100020U)
Kojto 122:f9eeca106725 333 #define I2C_FLAG_GENCALL ((uint32_t)0x00100010U)
Kojto 122:f9eeca106725 334 #define I2C_FLAG_TRA ((uint32_t)0x00100004U)
Kojto 122:f9eeca106725 335 #define I2C_FLAG_BUSY ((uint32_t)0x00100002U)
Kojto 122:f9eeca106725 336 #define I2C_FLAG_MSL ((uint32_t)0x00100001U)
bogdanm 86:04dd9b1680ae 337 /**
bogdanm 86:04dd9b1680ae 338 * @}
bogdanm 86:04dd9b1680ae 339 */
bogdanm 86:04dd9b1680ae 340
bogdanm 86:04dd9b1680ae 341 /**
bogdanm 86:04dd9b1680ae 342 * @}
bogdanm 86:04dd9b1680ae 343 */
bogdanm 86:04dd9b1680ae 344
bogdanm 86:04dd9b1680ae 345 /* Exported macro ------------------------------------------------------------*/
Kojto 99:dbbf35b96557 346 /** @defgroup I2C_Exported_Macros I2C Exported Macros
Kojto 99:dbbf35b96557 347 * @{
Kojto 99:dbbf35b96557 348 */
bogdanm 86:04dd9b1680ae 349
bogdanm 86:04dd9b1680ae 350 /** @brief Reset I2C handle state
bogdanm 86:04dd9b1680ae 351 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 352 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 353 * @retval None
bogdanm 86:04dd9b1680ae 354 */
bogdanm 86:04dd9b1680ae 355 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
bogdanm 86:04dd9b1680ae 356
bogdanm 86:04dd9b1680ae 357 /** @brief Enable or disable the specified I2C interrupts.
bogdanm 86:04dd9b1680ae 358 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 359 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 360 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
bogdanm 86:04dd9b1680ae 361 * This parameter can be one of the following values:
bogdanm 86:04dd9b1680ae 362 * @arg I2C_IT_BUF: Buffer interrupt enable
bogdanm 86:04dd9b1680ae 363 * @arg I2C_IT_EVT: Event interrupt enable
bogdanm 86:04dd9b1680ae 364 * @arg I2C_IT_ERR: Error interrupt enable
bogdanm 86:04dd9b1680ae 365 * @retval None
bogdanm 86:04dd9b1680ae 366 */
bogdanm 86:04dd9b1680ae 367 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
bogdanm 86:04dd9b1680ae 368 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
bogdanm 86:04dd9b1680ae 369
bogdanm 86:04dd9b1680ae 370 /** @brief Checks if the specified I2C interrupt source is enabled or disabled.
bogdanm 86:04dd9b1680ae 371 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 372 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 373 * @param __INTERRUPT__: specifies the I2C interrupt source to check.
bogdanm 86:04dd9b1680ae 374 * This parameter can be one of the following values:
bogdanm 86:04dd9b1680ae 375 * @arg I2C_IT_BUF: Buffer interrupt enable
bogdanm 86:04dd9b1680ae 376 * @arg I2C_IT_EVT: Event interrupt enable
bogdanm 86:04dd9b1680ae 377 * @arg I2C_IT_ERR: Error interrupt enable
bogdanm 86:04dd9b1680ae 378 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
bogdanm 86:04dd9b1680ae 379 */
bogdanm 86:04dd9b1680ae 380 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
bogdanm 86:04dd9b1680ae 381
bogdanm 86:04dd9b1680ae 382 /** @brief Checks whether the specified I2C flag is set or not.
bogdanm 86:04dd9b1680ae 383 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 384 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 385 * @param __FLAG__: specifies the flag to check.
bogdanm 86:04dd9b1680ae 386 * This parameter can be one of the following values:
bogdanm 86:04dd9b1680ae 387 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
bogdanm 86:04dd9b1680ae 388 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
bogdanm 86:04dd9b1680ae 389 * @arg I2C_FLAG_PECERR: PEC error in reception flag
bogdanm 86:04dd9b1680ae 390 * @arg I2C_FLAG_OVR: Overrun/Underrun flag
bogdanm 86:04dd9b1680ae 391 * @arg I2C_FLAG_AF: Acknowledge failure flag
bogdanm 86:04dd9b1680ae 392 * @arg I2C_FLAG_ARLO: Arbitration lost flag
bogdanm 86:04dd9b1680ae 393 * @arg I2C_FLAG_BERR: Bus error flag
bogdanm 86:04dd9b1680ae 394 * @arg I2C_FLAG_TXE: Data register empty flag
bogdanm 86:04dd9b1680ae 395 * @arg I2C_FLAG_RXNE: Data register not empty flag
bogdanm 86:04dd9b1680ae 396 * @arg I2C_FLAG_STOPF: Stop detection flag
bogdanm 86:04dd9b1680ae 397 * @arg I2C_FLAG_ADD10: 10-bit header sent flag
bogdanm 86:04dd9b1680ae 398 * @arg I2C_FLAG_BTF: Byte transfer finished flag
bogdanm 86:04dd9b1680ae 399 * @arg I2C_FLAG_ADDR: Address sent flag
bogdanm 86:04dd9b1680ae 400 * Address matched flag
bogdanm 86:04dd9b1680ae 401 * @arg I2C_FLAG_SB: Start bit flag
bogdanm 86:04dd9b1680ae 402 * @arg I2C_FLAG_DUALF: Dual flag
bogdanm 86:04dd9b1680ae 403 * @arg I2C_FLAG_SMBHOST: SMBus host header
bogdanm 86:04dd9b1680ae 404 * @arg I2C_FLAG_SMBDEFAULT: SMBus default header
bogdanm 86:04dd9b1680ae 405 * @arg I2C_FLAG_GENCALL: General call header flag
bogdanm 86:04dd9b1680ae 406 * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
bogdanm 86:04dd9b1680ae 407 * @arg I2C_FLAG_BUSY: Bus busy flag
bogdanm 86:04dd9b1680ae 408 * @arg I2C_FLAG_MSL: Master/Slave flag
bogdanm 86:04dd9b1680ae 409 * @retval The new state of __FLAG__ (TRUE or FALSE).
bogdanm 86:04dd9b1680ae 410 */
Kojto 122:f9eeca106725 411 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \
bogdanm 86:04dd9b1680ae 412 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
bogdanm 86:04dd9b1680ae 413
bogdanm 86:04dd9b1680ae 414 /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
bogdanm 86:04dd9b1680ae 415 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 416 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 417 * @param __FLAG__: specifies the flag to clear.
bogdanm 86:04dd9b1680ae 418 * This parameter can be any combination of the following values:
bogdanm 86:04dd9b1680ae 419 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
bogdanm 86:04dd9b1680ae 420 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
bogdanm 86:04dd9b1680ae 421 * @arg I2C_FLAG_PECERR: PEC error in reception flag
bogdanm 86:04dd9b1680ae 422 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
bogdanm 86:04dd9b1680ae 423 * @arg I2C_FLAG_AF: Acknowledge failure flag
bogdanm 86:04dd9b1680ae 424 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
bogdanm 86:04dd9b1680ae 425 * @arg I2C_FLAG_BERR: Bus error flag
bogdanm 86:04dd9b1680ae 426 * @retval None
bogdanm 86:04dd9b1680ae 427 */
bogdanm 86:04dd9b1680ae 428 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
bogdanm 86:04dd9b1680ae 429
bogdanm 86:04dd9b1680ae 430 /** @brief Clears the I2C ADDR pending flag.
bogdanm 86:04dd9b1680ae 431 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 432 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 433 * @retval None
bogdanm 86:04dd9b1680ae 434 */
Kojto 99:dbbf35b96557 435 #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \
Kojto 99:dbbf35b96557 436 do{ \
Kojto 122:f9eeca106725 437 __IO uint32_t tmpreg = 0x00U; \
Kojto 99:dbbf35b96557 438 tmpreg = (__HANDLE__)->Instance->SR1; \
Kojto 99:dbbf35b96557 439 tmpreg = (__HANDLE__)->Instance->SR2; \
Kojto 99:dbbf35b96557 440 UNUSED(tmpreg); \
Kojto 99:dbbf35b96557 441 } while(0)
bogdanm 86:04dd9b1680ae 442
bogdanm 86:04dd9b1680ae 443 /** @brief Clears the I2C STOPF pending flag.
bogdanm 86:04dd9b1680ae 444 * @param __HANDLE__: specifies the I2C Handle.
bogdanm 86:04dd9b1680ae 445 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
bogdanm 86:04dd9b1680ae 446 * @retval None
bogdanm 86:04dd9b1680ae 447 */
Kojto 99:dbbf35b96557 448 #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \
Kojto 99:dbbf35b96557 449 do{ \
Kojto 122:f9eeca106725 450 __IO uint32_t tmpreg = 0x00U; \
Kojto 99:dbbf35b96557 451 tmpreg = (__HANDLE__)->Instance->SR1; \
Kojto 99:dbbf35b96557 452 (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \
Kojto 99:dbbf35b96557 453 UNUSED(tmpreg); \
Kojto 99:dbbf35b96557 454 } while(0)
Kojto 99:dbbf35b96557 455
Kojto 122:f9eeca106725 456 /** @brief Enable the I2C peripheral.
Kojto 122:f9eeca106725 457 * @param __HANDLE__: specifies the I2C Handle.
Kojto 122:f9eeca106725 458 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
Kojto 122:f9eeca106725 459 * @retval None
Kojto 122:f9eeca106725 460 */
bogdanm 86:04dd9b1680ae 461 #define __HAL_I2C_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
Kojto 122:f9eeca106725 462
Kojto 122:f9eeca106725 463 /** @brief Disable the I2C peripheral.
Kojto 122:f9eeca106725 464 * @param __HANDLE__: specifies the I2C Handle.
Kojto 122:f9eeca106725 465 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
Kojto 122:f9eeca106725 466 * @retval None
Kojto 122:f9eeca106725 467 */
bogdanm 86:04dd9b1680ae 468 #define __HAL_I2C_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
bogdanm 86:04dd9b1680ae 469
Kojto 99:dbbf35b96557 470 /**
Kojto 99:dbbf35b96557 471 * @}
Kojto 99:dbbf35b96557 472 */
bogdanm 86:04dd9b1680ae 473
bogdanm 86:04dd9b1680ae 474 /* Include I2C HAL Extension module */
bogdanm 86:04dd9b1680ae 475 #include "stm32f4xx_hal_i2c_ex.h"
bogdanm 86:04dd9b1680ae 476
bogdanm 86:04dd9b1680ae 477 /* Exported functions --------------------------------------------------------*/
Kojto 99:dbbf35b96557 478 /** @addtogroup I2C_Exported_Functions
Kojto 99:dbbf35b96557 479 * @{
Kojto 99:dbbf35b96557 480 */
Kojto 99:dbbf35b96557 481
Kojto 99:dbbf35b96557 482 /** @addtogroup I2C_Exported_Functions_Group1
Kojto 99:dbbf35b96557 483 * @{
Kojto 99:dbbf35b96557 484 */
bogdanm 86:04dd9b1680ae 485 /* Initialization/de-initialization functions **********************************/
bogdanm 86:04dd9b1680ae 486 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 487 HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 488 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 489 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
Kojto 99:dbbf35b96557 490 /**
Kojto 99:dbbf35b96557 491 * @}
Kojto 99:dbbf35b96557 492 */
bogdanm 86:04dd9b1680ae 493
Kojto 99:dbbf35b96557 494 /** @addtogroup I2C_Exported_Functions_Group2
Kojto 99:dbbf35b96557 495 * @{
Kojto 99:dbbf35b96557 496 */
bogdanm 86:04dd9b1680ae 497 /* I/O operation functions *****************************************************/
bogdanm 86:04dd9b1680ae 498 /******* Blocking mode: Polling */
bogdanm 86:04dd9b1680ae 499 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 500 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 501 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 502 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 503 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 504 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 505 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
bogdanm 86:04dd9b1680ae 506
bogdanm 86:04dd9b1680ae 507 /******* Non-Blocking mode: Interrupt */
bogdanm 86:04dd9b1680ae 508 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 509 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 510 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 511 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 512 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 513 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 514
Kojto 122:f9eeca106725 515 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 516 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 517 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 518 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
Kojto 122:f9eeca106725 519 HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
Kojto 122:f9eeca106725 520 HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 521 HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 522
bogdanm 86:04dd9b1680ae 523 /******* Non-Blocking mode: DMA */
bogdanm 86:04dd9b1680ae 524 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 525 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 526 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 527 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
bogdanm 86:04dd9b1680ae 528 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 529 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 86:04dd9b1680ae 530
bogdanm 86:04dd9b1680ae 531 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
bogdanm 86:04dd9b1680ae 532 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 533 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 534 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 535 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 536 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 537 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 538 void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode);
Kojto 122:f9eeca106725 539 void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 540 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 541 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
bogdanm 86:04dd9b1680ae 542 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 543 void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
Kojto 99:dbbf35b96557 544 /**
Kojto 99:dbbf35b96557 545 * @}
Kojto 99:dbbf35b96557 546 */
bogdanm 86:04dd9b1680ae 547
Kojto 99:dbbf35b96557 548 /** @addtogroup I2C_Exported_Functions_Group3
Kojto 99:dbbf35b96557 549 * @{
Kojto 99:dbbf35b96557 550 */
Kojto 122:f9eeca106725 551 /* Peripheral State, Mode and Errors functions *********************************/
bogdanm 86:04dd9b1680ae 552 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
Kojto 122:f9eeca106725 553 HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
Kojto 99:dbbf35b96557 554 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
Kojto 99:dbbf35b96557 555
Kojto 99:dbbf35b96557 556 /**
Kojto 99:dbbf35b96557 557 * @}
Kojto 99:dbbf35b96557 558 */
Kojto 99:dbbf35b96557 559
Kojto 99:dbbf35b96557 560 /**
Kojto 99:dbbf35b96557 561 * @}
Kojto 99:dbbf35b96557 562 */
Kojto 99:dbbf35b96557 563 /* Private types -------------------------------------------------------------*/
Kojto 99:dbbf35b96557 564 /* Private variables ---------------------------------------------------------*/
Kojto 99:dbbf35b96557 565 /* Private constants ---------------------------------------------------------*/
Kojto 99:dbbf35b96557 566 /** @defgroup I2C_Private_Constants I2C Private Constants
Kojto 99:dbbf35b96557 567 * @{
Kojto 99:dbbf35b96557 568 */
Kojto 122:f9eeca106725 569 #define I2C_FLAG_MASK ((uint32_t)0x0000FFFFU)
Kojto 99:dbbf35b96557 570 /**
Kojto 99:dbbf35b96557 571 * @}
Kojto 99:dbbf35b96557 572 */
Kojto 99:dbbf35b96557 573
Kojto 99:dbbf35b96557 574 /* Private macros ------------------------------------------------------------*/
Kojto 99:dbbf35b96557 575 /** @defgroup I2C_Private_Macros I2C Private Macros
Kojto 99:dbbf35b96557 576 * @{
Kojto 99:dbbf35b96557 577 */
Kojto 99:dbbf35b96557 578
Kojto 122:f9eeca106725 579 #define I2C_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U)
Kojto 122:f9eeca106725 580 #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= 100000U) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
Kojto 122:f9eeca106725 581 #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
Kojto 122:f9eeca106725 582 #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3U)) : (((__PCLK__) / ((__SPEED__) * 25U)) | I2C_DUTYCYCLE_16_9))
Kojto 122:f9eeca106725 583 #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
Kojto 122:f9eeca106725 584 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
Kojto 99:dbbf35b96557 585 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
Kojto 99:dbbf35b96557 586
Kojto 99:dbbf35b96557 587 #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
Kojto 99:dbbf35b96557 588 #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
Kojto 99:dbbf35b96557 589
Kojto 122:f9eeca106725 590 #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
Kojto 122:f9eeca106725 591 #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F0U))))
Kojto 122:f9eeca106725 592 #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F1U))))
Kojto 99:dbbf35b96557 593
Kojto 122:f9eeca106725 594 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
Kojto 122:f9eeca106725 595 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
Kojto 99:dbbf35b96557 596
Kojto 99:dbbf35b96557 597 /** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
Kojto 99:dbbf35b96557 598 * @{
Kojto 99:dbbf35b96557 599 */
Kojto 99:dbbf35b96557 600 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
Kojto 99:dbbf35b96557 601 ((CYCLE) == I2C_DUTYCYCLE_16_9))
Kojto 99:dbbf35b96557 602 #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \
Kojto 99:dbbf35b96557 603 ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT))
Kojto 99:dbbf35b96557 604 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
Kojto 99:dbbf35b96557 605 ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
Kojto 99:dbbf35b96557 606 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
Kojto 99:dbbf35b96557 607 ((CALL) == I2C_GENERALCALL_ENABLE))
Kojto 99:dbbf35b96557 608 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
Kojto 99:dbbf35b96557 609 ((STRETCH) == I2C_NOSTRETCH_ENABLE))
Kojto 99:dbbf35b96557 610 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
Kojto 99:dbbf35b96557 611 ((SIZE) == I2C_MEMADD_SIZE_16BIT))
Kojto 122:f9eeca106725 612 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0) && ((SPEED) <= 400000U))
Kojto 122:f9eeca106725 613 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00U)) == 0U)
Kojto 122:f9eeca106725 614 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01U)) == 0U)
Kojto 122:f9eeca106725 615 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_FIRST_FRAME) || \
Kojto 122:f9eeca106725 616 ((REQUEST) == I2C_NEXT_FRAME) || \
Kojto 122:f9eeca106725 617 ((REQUEST) == I2C_FIRST_AND_LAST_FRAME) || \
Kojto 122:f9eeca106725 618 ((REQUEST) == I2C_LAST_FRAME))
Kojto 99:dbbf35b96557 619 /**
Kojto 99:dbbf35b96557 620 * @}
Kojto 99:dbbf35b96557 621 */
Kojto 99:dbbf35b96557 622
Kojto 99:dbbf35b96557 623 /**
Kojto 99:dbbf35b96557 624 * @}
Kojto 99:dbbf35b96557 625 */
Kojto 99:dbbf35b96557 626
Kojto 99:dbbf35b96557 627 /* Private functions ---------------------------------------------------------*/
Kojto 99:dbbf35b96557 628 /** @defgroup I2C_Private_Functions I2C Private Functions
Kojto 99:dbbf35b96557 629 * @{
Kojto 99:dbbf35b96557 630 */
Kojto 99:dbbf35b96557 631
Kojto 99:dbbf35b96557 632 /**
Kojto 99:dbbf35b96557 633 * @}
Kojto 99:dbbf35b96557 634 */
bogdanm 86:04dd9b1680ae 635
bogdanm 86:04dd9b1680ae 636 /**
bogdanm 86:04dd9b1680ae 637 * @}
bogdanm 86:04dd9b1680ae 638 */
bogdanm 86:04dd9b1680ae 639
bogdanm 86:04dd9b1680ae 640 /**
bogdanm 86:04dd9b1680ae 641 * @}
bogdanm 86:04dd9b1680ae 642 */
bogdanm 86:04dd9b1680ae 643
bogdanm 86:04dd9b1680ae 644 #ifdef __cplusplus
bogdanm 86:04dd9b1680ae 645 }
bogdanm 86:04dd9b1680ae 646 #endif
bogdanm 86:04dd9b1680ae 647
bogdanm 86:04dd9b1680ae 648
bogdanm 86:04dd9b1680ae 649 #endif /* __STM32F4xx_HAL_I2C_H */
bogdanm 86:04dd9b1680ae 650
bogdanm 86:04dd9b1680ae 651 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/