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.
 
 
 

750 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_hal_smbus.h
  4. * @author MCD Application Team
  5. * @brief Header file of SMBUS HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32WBxx_HAL_SMBUS_H
  21. #define STM32WBxx_HAL_SMBUS_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32wbxx_hal_def.h"
  27. /** @addtogroup STM32WBxx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup SMBUS
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup SMBUS_Exported_Types SMBUS Exported Types
  35. * @{
  36. */
  37. /** @defgroup SMBUS_Configuration_Structure_definition SMBUS Configuration Structure definition
  38. * @brief SMBUS Configuration Structure definition
  39. * @{
  40. */
  41. typedef struct
  42. {
  43. uint32_t Timing; /*!< Specifies the SMBUS_TIMINGR_register value.
  44. This parameter calculated by referring to SMBUS initialization
  45. section in Reference manual */
  46. uint32_t AnalogFilter; /*!< Specifies if Analog Filter is enable or not.
  47. This parameter can be a value of @ref SMBUS_Analog_Filter */
  48. uint32_t OwnAddress1; /*!< Specifies the first device own address.
  49. This parameter can be a 7-bit or 10-bit address. */
  50. uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode for master is selected.
  51. This parameter can be a value of @ref SMBUS_addressing_mode */
  52. uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
  53. This parameter can be a value of @ref SMBUS_dual_addressing_mode */
  54. uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected
  55. This parameter can be a 7-bit address. */
  56. uint32_t OwnAddress2Masks; /*!< Specifies the acknowledge mask address second device own address if dual addressing mode is selected
  57. This parameter can be a value of @ref SMBUS_own_address2_masks. */
  58. uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
  59. This parameter can be a value of @ref SMBUS_general_call_addressing_mode. */
  60. uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
  61. This parameter can be a value of @ref SMBUS_nostretch_mode */
  62. uint32_t PacketErrorCheckMode; /*!< Specifies if Packet Error Check mode is selected.
  63. This parameter can be a value of @ref SMBUS_packet_error_check_mode */
  64. uint32_t PeripheralMode; /*!< Specifies which mode of Periphal is selected.
  65. This parameter can be a value of @ref SMBUS_peripheral_mode */
  66. uint32_t SMBusTimeout; /*!< Specifies the content of the 32 Bits SMBUS_TIMEOUT_register value.
  67. (Enable bits and different timeout values)
  68. This parameter calculated by referring to SMBUS initialization
  69. section in Reference manual */
  70. } SMBUS_InitTypeDef;
  71. /**
  72. * @}
  73. */
  74. /** @defgroup HAL_state_definition HAL state definition
  75. * @brief HAL State definition
  76. * @{
  77. */
  78. #define HAL_SMBUS_STATE_RESET (0x00000000U) /*!< SMBUS not yet initialized or disabled */
  79. #define HAL_SMBUS_STATE_READY (0x00000001U) /*!< SMBUS initialized and ready for use */
  80. #define HAL_SMBUS_STATE_BUSY (0x00000002U) /*!< SMBUS internal process is ongoing */
  81. #define HAL_SMBUS_STATE_MASTER_BUSY_TX (0x00000012U) /*!< Master Data Transmission process is ongoing */
  82. #define HAL_SMBUS_STATE_MASTER_BUSY_RX (0x00000022U) /*!< Master Data Reception process is ongoing */
  83. #define HAL_SMBUS_STATE_SLAVE_BUSY_TX (0x00000032U) /*!< Slave Data Transmission process is ongoing */
  84. #define HAL_SMBUS_STATE_SLAVE_BUSY_RX (0x00000042U) /*!< Slave Data Reception process is ongoing */
  85. #define HAL_SMBUS_STATE_TIMEOUT (0x00000003U) /*!< Timeout state */
  86. #define HAL_SMBUS_STATE_ERROR (0x00000004U) /*!< Reception process is ongoing */
  87. #define HAL_SMBUS_STATE_LISTEN (0x00000008U) /*!< Address Listen Mode is ongoing */
  88. /**
  89. * @}
  90. */
  91. /** @defgroup SMBUS_Error_Code_definition SMBUS Error Code definition
  92. * @brief SMBUS Error Code definition
  93. * @{
  94. */
  95. #define HAL_SMBUS_ERROR_NONE (0x00000000U) /*!< No error */
  96. #define HAL_SMBUS_ERROR_BERR (0x00000001U) /*!< BERR error */
  97. #define HAL_SMBUS_ERROR_ARLO (0x00000002U) /*!< ARLO error */
  98. #define HAL_SMBUS_ERROR_ACKF (0x00000004U) /*!< ACKF error */
  99. #define HAL_SMBUS_ERROR_OVR (0x00000008U) /*!< OVR error */
  100. #define HAL_SMBUS_ERROR_HALTIMEOUT (0x00000010U) /*!< Timeout error */
  101. #define HAL_SMBUS_ERROR_BUSTIMEOUT (0x00000020U) /*!< Bus Timeout error */
  102. #define HAL_SMBUS_ERROR_ALERT (0x00000040U) /*!< Alert error */
  103. #define HAL_SMBUS_ERROR_PECERR (0x00000080U) /*!< PEC error */
  104. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  105. #define HAL_SMBUS_ERROR_INVALID_CALLBACK (0x00000100U) /*!< Invalid Callback error */
  106. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  107. #define HAL_SMBUS_ERROR_INVALID_PARAM (0x00000200U) /*!< Invalid Parameters error */
  108. /**
  109. * @}
  110. */
  111. /** @defgroup SMBUS_handle_Structure_definition SMBUS handle Structure definition
  112. * @brief SMBUS handle Structure definition
  113. * @{
  114. */
  115. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  116. typedef struct __SMBUS_HandleTypeDef
  117. #else
  118. typedef struct
  119. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  120. {
  121. I2C_TypeDef *Instance; /*!< SMBUS registers base address */
  122. SMBUS_InitTypeDef Init; /*!< SMBUS communication parameters */
  123. uint8_t *pBuffPtr; /*!< Pointer to SMBUS transfer buffer */
  124. uint16_t XferSize; /*!< SMBUS transfer size */
  125. __IO uint16_t XferCount; /*!< SMBUS transfer counter */
  126. __IO uint32_t XferOptions; /*!< SMBUS transfer options */
  127. __IO uint32_t PreviousState; /*!< SMBUS communication Previous state */
  128. HAL_LockTypeDef Lock; /*!< SMBUS locking object */
  129. __IO uint32_t State; /*!< SMBUS communication state */
  130. __IO uint32_t ErrorCode; /*!< SMBUS Error code */
  131. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  132. void (* MasterTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Tx Transfer completed callback */
  133. void (* MasterRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Rx Transfer completed callback */
  134. void (* SlaveTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Tx Transfer completed callback */
  135. void (* SlaveRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Rx Transfer completed callback */
  136. void (* ListenCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Listen Complete callback */
  137. void (* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Error callback */
  138. void (* AddrCallback)(struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< SMBUS Slave Address Match callback */
  139. void (* MspInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp Init callback */
  140. void (* MspDeInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp DeInit callback */
  141. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  142. } SMBUS_HandleTypeDef;
  143. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  144. /**
  145. * @brief HAL SMBUS Callback ID enumeration definition
  146. */
  147. typedef enum
  148. {
  149. HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID = 0x00U, /*!< SMBUS Master Tx Transfer completed callback ID */
  150. HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID = 0x01U, /*!< SMBUS Master Rx Transfer completed callback ID */
  151. HAL_SMBUS_SLAVE_TX_COMPLETE_CB_ID = 0x02U, /*!< SMBUS Slave Tx Transfer completed callback ID */
  152. HAL_SMBUS_SLAVE_RX_COMPLETE_CB_ID = 0x03U, /*!< SMBUS Slave Rx Transfer completed callback ID */
  153. HAL_SMBUS_LISTEN_COMPLETE_CB_ID = 0x04U, /*!< SMBUS Listen Complete callback ID */
  154. HAL_SMBUS_ERROR_CB_ID = 0x05U, /*!< SMBUS Error callback ID */
  155. HAL_SMBUS_MSPINIT_CB_ID = 0x06U, /*!< SMBUS Msp Init callback ID */
  156. HAL_SMBUS_MSPDEINIT_CB_ID = 0x07U /*!< SMBUS Msp DeInit callback ID */
  157. } HAL_SMBUS_CallbackIDTypeDef;
  158. /**
  159. * @brief HAL SMBUS Callback pointer definition
  160. */
  161. typedef void (*pSMBUS_CallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus); /*!< pointer to an SMBUS callback function */
  162. typedef void (*pSMBUS_AddrCallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< pointer to an SMBUS Address Match callback function */
  163. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  164. /**
  165. * @}
  166. */
  167. /**
  168. * @}
  169. */
  170. /* Exported constants --------------------------------------------------------*/
  171. /** @defgroup SMBUS_Exported_Constants SMBUS Exported Constants
  172. * @{
  173. */
  174. /** @defgroup SMBUS_Analog_Filter SMBUS Analog Filter
  175. * @{
  176. */
  177. #define SMBUS_ANALOGFILTER_ENABLE (0x00000000U)
  178. #define SMBUS_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF
  179. /**
  180. * @}
  181. */
  182. /** @defgroup SMBUS_addressing_mode SMBUS addressing mode
  183. * @{
  184. */
  185. #define SMBUS_ADDRESSINGMODE_7BIT (0x00000001U)
  186. #define SMBUS_ADDRESSINGMODE_10BIT (0x00000002U)
  187. /**
  188. * @}
  189. */
  190. /** @defgroup SMBUS_dual_addressing_mode SMBUS dual addressing mode
  191. * @{
  192. */
  193. #define SMBUS_DUALADDRESS_DISABLE (0x00000000U)
  194. #define SMBUS_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
  195. /**
  196. * @}
  197. */
  198. /** @defgroup SMBUS_own_address2_masks SMBUS ownaddress2 masks
  199. * @{
  200. */
  201. #define SMBUS_OA2_NOMASK ((uint8_t)0x00U)
  202. #define SMBUS_OA2_MASK01 ((uint8_t)0x01U)
  203. #define SMBUS_OA2_MASK02 ((uint8_t)0x02U)
  204. #define SMBUS_OA2_MASK03 ((uint8_t)0x03U)
  205. #define SMBUS_OA2_MASK04 ((uint8_t)0x04U)
  206. #define SMBUS_OA2_MASK05 ((uint8_t)0x05U)
  207. #define SMBUS_OA2_MASK06 ((uint8_t)0x06U)
  208. #define SMBUS_OA2_MASK07 ((uint8_t)0x07U)
  209. /**
  210. * @}
  211. */
  212. /** @defgroup SMBUS_general_call_addressing_mode SMBUS general call addressing mode
  213. * @{
  214. */
  215. #define SMBUS_GENERALCALL_DISABLE (0x00000000U)
  216. #define SMBUS_GENERALCALL_ENABLE I2C_CR1_GCEN
  217. /**
  218. * @}
  219. */
  220. /** @defgroup SMBUS_nostretch_mode SMBUS nostretch mode
  221. * @{
  222. */
  223. #define SMBUS_NOSTRETCH_DISABLE (0x00000000U)
  224. #define SMBUS_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
  225. /**
  226. * @}
  227. */
  228. /** @defgroup SMBUS_packet_error_check_mode SMBUS packet error check mode
  229. * @{
  230. */
  231. #define SMBUS_PEC_DISABLE (0x00000000U)
  232. #define SMBUS_PEC_ENABLE I2C_CR1_PECEN
  233. /**
  234. * @}
  235. */
  236. /** @defgroup SMBUS_peripheral_mode SMBUS peripheral mode
  237. * @{
  238. */
  239. #define SMBUS_PERIPHERAL_MODE_SMBUS_HOST I2C_CR1_SMBHEN
  240. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE (0x00000000U)
  241. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP I2C_CR1_SMBDEN
  242. /**
  243. * @}
  244. */
  245. /** @defgroup SMBUS_ReloadEndMode_definition SMBUS ReloadEndMode definition
  246. * @{
  247. */
  248. #define SMBUS_SOFTEND_MODE (0x00000000U)
  249. #define SMBUS_RELOAD_MODE I2C_CR2_RELOAD
  250. #define SMBUS_AUTOEND_MODE I2C_CR2_AUTOEND
  251. #define SMBUS_SENDPEC_MODE I2C_CR2_PECBYTE
  252. /**
  253. * @}
  254. */
  255. /** @defgroup SMBUS_StartStopMode_definition SMBUS StartStopMode definition
  256. * @{
  257. */
  258. #define SMBUS_NO_STARTSTOP (0x00000000U)
  259. #define SMBUS_GENERATE_STOP (uint32_t)(0x80000000U | I2C_CR2_STOP)
  260. #define SMBUS_GENERATE_START_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN)
  261. #define SMBUS_GENERATE_START_WRITE (uint32_t)(0x80000000U | I2C_CR2_START)
  262. /**
  263. * @}
  264. */
  265. /** @defgroup SMBUS_XferOptions_definition SMBUS XferOptions definition
  266. * @{
  267. */
  268. /* List of XferOptions in usage of :
  269. * 1- Restart condition when direction change
  270. * 2- No Restart condition in other use cases
  271. */
  272. #define SMBUS_FIRST_FRAME SMBUS_SOFTEND_MODE
  273. #define SMBUS_NEXT_FRAME ((uint32_t)(SMBUS_RELOAD_MODE | SMBUS_SOFTEND_MODE))
  274. #define SMBUS_FIRST_AND_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
  275. #define SMBUS_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
  276. #define SMBUS_FIRST_FRAME_WITH_PEC ((uint32_t)(SMBUS_SOFTEND_MODE | SMBUS_SENDPEC_MODE))
  277. #define SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
  278. #define SMBUS_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
  279. /* List of XferOptions in usage of :
  280. * 1- Restart condition in all use cases (direction change or not)
  281. */
  282. #define SMBUS_OTHER_FRAME_NO_PEC (0x000000AAU)
  283. #define SMBUS_OTHER_FRAME_WITH_PEC (0x0000AA00U)
  284. #define SMBUS_OTHER_AND_LAST_FRAME_NO_PEC (0x00AA0000U)
  285. #define SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC (0xAA000000U)
  286. /**
  287. * @}
  288. */
  289. /** @defgroup SMBUS_Interrupt_configuration_definition SMBUS Interrupt configuration definition
  290. * @brief SMBUS Interrupt definition
  291. * Elements values convention: 0xXXXXXXXX
  292. * - XXXXXXXX : Interrupt control mask
  293. * @{
  294. */
  295. #define SMBUS_IT_ERRI I2C_CR1_ERRIE
  296. #define SMBUS_IT_TCI I2C_CR1_TCIE
  297. #define SMBUS_IT_STOPI I2C_CR1_STOPIE
  298. #define SMBUS_IT_NACKI I2C_CR1_NACKIE
  299. #define SMBUS_IT_ADDRI I2C_CR1_ADDRIE
  300. #define SMBUS_IT_RXI I2C_CR1_RXIE
  301. #define SMBUS_IT_TXI I2C_CR1_TXIE
  302. #define SMBUS_IT_TX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_TXI)
  303. #define SMBUS_IT_RX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_NACKI | SMBUS_IT_RXI)
  304. #define SMBUS_IT_ALERT (SMBUS_IT_ERRI)
  305. #define SMBUS_IT_ADDR (SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI)
  306. /**
  307. * @}
  308. */
  309. /** @defgroup SMBUS_Flag_definition SMBUS Flag definition
  310. * @brief Flag definition
  311. * Elements values convention: 0xXXXXYYYY
  312. * - XXXXXXXX : Flag mask
  313. * @{
  314. */
  315. #define SMBUS_FLAG_TXE I2C_ISR_TXE
  316. #define SMBUS_FLAG_TXIS I2C_ISR_TXIS
  317. #define SMBUS_FLAG_RXNE I2C_ISR_RXNE
  318. #define SMBUS_FLAG_ADDR I2C_ISR_ADDR
  319. #define SMBUS_FLAG_AF I2C_ISR_NACKF
  320. #define SMBUS_FLAG_STOPF I2C_ISR_STOPF
  321. #define SMBUS_FLAG_TC I2C_ISR_TC
  322. #define SMBUS_FLAG_TCR I2C_ISR_TCR
  323. #define SMBUS_FLAG_BERR I2C_ISR_BERR
  324. #define SMBUS_FLAG_ARLO I2C_ISR_ARLO
  325. #define SMBUS_FLAG_OVR I2C_ISR_OVR
  326. #define SMBUS_FLAG_PECERR I2C_ISR_PECERR
  327. #define SMBUS_FLAG_TIMEOUT I2C_ISR_TIMEOUT
  328. #define SMBUS_FLAG_ALERT I2C_ISR_ALERT
  329. #define SMBUS_FLAG_BUSY I2C_ISR_BUSY
  330. #define SMBUS_FLAG_DIR I2C_ISR_DIR
  331. /**
  332. * @}
  333. */
  334. /**
  335. * @}
  336. */
  337. /* Exported macros ------------------------------------------------------------*/
  338. /** @defgroup SMBUS_Exported_Macros SMBUS Exported Macros
  339. * @{
  340. */
  341. /** @brief Reset SMBUS handle state.
  342. * @param __HANDLE__ specifies the SMBUS Handle.
  343. * @retval None
  344. */
  345. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  346. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) do{ \
  347. (__HANDLE__)->State = HAL_SMBUS_STATE_RESET; \
  348. (__HANDLE__)->MspInitCallback = NULL; \
  349. (__HANDLE__)->MspDeInitCallback = NULL; \
  350. } while(0)
  351. #else
  352. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMBUS_STATE_RESET)
  353. #endif
  354. /** @brief Enable the specified SMBUS interrupts.
  355. * @param __HANDLE__ specifies the SMBUS Handle.
  356. * @param __INTERRUPT__ specifies the interrupt source to enable.
  357. * This parameter can be one of the following values:
  358. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  359. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  360. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  361. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  362. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  363. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  364. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  365. *
  366. * @retval None
  367. */
  368. #define __HAL_SMBUS_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
  369. /** @brief Disable the specified SMBUS interrupts.
  370. * @param __HANDLE__ specifies the SMBUS Handle.
  371. * @param __INTERRUPT__ specifies the interrupt source to disable.
  372. * This parameter can be one of the following values:
  373. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  374. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  375. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  376. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  377. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  378. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  379. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  380. *
  381. * @retval None
  382. */
  383. #define __HAL_SMBUS_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
  384. /** @brief Check whether the specified SMBUS interrupt source is enabled or not.
  385. * @param __HANDLE__ specifies the SMBUS Handle.
  386. * @param __INTERRUPT__ specifies the SMBUS interrupt source to check.
  387. * This parameter can be one of the following values:
  388. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  389. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  390. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  391. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  392. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  393. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  394. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  395. *
  396. * @retval The new state of __IT__ (SET or RESET).
  397. */
  398. #define __HAL_SMBUS_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  399. /** @brief Check whether the specified SMBUS flag is set or not.
  400. * @param __HANDLE__ specifies the SMBUS Handle.
  401. * @param __FLAG__ specifies the flag to check.
  402. * This parameter can be one of the following values:
  403. * @arg @ref SMBUS_FLAG_TXE Transmit data register empty
  404. * @arg @ref SMBUS_FLAG_TXIS Transmit interrupt status
  405. * @arg @ref SMBUS_FLAG_RXNE Receive data register not empty
  406. * @arg @ref SMBUS_FLAG_ADDR Address matched (slave mode)
  407. * @arg @ref SMBUS_FLAG_AF NACK received flag
  408. * @arg @ref SMBUS_FLAG_STOPF STOP detection flag
  409. * @arg @ref SMBUS_FLAG_TC Transfer complete (master mode)
  410. * @arg @ref SMBUS_FLAG_TCR Transfer complete reload
  411. * @arg @ref SMBUS_FLAG_BERR Bus error
  412. * @arg @ref SMBUS_FLAG_ARLO Arbitration lost
  413. * @arg @ref SMBUS_FLAG_OVR Overrun/Underrun
  414. * @arg @ref SMBUS_FLAG_PECERR PEC error in reception
  415. * @arg @ref SMBUS_FLAG_TIMEOUT Timeout or Tlow detection flag
  416. * @arg @ref SMBUS_FLAG_ALERT SMBus alert
  417. * @arg @ref SMBUS_FLAG_BUSY Bus busy
  418. * @arg @ref SMBUS_FLAG_DIR Transfer direction (slave mode)
  419. *
  420. * @retval The new state of __FLAG__ (SET or RESET).
  421. */
  422. #define SMBUS_FLAG_MASK (0x0001FFFFU)
  423. #define __HAL_SMBUS_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
  424. /** @brief Clear the SMBUS pending flags which are cleared by writing 1 in a specific bit.
  425. * @param __HANDLE__ specifies the SMBUS Handle.
  426. * @param __FLAG__ specifies the flag to clear.
  427. * This parameter can be any combination of the following values:
  428. * @arg @ref SMBUS_FLAG_ADDR Address matched (slave mode)
  429. * @arg @ref SMBUS_FLAG_AF NACK received flag
  430. * @arg @ref SMBUS_FLAG_STOPF STOP detection flag
  431. * @arg @ref SMBUS_FLAG_BERR Bus error
  432. * @arg @ref SMBUS_FLAG_ARLO Arbitration lost
  433. * @arg @ref SMBUS_FLAG_OVR Overrun/Underrun
  434. * @arg @ref SMBUS_FLAG_PECERR PEC error in reception
  435. * @arg @ref SMBUS_FLAG_TIMEOUT Timeout or Tlow detection flag
  436. * @arg @ref SMBUS_FLAG_ALERT SMBus alert
  437. *
  438. * @retval None
  439. */
  440. #define __HAL_SMBUS_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  441. /** @brief Enable the specified SMBUS peripheral.
  442. * @param __HANDLE__ specifies the SMBUS Handle.
  443. * @retval None
  444. */
  445. #define __HAL_SMBUS_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  446. /** @brief Disable the specified SMBUS peripheral.
  447. * @param __HANDLE__ specifies the SMBUS Handle.
  448. * @retval None
  449. */
  450. #define __HAL_SMBUS_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  451. /** @brief Generate a Non-Acknowledge SMBUS peripheral in Slave mode.
  452. * @param __HANDLE__ specifies the SMBUS Handle.
  453. * @retval None
  454. */
  455. #define __HAL_SMBUS_GENERATE_NACK(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR2, I2C_CR2_NACK))
  456. /**
  457. * @}
  458. */
  459. /* Private constants ---------------------------------------------------------*/
  460. /* Private macros ------------------------------------------------------------*/
  461. /** @defgroup SMBUS_Private_Macro SMBUS Private Macros
  462. * @{
  463. */
  464. #define IS_SMBUS_ANALOG_FILTER(FILTER) (((FILTER) == SMBUS_ANALOGFILTER_ENABLE) || \
  465. ((FILTER) == SMBUS_ANALOGFILTER_DISABLE))
  466. #define IS_SMBUS_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
  467. #define IS_SMBUS_ADDRESSING_MODE(MODE) (((MODE) == SMBUS_ADDRESSINGMODE_7BIT) || \
  468. ((MODE) == SMBUS_ADDRESSINGMODE_10BIT))
  469. #define IS_SMBUS_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == SMBUS_DUALADDRESS_DISABLE) || \
  470. ((ADDRESS) == SMBUS_DUALADDRESS_ENABLE))
  471. #define IS_SMBUS_OWN_ADDRESS2_MASK(MASK) (((MASK) == SMBUS_OA2_NOMASK) || \
  472. ((MASK) == SMBUS_OA2_MASK01) || \
  473. ((MASK) == SMBUS_OA2_MASK02) || \
  474. ((MASK) == SMBUS_OA2_MASK03) || \
  475. ((MASK) == SMBUS_OA2_MASK04) || \
  476. ((MASK) == SMBUS_OA2_MASK05) || \
  477. ((MASK) == SMBUS_OA2_MASK06) || \
  478. ((MASK) == SMBUS_OA2_MASK07))
  479. #define IS_SMBUS_GENERAL_CALL(CALL) (((CALL) == SMBUS_GENERALCALL_DISABLE) || \
  480. ((CALL) == SMBUS_GENERALCALL_ENABLE))
  481. #define IS_SMBUS_NO_STRETCH(STRETCH) (((STRETCH) == SMBUS_NOSTRETCH_DISABLE) || \
  482. ((STRETCH) == SMBUS_NOSTRETCH_ENABLE))
  483. #define IS_SMBUS_PEC(PEC) (((PEC) == SMBUS_PEC_DISABLE) || \
  484. ((PEC) == SMBUS_PEC_ENABLE))
  485. #define IS_SMBUS_PERIPHERAL_MODE(MODE) (((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_HOST) || \
  486. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || \
  487. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP))
  488. #define IS_SMBUS_TRANSFER_MODE(MODE) (((MODE) == SMBUS_RELOAD_MODE) || \
  489. ((MODE) == SMBUS_AUTOEND_MODE) || \
  490. ((MODE) == SMBUS_SOFTEND_MODE) || \
  491. ((MODE) == SMBUS_SENDPEC_MODE) || \
  492. ((MODE) == (SMBUS_RELOAD_MODE | SMBUS_SENDPEC_MODE)) || \
  493. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE)) || \
  494. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_RELOAD_MODE)) || \
  495. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE | SMBUS_RELOAD_MODE )))
  496. #define IS_SMBUS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == SMBUS_GENERATE_STOP) || \
  497. ((REQUEST) == SMBUS_GENERATE_START_READ) || \
  498. ((REQUEST) == SMBUS_GENERATE_START_WRITE) || \
  499. ((REQUEST) == SMBUS_NO_STARTSTOP))
  500. #define IS_SMBUS_TRANSFER_OPTIONS_REQUEST(REQUEST) (IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) || \
  501. ((REQUEST) == SMBUS_FIRST_FRAME) || \
  502. ((REQUEST) == SMBUS_NEXT_FRAME) || \
  503. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || \
  504. ((REQUEST) == SMBUS_LAST_FRAME_NO_PEC) || \
  505. ((REQUEST) == SMBUS_FIRST_FRAME_WITH_PEC) || \
  506. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC) || \
  507. ((REQUEST) == SMBUS_LAST_FRAME_WITH_PEC))
  508. #define IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == SMBUS_OTHER_FRAME_NO_PEC) || \
  509. ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_NO_PEC) || \
  510. ((REQUEST) == SMBUS_OTHER_FRAME_WITH_PEC) || \
  511. ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC))
  512. #define SMBUS_RESET_CR1(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (uint32_t)~((uint32_t)(I2C_CR1_SMBHEN | I2C_CR1_SMBDEN | I2C_CR1_PECEN)))
  513. #define SMBUS_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)))
  514. #define SMBUS_GENERATE_START(__ADDMODE__,__ADDRESS__) (((__ADDMODE__) == SMBUS_ADDRESSINGMODE_7BIT) ? (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_START) | (I2C_CR2_AUTOEND)) & (~I2C_CR2_RD_WRN)) : \
  515. (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
  516. #define SMBUS_GET_ADDR_MATCH(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_ADDCODE) >> 17U)
  517. #define SMBUS_GET_DIR(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_DIR) >> 16U)
  518. #define SMBUS_GET_STOP_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_AUTOEND)
  519. #define SMBUS_GET_PEC_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_PECBYTE)
  520. #define SMBUS_GET_ALERT_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR1 & I2C_CR1_ALERTEN)
  521. #define SMBUS_CHECK_FLAG(__ISR__, __FLAG__) ((((__ISR__) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
  522. #define SMBUS_CHECK_IT_SOURCE(__CR1__, __IT__) ((((__CR1__) & (__IT__)) == (__IT__)) ? SET : RESET)
  523. #define IS_SMBUS_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x000003FFU)
  524. #define IS_SMBUS_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FFU)
  525. /**
  526. * @}
  527. */
  528. /* Exported functions --------------------------------------------------------*/
  529. /** @addtogroup SMBUS_Exported_Functions SMBUS Exported Functions
  530. * @{
  531. */
  532. /** @addtogroup SMBUS_Exported_Functions_Group1 Initialization and de-initialization functions
  533. * @{
  534. */
  535. /* Initialization and de-initialization functions ****************************/
  536. HAL_StatusTypeDef HAL_SMBUS_Init(SMBUS_HandleTypeDef *hsmbus);
  537. HAL_StatusTypeDef HAL_SMBUS_DeInit(SMBUS_HandleTypeDef *hsmbus);
  538. void HAL_SMBUS_MspInit(SMBUS_HandleTypeDef *hsmbus);
  539. void HAL_SMBUS_MspDeInit(SMBUS_HandleTypeDef *hsmbus);
  540. HAL_StatusTypeDef HAL_SMBUS_ConfigAnalogFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t AnalogFilter);
  541. HAL_StatusTypeDef HAL_SMBUS_ConfigDigitalFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t DigitalFilter);
  542. /* Callbacks Register/UnRegister functions ***********************************/
  543. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  544. HAL_StatusTypeDef HAL_SMBUS_RegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID, pSMBUS_CallbackTypeDef pCallback);
  545. HAL_StatusTypeDef HAL_SMBUS_UnRegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID);
  546. HAL_StatusTypeDef HAL_SMBUS_RegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus, pSMBUS_AddrCallbackTypeDef pCallback);
  547. HAL_StatusTypeDef HAL_SMBUS_UnRegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus);
  548. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  549. /**
  550. * @}
  551. */
  552. /** @addtogroup SMBUS_Exported_Functions_Group2 Input and Output operation functions
  553. * @{
  554. */
  555. /* IO operation functions *****************************************************/
  556. /** @addtogroup Blocking_mode_Polling Blocking mode Polling
  557. * @{
  558. */
  559. /******* Blocking mode: Polling */
  560. HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
  561. /**
  562. * @}
  563. */
  564. /** @addtogroup Non-Blocking_mode_Interrupt Non-Blocking mode Interrupt
  565. * @{
  566. */
  567. /******* Non-Blocking mode: Interrupt */
  568. HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  569. HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  570. HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress);
  571. HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  572. HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  573. HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  574. HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  575. HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  576. HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  577. /**
  578. * @}
  579. */
  580. /** @addtogroup SMBUS_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
  581. * @{
  582. */
  583. /******* SMBUS IRQHandler and Callbacks used in non blocking modes (Interrupt) */
  584. void HAL_SMBUS_EV_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  585. void HAL_SMBUS_ER_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  586. void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  587. void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  588. void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  589. void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  590. void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
  591. void HAL_SMBUS_ListenCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  592. void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus);
  593. /**
  594. * @}
  595. */
  596. /** @addtogroup SMBUS_Exported_Functions_Group3 Peripheral State and Errors functions
  597. * @{
  598. */
  599. /* Peripheral State and Errors functions **************************************************/
  600. uint32_t HAL_SMBUS_GetState(SMBUS_HandleTypeDef *hsmbus);
  601. uint32_t HAL_SMBUS_GetError(SMBUS_HandleTypeDef *hsmbus);
  602. /**
  603. * @}
  604. */
  605. /**
  606. * @}
  607. */
  608. /* Private Functions ---------------------------------------------------------*/
  609. /** @defgroup SMBUS_Private_Functions SMBUS Private Functions
  610. * @{
  611. */
  612. /* Private functions are defined in stm32wbxx_hal_smbus.c file */
  613. /**
  614. * @}
  615. */
  616. /**
  617. * @}
  618. */
  619. /**
  620. * @}
  621. */
  622. /**
  623. * @}
  624. */
  625. #ifdef __cplusplus
  626. }
  627. #endif
  628. #endif /* STM32WBxx_HAL_SMBUS_H */
  629. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/