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.
 
 
 

599 lines
25 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_i2c.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of I2C HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 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 __STM32F7xx_HAL_I2C_H
  39. #define __STM32F7xx_HAL_I2C_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_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 acknoledge 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, /*!< I2C not yet initialized or disabled */
  89. HAL_I2C_STATE_READY = 0x01, /*!< I2C initialized and ready for use */
  90. HAL_I2C_STATE_BUSY = 0x02, /*!< I2C internal process is ongoing */
  91. HAL_I2C_STATE_MASTER_BUSY_TX = 0x12, /*!< Master Data Transmission process is ongoing */
  92. HAL_I2C_STATE_MASTER_BUSY_RX = 0x22, /*!< Master Data Reception process is ongoing */
  93. HAL_I2C_STATE_SLAVE_BUSY_TX = 0x32, /*!< Slave Data Transmission process is ongoing */
  94. HAL_I2C_STATE_SLAVE_BUSY_RX = 0x42, /*!< Slave Data Reception process is ongoing */
  95. HAL_I2C_STATE_MEM_BUSY_TX = 0x52, /*!< Memory Data Transmission process is ongoing */
  96. HAL_I2C_STATE_MEM_BUSY_RX = 0x62, /*!< Memory Data Reception process is ongoing */
  97. HAL_I2C_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  98. HAL_I2C_STATE_ERROR = 0x04 /*!< Reception process is ongoing */
  99. }HAL_I2C_StateTypeDef;
  100. /**
  101. * @}
  102. */
  103. /** @defgroup I2C_Error_Code_definition I2C Error Code definition
  104. * @brief I2C Error Code definition
  105. * @{
  106. */
  107. #define HAL_I2C_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
  108. #define HAL_I2C_ERROR_BERR ((uint32_t)0x00000001) /*!< BERR error */
  109. #define HAL_I2C_ERROR_ARLO ((uint32_t)0x00000002) /*!< ARLO error */
  110. #define HAL_I2C_ERROR_AF ((uint32_t)0x00000004) /*!< ACKF error */
  111. #define HAL_I2C_ERROR_OVR ((uint32_t)0x00000008) /*!< OVR error */
  112. #define HAL_I2C_ERROR_DMA ((uint32_t)0x00000010) /*!< DMA transfer error */
  113. #define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x00000020) /*!< Timeout error */
  114. #define HAL_I2C_ERROR_SIZE ((uint32_t)0x00000040) /*!< Size Management error */
  115. /**
  116. * @}
  117. */
  118. /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition
  119. * @brief I2C handle Structure definition
  120. * @{
  121. */
  122. typedef struct
  123. {
  124. I2C_TypeDef *Instance; /*!< I2C registers base address */
  125. I2C_InitTypeDef Init; /*!< I2C communication parameters */
  126. uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */
  127. uint16_t XferSize; /*!< I2C transfer size */
  128. __IO uint16_t XferCount; /*!< I2C transfer counter */
  129. DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */
  130. DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */
  131. HAL_LockTypeDef Lock; /*!< I2C locking object */
  132. __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */
  133. __IO uint32_t ErrorCode; /*!< I2C Error code */
  134. }I2C_HandleTypeDef;
  135. /**
  136. * @}
  137. */
  138. /**
  139. * @}
  140. */
  141. /* Exported constants --------------------------------------------------------*/
  142. /** @defgroup I2C_Exported_Constants I2C Exported Constants
  143. * @{
  144. */
  145. /** @defgroup I2C_addressing_mode I2C addressing mode
  146. * @{
  147. */
  148. #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00000001)
  149. #define I2C_ADDRESSINGMODE_10BIT ((uint32_t)0x00000002)
  150. /**
  151. * @}
  152. */
  153. /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode
  154. * @{
  155. */
  156. #define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000)
  157. #define I2C_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
  158. /**
  159. * @}
  160. */
  161. /** @defgroup I2C_own_address2_masks I2C own address2 masks
  162. * @{
  163. */
  164. #define I2C_OA2_NOMASK ((uint8_t)0x00)
  165. #define I2C_OA2_MASK01 ((uint8_t)0x01)
  166. #define I2C_OA2_MASK02 ((uint8_t)0x02)
  167. #define I2C_OA2_MASK03 ((uint8_t)0x03)
  168. #define I2C_OA2_MASK04 ((uint8_t)0x04)
  169. #define I2C_OA2_MASK05 ((uint8_t)0x05)
  170. #define I2C_OA2_MASK06 ((uint8_t)0x06)
  171. #define I2C_OA2_MASK07 ((uint8_t)0x07)
  172. /**
  173. * @}
  174. */
  175. /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode
  176. * @{
  177. */
  178. #define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000)
  179. #define I2C_GENERALCALL_ENABLE I2C_CR1_GCEN
  180. /**
  181. * @}
  182. */
  183. /** @defgroup I2C_nostretch_mode I2C nostretch mode
  184. * @{
  185. */
  186. #define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000)
  187. #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
  188. /**
  189. * @}
  190. */
  191. /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size
  192. * @{
  193. */
  194. #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001)
  195. #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000002)
  196. /**
  197. * @}
  198. */
  199. /** @defgroup I2C_ReloadEndMode_definition I2C ReloadEndMode definition
  200. * @{
  201. */
  202. #define I2C_RELOAD_MODE I2C_CR2_RELOAD
  203. #define I2C_AUTOEND_MODE I2C_CR2_AUTOEND
  204. #define I2C_SOFTEND_MODE ((uint32_t)0x00000000)
  205. /**
  206. * @}
  207. */
  208. /** @defgroup I2C_StartStopMode_definition I2C StartStopMode definition
  209. * @{
  210. */
  211. #define I2C_NO_STARTSTOP ((uint32_t)0x00000000)
  212. #define I2C_GENERATE_STOP I2C_CR2_STOP
  213. #define I2C_GENERATE_START_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN)
  214. #define I2C_GENERATE_START_WRITE I2C_CR2_START
  215. /**
  216. * @}
  217. */
  218. /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
  219. * @brief I2C Interrupt definition
  220. * Elements values convention: 0xXXXXXXXX
  221. * - XXXXXXXX : Interrupt control mask
  222. * @{
  223. */
  224. #define I2C_IT_ERRI I2C_CR1_ERRIE
  225. #define I2C_IT_TCI I2C_CR1_TCIE
  226. #define I2C_IT_STOPI I2C_CR1_STOPIE
  227. #define I2C_IT_NACKI I2C_CR1_NACKIE
  228. #define I2C_IT_ADDRI I2C_CR1_ADDRIE
  229. #define I2C_IT_RXI I2C_CR1_RXIE
  230. #define I2C_IT_TXI I2C_CR1_TXIE
  231. /**
  232. * @}
  233. */
  234. /** @defgroup I2C_Flag_definition I2C Flag definition
  235. * @{
  236. */
  237. #define I2C_FLAG_TXE I2C_ISR_TXE
  238. #define I2C_FLAG_TXIS I2C_ISR_TXIS
  239. #define I2C_FLAG_RXNE I2C_ISR_RXNE
  240. #define I2C_FLAG_ADDR I2C_ISR_ADDR
  241. #define I2C_FLAG_AF I2C_ISR_NACKF
  242. #define I2C_FLAG_STOPF I2C_ISR_STOPF
  243. #define I2C_FLAG_TC I2C_ISR_TC
  244. #define I2C_FLAG_TCR I2C_ISR_TCR
  245. #define I2C_FLAG_BERR I2C_ISR_BERR
  246. #define I2C_FLAG_ARLO I2C_ISR_ARLO
  247. #define I2C_FLAG_OVR I2C_ISR_OVR
  248. #define I2C_FLAG_PECERR I2C_ISR_PECERR
  249. #define I2C_FLAG_TIMEOUT I2C_ISR_TIMEOUT
  250. #define I2C_FLAG_ALERT I2C_ISR_ALERT
  251. #define I2C_FLAG_BUSY I2C_ISR_BUSY
  252. #define I2C_FLAG_DIR I2C_ISR_DIR
  253. /**
  254. * @}
  255. */
  256. /**
  257. * @}
  258. */
  259. /* Exported macros -----------------------------------------------------------*/
  260. /** @defgroup I2C_Exported_Macros I2C Exported Macros
  261. * @{
  262. */
  263. /** @brief Reset I2C handle state
  264. * @param __HANDLE__: specifies the I2C Handle.
  265. * @retval None
  266. */
  267. #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
  268. /** @brief Enable the specified I2C interrupts.
  269. * @param __HANDLE__: specifies the I2C Handle.
  270. * @param __INTERRUPT__: specifies the interrupt source to enable.
  271. * This parameter can be one of the following values:
  272. * @arg I2C_IT_ERRI: Errors interrupt enable
  273. * @arg I2C_IT_TCI: Transfer complete interrupt enable
  274. * @arg I2C_IT_STOPI: STOP detection interrupt enable
  275. * @arg I2C_IT_NACKI: NACK received interrupt enable
  276. * @arg I2C_IT_ADDRI: Address match interrupt enable
  277. * @arg I2C_IT_RXI: RX interrupt enable
  278. * @arg I2C_IT_TXI: TX interrupt enable
  279. *
  280. * @retval None
  281. */
  282. #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
  283. /** @brief Disable the specified I2C interrupts.
  284. * @param __HANDLE__: specifies the I2C Handle.
  285. * @param __INTERRUPT__: specifies the interrupt source to disable.
  286. * This parameter can be one of the following values:
  287. * @arg I2C_IT_ERRI: Errors interrupt enable
  288. * @arg I2C_IT_TCI: Transfer complete interrupt enable
  289. * @arg I2C_IT_STOPI: STOP detection interrupt enable
  290. * @arg I2C_IT_NACKI: NACK received interrupt enable
  291. * @arg I2C_IT_ADDRI: Address match interrupt enable
  292. * @arg I2C_IT_RXI: RX interrupt enable
  293. * @arg I2C_IT_TXI: TX interrupt enable
  294. *
  295. * @retval None
  296. */
  297. #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
  298. /** @brief Checks if the specified I2C interrupt source is enabled or disabled.
  299. * @param __HANDLE__: specifies the I2C Handle.
  300. * @param __INTERRUPT__: specifies the I2C interrupt source to check.
  301. * This parameter can be one of the following values:
  302. * @arg I2C_IT_ERRI: Errors interrupt enable
  303. * @arg I2C_IT_TCI: Transfer complete interrupt enable
  304. * @arg I2C_IT_STOPI: STOP detection interrupt enable
  305. * @arg I2C_IT_NACKI: NACK received interrupt enable
  306. * @arg I2C_IT_ADDRI: Address match interrupt enable
  307. * @arg I2C_IT_RXI: RX interrupt enable
  308. * @arg I2C_IT_TXI: TX interrupt enable
  309. *
  310. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  311. */
  312. #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  313. /** @brief Checks whether the specified I2C flag is set or not.
  314. * @param __HANDLE__: specifies the I2C Handle.
  315. * @param __FLAG__: specifies the flag to check.
  316. * This parameter can be one of the following values:
  317. * @arg I2C_FLAG_TXE: Transmit data register empty
  318. * @arg I2C_FLAG_TXIS: Transmit interrupt status
  319. * @arg I2C_FLAG_RXNE: Receive data register not empty
  320. * @arg I2C_FLAG_ADDR: Address matched (slave mode)
  321. * @arg I2C_FLAG_AF: Acknowledge failure received flag
  322. * @arg I2C_FLAG_STOPF: STOP detection flag
  323. * @arg I2C_FLAG_TC: Transfer complete (master mode)
  324. * @arg I2C_FLAG_TCR: Transfer complete reload
  325. * @arg I2C_FLAG_BERR: Bus error
  326. * @arg I2C_FLAG_ARLO: Arbitration lost
  327. * @arg I2C_FLAG_OVR: Overrun/Underrun
  328. * @arg I2C_FLAG_PECERR: PEC error in reception
  329. * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
  330. * @arg I2C_FLAG_ALERT: SMBus alert
  331. * @arg I2C_FLAG_BUSY: Bus busy
  332. * @arg I2C_FLAG_DIR: Transfer direction (slave mode)
  333. *
  334. * @retval The new state of __FLAG__ (TRUE or FALSE).
  335. */
  336. #define I2C_FLAG_MASK ((uint32_t)0x0001FFFF)
  337. #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
  338. /** @brief Clears the I2C pending flags which are cleared by writing 1 in a specific bit.
  339. * @param __HANDLE__: specifies the I2C Handle.
  340. * @param __FLAG__: specifies the flag to clear.
  341. * This parameter can be any combination of the following values:
  342. * @arg I2C_FLAG_ADDR: Address matched (slave mode)
  343. * @arg I2C_FLAG_AF: Acknowledge failure received flag
  344. * @arg I2C_FLAG_STOPF: STOP detection flag
  345. * @arg I2C_FLAG_BERR: Bus error
  346. * @arg I2C_FLAG_ARLO: Arbitration lost
  347. * @arg I2C_FLAG_OVR: Overrun/Underrun
  348. * @arg I2C_FLAG_PECERR: PEC error in reception
  349. * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow detection flag
  350. * @arg I2C_FLAG_ALERT: SMBus alert
  351. *
  352. * @retval None
  353. */
  354. #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = ((__FLAG__) & I2C_FLAG_MASK))
  355. /** @brief Enable the specified I2C peripheral.
  356. * @param __HANDLE__: specifies the I2C Handle.
  357. * @retval None
  358. */
  359. #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  360. /** @brief Disable the specified I2C peripheral.
  361. * @param __HANDLE__: specifies the I2C Handle.
  362. * @retval None
  363. */
  364. #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  365. /**
  366. * @}
  367. */
  368. /* Include I2C HAL Extension module */
  369. #include "stm32f7xx_hal_i2c_ex.h"
  370. /* Exported functions --------------------------------------------------------*/
  371. /** @addtogroup I2C_Exported_Functions
  372. * @{
  373. */
  374. /** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions
  375. * @{
  376. */
  377. /* Initialization and de-initialization functions******************************/
  378. HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
  379. HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
  380. void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
  381. void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
  382. /**
  383. * @}
  384. */
  385. /** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions
  386. * @{
  387. */
  388. /* IO operation functions ****************************************************/
  389. /******* Blocking mode: Polling */
  390. HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  391. HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  392. HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  393. HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  394. 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);
  395. 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);
  396. HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
  397. /******* Non-Blocking mode: Interrupt */
  398. HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
  399. HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
  400. HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
  401. HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
  402. 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);
  403. 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);
  404. /******* Non-Blocking mode: DMA */
  405. HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
  406. HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
  407. HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
  408. HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
  409. 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);
  410. 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);
  411. /**
  412. * @}
  413. */
  414. /** @addtogroup IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
  415. * @{
  416. */
  417. /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
  418. void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
  419. void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
  420. void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
  421. void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
  422. void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
  423. void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
  424. void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
  425. void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
  426. void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
  427. /**
  428. * @}
  429. */
  430. /** @addtogroup I2C_Exported_Functions_Group3 Peripheral State and Errors functions
  431. * @{
  432. */
  433. /* Peripheral State and Errors functions *************************************/
  434. HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
  435. uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
  436. /**
  437. * @}
  438. */
  439. /**
  440. * @}
  441. */
  442. /* Private constants ---------------------------------------------------------*/
  443. /** @defgroup I2C_Private_Constants I2C Private Constants
  444. * @{
  445. */
  446. /**
  447. * @}
  448. */
  449. /* Private macros ------------------------------------------------------------*/
  450. /** @defgroup I2C_Private_Macro I2C Private Macros
  451. * @{
  452. */
  453. #define IS_I2C_ADDRESSING_MODE(MODE) (((MODE) == I2C_ADDRESSINGMODE_7BIT) || \
  454. ((MODE) == I2C_ADDRESSINGMODE_10BIT))
  455. #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
  456. ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
  457. #define IS_I2C_OWN_ADDRESS2_MASK(MASK) (((MASK) == I2C_OA2_NOMASK) || \
  458. ((MASK) == I2C_OA2_MASK01) || \
  459. ((MASK) == I2C_OA2_MASK02) || \
  460. ((MASK) == I2C_OA2_MASK03) || \
  461. ((MASK) == I2C_OA2_MASK04) || \
  462. ((MASK) == I2C_OA2_MASK05) || \
  463. ((MASK) == I2C_OA2_MASK06) || \
  464. ((MASK) == I2C_OA2_MASK07))
  465. #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
  466. ((CALL) == I2C_GENERALCALL_ENABLE))
  467. #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
  468. ((STRETCH) == I2C_NOSTRETCH_ENABLE))
  469. #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
  470. ((SIZE) == I2C_MEMADD_SIZE_16BIT))
  471. #define IS_TRANSFER_MODE(MODE) (((MODE) == I2C_RELOAD_MODE) || \
  472. ((MODE) == I2C_AUTOEND_MODE) || \
  473. ((MODE) == I2C_SOFTEND_MODE))
  474. #define IS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == I2C_GENERATE_STOP) || \
  475. ((REQUEST) == I2C_GENERATE_START_READ) || \
  476. ((REQUEST) == I2C_GENERATE_START_WRITE) || \
  477. ((REQUEST) == I2C_NO_STARTSTOP))
  478. #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)))
  479. #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= (uint32_t)0x000003FF)
  480. #define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FF)
  481. #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00))) >> 8)))
  482. #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF))))
  483. #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)) : \
  484. (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
  485. /**
  486. * @}
  487. */
  488. /* Private Functions ---------------------------------------------------------*/
  489. /** @defgroup I2C_Private_Functions I2C Private Functions
  490. * @{
  491. */
  492. /* Private functions are defined in stm32f7xx_hal_i2c.c file */
  493. /**
  494. * @}
  495. */
  496. /**
  497. * @}
  498. */
  499. /**
  500. * @}
  501. */
  502. #ifdef __cplusplus
  503. }
  504. #endif
  505. #endif /* __STM32F7xx_HAL_I2C_H */
  506. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/