训练营PLSR题目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

732 linhas
32 KiB

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