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.
 
 
 

744 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 acknoledge 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. typedef struct __SMBUS_HandleTypeDef
  116. {
  117. I2C_TypeDef *Instance; /*!< SMBUS registers base address */
  118. SMBUS_InitTypeDef Init; /*!< SMBUS communication parameters */
  119. uint8_t *pBuffPtr; /*!< Pointer to SMBUS transfer buffer */
  120. uint16_t XferSize; /*!< SMBUS transfer size */
  121. __IO uint16_t XferCount; /*!< SMBUS transfer counter */
  122. __IO uint32_t XferOptions; /*!< SMBUS transfer options */
  123. __IO uint32_t PreviousState; /*!< SMBUS communication Previous state */
  124. HAL_LockTypeDef Lock; /*!< SMBUS locking object */
  125. __IO uint32_t State; /*!< SMBUS communication state */
  126. __IO uint32_t ErrorCode; /*!< SMBUS Error code */
  127. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  128. void (* MasterTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Tx Transfer completed callback */
  129. void (* MasterRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Rx Transfer completed callback */
  130. void (* SlaveTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Tx Transfer completed callback */
  131. void (* SlaveRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Rx Transfer completed callback */
  132. void (* ListenCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Listen Complete callback */
  133. void (* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Error callback */
  134. void (* AddrCallback)(struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< SMBUS Slave Address Match callback */
  135. void (* MspInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp Init callback */
  136. void (* MspDeInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp DeInit callback */
  137. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  138. } SMBUS_HandleTypeDef;
  139. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  140. /**
  141. * @brief HAL SMBUS Callback ID enumeration definition
  142. */
  143. typedef enum
  144. {
  145. HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID = 0x00U, /*!< SMBUS Master Tx Transfer completed callback ID */
  146. HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID = 0x01U, /*!< SMBUS Master Rx Transfer completed callback ID */
  147. HAL_SMBUS_SLAVE_TX_COMPLETE_CB_ID = 0x02U, /*!< SMBUS Slave Tx Transfer completed callback ID */
  148. HAL_SMBUS_SLAVE_RX_COMPLETE_CB_ID = 0x03U, /*!< SMBUS Slave Rx Transfer completed callback ID */
  149. HAL_SMBUS_LISTEN_COMPLETE_CB_ID = 0x04U, /*!< SMBUS Listen Complete callback ID */
  150. HAL_SMBUS_ERROR_CB_ID = 0x05U, /*!< SMBUS Error callback ID */
  151. HAL_SMBUS_MSPINIT_CB_ID = 0x06U, /*!< SMBUS Msp Init callback ID */
  152. HAL_SMBUS_MSPDEINIT_CB_ID = 0x07U /*!< SMBUS Msp DeInit callback ID */
  153. } HAL_SMBUS_CallbackIDTypeDef;
  154. /**
  155. * @brief HAL SMBUS Callback pointer definition
  156. */
  157. typedef void (*pSMBUS_CallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus); /*!< pointer to an SMBUS callback function */
  158. typedef void (*pSMBUS_AddrCallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< pointer to an SMBUS Address Match callback function */
  159. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */
  166. /* Exported constants --------------------------------------------------------*/
  167. /** @defgroup SMBUS_Exported_Constants SMBUS Exported Constants
  168. * @{
  169. */
  170. /** @defgroup SMBUS_Analog_Filter SMBUS Analog Filter
  171. * @{
  172. */
  173. #define SMBUS_ANALOGFILTER_ENABLE (0x00000000U)
  174. #define SMBUS_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF
  175. /**
  176. * @}
  177. */
  178. /** @defgroup SMBUS_addressing_mode SMBUS addressing mode
  179. * @{
  180. */
  181. #define SMBUS_ADDRESSINGMODE_7BIT (0x00000001U)
  182. #define SMBUS_ADDRESSINGMODE_10BIT (0x00000002U)
  183. /**
  184. * @}
  185. */
  186. /** @defgroup SMBUS_dual_addressing_mode SMBUS dual addressing mode
  187. * @{
  188. */
  189. #define SMBUS_DUALADDRESS_DISABLE (0x00000000U)
  190. #define SMBUS_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
  191. /**
  192. * @}
  193. */
  194. /** @defgroup SMBUS_own_address2_masks SMBUS ownaddress2 masks
  195. * @{
  196. */
  197. #define SMBUS_OA2_NOMASK ((uint8_t)0x00U)
  198. #define SMBUS_OA2_MASK01 ((uint8_t)0x01U)
  199. #define SMBUS_OA2_MASK02 ((uint8_t)0x02U)
  200. #define SMBUS_OA2_MASK03 ((uint8_t)0x03U)
  201. #define SMBUS_OA2_MASK04 ((uint8_t)0x04U)
  202. #define SMBUS_OA2_MASK05 ((uint8_t)0x05U)
  203. #define SMBUS_OA2_MASK06 ((uint8_t)0x06U)
  204. #define SMBUS_OA2_MASK07 ((uint8_t)0x07U)
  205. /**
  206. * @}
  207. */
  208. /** @defgroup SMBUS_general_call_addressing_mode SMBUS general call addressing mode
  209. * @{
  210. */
  211. #define SMBUS_GENERALCALL_DISABLE (0x00000000U)
  212. #define SMBUS_GENERALCALL_ENABLE I2C_CR1_GCEN
  213. /**
  214. * @}
  215. */
  216. /** @defgroup SMBUS_nostretch_mode SMBUS nostretch mode
  217. * @{
  218. */
  219. #define SMBUS_NOSTRETCH_DISABLE (0x00000000U)
  220. #define SMBUS_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
  221. /**
  222. * @}
  223. */
  224. /** @defgroup SMBUS_packet_error_check_mode SMBUS packet error check mode
  225. * @{
  226. */
  227. #define SMBUS_PEC_DISABLE (0x00000000U)
  228. #define SMBUS_PEC_ENABLE I2C_CR1_PECEN
  229. /**
  230. * @}
  231. */
  232. /** @defgroup SMBUS_peripheral_mode SMBUS peripheral mode
  233. * @{
  234. */
  235. #define SMBUS_PERIPHERAL_MODE_SMBUS_HOST I2C_CR1_SMBHEN
  236. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE (0x00000000U)
  237. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP I2C_CR1_SMBDEN
  238. /**
  239. * @}
  240. */
  241. /** @defgroup SMBUS_ReloadEndMode_definition SMBUS ReloadEndMode definition
  242. * @{
  243. */
  244. #define SMBUS_SOFTEND_MODE (0x00000000U)
  245. #define SMBUS_RELOAD_MODE I2C_CR2_RELOAD
  246. #define SMBUS_AUTOEND_MODE I2C_CR2_AUTOEND
  247. #define SMBUS_SENDPEC_MODE I2C_CR2_PECBYTE
  248. /**
  249. * @}
  250. */
  251. /** @defgroup SMBUS_StartStopMode_definition SMBUS StartStopMode definition
  252. * @{
  253. */
  254. #define SMBUS_NO_STARTSTOP (0x00000000U)
  255. #define SMBUS_GENERATE_STOP (uint32_t)(0x80000000U | I2C_CR2_STOP)
  256. #define SMBUS_GENERATE_START_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN)
  257. #define SMBUS_GENERATE_START_WRITE (uint32_t)(0x80000000U | I2C_CR2_START)
  258. /**
  259. * @}
  260. */
  261. /** @defgroup SMBUS_XferOptions_definition SMBUS XferOptions definition
  262. * @{
  263. */
  264. /* List of XferOptions in usage of :
  265. * 1- Restart condition when direction change
  266. * 2- No Restart condition in other use cases
  267. */
  268. #define SMBUS_FIRST_FRAME SMBUS_SOFTEND_MODE
  269. #define SMBUS_NEXT_FRAME ((uint32_t)(SMBUS_RELOAD_MODE | SMBUS_SOFTEND_MODE))
  270. #define SMBUS_FIRST_AND_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
  271. #define SMBUS_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
  272. #define SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
  273. #define SMBUS_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
  274. /* List of XferOptions in usage of :
  275. * 1- Restart condition in all use cases (direction change or not)
  276. */
  277. #define SMBUS_OTHER_FRAME_NO_PEC (0x000000AAU)
  278. #define SMBUS_OTHER_FRAME_WITH_PEC (0x0000AA00U)
  279. #define SMBUS_OTHER_AND_LAST_FRAME_NO_PEC (0x00AA0000U)
  280. #define SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC (0xAA000000U)
  281. /**
  282. * @}
  283. */
  284. /** @defgroup SMBUS_Interrupt_configuration_definition SMBUS Interrupt configuration definition
  285. * @brief SMBUS Interrupt definition
  286. * Elements values convention: 0xXXXXXXXX
  287. * - XXXXXXXX : Interrupt control mask
  288. * @{
  289. */
  290. #define SMBUS_IT_ERRI I2C_CR1_ERRIE
  291. #define SMBUS_IT_TCI I2C_CR1_TCIE
  292. #define SMBUS_IT_STOPI I2C_CR1_STOPIE
  293. #define SMBUS_IT_NACKI I2C_CR1_NACKIE
  294. #define SMBUS_IT_ADDRI I2C_CR1_ADDRIE
  295. #define SMBUS_IT_RXI I2C_CR1_RXIE
  296. #define SMBUS_IT_TXI I2C_CR1_TXIE
  297. #define SMBUS_IT_TX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_TXI)
  298. #define SMBUS_IT_RX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_NACKI | SMBUS_IT_RXI)
  299. #define SMBUS_IT_ALERT (SMBUS_IT_ERRI)
  300. #define SMBUS_IT_ADDR (SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI)
  301. /**
  302. * @}
  303. */
  304. /** @defgroup SMBUS_Flag_definition SMBUS Flag definition
  305. * @brief Flag definition
  306. * Elements values convention: 0xXXXXYYYY
  307. * - XXXXXXXX : Flag mask
  308. * @{
  309. */
  310. #define SMBUS_FLAG_TXE I2C_ISR_TXE
  311. #define SMBUS_FLAG_TXIS I2C_ISR_TXIS
  312. #define SMBUS_FLAG_RXNE I2C_ISR_RXNE
  313. #define SMBUS_FLAG_ADDR I2C_ISR_ADDR
  314. #define SMBUS_FLAG_AF I2C_ISR_NACKF
  315. #define SMBUS_FLAG_STOPF I2C_ISR_STOPF
  316. #define SMBUS_FLAG_TC I2C_ISR_TC
  317. #define SMBUS_FLAG_TCR I2C_ISR_TCR
  318. #define SMBUS_FLAG_BERR I2C_ISR_BERR
  319. #define SMBUS_FLAG_ARLO I2C_ISR_ARLO
  320. #define SMBUS_FLAG_OVR I2C_ISR_OVR
  321. #define SMBUS_FLAG_PECERR I2C_ISR_PECERR
  322. #define SMBUS_FLAG_TIMEOUT I2C_ISR_TIMEOUT
  323. #define SMBUS_FLAG_ALERT I2C_ISR_ALERT
  324. #define SMBUS_FLAG_BUSY I2C_ISR_BUSY
  325. #define SMBUS_FLAG_DIR I2C_ISR_DIR
  326. /**
  327. * @}
  328. */
  329. /**
  330. * @}
  331. */
  332. /* Exported macros ------------------------------------------------------------*/
  333. /** @defgroup SMBUS_Exported_Macros SMBUS Exported Macros
  334. * @{
  335. */
  336. /** @brief Reset SMBUS handle state.
  337. * @param __HANDLE__ specifies the SMBUS Handle.
  338. * @retval None
  339. */
  340. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  341. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) do{ \
  342. (__HANDLE__)->State = HAL_SMBUS_STATE_RESET; \
  343. (__HANDLE__)->MspInitCallback = NULL; \
  344. (__HANDLE__)->MspDeInitCallback = NULL; \
  345. } while(0)
  346. #else
  347. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMBUS_STATE_RESET)
  348. #endif
  349. /** @brief Enable the specified SMBUS interrupts.
  350. * @param __HANDLE__ specifies the SMBUS Handle.
  351. * @param __INTERRUPT__ specifies the interrupt source to enable.
  352. * This parameter can be one of the following values:
  353. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  354. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  355. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  356. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  357. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  358. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  359. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  360. *
  361. * @retval None
  362. */
  363. #define __HAL_SMBUS_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
  364. /** @brief Disable the specified SMBUS interrupts.
  365. * @param __HANDLE__ specifies the SMBUS Handle.
  366. * @param __INTERRUPT__ specifies the interrupt source to disable.
  367. * This parameter can be one of the following values:
  368. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  369. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  370. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  371. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  372. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  373. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  374. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  375. *
  376. * @retval None
  377. */
  378. #define __HAL_SMBUS_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
  379. /** @brief Check whether the specified SMBUS interrupt source is enabled or not.
  380. * @param __HANDLE__ specifies the SMBUS Handle.
  381. * @param __INTERRUPT__ specifies the SMBUS interrupt source to check.
  382. * This parameter can be one of the following values:
  383. * @arg @ref SMBUS_IT_ERRI Errors interrupt enable
  384. * @arg @ref SMBUS_IT_TCI Transfer complete interrupt enable
  385. * @arg @ref SMBUS_IT_STOPI STOP detection interrupt enable
  386. * @arg @ref SMBUS_IT_NACKI NACK received interrupt enable
  387. * @arg @ref SMBUS_IT_ADDRI Address match interrupt enable
  388. * @arg @ref SMBUS_IT_RXI RX interrupt enable
  389. * @arg @ref SMBUS_IT_TXI TX interrupt enable
  390. *
  391. * @retval The new state of __IT__ (SET or RESET).
  392. */
  393. #define __HAL_SMBUS_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  394. /** @brief Check whether the specified SMBUS flag is set or not.
  395. * @param __HANDLE__ specifies the SMBUS Handle.
  396. * @param __FLAG__ specifies the flag to check.
  397. * This parameter can be one of the following values:
  398. * @arg @ref SMBUS_FLAG_TXE Transmit data register empty
  399. * @arg @ref SMBUS_FLAG_TXIS Transmit interrupt status
  400. * @arg @ref SMBUS_FLAG_RXNE Receive data register not empty
  401. * @arg @ref SMBUS_FLAG_ADDR Address matched (slave mode)
  402. * @arg @ref SMBUS_FLAG_AF NACK received flag
  403. * @arg @ref SMBUS_FLAG_STOPF STOP detection flag
  404. * @arg @ref SMBUS_FLAG_TC Transfer complete (master mode)
  405. * @arg @ref SMBUS_FLAG_TCR Transfer complete reload
  406. * @arg @ref SMBUS_FLAG_BERR Bus error
  407. * @arg @ref SMBUS_FLAG_ARLO Arbitration lost
  408. * @arg @ref SMBUS_FLAG_OVR Overrun/Underrun
  409. * @arg @ref SMBUS_FLAG_PECERR PEC error in reception
  410. * @arg @ref SMBUS_FLAG_TIMEOUT Timeout or Tlow detection flag
  411. * @arg @ref SMBUS_FLAG_ALERT SMBus alert
  412. * @arg @ref SMBUS_FLAG_BUSY Bus busy
  413. * @arg @ref SMBUS_FLAG_DIR Transfer direction (slave mode)
  414. *
  415. * @retval The new state of __FLAG__ (SET or RESET).
  416. */
  417. #define SMBUS_FLAG_MASK (0x0001FFFFU)
  418. #define __HAL_SMBUS_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
  419. /** @brief Clear the SMBUS pending flags which are cleared by writing 1 in a specific bit.
  420. * @param __HANDLE__ specifies the SMBUS Handle.
  421. * @param __FLAG__ specifies the flag to clear.
  422. * This parameter can be any combination of the following values:
  423. * @arg @ref SMBUS_FLAG_ADDR Address matched (slave mode)
  424. * @arg @ref SMBUS_FLAG_AF NACK received flag
  425. * @arg @ref SMBUS_FLAG_STOPF STOP detection flag
  426. * @arg @ref SMBUS_FLAG_BERR Bus error
  427. * @arg @ref SMBUS_FLAG_ARLO Arbitration lost
  428. * @arg @ref SMBUS_FLAG_OVR Overrun/Underrun
  429. * @arg @ref SMBUS_FLAG_PECERR PEC error in reception
  430. * @arg @ref SMBUS_FLAG_TIMEOUT Timeout or Tlow detection flag
  431. * @arg @ref SMBUS_FLAG_ALERT SMBus alert
  432. *
  433. * @retval None
  434. */
  435. #define __HAL_SMBUS_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  436. /** @brief Enable the specified SMBUS peripheral.
  437. * @param __HANDLE__ specifies the SMBUS Handle.
  438. * @retval None
  439. */
  440. #define __HAL_SMBUS_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  441. /** @brief Disable the specified SMBUS peripheral.
  442. * @param __HANDLE__ specifies the SMBUS Handle.
  443. * @retval None
  444. */
  445. #define __HAL_SMBUS_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
  446. /** @brief Generate a Non-Acknowledge SMBUS peripheral in Slave mode.
  447. * @param __HANDLE__ specifies the SMBUS Handle.
  448. * @retval None
  449. */
  450. #define __HAL_SMBUS_GENERATE_NACK(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR2, I2C_CR2_NACK))
  451. /**
  452. * @}
  453. */
  454. /* Private constants ---------------------------------------------------------*/
  455. /* Private macros ------------------------------------------------------------*/
  456. /** @defgroup SMBUS_Private_Macro SMBUS Private Macros
  457. * @{
  458. */
  459. #define IS_SMBUS_ANALOG_FILTER(FILTER) (((FILTER) == SMBUS_ANALOGFILTER_ENABLE) || \
  460. ((FILTER) == SMBUS_ANALOGFILTER_DISABLE))
  461. #define IS_SMBUS_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
  462. #define IS_SMBUS_ADDRESSING_MODE(MODE) (((MODE) == SMBUS_ADDRESSINGMODE_7BIT) || \
  463. ((MODE) == SMBUS_ADDRESSINGMODE_10BIT))
  464. #define IS_SMBUS_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == SMBUS_DUALADDRESS_DISABLE) || \
  465. ((ADDRESS) == SMBUS_DUALADDRESS_ENABLE))
  466. #define IS_SMBUS_OWN_ADDRESS2_MASK(MASK) (((MASK) == SMBUS_OA2_NOMASK) || \
  467. ((MASK) == SMBUS_OA2_MASK01) || \
  468. ((MASK) == SMBUS_OA2_MASK02) || \
  469. ((MASK) == SMBUS_OA2_MASK03) || \
  470. ((MASK) == SMBUS_OA2_MASK04) || \
  471. ((MASK) == SMBUS_OA2_MASK05) || \
  472. ((MASK) == SMBUS_OA2_MASK06) || \
  473. ((MASK) == SMBUS_OA2_MASK07))
  474. #define IS_SMBUS_GENERAL_CALL(CALL) (((CALL) == SMBUS_GENERALCALL_DISABLE) || \
  475. ((CALL) == SMBUS_GENERALCALL_ENABLE))
  476. #define IS_SMBUS_NO_STRETCH(STRETCH) (((STRETCH) == SMBUS_NOSTRETCH_DISABLE) || \
  477. ((STRETCH) == SMBUS_NOSTRETCH_ENABLE))
  478. #define IS_SMBUS_PEC(PEC) (((PEC) == SMBUS_PEC_DISABLE) || \
  479. ((PEC) == SMBUS_PEC_ENABLE))
  480. #define IS_SMBUS_PERIPHERAL_MODE(MODE) (((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_HOST) || \
  481. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || \
  482. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP))
  483. #define IS_SMBUS_TRANSFER_MODE(MODE) (((MODE) == SMBUS_RELOAD_MODE) || \
  484. ((MODE) == SMBUS_AUTOEND_MODE) || \
  485. ((MODE) == SMBUS_SOFTEND_MODE) || \
  486. ((MODE) == SMBUS_SENDPEC_MODE) || \
  487. ((MODE) == (SMBUS_RELOAD_MODE | SMBUS_SENDPEC_MODE)) || \
  488. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE)) || \
  489. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_RELOAD_MODE)) || \
  490. ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE | SMBUS_RELOAD_MODE )))
  491. #define IS_SMBUS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == SMBUS_GENERATE_STOP) || \
  492. ((REQUEST) == SMBUS_GENERATE_START_READ) || \
  493. ((REQUEST) == SMBUS_GENERATE_START_WRITE) || \
  494. ((REQUEST) == SMBUS_NO_STARTSTOP))
  495. #define IS_SMBUS_TRANSFER_OPTIONS_REQUEST(REQUEST) (IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) || \
  496. ((REQUEST) == SMBUS_FIRST_FRAME) || \
  497. ((REQUEST) == SMBUS_NEXT_FRAME) || \
  498. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || \
  499. ((REQUEST) == SMBUS_LAST_FRAME_NO_PEC) || \
  500. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC) || \
  501. ((REQUEST) == SMBUS_LAST_FRAME_WITH_PEC))
  502. #define IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == SMBUS_OTHER_FRAME_NO_PEC) || \
  503. ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_NO_PEC) || \
  504. ((REQUEST) == SMBUS_OTHER_FRAME_WITH_PEC) || \
  505. ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC))
  506. #define SMBUS_RESET_CR1(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (uint32_t)~((uint32_t)(I2C_CR1_SMBHEN | I2C_CR1_SMBDEN | I2C_CR1_PECEN)))
  507. #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)))
  508. #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)) : \
  509. (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
  510. #define SMBUS_GET_ADDR_MATCH(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_ADDCODE) >> 17U)
  511. #define SMBUS_GET_DIR(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_DIR) >> 16U)
  512. #define SMBUS_GET_STOP_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_AUTOEND)
  513. #define SMBUS_GET_PEC_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_PECBYTE)
  514. #define SMBUS_GET_ALERT_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR1 & I2C_CR1_ALERTEN)
  515. #define SMBUS_CHECK_FLAG(__ISR__, __FLAG__) ((((__ISR__) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
  516. #define SMBUS_CHECK_IT_SOURCE(__CR1__, __IT__) ((((__CR1__) & (__IT__)) == (__IT__)) ? SET : RESET)
  517. #define IS_SMBUS_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x000003FFU)
  518. #define IS_SMBUS_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FFU)
  519. /**
  520. * @}
  521. */
  522. /* Exported functions --------------------------------------------------------*/
  523. /** @addtogroup SMBUS_Exported_Functions SMBUS Exported Functions
  524. * @{
  525. */
  526. /** @addtogroup SMBUS_Exported_Functions_Group1 Initialization and de-initialization functions
  527. * @{
  528. */
  529. /* Initialization and de-initialization functions ****************************/
  530. HAL_StatusTypeDef HAL_SMBUS_Init(SMBUS_HandleTypeDef *hsmbus);
  531. HAL_StatusTypeDef HAL_SMBUS_DeInit(SMBUS_HandleTypeDef *hsmbus);
  532. void HAL_SMBUS_MspInit(SMBUS_HandleTypeDef *hsmbus);
  533. void HAL_SMBUS_MspDeInit(SMBUS_HandleTypeDef *hsmbus);
  534. HAL_StatusTypeDef HAL_SMBUS_ConfigAnalogFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t AnalogFilter);
  535. HAL_StatusTypeDef HAL_SMBUS_ConfigDigitalFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t DigitalFilter);
  536. /* Callbacks Register/UnRegister functions ***********************************/
  537. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  538. HAL_StatusTypeDef HAL_SMBUS_RegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID, pSMBUS_CallbackTypeDef pCallback);
  539. HAL_StatusTypeDef HAL_SMBUS_UnRegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID);
  540. HAL_StatusTypeDef HAL_SMBUS_RegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus, pSMBUS_AddrCallbackTypeDef pCallback);
  541. HAL_StatusTypeDef HAL_SMBUS_UnRegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus);
  542. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  543. /**
  544. * @}
  545. */
  546. /** @addtogroup SMBUS_Exported_Functions_Group2 Input and Output operation functions
  547. * @{
  548. */
  549. /* IO operation functions *****************************************************/
  550. /** @addtogroup Blocking_mode_Polling Blocking mode Polling
  551. * @{
  552. */
  553. /******* Blocking mode: Polling */
  554. HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
  555. /**
  556. * @}
  557. */
  558. /** @addtogroup Non-Blocking_mode_Interrupt Non-Blocking mode Interrupt
  559. * @{
  560. */
  561. /******* Non-Blocking mode: Interrupt */
  562. HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  563. HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  564. HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress);
  565. HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  566. HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  567. HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  568. HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  569. HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  570. HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  571. /**
  572. * @}
  573. */
  574. /** @addtogroup SMBUS_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
  575. * @{
  576. */
  577. /******* SMBUS IRQHandler and Callbacks used in non blocking modes (Interrupt) */
  578. void HAL_SMBUS_EV_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  579. void HAL_SMBUS_ER_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  580. void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  581. void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  582. void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  583. void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  584. void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
  585. void HAL_SMBUS_ListenCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  586. void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus);
  587. /**
  588. * @}
  589. */
  590. /** @addtogroup SMBUS_Exported_Functions_Group3 Peripheral State and Errors functions
  591. * @{
  592. */
  593. /* Peripheral State and Errors functions **************************************************/
  594. uint32_t HAL_SMBUS_GetState(SMBUS_HandleTypeDef *hsmbus);
  595. uint32_t HAL_SMBUS_GetError(SMBUS_HandleTypeDef *hsmbus);
  596. /**
  597. * @}
  598. */
  599. /**
  600. * @}
  601. */
  602. /* Private Functions ---------------------------------------------------------*/
  603. /** @defgroup SMBUS_Private_Functions SMBUS Private Functions
  604. * @{
  605. */
  606. /* Private functions are defined in stm32wbxx_hal_smbus.c file */
  607. /**
  608. * @}
  609. */
  610. /**
  611. * @}
  612. */
  613. /**
  614. * @}
  615. */
  616. /**
  617. * @}
  618. */
  619. #ifdef __cplusplus
  620. }
  621. #endif
  622. #endif /* STM32WBxx_HAL_SMBUS_H */
  623. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/