Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

760 lines
36 KiB

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