You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

666 lines
29 KiB

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