stm32l4xx_hal_smbus.h 32 KB

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