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.
 
 
 

754 lines
32 KiB

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