stm32f0xx_hal_cec.h 36 KB

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