stm32f0xx_hal_smbus.h 37 KB

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