stm32f4xx_hal_smbus.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_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) 2016 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 __STM32F4xx_HAL_SMBUS_H
  21. #define __STM32F4xx_HAL_SMBUS_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup SMBUS
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup SMBUS_Exported_Types SMBUS Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief SMBUS Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t ClockSpeed; /*!< Specifies the clock frequency.
  43. This parameter must be set to a value lower than 100kHz */
  44. uint32_t AnalogFilter; /*!< Specifies if Analog Filter is enable or not.
  45. This parameter can be a value of @ref SMBUS_Analog_Filter */
  46. uint32_t OwnAddress1; /*!< Specifies the first device own address.
  47. This parameter can be a 7-bit or 10-bit address. */
  48. uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
  49. This parameter can be a value of @ref SMBUS_addressing_mode */
  50. uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected.
  51. This parameter can be a value of @ref SMBUS_dual_addressing_mode */
  52. uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is
  53. selected. This parameter can be a 7-bit address. */
  54. uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected.
  55. This parameter can be a value of @ref SMBUS_general_call_addressing_mode */
  56. uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected.
  57. This parameter can be a value of @ref SMBUS_nostretch_mode */
  58. uint32_t PacketErrorCheckMode; /*!< Specifies if Packet Error Check mode is selected.
  59. This parameter can be a value of @ref SMBUS_packet_error_check_mode */
  60. uint32_t PeripheralMode; /*!< Specifies which mode of Periphal is selected.
  61. This parameter can be a value of @ref SMBUS_peripheral_mode */
  62. } SMBUS_InitTypeDef;
  63. /**
  64. * @brief HAL State structure definition
  65. * @note HAL SMBUS State value coding follow below described bitmap :
  66. * b7-b6 Error information
  67. * 00 : No Error
  68. * 01 : Abort (Abort user request on going)
  69. * 10 : Timeout
  70. * 11 : Error
  71. * b5 IP initilisation status
  72. * 0 : Reset (IP not initialized)
  73. * 1 : Init done (IP initialized and ready to use. HAL SMBUS Init function called)
  74. * b4 (not used)
  75. * x : Should be set to 0
  76. * b3
  77. * 0 : Ready or Busy (No Listen mode ongoing)
  78. * 1 : Listen (IP in Address Listen Mode)
  79. * b2 Intrinsic process state
  80. * 0 : Ready
  81. * 1 : Busy (IP busy with some configuration or internal operations)
  82. * b1 Rx state
  83. * 0 : Ready (no Rx operation ongoing)
  84. * 1 : Busy (Rx operation ongoing)
  85. * b0 Tx state
  86. * 0 : Ready (no Tx operation ongoing)
  87. * 1 : Busy (Tx operation ongoing)
  88. */
  89. typedef enum
  90. {
  91. HAL_SMBUS_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
  92. HAL_SMBUS_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use */
  93. HAL_SMBUS_STATE_BUSY = 0x24U, /*!< An internal process is ongoing */
  94. HAL_SMBUS_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing */
  95. HAL_SMBUS_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
  96. HAL_SMBUS_STATE_LISTEN = 0x28U, /*!< Address Listen Mode is ongoing */
  97. HAL_SMBUS_STATE_BUSY_TX_LISTEN = 0x29U, /*!< Address Listen Mode and Data Transmission
  98. process is ongoing */
  99. HAL_SMBUS_STATE_BUSY_RX_LISTEN = 0x2AU, /*!< Address Listen Mode and Data Reception
  100. process is ongoing */
  101. HAL_SMBUS_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */
  102. HAL_SMBUS_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
  103. HAL_SMBUS_STATE_ERROR = 0xE0U /*!< Error */
  104. } HAL_SMBUS_StateTypeDef;
  105. /**
  106. * @brief HAL Mode structure definition
  107. * @note HAL SMBUS Mode value coding follow below described bitmap :
  108. * b7 (not used)
  109. * x : Should be set to 0
  110. * b6 (not used)
  111. * x : Should be set to 0
  112. * b5
  113. * 0 : None
  114. * 1 : Slave (HAL SMBUS communication is in Slave/Device Mode)
  115. * b4
  116. * 0 : None
  117. * 1 : Master (HAL SMBUS communication is in Master/Host Mode)
  118. * b3-b2-b1-b0 (not used)
  119. * xxxx : Should be set to 0000
  120. */
  121. typedef enum
  122. {
  123. HAL_SMBUS_MODE_NONE = 0x00U, /*!< No SMBUS communication on going */
  124. HAL_SMBUS_MODE_MASTER = 0x10U, /*!< SMBUS communication is in Master Mode */
  125. HAL_SMBUS_MODE_SLAVE = 0x20U, /*!< SMBUS communication is in Slave Mode */
  126. } HAL_SMBUS_ModeTypeDef;
  127. /**
  128. * @brief SMBUS handle Structure definition
  129. */
  130. typedef struct __SMBUS_HandleTypeDef
  131. {
  132. I2C_TypeDef *Instance; /*!< SMBUS registers base address */
  133. SMBUS_InitTypeDef Init; /*!< SMBUS communication parameters */
  134. uint8_t *pBuffPtr; /*!< Pointer to SMBUS transfer buffer */
  135. uint16_t XferSize; /*!< SMBUS transfer size */
  136. __IO uint16_t XferCount; /*!< SMBUS transfer counter */
  137. __IO uint32_t XferOptions; /*!< SMBUS transfer options this parameter can
  138. be a value of @ref SMBUS_OPTIONS */
  139. __IO uint32_t PreviousState; /*!< SMBUS communication Previous state and mode
  140. context for internal usage */
  141. HAL_LockTypeDef Lock; /*!< SMBUS locking object */
  142. __IO HAL_SMBUS_StateTypeDef State; /*!< SMBUS communication state */
  143. __IO HAL_SMBUS_ModeTypeDef Mode; /*!< SMBUS communication mode */
  144. __IO uint32_t ErrorCode; /*!< SMBUS Error code */
  145. __IO uint32_t Devaddress; /*!< SMBUS Target device address */
  146. __IO uint32_t EventCount; /*!< SMBUS Event counter */
  147. uint8_t XferPEC; /*!< SMBUS PEC data in reception mode */
  148. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  149. void (* MasterTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Tx Transfer completed callback */
  150. void (* MasterRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Master Rx Transfer completed callback */
  151. void (* SlaveTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Tx Transfer completed callback */
  152. void (* SlaveRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Slave Rx Transfer completed callback */
  153. void (* ListenCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Listen Complete callback */
  154. void (* MemTxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Memory Tx Transfer completed callback */
  155. void (* MemRxCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Memory Rx Transfer completed callback */
  156. void (* ErrorCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Error callback */
  157. void (* AbortCpltCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Abort callback */
  158. void (* AddrCallback)(struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< SMBUS Slave Address Match callback */
  159. void (* MspInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp Init callback */
  160. void (* MspDeInitCallback)(struct __SMBUS_HandleTypeDef *hsmbus); /*!< SMBUS Msp DeInit callback */
  161. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  162. } SMBUS_HandleTypeDef;
  163. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  164. /**
  165. * @brief HAL SMBUS Callback ID enumeration definition
  166. */
  167. typedef enum
  168. {
  169. HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID = 0x00U, /*!< SMBUS Master Tx Transfer completed callback ID */
  170. HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID = 0x01U, /*!< SMBUS Master Rx Transfer completed callback ID */
  171. HAL_SMBUS_SLAVE_TX_COMPLETE_CB_ID = 0x02U, /*!< SMBUS Slave Tx Transfer completed callback ID */
  172. HAL_SMBUS_SLAVE_RX_COMPLETE_CB_ID = 0x03U, /*!< SMBUS Slave Rx Transfer completed callback ID */
  173. HAL_SMBUS_LISTEN_COMPLETE_CB_ID = 0x04U, /*!< SMBUS Listen Complete callback ID */
  174. HAL_SMBUS_ERROR_CB_ID = 0x07U, /*!< SMBUS Error callback ID */
  175. HAL_SMBUS_ABORT_CB_ID = 0x08U, /*!< SMBUS Abort callback ID */
  176. HAL_SMBUS_MSPINIT_CB_ID = 0x09U, /*!< SMBUS Msp Init callback ID */
  177. HAL_SMBUS_MSPDEINIT_CB_ID = 0x0AU /*!< SMBUS Msp DeInit callback ID */
  178. } HAL_SMBUS_CallbackIDTypeDef;
  179. /**
  180. * @brief HAL SMBUS Callback pointer definition
  181. */
  182. typedef void (*pSMBUS_CallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus); /*!< pointer to an I2C callback function */
  183. typedef void (*pSMBUS_AddrCallbackTypeDef)(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode); /*!< pointer to an I2C Address Match callback function */
  184. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  185. /**
  186. * @}
  187. */
  188. /* Exported constants --------------------------------------------------------*/
  189. /** @defgroup SMBUS_Exported_Constants SMBUS Exported Constants
  190. * @{
  191. */
  192. /** @defgroup SMBUS_Error_Code_definition SMBUS Error Code
  193. * @brief SMBUS Error Code
  194. * @{
  195. */
  196. #define HAL_SMBUS_ERROR_NONE 0x00000000U /*!< No error */
  197. #define HAL_SMBUS_ERROR_BERR 0x00000001U /*!< BERR error */
  198. #define HAL_SMBUS_ERROR_ARLO 0x00000002U /*!< ARLO error */
  199. #define HAL_SMBUS_ERROR_AF 0x00000004U /*!< AF error */
  200. #define HAL_SMBUS_ERROR_OVR 0x00000008U /*!< OVR error */
  201. #define HAL_SMBUS_ERROR_TIMEOUT 0x00000010U /*!< Timeout Error */
  202. #define HAL_SMBUS_ERROR_ALERT 0x00000020U /*!< Alert error */
  203. #define HAL_SMBUS_ERROR_PECERR 0x00000040U /*!< PEC error */
  204. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  205. #define HAL_SMBUS_ERROR_INVALID_CALLBACK 0x00000080U /*!< Invalid Callback error */
  206. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup SMBUS_Analog_Filter SMBUS Analog Filter
  211. * @{
  212. */
  213. #define SMBUS_ANALOGFILTER_ENABLE 0x00000000U
  214. #define SMBUS_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF
  215. /**
  216. * @}
  217. */
  218. /** @defgroup SMBUS_addressing_mode SMBUS addressing mode
  219. * @{
  220. */
  221. #define SMBUS_ADDRESSINGMODE_7BIT 0x00004000U
  222. #define SMBUS_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | 0x00004000U)
  223. /**
  224. * @}
  225. */
  226. /** @defgroup SMBUS_dual_addressing_mode SMBUS dual addressing mode
  227. * @{
  228. */
  229. #define SMBUS_DUALADDRESS_DISABLE 0x00000000U
  230. #define SMBUS_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL
  231. /**
  232. * @}
  233. */
  234. /** @defgroup SMBUS_general_call_addressing_mode SMBUS general call addressing mode
  235. * @{
  236. */
  237. #define SMBUS_GENERALCALL_DISABLE 0x00000000U
  238. #define SMBUS_GENERALCALL_ENABLE I2C_CR1_ENGC
  239. /**
  240. * @}
  241. */
  242. /** @defgroup SMBUS_nostretch_mode SMBUS nostretch mode
  243. * @{
  244. */
  245. #define SMBUS_NOSTRETCH_DISABLE 0x00000000U
  246. #define SMBUS_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
  247. /**
  248. * @}
  249. */
  250. /** @defgroup SMBUS_packet_error_check_mode SMBUS packet error check mode
  251. * @{
  252. */
  253. #define SMBUS_PEC_DISABLE 0x00000000U
  254. #define SMBUS_PEC_ENABLE I2C_CR1_ENPEC
  255. /**
  256. * @}
  257. */
  258. /** @defgroup SMBUS_peripheral_mode SMBUS peripheral mode
  259. * @{
  260. */
  261. #define SMBUS_PERIPHERAL_MODE_SMBUS_HOST (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP)
  262. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE I2C_CR1_SMBUS
  263. #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_ENARP)
  264. /**
  265. * @}
  266. */
  267. /** @defgroup SMBUS_XferDirection_definition SMBUS XferDirection definition
  268. * @{
  269. */
  270. #define SMBUS_DIRECTION_RECEIVE 0x00000000U
  271. #define SMBUS_DIRECTION_TRANSMIT 0x00000001U
  272. /**
  273. * @}
  274. */
  275. /** @defgroup SMBUS_XferOptions_definition SMBUS XferOptions definition
  276. * @{
  277. */
  278. #define SMBUS_FIRST_FRAME 0x00000001U
  279. #define SMBUS_NEXT_FRAME 0x00000002U
  280. #define SMBUS_FIRST_AND_LAST_FRAME_NO_PEC 0x00000003U
  281. #define SMBUS_LAST_FRAME_NO_PEC 0x00000004U
  282. #define SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC 0x00000005U
  283. #define SMBUS_LAST_FRAME_WITH_PEC 0x00000006U
  284. /**
  285. * @}
  286. */
  287. /** @defgroup SMBUS_Interrupt_configuration_definition SMBUS Interrupt configuration definition
  288. * @{
  289. */
  290. #define SMBUS_IT_BUF I2C_CR2_ITBUFEN
  291. #define SMBUS_IT_EVT I2C_CR2_ITEVTEN
  292. #define SMBUS_IT_ERR I2C_CR2_ITERREN
  293. /**
  294. * @}
  295. */
  296. /** @defgroup SMBUS_Flag_definition SMBUS Flag definition
  297. * @{
  298. */
  299. #define SMBUS_FLAG_SMBALERT 0x00018000U
  300. #define SMBUS_FLAG_TIMEOUT 0x00014000U
  301. #define SMBUS_FLAG_PECERR 0x00011000U
  302. #define SMBUS_FLAG_OVR 0x00010800U
  303. #define SMBUS_FLAG_AF 0x00010400U
  304. #define SMBUS_FLAG_ARLO 0x00010200U
  305. #define SMBUS_FLAG_BERR 0x00010100U
  306. #define SMBUS_FLAG_TXE 0x00010080U
  307. #define SMBUS_FLAG_RXNE 0x00010040U
  308. #define SMBUS_FLAG_STOPF 0x00010010U
  309. #define SMBUS_FLAG_ADD10 0x00010008U
  310. #define SMBUS_FLAG_BTF 0x00010004U
  311. #define SMBUS_FLAG_ADDR 0x00010002U
  312. #define SMBUS_FLAG_SB 0x00010001U
  313. #define SMBUS_FLAG_DUALF 0x00100080U
  314. #define SMBUS_FLAG_SMBHOST 0x00100040U
  315. #define SMBUS_FLAG_SMBDEFAULT 0x00100020U
  316. #define SMBUS_FLAG_GENCALL 0x00100010U
  317. #define SMBUS_FLAG_TRA 0x00100004U
  318. #define SMBUS_FLAG_BUSY 0x00100002U
  319. #define SMBUS_FLAG_MSL 0x00100001U
  320. /**
  321. * @}
  322. */
  323. /**
  324. * @}
  325. */
  326. /* Exported macro ------------------------------------------------------------*/
  327. /** @defgroup SMBUS_Exported_Macros SMBUS Exported Macros
  328. * @{
  329. */
  330. /** @brief Reset SMBUS handle state
  331. * @param __HANDLE__ specifies the SMBUS Handle.
  332. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  333. * @retval None
  334. */
  335. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  336. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) do{ \
  337. (__HANDLE__)->State = HAL_SMBUS_STATE_RESET; \
  338. (__HANDLE__)->MspInitCallback = NULL; \
  339. (__HANDLE__)->MspDeInitCallback = NULL; \
  340. } while(0)
  341. #else
  342. #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMBUS_STATE_RESET)
  343. #endif
  344. /** @brief Enable or disable the specified SMBUS interrupts.
  345. * @param __HANDLE__ specifies the SMBUS Handle.
  346. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  347. * @param __INTERRUPT__ specifies the interrupt source to enable or disable.
  348. * This parameter can be one of the following values:
  349. * @arg SMBUS_IT_BUF: Buffer interrupt enable
  350. * @arg SMBUS_IT_EVT: Event interrupt enable
  351. * @arg SMBUS_IT_ERR: Error interrupt enable
  352. * @retval None
  353. */
  354. #define __HAL_SMBUS_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
  355. #define __HAL_SMBUS_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
  356. /** @brief Checks if the specified SMBUS interrupt source is enabled or disabled.
  357. * @param __HANDLE__ specifies the SMBUS Handle.
  358. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  359. * @param __INTERRUPT__ specifies the SMBUS interrupt source to check.
  360. * This parameter can be one of the following values:
  361. * @arg SMBUS_IT_BUF: Buffer interrupt enable
  362. * @arg SMBUS_IT_EVT: Event interrupt enable
  363. * @arg SMBUS_IT_ERR: Error interrupt enable
  364. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  365. */
  366. #define __HAL_SMBUS_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  367. /** @brief Checks whether the specified SMBUS flag is set or not.
  368. * @param __HANDLE__ specifies the SMBUS Handle.
  369. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  370. * @param __FLAG__ specifies the flag to check.
  371. * This parameter can be one of the following values:
  372. * @arg SMBUS_FLAG_SMBALERT: SMBus Alert flag
  373. * @arg SMBUS_FLAG_TIMEOUT: Timeout or Tlow error flag
  374. * @arg SMBUS_FLAG_PECERR: PEC error in reception flag
  375. * @arg SMBUS_FLAG_OVR: Overrun/Underrun flag
  376. * @arg SMBUS_FLAG_AF: Acknowledge failure flag
  377. * @arg SMBUS_FLAG_ARLO: Arbitration lost flag
  378. * @arg SMBUS_FLAG_BERR: Bus error flag
  379. * @arg SMBUS_FLAG_TXE: Data register empty flag
  380. * @arg SMBUS_FLAG_RXNE: Data register not empty flag
  381. * @arg SMBUS_FLAG_STOPF: Stop detection flag
  382. * @arg SMBUS_FLAG_ADD10: 10-bit header sent flag
  383. * @arg SMBUS_FLAG_BTF: Byte transfer finished flag
  384. * @arg SMBUS_FLAG_ADDR: Address sent flag
  385. * Address matched flag
  386. * @arg SMBUS_FLAG_SB: Start bit flag
  387. * @arg SMBUS_FLAG_DUALF: Dual flag
  388. * @arg SMBUS_FLAG_SMBHOST: SMBus host header
  389. * @arg SMBUS_FLAG_SMBDEFAULT: SMBus default header
  390. * @arg SMBUS_FLAG_GENCALL: General call header flag
  391. * @arg SMBUS_FLAG_TRA: Transmitter/Receiver flag
  392. * @arg SMBUS_FLAG_BUSY: Bus busy flag
  393. * @arg SMBUS_FLAG_MSL: Master/Slave flag
  394. * @retval The new state of __FLAG__ (TRUE or FALSE).
  395. */
  396. #define __HAL_SMBUS_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)): \
  397. ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)))
  398. /** @brief Clears the SMBUS pending flags which are cleared by writing 0 in a specific bit.
  399. * @param __HANDLE__ specifies the SMBUS Handle.
  400. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  401. * @param __FLAG__ specifies the flag to clear.
  402. * This parameter can be any combination of the following values:
  403. * @arg SMBUS_FLAG_SMBALERT: SMBus Alert flag
  404. * @arg SMBUS_FLAG_TIMEOUT: Timeout or Tlow error flag
  405. * @arg SMBUS_FLAG_PECERR: PEC error in reception flag
  406. * @arg SMBUS_FLAG_OVR: Overrun/Underrun flag (Slave mode)
  407. * @arg SMBUS_FLAG_AF: Acknowledge failure flag
  408. * @arg SMBUS_FLAG_ARLO: Arbitration lost flag (Master mode)
  409. * @arg SMBUS_FLAG_BERR: Bus error flag
  410. * @retval None
  411. */
  412. #define __HAL_SMBUS_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & SMBUS_FLAG_MASK))
  413. /** @brief Clears the SMBUS ADDR pending flag.
  414. * @param __HANDLE__ specifies the SMBUS Handle.
  415. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  416. * @retval None
  417. */
  418. #define __HAL_SMBUS_CLEAR_ADDRFLAG(__HANDLE__) \
  419. do{ \
  420. __IO uint32_t tmpreg = 0x00U; \
  421. tmpreg = (__HANDLE__)->Instance->SR1; \
  422. tmpreg = (__HANDLE__)->Instance->SR2; \
  423. UNUSED(tmpreg); \
  424. } while(0)
  425. /** @brief Clears the SMBUS STOPF pending flag.
  426. * @param __HANDLE__ specifies the SMBUS Handle.
  427. * This parameter can be SMBUS where x: 1, 2, or 3 to select the SMBUS peripheral.
  428. * @retval None
  429. */
  430. #define __HAL_SMBUS_CLEAR_STOPFLAG(__HANDLE__) \
  431. do{ \
  432. __IO uint32_t tmpreg = 0x00U; \
  433. tmpreg = (__HANDLE__)->Instance->SR1; \
  434. (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \
  435. UNUSED(tmpreg); \
  436. } while(0)
  437. /** @brief Enable the SMBUS peripheral.
  438. * @param __HANDLE__ specifies the SMBUS Handle.
  439. * This parameter can be SMBUSx where x: 1 or 2 to select the SMBUS peripheral.
  440. * @retval None
  441. */
  442. #define __HAL_SMBUS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
  443. /** @brief Disable the SMBUS peripheral.
  444. * @param __HANDLE__ specifies the SMBUS Handle.
  445. * This parameter can be SMBUSx where x: 1 or 2 to select the SMBUS peripheral.
  446. * @retval None
  447. */
  448. #define __HAL_SMBUS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
  449. /** @brief Generate a Non-Acknowledge SMBUS peripheral in Slave mode.
  450. * @param __HANDLE__ specifies the SMBUS Handle.
  451. * @retval None
  452. */
  453. #define __HAL_SMBUS_GENERATE_NACK(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_ACK))
  454. /**
  455. * @}
  456. */
  457. /* Exported functions --------------------------------------------------------*/
  458. /** @addtogroup SMBUS_Exported_Functions
  459. * @{
  460. */
  461. /** @addtogroup SMBUS_Exported_Functions_Group1 Initialization and de-initialization functions
  462. * @{
  463. */
  464. /* Initialization/de-initialization functions **********************************/
  465. HAL_StatusTypeDef HAL_SMBUS_Init(SMBUS_HandleTypeDef *hsmbus);
  466. HAL_StatusTypeDef HAL_SMBUS_DeInit(SMBUS_HandleTypeDef *hsmbus);
  467. void HAL_SMBUS_MspInit(SMBUS_HandleTypeDef *hsmbus);
  468. void HAL_SMBUS_MspDeInit(SMBUS_HandleTypeDef *hsmbus);
  469. /* Callbacks Register/UnRegister functions ************************************/
  470. #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
  471. HAL_StatusTypeDef HAL_SMBUS_RegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID, pSMBUS_CallbackTypeDef pCallback);
  472. HAL_StatusTypeDef HAL_SMBUS_UnRegisterCallback(SMBUS_HandleTypeDef *hsmbus, HAL_SMBUS_CallbackIDTypeDef CallbackID);
  473. HAL_StatusTypeDef HAL_SMBUS_RegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus, pSMBUS_AddrCallbackTypeDef pCallback);
  474. HAL_StatusTypeDef HAL_SMBUS_UnRegisterAddrCallback(SMBUS_HandleTypeDef *hsmbus);
  475. #endif /* USE_HAL_SMBUS_REGISTER_CALLBACKS */
  476. /**
  477. * @}
  478. */
  479. /** @addtogroup SMBUS_Exported_Functions_Group2 Input and Output operation functions
  480. * @{
  481. */
  482. /* IO operation functions *****************************************************/
  483. /** @addtogroup Blocking_mode_Polling Blocking mode Polling
  484. * @{
  485. */
  486. /******* Blocking mode: Polling */
  487. HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
  488. /**
  489. * @}
  490. */
  491. /** @addtogroup Non-Blocking_mode_Interrupt Non-Blocking mode Interrupt
  492. * @{
  493. */
  494. /******* Non-Blocking mode: Interrupt */
  495. HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  496. HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  497. HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress);
  498. HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  499. HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
  500. HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  501. HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT(SMBUS_HandleTypeDef *hsmbus);
  502. HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  503. HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT(SMBUS_HandleTypeDef *hsmbus);
  504. /****** Filter Configuration functions */
  505. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  506. HAL_StatusTypeDef HAL_SMBUS_ConfigAnalogFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t AnalogFilter);
  507. HAL_StatusTypeDef HAL_SMBUS_ConfigDigitalFilter(SMBUS_HandleTypeDef *hsmbus, uint32_t DigitalFilter);
  508. #endif
  509. /**
  510. * @}
  511. */
  512. /** @addtogroup SMBUS_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
  513. * @{
  514. */
  515. /******* SMBUS IRQHandler and Callbacks used in non blocking modes (Interrupt) */
  516. void HAL_SMBUS_EV_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  517. void HAL_SMBUS_ER_IRQHandler(SMBUS_HandleTypeDef *hsmbus);
  518. void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  519. void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  520. void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  521. void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  522. void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
  523. void HAL_SMBUS_ListenCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  524. void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus);
  525. void HAL_SMBUS_AbortCpltCallback(SMBUS_HandleTypeDef *hsmbus);
  526. /**
  527. * @}
  528. */
  529. /** @addtogroup SMBUS_Exported_Functions_Group3 Peripheral State and Errors functions
  530. * @{
  531. */
  532. /* Peripheral State, mode and Errors functions **************************************************/
  533. HAL_SMBUS_StateTypeDef HAL_SMBUS_GetState(SMBUS_HandleTypeDef *hsmbus);
  534. HAL_SMBUS_ModeTypeDef HAL_SMBUS_GetMode(SMBUS_HandleTypeDef *hsmbus);
  535. uint32_t HAL_SMBUS_GetError(SMBUS_HandleTypeDef *hsmbus);
  536. /**
  537. * @}
  538. */
  539. /**
  540. * @}
  541. */
  542. /* Private types -------------------------------------------------------------*/
  543. /* Private variables ---------------------------------------------------------*/
  544. /* Private constants ---------------------------------------------------------*/
  545. /** @defgroup SMBUS_Private_Constants SMBUS Private Constants
  546. * @{
  547. */
  548. #define SMBUS_FLAG_MASK 0x0000FFFFU
  549. /**
  550. * @}
  551. */
  552. /* Private macros ------------------------------------------------------------*/
  553. /** @defgroup SMBUS_Private_Macros SMBUS Private Macros
  554. * @{
  555. */
  556. #define SMBUS_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U)
  557. #define SMBUS_RISE_TIME(__FREQRANGE__) ( ((__FREQRANGE__) + 1U))
  558. #define SMBUS_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
  559. #define SMBUS_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
  560. #define SMBUS_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
  561. #define SMBUS_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
  562. #define SMBUS_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)0x00F0)))
  563. #define SMBUS_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)(0x00F1))))
  564. #define SMBUS_GET_PEC_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR1 & I2C_CR1_ENPEC)
  565. #define SMBUS_GET_PEC_VALUE(__HANDLE__) ((__HANDLE__)->XferPEC)
  566. #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  567. #define IS_SMBUS_ANALOG_FILTER(FILTER) (((FILTER) == SMBUS_ANALOGFILTER_ENABLE) || \
  568. ((FILTER) == SMBUS_ANALOGFILTER_DISABLE))
  569. #define IS_SMBUS_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
  570. #endif
  571. #define IS_SMBUS_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == SMBUS_ADDRESSINGMODE_7BIT) || \
  572. ((ADDRESS) == SMBUS_ADDRESSINGMODE_10BIT))
  573. #define IS_SMBUS_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == SMBUS_DUALADDRESS_DISABLE) || \
  574. ((ADDRESS) == SMBUS_DUALADDRESS_ENABLE))
  575. #define IS_SMBUS_GENERAL_CALL(CALL) (((CALL) == SMBUS_GENERALCALL_DISABLE) || \
  576. ((CALL) == SMBUS_GENERALCALL_ENABLE))
  577. #define IS_SMBUS_NO_STRETCH(STRETCH) (((STRETCH) == SMBUS_NOSTRETCH_DISABLE) || \
  578. ((STRETCH) == SMBUS_NOSTRETCH_ENABLE))
  579. #define IS_SMBUS_PEC(PEC) (((PEC) == SMBUS_PEC_DISABLE) || \
  580. ((PEC) == SMBUS_PEC_ENABLE))
  581. #define IS_SMBUS_PERIPHERAL_MODE(MODE) (((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_HOST) || \
  582. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || \
  583. ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP))
  584. #define IS_SMBUS_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 100000U))
  585. #define IS_SMBUS_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & 0xFFFFFC00U) == 0U)
  586. #define IS_SMBUS_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & 0xFFFFFF01U) == 0U)
  587. #define IS_SMBUS_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == SMBUS_FIRST_FRAME) || \
  588. ((REQUEST) == SMBUS_NEXT_FRAME) || \
  589. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || \
  590. ((REQUEST) == SMBUS_LAST_FRAME_NO_PEC) || \
  591. ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC) || \
  592. ((REQUEST) == SMBUS_LAST_FRAME_WITH_PEC))
  593. /**
  594. * @}
  595. */
  596. /* Private Functions ---------------------------------------------------------*/
  597. /** @defgroup SMBUS_Private_Functions SMBUS Private Functions
  598. * @{
  599. */
  600. /**
  601. * @}
  602. */
  603. /**
  604. * @}
  605. */
  606. /**
  607. * @}
  608. */
  609. /**
  610. * @}
  611. */
  612. #ifdef __cplusplus
  613. }
  614. #endif
  615. #endif /* __STM32F4xx_HAL_SMBUS_H */
  616. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/