stm32h7xx_hal_cec.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_cec.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 21-April-2017
  7. * @brief Header file of CEC 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 __STM32H7xx_HAL_CEC_H
  39. #define __STM32H7xx_HAL_CEC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32h7xx_hal_def.h"
  45. /** @addtogroup STM32H7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup CEC
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup CEC_Exported_Types CEC Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief CEC Init Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t SignalFreeTime; /*!< Set SFT field, specifies the Signal Free Time.
  61. It can be one of @ref CEC_Signal_Free_Time
  62. and belongs to the set {0,...,7} where
  63. 0x0 is the default configuration
  64. else means 0.5 + (SignalFreeTime - 1) nominal data bit periods */
  65. uint32_t Tolerance; /*!< Set RXTOL bit, specifies the tolerance accepted on the received waveforms,
  66. it can be a value of @ref CEC_Tolerance : it is either CEC_STANDARD_TOLERANCE
  67. or CEC_EXTENDED_TOLERANCE */
  68. uint32_t BRERxStop; /*!< Set BRESTP bit @ref CEC_BRERxStop : specifies whether or not a Bit Rising Error stops the reception.
  69. - CEC_NO_RX_STOP_ON_BRE: reception is not stopped.
  70. - CEC_RX_STOP_ON_BRE: reception is stopped. */
  71. uint32_t BREErrorBitGen; /*!< Set BREGEN bit @ref CEC_BREErrorBitGen : specifies whether or not an Error-Bit is generated on the
  72. CEC line upon Bit Rising Error detection.
  73. - CEC_BRE_ERRORBIT_NO_GENERATION: no error-bit generation.
  74. - CEC_BRE_ERRORBIT_GENERATION: error-bit generation if BRESTP is set. */
  75. uint32_t LBPEErrorBitGen; /*!< Set LBPEGEN bit @ref CEC_LBPEErrorBitGen : specifies whether or not an Error-Bit is generated on the
  76. CEC line upon Long Bit Period Error detection.
  77. - CEC_LBPE_ERRORBIT_NO_GENERATION: no error-bit generation.
  78. - CEC_LBPE_ERRORBIT_GENERATION: error-bit generation. */
  79. uint32_t BroadcastMsgNoErrorBitGen; /*!< Set BRDNOGEN bit @ref CEC_BroadCastMsgErrorBitGen : allows to avoid an Error-Bit generation on the CEC line
  80. upon an error detected on a broadcast message.
  81. It supersedes BREGEN and LBPEGEN bits for a broadcast message error handling. It can take two values:
  82. - CEC_BROADCASTERROR_ERRORBIT_GENERATION.
  83. - a) BRE detection: error-bit generation on the CEC line if BRESTP=CEC_RX_STOP_ON_BRE
  84. and BREGEN=CEC_BRE_ERRORBIT_NO_GENERATION.
  85. - b) LBPE detection: error-bit generation on the CEC line
  86. if LBPGEN=CEC_LBPE_ERRORBIT_NO_GENERATION.
  87. - CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION.
  88. no error-bit generation in case neither a) nor b) are satisfied. Additionally,
  89. there is no error-bit generation in case of Short Bit Period Error detection in
  90. a broadcast message while LSTN bit is set. */
  91. uint32_t SignalFreeTimeOption; /*!< Set SFTOP bit @ref CEC_SFT_Option : specifies when SFT timer starts.
  92. - CEC_SFT_START_ON_TXSOM SFT: timer starts when TXSOM is set by software.
  93. - CEC_SFT_START_ON_TX_RX_END: SFT timer starts automatically at the end of message transmission/reception. */
  94. uint32_t ListenMode; /*!< Set LSTN bit @ref CEC_Listening_Mode : specifies device listening mode. It can take two values:
  95. - CEC_REDUCED_LISTENING_MODE: CEC peripheral receives only message addressed to its
  96. own address (OAR). Messages addressed to different destination are ignored.
  97. Broadcast messages are always received.
  98. - CEC_FULL_LISTENING_MODE: CEC peripheral receives messages addressed to its own
  99. address (OAR) with positive acknowledge. Messages addressed to different destination
  100. are received, but without interfering with the CEC bus: no acknowledge sent. */
  101. uint16_t OwnAddress; /*!< Own addresses configuration
  102. This parameter can be a value of @ref CEC_OWN_ADDRESS */
  103. uint8_t *RxBuffer; /*!< CEC Rx buffer pointer */
  104. }CEC_InitTypeDef;
  105. /**
  106. * @brief HAL CEC State structures definition
  107. * @note HAL CEC State value is a combination of 2 different substates: gState and RxState.
  108. * - gState contains CEC state information related to global Handle management
  109. * and also information related to Tx operations.
  110. * gState value coding follow below described bitmap :
  111. * b7 (not used)
  112. * x : Should be set to 0
  113. * b6 Error information
  114. * 0 : No Error
  115. * 1 : Error
  116. * b5 IP initilisation status
  117. * 0 : Reset (IP not initialized)
  118. * 1 : Init done (IP initialized. HAL CEC Init function already called)
  119. * b4-b3 (not used)
  120. * xx : Should be set to 00
  121. * b2 Intrinsic process state
  122. * 0 : Ready
  123. * 1 : Busy (IP busy with some configuration or internal operations)
  124. * b1 (not used)
  125. * x : Should be set to 0
  126. * b0 Tx state
  127. * 0 : Ready (no Tx operation ongoing)
  128. * 1 : Busy (Tx operation ongoing)
  129. * - RxState contains information related to Rx operations.
  130. * RxState value coding follow below described bitmap :
  131. * b7-b6 (not used)
  132. * xx : Should be set to 00
  133. * b5 IP initilisation status
  134. * 0 : Reset (IP not initialized)
  135. * 1 : Init done (IP initialized)
  136. * b4-b2 (not used)
  137. * xxx : Should be set to 000
  138. * b1 Rx state
  139. * 0 : Ready (no Rx operation ongoing)
  140. * 1 : Busy (Rx operation ongoing)
  141. * b0 (not used)
  142. * x : Should be set to 0.
  143. */
  144. typedef enum
  145. {
  146. HAL_CEC_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
  147. Value is allowed for gState and RxState */
  148. HAL_CEC_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
  149. Value is allowed for gState and RxState */
  150. HAL_CEC_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
  151. Value is allowed for gState only */
  152. HAL_CEC_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
  153. Value is allowed for RxState only */
  154. HAL_CEC_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
  155. Value is allowed for gState only */
  156. HAL_CEC_STATE_BUSY_RX_TX = 0x23U, /*!< an internal process is ongoing
  157. Value is allowed for gState only */
  158. HAL_CEC_STATE_ERROR = 0x60U /*!< Error Value is allowed for gState only */
  159. }HAL_CEC_StateTypeDef;
  160. /**
  161. * @brief CEC handle Structure definition
  162. */
  163. typedef struct
  164. {
  165. CEC_TypeDef *Instance; /*!< CEC registers base address */
  166. CEC_InitTypeDef Init; /*!< CEC communication parameters */
  167. uint8_t *pTxBuffPtr; /*!< Pointer to CEC Tx transfer Buffer */
  168. uint16_t TxXferCount; /*!< CEC Tx Transfer Counter */
  169. uint16_t RxXferSize; /*!< CEC Rx Transfer size, 0: header received only */
  170. HAL_LockTypeDef Lock; /*!< Locking object */
  171. HAL_CEC_StateTypeDef gState; /*!< CEC state information related to global Handle management
  172. and also related to Tx operations.
  173. This parameter can be a value of @ref HAL_CEC_StateTypeDef */
  174. HAL_CEC_StateTypeDef RxState; /*!< CEC state information related to Rx operations.
  175. This parameter can be a value of @ref HAL_CEC_StateTypeDef */
  176. uint32_t ErrorCode; /*!< For errors handling purposes, copy of ISR register
  177. in case error is reported */
  178. }CEC_HandleTypeDef;
  179. /**
  180. * @}
  181. */
  182. /* Exported constants --------------------------------------------------------*/
  183. /** @defgroup CEC_Exported_Constants CEC Exported Constants
  184. * @{
  185. */
  186. /** @defgroup CEC_Error_Code CEC Error Code
  187. * @{
  188. */
  189. #define HAL_CEC_ERROR_NONE (uint32_t) 0x0000U /*!< no error */
  190. #define HAL_CEC_ERROR_RXOVR CEC_ISR_RXOVR /*!< CEC Rx-Overrun */
  191. #define HAL_CEC_ERROR_BRE CEC_ISR_BRE /*!< CEC Rx Bit Rising Error */
  192. #define HAL_CEC_ERROR_SBPE CEC_ISR_SBPE /*!< CEC Rx Short Bit period Error */
  193. #define HAL_CEC_ERROR_LBPE CEC_ISR_LBPE /*!< CEC Rx Long Bit period Error */
  194. #define HAL_CEC_ERROR_RXACKE CEC_ISR_RXACKE /*!< CEC Rx Missing Acknowledge */
  195. #define HAL_CEC_ERROR_ARBLST CEC_ISR_ARBLST /*!< CEC Arbitration Lost */
  196. #define HAL_CEC_ERROR_TXUDR CEC_ISR_TXUDR /*!< CEC Tx-Buffer Underrun */
  197. #define HAL_CEC_ERROR_TXERR CEC_ISR_TXERR /*!< CEC Tx-Error */
  198. #define HAL_CEC_ERROR_TXACKE CEC_ISR_TXACKE /*!< CEC Tx Missing Acknowledge */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup CEC_Signal_Free_Time CEC Signal Free Time setting parameter
  203. * @{
  204. */
  205. #define CEC_DEFAULT_SFT ((uint32_t)0x00000000U)
  206. #define CEC_0_5_BITPERIOD_SFT ((uint32_t)0x00000001U)
  207. #define CEC_1_5_BITPERIOD_SFT ((uint32_t)0x00000002U)
  208. #define CEC_2_5_BITPERIOD_SFT ((uint32_t)0x00000003U)
  209. #define CEC_3_5_BITPERIOD_SFT ((uint32_t)0x00000004U)
  210. #define CEC_4_5_BITPERIOD_SFT ((uint32_t)0x00000005U)
  211. #define CEC_5_5_BITPERIOD_SFT ((uint32_t)0x00000006U)
  212. #define CEC_6_5_BITPERIOD_SFT ((uint32_t)0x00000007U)
  213. /**
  214. * @}
  215. */
  216. /** @defgroup CEC_Tolerance CEC Receiver Tolerance
  217. * @{
  218. */
  219. #define CEC_STANDARD_TOLERANCE ((uint32_t)0x00000000U)
  220. #define CEC_EXTENDED_TOLERANCE ((uint32_t)CEC_CFGR_RXTOL)
  221. /**
  222. * @}
  223. */
  224. /** @defgroup CEC_BRERxStop CEC Reception Stop on Error
  225. * @{
  226. */
  227. #define CEC_NO_RX_STOP_ON_BRE ((uint32_t)0x00000000U)
  228. #define CEC_RX_STOP_ON_BRE ((uint32_t)CEC_CFGR_BRESTP)
  229. /**
  230. * @}
  231. */
  232. /** @defgroup CEC_BREErrorBitGen CEC Error Bit Generation if Bit Rise Error reported
  233. * @{
  234. */
  235. #define CEC_BRE_ERRORBIT_NO_GENERATION ((uint32_t)0x00000000U)
  236. #define CEC_BRE_ERRORBIT_GENERATION ((uint32_t)CEC_CFGR_BREGEN)
  237. /**
  238. * @}
  239. */
  240. /** @defgroup CEC_LBPEErrorBitGen CEC Error Bit Generation if Long Bit Period Error reported
  241. * @{
  242. */
  243. #define CEC_LBPE_ERRORBIT_NO_GENERATION ((uint32_t)0x00000000U)
  244. #define CEC_LBPE_ERRORBIT_GENERATION ((uint32_t)CEC_CFGR_LBPEGEN)
  245. /**
  246. * @}
  247. */
  248. /** @defgroup CEC_BroadCastMsgErrorBitGen CEC Error Bit Generation on Broadcast message
  249. * @{
  250. */
  251. #define CEC_BROADCASTERROR_ERRORBIT_GENERATION ((uint32_t)0x00000000U)
  252. #define CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION ((uint32_t)CEC_CFGR_BRDNOGEN)
  253. /**
  254. * @}
  255. */
  256. /** @defgroup CEC_SFT_Option CEC Signal Free Time start option
  257. * @{
  258. */
  259. #define CEC_SFT_START_ON_TXSOM ((uint32_t)0x00000000U)
  260. #define CEC_SFT_START_ON_TX_RX_END ((uint32_t)CEC_CFGR_SFTOPT)
  261. /**
  262. * @}
  263. */
  264. /** @defgroup CEC_Listening_Mode CEC Listening mode option
  265. * @{
  266. */
  267. #define CEC_REDUCED_LISTENING_MODE ((uint32_t)0x00000000U)
  268. #define CEC_FULL_LISTENING_MODE ((uint32_t)CEC_CFGR_LSTN)
  269. /**
  270. * @}
  271. */
  272. /** @defgroup CEC_OAR_Position CEC Device Own Address position in CEC CFGR register
  273. * @{
  274. */
  275. #define CEC_CFGR_OAR_LSB_POS ((uint32_t) 16U)
  276. /**
  277. * @}
  278. */
  279. /** @defgroup CEC_Initiator_Position CEC Initiator logical address position in message header
  280. * @{
  281. */
  282. #define CEC_INITIATOR_LSB_POS ((uint32_t) 4U)
  283. /**
  284. * @}
  285. */
  286. /** @defgroup CEC_OWN_ADDRESS CEC Own Address
  287. * @{
  288. */
  289. #define CEC_OWN_ADDRESS_NONE ((uint16_t) 0x0000U) /* Reset value */
  290. #define CEC_OWN_ADDRESS_0 ((uint16_t) 0x0001U) /* Logical Address 0 */
  291. #define CEC_OWN_ADDRESS_1 ((uint16_t) 0x0002U) /* Logical Address 1 */
  292. #define CEC_OWN_ADDRESS_2 ((uint16_t) 0x0004U) /* Logical Address 2 */
  293. #define CEC_OWN_ADDRESS_3 ((uint16_t) 0x0008U) /* Logical Address 3 */
  294. #define CEC_OWN_ADDRESS_4 ((uint16_t) 0x0010U) /* Logical Address 4 */
  295. #define CEC_OWN_ADDRESS_5 ((uint16_t) 0x0020U) /* Logical Address 5 */
  296. #define CEC_OWN_ADDRESS_6 ((uint16_t) 0x0040U) /* Logical Address 6 */
  297. #define CEC_OWN_ADDRESS_7 ((uint16_t) 0x0080U) /* Logical Address 7 */
  298. #define CEC_OWN_ADDRESS_8 ((uint16_t) 0x0100U) /* Logical Address 9 */
  299. #define CEC_OWN_ADDRESS_9 ((uint16_t) 0x0200U) /* Logical Address 10 */
  300. #define CEC_OWN_ADDRESS_10 ((uint16_t) 0x0400U) /* Logical Address 11 */
  301. #define CEC_OWN_ADDRESS_11 ((uint16_t) 0x0800U) /* Logical Address 12 */
  302. #define CEC_OWN_ADDRESS_12 ((uint16_t) 0x1000U) /* Logical Address 13 */
  303. #define CEC_OWN_ADDRESS_13 ((uint16_t) 0x2000U) /* Logical Address 14 */
  304. #define CEC_OWN_ADDRESS_14 ((uint16_t) 0x4000U) /* Logical Address 15 */
  305. /**
  306. * @}
  307. */
  308. /** @defgroup CEC_Interrupts_Definitions CEC Interrupts definition
  309. * @{
  310. */
  311. #define CEC_IT_TXACKE CEC_IER_TXACKEIE
  312. #define CEC_IT_TXERR CEC_IER_TXERRIE
  313. #define CEC_IT_TXUDR CEC_IER_TXUDRIE
  314. #define CEC_IT_TXEND CEC_IER_TXENDIE
  315. #define CEC_IT_TXBR CEC_IER_TXBRIE
  316. #define CEC_IT_ARBLST CEC_IER_ARBLSTIE
  317. #define CEC_IT_RXACKE CEC_IER_RXACKEIE
  318. #define CEC_IT_LBPE CEC_IER_LBPEIE
  319. #define CEC_IT_SBPE CEC_IER_SBPEIE
  320. #define CEC_IT_BRE CEC_IER_BREIE
  321. #define CEC_IT_RXOVR CEC_IER_RXOVRIE
  322. #define CEC_IT_RXEND CEC_IER_RXENDIE
  323. #define CEC_IT_RXBR CEC_IER_RXBRIE
  324. /**
  325. * @}
  326. */
  327. /** @defgroup CEC_Flags_Definitions CEC Flags definition
  328. * @{
  329. */
  330. #define CEC_FLAG_TXACKE CEC_ISR_TXACKE
  331. #define CEC_FLAG_TXERR CEC_ISR_TXERR
  332. #define CEC_FLAG_TXUDR CEC_ISR_TXUDR
  333. #define CEC_FLAG_TXEND CEC_ISR_TXEND
  334. #define CEC_FLAG_TXBR CEC_ISR_TXBR
  335. #define CEC_FLAG_ARBLST CEC_ISR_ARBLST
  336. #define CEC_FLAG_RXACKE CEC_ISR_RXACKE
  337. #define CEC_FLAG_LBPE CEC_ISR_LBPE
  338. #define CEC_FLAG_SBPE CEC_ISR_SBPE
  339. #define CEC_FLAG_BRE CEC_ISR_BRE
  340. #define CEC_FLAG_RXOVR CEC_ISR_RXOVR
  341. #define CEC_FLAG_RXEND CEC_ISR_RXEND
  342. #define CEC_FLAG_RXBR CEC_ISR_RXBR
  343. /**
  344. * @}
  345. */
  346. /** @defgroup CEC_ALL_ERROR CEC all RX or TX errors flags
  347. * @{
  348. */
  349. #define CEC_ISR_ALL_ERROR ((uint32_t)CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|\
  350. CEC_ISR_ARBLST|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)
  351. /**
  352. * @}
  353. */
  354. /** @defgroup CEC_IER_ALL_RX CEC all RX errors interrupts enabling flag
  355. * @{
  356. */
  357. #define CEC_IER_RX_ALL_ERR ((uint32_t)CEC_IER_RXACKEIE|CEC_IER_LBPEIE|CEC_IER_SBPEIE|CEC_IER_BREIE|CEC_IER_RXOVRIE)
  358. /**
  359. * @}
  360. */
  361. /** @defgroup CEC_IER_ALL_TX CEC all TX errors interrupts enabling flag
  362. * @{
  363. */
  364. #define CEC_IER_TX_ALL_ERR ((uint32_t)CEC_IER_TXACKEIE|CEC_IER_TXERRIE|CEC_IER_TXUDRIE|CEC_IER_ARBLSTIE)
  365. /**
  366. * @}
  367. */
  368. /**
  369. * @}
  370. */
  371. /* Exported macros -----------------------------------------------------------*/
  372. /** @defgroup CEC_Exported_Macros CEC Exported Macros
  373. * @{
  374. */
  375. /** @brief Reset CEC handle gstate & RxState
  376. * @param __HANDLE__: CEC handle.
  377. * @retval None
  378. */
  379. #define __HAL_CEC_RESET_HANDLE_STATE(__HANDLE__) do{ \
  380. (__HANDLE__)->gState = HAL_CEC_STATE_RESET; \
  381. (__HANDLE__)->RxState = HAL_CEC_STATE_RESET; \
  382. } while(0)
  383. /** @brief Checks whether or not the specified CEC interrupt flag is set.
  384. * @param __HANDLE__: specifies the CEC Handle.
  385. * @param __FLAG__: specifies the flag to check.
  386. * @arg CEC_FLAG_TXACKE: Tx Missing acknowledge Error
  387. * @arg CEC_FLAG_TXERR: Tx Error.
  388. * @arg CEC_FLAG_TXUDR: Tx-Buffer Underrun.
  389. * @arg CEC_FLAG_TXEND: End of transmission (successful transmission of the last byte).
  390. * @arg CEC_FLAG_TXBR: Tx-Byte Request.
  391. * @arg CEC_FLAG_ARBLST: Arbitration Lost
  392. * @arg CEC_FLAG_RXACKE: Rx-Missing Acknowledge
  393. * @arg CEC_FLAG_LBPE: Rx Long period Error
  394. * @arg CEC_FLAG_SBPE: Rx Short period Error
  395. * @arg CEC_FLAG_BRE: Rx Bit Rising Error
  396. * @arg CEC_FLAG_RXOVR: Rx Overrun.
  397. * @arg CEC_FLAG_RXEND: End Of Reception.
  398. * @arg CEC_FLAG_RXBR: Rx-Byte Received.
  399. * @retval ITStatus
  400. */
  401. #define __HAL_CEC_GET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR & (__FLAG__))
  402. /** @brief Clears the interrupt or status flag when raised (write at 1)
  403. * @param __HANDLE__: specifies the CEC Handle.
  404. * @param __FLAG__: specifies the interrupt/status flag to clear.
  405. * This parameter can be one of the following values:
  406. * @arg CEC_FLAG_TXACKE: Tx Missing acknowledge Error
  407. * @arg CEC_FLAG_TXERR: Tx Error.
  408. * @arg CEC_FLAG_TXUDR: Tx-Buffer Underrun.
  409. * @arg CEC_FLAG_TXEND: End of transmission (successful transmission of the last byte).
  410. * @arg CEC_FLAG_TXBR: Tx-Byte Request.
  411. * @arg CEC_FLAG_ARBLST: Arbitration Lost
  412. * @arg CEC_FLAG_RXACKE: Rx-Missing Acknowledge
  413. * @arg CEC_FLAG_LBPE: Rx Long period Error
  414. * @arg CEC_FLAG_SBPE: Rx Short period Error
  415. * @arg CEC_FLAG_BRE: Rx Bit Rising Error
  416. * @arg CEC_FLAG_RXOVR: Rx Overrun.
  417. * @arg CEC_FLAG_RXEND: End Of Reception.
  418. * @arg CEC_FLAG_RXBR: Rx-Byte Received.
  419. * @retval none
  420. */
  421. #define __HAL_CEC_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR |= (__FLAG__))
  422. /** @brief Enables the specified CEC interrupt.
  423. * @param __HANDLE__: specifies the CEC Handle.
  424. * @param __INTERRUPT__: specifies the CEC interrupt to enable.
  425. * This parameter can be one of the following values:
  426. * @arg CEC_IT_TXACKE: Tx Missing acknowledge Error IT Enable
  427. * @arg CEC_IT_TXERR: Tx Error IT Enable
  428. * @arg CEC_IT_TXUDR: Tx-Buffer Underrun IT Enable
  429. * @arg CEC_IT_TXEND: End of transmission IT Enable
  430. * @arg CEC_IT_TXBR: Tx-Byte Request IT Enable
  431. * @arg CEC_IT_ARBLST: Arbitration Lost IT Enable
  432. * @arg CEC_IT_RXACKE: Rx-Missing Acknowledge IT Enable
  433. * @arg CEC_IT_LBPE: Rx Long period Error IT Enable
  434. * @arg CEC_IT_SBPE: Rx Short period Error IT Enable
  435. * @arg CEC_IT_BRE: Rx Bit Rising Error IT Enable
  436. * @arg CEC_IT_RXOVR: Rx Overrun IT Enable
  437. * @arg CEC_IT_RXEND: End Of Reception IT Enable
  438. * @arg CEC_IT_RXBR: Rx-Byte Received IT Enable
  439. * @retval none
  440. */
  441. #define __HAL_CEC_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
  442. /** @brief Disables the specified CEC interrupt.
  443. * @param __HANDLE__: specifies the CEC Handle.
  444. * @param __INTERRUPT__: specifies the CEC interrupt to disable.
  445. * This parameter can be one of the following values:
  446. * @arg CEC_IT_TXACKE: Tx Missing acknowledge Error IT Enable
  447. * @arg CEC_IT_TXERR: Tx Error IT Enable
  448. * @arg CEC_IT_TXUDR: Tx-Buffer Underrun IT Enable
  449. * @arg CEC_IT_TXEND: End of transmission IT Enable
  450. * @arg CEC_IT_TXBR: Tx-Byte Request IT Enable
  451. * @arg CEC_IT_ARBLST: Arbitration Lost IT Enable
  452. * @arg CEC_IT_RXACKE: Rx-Missing Acknowledge IT Enable
  453. * @arg CEC_IT_LBPE: Rx Long period Error IT Enable
  454. * @arg CEC_IT_SBPE: Rx Short period Error IT Enable
  455. * @arg CEC_IT_BRE: Rx Bit Rising Error IT Enable
  456. * @arg CEC_IT_RXOVR: Rx Overrun IT Enable
  457. * @arg CEC_IT_RXEND: End Of Reception IT Enable
  458. * @arg CEC_IT_RXBR: Rx-Byte Received IT Enable
  459. * @retval none
  460. */
  461. #define __HAL_CEC_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
  462. /** @brief Checks whether or not the specified CEC interrupt is enabled.
  463. * @param __HANDLE__: specifies the CEC Handle.
  464. * @param __INTERRUPT__: specifies the CEC interrupt to check.
  465. * This parameter can be one of the following values:
  466. * @arg CEC_IT_TXACKE: Tx Missing acknowledge Error IT Enable
  467. * @arg CEC_IT_TXERR: Tx Error IT Enable
  468. * @arg CEC_IT_TXUDR: Tx-Buffer Underrun IT Enable
  469. * @arg CEC_IT_TXEND: End of transmission IT Enable
  470. * @arg CEC_IT_TXBR: Tx-Byte Request IT Enable
  471. * @arg CEC_IT_ARBLST: Arbitration Lost IT Enable
  472. * @arg CEC_IT_RXACKE: Rx-Missing Acknowledge IT Enable
  473. * @arg CEC_IT_LBPE: Rx Long period Error IT Enable
  474. * @arg CEC_IT_SBPE: Rx Short period Error IT Enable
  475. * @arg CEC_IT_BRE: Rx Bit Rising Error IT Enable
  476. * @arg CEC_IT_RXOVR: Rx Overrun IT Enable
  477. * @arg CEC_IT_RXEND: End Of Reception IT Enable
  478. * @arg CEC_IT_RXBR: Rx-Byte Received IT Enable
  479. * @retval FlagStatus
  480. */
  481. #define __HAL_CEC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER & (__INTERRUPT__))
  482. /** @brief Enables the CEC device
  483. * @param __HANDLE__: specifies the CEC Handle.
  484. * @retval none
  485. */
  486. #define __HAL_CEC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CEC_CR_CECEN)
  487. /** @brief Disables the CEC device
  488. * @param __HANDLE__: specifies the CEC Handle.
  489. * @retval none
  490. */
  491. #define __HAL_CEC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CEC_CR_CECEN)
  492. /** @brief Set Transmission Start flag
  493. * @param __HANDLE__: specifies the CEC Handle.
  494. * @retval none
  495. */
  496. #define __HAL_CEC_FIRST_BYTE_TX_SET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CEC_CR_TXSOM)
  497. /** @brief Set Transmission End flag
  498. * @param __HANDLE__: specifies the CEC Handle.
  499. * @retval none
  500. * If the CEC message consists of only one byte, TXEOM must be set before of TXSOM.
  501. */
  502. #define __HAL_CEC_LAST_BYTE_TX_SET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CEC_CR_TXEOM)
  503. /** @brief Get Transmission Start flag
  504. * @param __HANDLE__: specifies the CEC Handle.
  505. * @retval FlagStatus
  506. */
  507. #define __HAL_CEC_GET_TRANSMISSION_START_FLAG(__HANDLE__) ((__HANDLE__)->Instance->CR & CEC_CR_TXSOM)
  508. /** @brief Get Transmission End flag
  509. * @param __HANDLE__: specifies the CEC Handle.
  510. * @retval FlagStatus
  511. */
  512. #define __HAL_CEC_GET_TRANSMISSION_END_FLAG(__HANDLE__) ((__HANDLE__)->Instance->CR & CEC_CR_TXEOM)
  513. /** @brief Clear OAR register
  514. * @param __HANDLE__: specifies the CEC Handle.
  515. * @retval none
  516. */
  517. #define __HAL_CEC_CLEAR_OAR(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CFGR, CEC_CFGR_OAR)
  518. /** @brief Set OAR register (without resetting previously set address in case of multi-address mode)
  519. * To reset OAR, __HAL_CEC_CLEAR_OAR() needs to be called beforehand
  520. * @param __HANDLE__: specifies the CEC Handle.
  521. * @param __ADDRESS__: Own Address value (CEC logical address is identified by bit position)
  522. * @retval none
  523. */
  524. #define __HAL_CEC_SET_OAR(__HANDLE__,__ADDRESS__) SET_BIT((__HANDLE__)->Instance->CFGR, (__ADDRESS__)<< CEC_CFGR_OAR_LSB_POS)
  525. /**
  526. * @}
  527. */
  528. /* Exported functions --------------------------------------------------------*/
  529. /** @addtogroup CEC_Exported_Functions
  530. * @{
  531. */
  532. /** @addtogroup CEC_Exported_Functions_Group1
  533. * @{
  534. */
  535. /* Initialization and de-initialization functions ****************************/
  536. HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec);
  537. HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec);
  538. HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress);
  539. void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec);
  540. void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec);
  541. /**
  542. * @}
  543. */
  544. /** @addtogroup CEC_Exported_Functions_Group2
  545. * @{
  546. */
  547. /* I/O operation functions ***************************************************/
  548. HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress,uint8_t DestinationAddress, uint8_t *pData, uint32_t Size);
  549. uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec);
  550. void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer);
  551. void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec);
  552. void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec);
  553. void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize);
  554. void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec);
  555. /**
  556. * @}
  557. */
  558. /** @addtogroup CEC_Exported_Functions_Group3
  559. * @{
  560. */
  561. /* Peripheral State functions ************************************************/
  562. HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec);
  563. uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec);
  564. /**
  565. * @}
  566. */
  567. /**
  568. * @}
  569. */
  570. /* Private types -------------------------------------------------------------*/
  571. /** @defgroup CEC_Private_Types CEC Private Types
  572. * @{
  573. */
  574. /**
  575. * @}
  576. */
  577. /* Private variables ---------------------------------------------------------*/
  578. /** @defgroup CEC_Private_Variables CEC Private Variables
  579. * @{
  580. */
  581. /**
  582. * @}
  583. */
  584. /* Private constants ---------------------------------------------------------*/
  585. /** @defgroup CEC_Private_Constants CEC Private Constants
  586. * @{
  587. */
  588. /**
  589. * @}
  590. */
  591. /* Private macros ------------------------------------------------------------*/
  592. /** @defgroup CEC_Private_Macros CEC Private Macros
  593. * @{
  594. */
  595. #define IS_CEC_SIGNALFREETIME(__SFT__) ((__SFT__) <= CEC_CFGR_SFT)
  596. #define IS_CEC_TOLERANCE(__RXTOL__) (((__RXTOL__) == CEC_STANDARD_TOLERANCE) || \
  597. ((__RXTOL__) == CEC_EXTENDED_TOLERANCE))
  598. #define IS_CEC_BRERXSTOP(__BRERXSTOP__) (((__BRERXSTOP__) == CEC_NO_RX_STOP_ON_BRE) || \
  599. ((__BRERXSTOP__) == CEC_RX_STOP_ON_BRE))
  600. #define IS_CEC_BREERRORBITGEN(__ERRORBITGEN__) (((__ERRORBITGEN__) == CEC_BRE_ERRORBIT_NO_GENERATION) || \
  601. ((__ERRORBITGEN__) == CEC_BRE_ERRORBIT_GENERATION))
  602. #define IS_CEC_LBPEERRORBITGEN(__ERRORBITGEN__) (((__ERRORBITGEN__) == CEC_LBPE_ERRORBIT_NO_GENERATION) || \
  603. ((__ERRORBITGEN__) == CEC_LBPE_ERRORBIT_GENERATION))
  604. #define IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(__ERRORBITGEN__) (((__ERRORBITGEN__) == CEC_BROADCASTERROR_ERRORBIT_GENERATION) || \
  605. ((__ERRORBITGEN__) == CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION))
  606. #define IS_CEC_SFTOP(__SFTOP__) (((__SFTOP__) == CEC_SFT_START_ON_TXSOM) || \
  607. ((__SFTOP__) == CEC_SFT_START_ON_TX_RX_END))
  608. #define IS_CEC_LISTENING_MODE(__MODE__) (((__MODE__) == CEC_REDUCED_LISTENING_MODE) || \
  609. ((__MODE__) == CEC_FULL_LISTENING_MODE))
  610. /** @brief Check CEC message size.
  611. * The message size is the payload size: without counting the header,
  612. * it varies from 0 byte (ping operation, one header only, no payload) to
  613. * 15 bytes (1 opcode and up to 14 operands following the header).
  614. * @param __SIZE__: CEC message size.
  615. * @retval Test result (TRUE or FALSE).
  616. */
  617. #define IS_CEC_MSGSIZE(__SIZE__) ((__SIZE__) <= 0x10)
  618. /** @brief Check CEC device Own Address Register (OAR) setting.
  619. * OAR address is written in a 15-bit field within CEC_CFGR register.
  620. * @param __ADDRESS__: CEC own address.
  621. * @retval Test result (TRUE or FALSE).
  622. */
  623. #define IS_CEC_OWN_ADDRESS(__ADDRESS__) ((__ADDRESS__) <= 0x7FFF)
  624. /** @brief Check CEC initiator or destination logical address setting.
  625. * Initiator and destination addresses are coded over 4 bits.
  626. * @param __ADDRESS__: CEC initiator or logical address.
  627. * @retval Test result (TRUE or FALSE).
  628. */
  629. #define IS_CEC_ADDRESS(__ADDRESS__) ((__ADDRESS__) <= 0xF)
  630. /**
  631. * @}
  632. */
  633. /* Private functions ---------------------------------------------------------*/
  634. /** @defgroup CEC_Private_Functions CEC Private Functions
  635. * @{
  636. */
  637. /**
  638. * @}
  639. */
  640. /**
  641. * @}
  642. */
  643. /**
  644. * @}
  645. */
  646. #ifdef __cplusplus
  647. }
  648. #endif
  649. #endif /* __STM32H7xx_HAL_CEC_H */
  650. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/