stm32l4xx_hal_smbus.h 32 KB

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