stm32f4xx_hal_cec.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_cec.c
  4. * @author MCD Application Team
  5. * @version V1.6.0
  6. * @date 04-November-2016
  7. * @brief CEC HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the High Definition Multimedia Interface
  10. * Consumer Electronics Control Peripheral (CEC).
  11. * + Initialization and de-initialization functions
  12. * + IO operation functions
  13. * + Peripheral Control functions
  14. *
  15. *
  16. @verbatim
  17. ===============================================================================
  18. ##### How to use this driver #####
  19. ===============================================================================
  20. [..]
  21. The CEC HAL driver can be used as follow:
  22. (#) Declare a CEC_HandleTypeDef handle structure.
  23. (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API:
  24. (##) Enable the CEC interface clock.
  25. (##) CEC pins configuration:
  26. (+++) Enable the clock for the CEC GPIOs.
  27. (+++) Configure these CEC pins as alternate function pull-up.
  28. (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT()
  29. and HAL_CEC_Receive_IT() APIs):
  30. (+++) Configure the CEC interrupt priority.
  31. (+++) Enable the NVIC CEC IRQ handle.
  32. (+++) The specific CEC interrupts (Transmission complete interrupt,
  33. RXNE interrupt and Error Interrupts) will be managed using the macros
  34. __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit
  35. and receive process.
  36. (#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in
  37. in case of Bit Rising Error, Error-Bit generation conditions, device logical
  38. address and Listen mode in the hcec Init structure.
  39. (#) Initialize the CEC registers by calling the HAL_CEC_Init() API.
  40. [..]
  41. (@) This API (HAL_CEC_Init()) configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
  42. by calling the customed HAL_CEC_MspInit() API.
  43. @endverbatim
  44. ******************************************************************************
  45. * @attention
  46. *
  47. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  48. *
  49. * Redistribution and use in source and binary forms, with or without modification,
  50. * are permitted provided that the following conditions are met:
  51. * 1. Redistributions of source code must retain the above copyright notice,
  52. * this list of conditions and the following disclaimer.
  53. * 2. Redistributions in binary form must reproduce the above copyright notice,
  54. * this list of conditions and the following disclaimer in the documentation
  55. * and/or other materials provided with the distribution.
  56. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  57. * may be used to endorse or promote products derived from this software
  58. * without specific prior written permission.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  61. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  63. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  64. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  68. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  69. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  70. *
  71. ******************************************************************************
  72. */
  73. /* Includes ------------------------------------------------------------------*/
  74. #include "stm32f4xx_hal.h"
  75. /** @addtogroup STM32F4xx_HAL_Driver
  76. * @{
  77. */
  78. /** @defgroup CEC CEC
  79. * @brief HAL CEC module driver
  80. * @{
  81. */
  82. #ifdef HAL_CEC_MODULE_ENABLED
  83. #if defined(STM32F446xx)
  84. /* Private typedef -----------------------------------------------------------*/
  85. /* Private define ------------------------------------------------------------*/
  86. /** @defgroup CEC_Private_Constants CEC Private Constants
  87. * @{
  88. */
  89. /**
  90. * @}
  91. */
  92. /* Private macro -------------------------------------------------------------*/
  93. /* Private variables ---------------------------------------------------------*/
  94. /* Private function prototypes -----------------------------------------------*/
  95. /** @defgroup CEC_Private_Functions CEC Private Functions
  96. * @{
  97. */
  98. /**
  99. * @}
  100. */
  101. /* Exported functions ---------------------------------------------------------*/
  102. /** @defgroup CEC_Exported_Functions CEC Exported Functions
  103. * @{
  104. */
  105. /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions
  106. * @brief Initialization and Configuration functions
  107. *
  108. @verbatim
  109. ===============================================================================
  110. ##### Initialization and Configuration functions #####
  111. ===============================================================================
  112. [..]
  113. This subsection provides a set of functions allowing to initialize the CEC
  114. (+) The following parameters need to be configured:
  115. (++) SignalFreeTime
  116. (++) Tolerance
  117. (++) BRERxStop (RX stopped or not upon Bit Rising Error)
  118. (++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error)
  119. (++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error)
  120. (++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error)
  121. (++) SignalFreeTimeOption (SFT Timer start definition)
  122. (++) OwnAddress (CEC device address)
  123. (++) ListenMode
  124. @endverbatim
  125. * @{
  126. */
  127. /**
  128. * @brief Initializes the CEC mode according to the specified
  129. * parameters in the CEC_InitTypeDef and creates the associated handle .
  130. * @param hcec: CEC handle
  131. * @retval HAL status
  132. */
  133. HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec)
  134. {
  135. /* Check the CEC handle allocation */
  136. if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL))
  137. {
  138. return HAL_ERROR;
  139. }
  140. /* Check the parameters */
  141. assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
  142. assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime));
  143. assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance));
  144. assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop));
  145. assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen));
  146. assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen));
  147. assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen));
  148. assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption));
  149. assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode));
  150. assert_param(IS_CEC_OWN_ADDRESS(hcec->Init.OwnAddress));
  151. if(hcec->gState == HAL_CEC_STATE_RESET)
  152. {
  153. /* Allocate lock resource and initialize it */
  154. hcec->Lock = HAL_UNLOCKED;
  155. /* Init the low level hardware : GPIO, CLOCK */
  156. HAL_CEC_MspInit(hcec);
  157. }
  158. hcec->gState = HAL_CEC_STATE_BUSY;
  159. /* Disable the Peripheral */
  160. __HAL_CEC_DISABLE(hcec);
  161. /* Write to CEC Control Register */
  162. hcec->Instance->CFGR = hcec->Init.SignalFreeTime | hcec->Init.Tolerance | hcec->Init.BRERxStop|\
  163. hcec->Init.BREErrorBitGen | hcec->Init.LBPEErrorBitGen | hcec->Init.BroadcastMsgNoErrorBitGen |\
  164. hcec->Init.SignalFreeTimeOption |((uint32_t)(hcec->Init.OwnAddress)<<16U) |\
  165. hcec->Init.ListenMode;
  166. /* Enable the following CEC Transmission/Reception interrupts as
  167. * well as the following CEC Transmission/Reception Errors interrupts
  168. * Rx Byte Received IT
  169. * End of Reception IT
  170. * Rx overrun
  171. * Rx bit rising error
  172. * Rx short bit period error
  173. * Rx long bit period error
  174. * Rx missing acknowledge
  175. * Tx Byte Request IT
  176. * End of Transmission IT
  177. * Tx Missing Acknowledge IT
  178. * Tx-Error IT
  179. * Tx-Buffer Underrun IT
  180. * Tx arbitration lost */
  181. __HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
  182. /* Enable the CEC Peripheral */
  183. __HAL_CEC_ENABLE(hcec);
  184. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  185. hcec->gState = HAL_CEC_STATE_READY;
  186. hcec->RxState = HAL_CEC_STATE_READY;
  187. return HAL_OK;
  188. }
  189. /**
  190. * @brief DeInitializes the CEC peripheral
  191. * @param hcec: CEC handle
  192. * @retval HAL status
  193. */
  194. HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec)
  195. {
  196. /* Check the CEC handle allocation */
  197. if(hcec == NULL)
  198. {
  199. return HAL_ERROR;
  200. }
  201. /* Check the parameters */
  202. assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance));
  203. hcec->gState = HAL_CEC_STATE_BUSY;
  204. /* DeInit the low level hardware */
  205. HAL_CEC_MspDeInit(hcec);
  206. /* Disable the Peripheral */
  207. __HAL_CEC_DISABLE(hcec);
  208. /* Clear Flags */
  209. __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXEND|CEC_FLAG_TXBR|CEC_FLAG_RXBR|CEC_FLAG_RXEND|CEC_ISR_ALL_ERROR);
  210. /* Disable the following CEC Transmission/Reception interrupts as
  211. * well as the following CEC Transmission/Reception Errors interrupts
  212. * Rx Byte Received IT
  213. * End of Reception IT
  214. * Rx overrun
  215. * Rx bit rising error
  216. * Rx short bit period error
  217. * Rx long bit period error
  218. * Rx missing acknowledge
  219. * Tx Byte Request IT
  220. * End of Transmission IT
  221. * Tx Missing Acknowledge IT
  222. * Tx-Error IT
  223. * Tx-Buffer Underrun IT
  224. * Tx arbitration lost */
  225. __HAL_CEC_DISABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR);
  226. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  227. hcec->gState = HAL_CEC_STATE_RESET;
  228. hcec->RxState = HAL_CEC_STATE_RESET;
  229. /* Process Unlock */
  230. __HAL_UNLOCK(hcec);
  231. return HAL_OK;
  232. }
  233. /**
  234. * @brief Initializes the Own Address of the CEC device
  235. * @param hcec: CEC handle
  236. * @param CEC_OwnAddress: The CEC own address.
  237. * @retval HAL status
  238. */
  239. HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress)
  240. {
  241. /* Check the parameters */
  242. assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress));
  243. if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY))
  244. {
  245. /* Process Locked */
  246. __HAL_LOCK(hcec);
  247. hcec->gState = HAL_CEC_STATE_BUSY;
  248. /* Disable the Peripheral */
  249. __HAL_CEC_DISABLE(hcec);
  250. if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE)
  251. {
  252. hcec->Instance->CFGR |= ((uint32_t)CEC_OwnAddress<<16);
  253. }
  254. else
  255. {
  256. hcec->Instance->CFGR &= ~(CEC_CFGR_OAR);
  257. }
  258. hcec->gState = HAL_CEC_STATE_READY;
  259. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  260. /* Process Unlocked */
  261. __HAL_UNLOCK(hcec);
  262. /* Enable the Peripheral */
  263. __HAL_CEC_ENABLE(hcec);
  264. return HAL_OK;
  265. }
  266. else
  267. {
  268. return HAL_BUSY;
  269. }
  270. }
  271. /**
  272. * @brief CEC MSP Init
  273. * @param hcec: CEC handle
  274. * @retval None
  275. */
  276. __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec)
  277. {
  278. /* Prevent unused argument(s) compilation warning */
  279. UNUSED(hcec);
  280. /* NOTE : This function should not be modified, when the callback is needed,
  281. the HAL_CEC_MspInit can be implemented in the user file
  282. */
  283. }
  284. /**
  285. * @brief CEC MSP DeInit
  286. * @param hcec: CEC handle
  287. * @retval None
  288. */
  289. __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec)
  290. {
  291. /* Prevent unused argument(s) compilation warning */
  292. UNUSED(hcec);
  293. /* NOTE : This function should not be modified, when the callback is needed,
  294. the HAL_CEC_MspDeInit can be implemented in the user file
  295. */
  296. }
  297. /**
  298. * @}
  299. */
  300. /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions
  301. * @brief CEC Transmit/Receive functions
  302. *
  303. @verbatim
  304. ===============================================================================
  305. ##### IO operation functions #####
  306. ===============================================================================
  307. This subsection provides a set of functions allowing to manage the CEC data transfers.
  308. (#) The CEC handle must contain the initiator (TX side) and the destination (RX side)
  309. logical addresses (4-bit long addresses, 0x0F for broadcast messages destination)
  310. (#) The communication is performed using Interrupts.
  311. These API's return the HAL status.
  312. The end of the data processing will be indicated through the
  313. dedicated CEC IRQ when using Interrupt mode.
  314. The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks
  315. will be executed respectivelly at the end of the transmit or Receive process
  316. The HAL_CEC_ErrorCallback()user callback will be executed when a communication
  317. error is detected
  318. (#) API's with Interrupt are :
  319. (+) HAL_CEC_Transmit_IT()
  320. (+) HAL_CEC_IRQHandler()
  321. (#) A set of User Callbacks are provided:
  322. (+) HAL_CEC_TxCpltCallback()
  323. (+) HAL_CEC_RxCpltCallback()
  324. (+) HAL_CEC_ErrorCallback()
  325. @endverbatim
  326. * @{
  327. */
  328. /**
  329. * @brief Send data in interrupt mode
  330. * @param hcec: CEC handle
  331. * @param InitiatorAddress: Initiator logical address
  332. * @param DestinationAddress: destination logical address
  333. * @param pData: pointer to input byte data buffer
  334. * @param Size: amount of data to be sent in bytes (without counting the header).
  335. * 0 means only the header is sent (ping operation).
  336. * Maximum TX size is 15 bytes (1 opcode and up to 14 operands).
  337. * @retval HAL status
  338. */
  339. HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size)
  340. {
  341. /* if the IP isn't already busy and if there is no previous transmission
  342. already pending due to arbitration lost */
  343. if (hcec->gState == HAL_CEC_STATE_READY)
  344. {
  345. if((pData == NULL ) && (Size > 0U))
  346. {
  347. return HAL_ERROR;
  348. }
  349. assert_param(IS_CEC_ADDRESS(DestinationAddress));
  350. assert_param(IS_CEC_ADDRESS(InitiatorAddress));
  351. assert_param(IS_CEC_MSGSIZE(Size));
  352. /* Process Locked */
  353. __HAL_LOCK(hcec);
  354. hcec->pTxBuffPtr = pData;
  355. hcec->gState = HAL_CEC_STATE_BUSY_TX;
  356. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  357. /* initialize the number of bytes to send,
  358. * 0 means only one header is sent (ping operation) */
  359. hcec->TxXferCount = Size;
  360. /* in case of no payload (Size = 0), sender is only pinging the system;
  361. Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */
  362. if (Size == 0U)
  363. {
  364. __HAL_CEC_LAST_BYTE_TX_SET(hcec);
  365. }
  366. /* send header block */
  367. hcec->Instance->TXDR = ((uint8_t)(InitiatorAddress << CEC_INITIATOR_LSB_POS) |(uint8_t) DestinationAddress);
  368. /* Set TX Start of Message (TXSOM) bit */
  369. __HAL_CEC_FIRST_BYTE_TX_SET(hcec);
  370. /* Process Unlocked */
  371. __HAL_UNLOCK(hcec);
  372. return HAL_OK;
  373. }
  374. else
  375. {
  376. return HAL_BUSY;
  377. }
  378. }
  379. /**
  380. * @brief Get size of the received frame.
  381. * @param hcec: CEC handle
  382. * @retval Frame size
  383. */
  384. uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec)
  385. {
  386. return hcec->RxXferSize;
  387. }
  388. /**
  389. * @brief Change Rx Buffer.
  390. * @param hcec: CEC handle
  391. * @param Rxbuffer: Rx Buffer
  392. * @note This function can be called only inside the HAL_CEC_RxCpltCallback()
  393. * @retval Frame size
  394. */
  395. void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer)
  396. {
  397. hcec->Init.RxBuffer = Rxbuffer;
  398. }
  399. /**
  400. * @brief This function handles CEC interrupt requests.
  401. * @param hcec: CEC handle
  402. * @retval None
  403. */
  404. void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec)
  405. {
  406. /* save interrupts register for further error or interrupts handling purposes */
  407. uint32_t reg = 0U;
  408. reg = hcec->Instance->ISR;
  409. /* ----------------------------Arbitration Lost Management----------------------------------*/
  410. /* CEC TX arbitration error interrupt occurred --------------------------------------*/
  411. if((reg & CEC_FLAG_ARBLST) != RESET)
  412. {
  413. hcec->ErrorCode = HAL_CEC_ERROR_ARBLST;
  414. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST);
  415. }
  416. /* ----------------------------Rx Management----------------------------------*/
  417. /* CEC RX byte received interrupt ---------------------------------------------------*/
  418. if((reg & CEC_FLAG_RXBR) != RESET)
  419. {
  420. /* reception is starting */
  421. hcec->RxState = HAL_CEC_STATE_BUSY_RX;
  422. hcec->RxXferSize++;
  423. /* read received byte */
  424. *hcec->Init.RxBuffer++ = hcec->Instance->RXDR;
  425. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR);
  426. }
  427. /* CEC RX end received interrupt ---------------------------------------------------*/
  428. if((reg & CEC_FLAG_RXEND) != RESET)
  429. {
  430. /* clear IT */
  431. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND);
  432. /* Rx process is completed, restore hcec->RxState to Ready */
  433. hcec->RxState = HAL_CEC_STATE_READY;
  434. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  435. hcec->Init.RxBuffer -= hcec->RxXferSize;
  436. HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize);
  437. hcec->RxXferSize = 0U;
  438. }
  439. /* ----------------------------Tx Management----------------------------------*/
  440. /* CEC TX byte request interrupt ------------------------------------------------*/
  441. if((reg & CEC_FLAG_TXBR) != RESET)
  442. {
  443. if (hcec->TxXferCount == 0U)
  444. {
  445. /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */
  446. __HAL_CEC_LAST_BYTE_TX_SET(hcec);
  447. hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
  448. }
  449. else
  450. {
  451. hcec->Instance->TXDR = *hcec->pTxBuffPtr++;
  452. hcec->TxXferCount--;
  453. }
  454. /* clear Tx-Byte request flag */
  455. __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR);
  456. }
  457. /* CEC TX end interrupt ------------------------------------------------*/
  458. if((reg & CEC_FLAG_TXEND) != RESET)
  459. {
  460. __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXEND);
  461. /* Tx process is ended, restore hcec->gState to Ready */
  462. hcec->gState = HAL_CEC_STATE_READY;
  463. /* Call the Process Unlocked before calling the Tx call back API to give the possibility to
  464. start again the Transmission under the Tx call back API */
  465. __HAL_UNLOCK(hcec);
  466. hcec->ErrorCode = HAL_CEC_ERROR_NONE;
  467. HAL_CEC_TxCpltCallback(hcec);
  468. }
  469. /* ----------------------------Rx/Tx Error Management----------------------------------*/
  470. if ((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != 0U)
  471. {
  472. hcec->ErrorCode = reg;
  473. __HAL_CEC_CLEAR_FLAG(hcec, HAL_CEC_ERROR_RXOVR|HAL_CEC_ERROR_BRE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|HAL_CEC_ERROR_RXACKE|HAL_CEC_ERROR_TXUDR|HAL_CEC_ERROR_TXERR|HAL_CEC_ERROR_TXACKE);
  474. if((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE)) != RESET)
  475. {
  476. hcec->Init.RxBuffer-=hcec->RxXferSize;
  477. hcec->RxXferSize = 0U;
  478. hcec->RxState = HAL_CEC_STATE_READY;
  479. }
  480. else if (((reg & (CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != RESET) && ((reg & CEC_ISR_ARBLST) == RESET))
  481. {
  482. /* Set the CEC state ready to be able to start again the process */
  483. hcec->gState = HAL_CEC_STATE_READY;
  484. }
  485. /* Error Call Back */
  486. HAL_CEC_ErrorCallback(hcec);
  487. }
  488. }
  489. /**
  490. * @brief Tx Transfer completed callback
  491. * @param hcec: CEC handle
  492. * @retval None
  493. */
  494. __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec)
  495. {
  496. /* Prevent unused argument(s) compilation warning */
  497. UNUSED(hcec);
  498. /* NOTE : This function should not be modified, when the callback is needed,
  499. the HAL_CEC_TxCpltCallback can be implemented in the user file
  500. */
  501. }
  502. /**
  503. * @brief Rx Transfer completed callback
  504. * @param hcec: CEC handle
  505. * @param RxFrameSize: Size of frame
  506. * @retval None
  507. */
  508. __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize)
  509. {
  510. /* Prevent unused argument(s) compilation warning */
  511. UNUSED(hcec);
  512. UNUSED(RxFrameSize);
  513. /* NOTE : This function should not be modified, when the callback is needed,
  514. the HAL_CEC_RxCpltCallback can be implemented in the user file
  515. */
  516. }
  517. /**
  518. * @brief CEC error callbacks
  519. * @param hcec: CEC handle
  520. * @retval None
  521. */
  522. __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec)
  523. {
  524. /* Prevent unused argument(s) compilation warning */
  525. UNUSED(hcec);
  526. /* NOTE : This function should not be modified, when the callback is needed,
  527. the HAL_CEC_ErrorCallback can be implemented in the user file
  528. */
  529. }
  530. /**
  531. * @}
  532. */
  533. /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function
  534. * @brief CEC control functions
  535. *
  536. @verbatim
  537. ===============================================================================
  538. ##### Peripheral Control function #####
  539. ===============================================================================
  540. [..]
  541. This subsection provides a set of functions allowing to control the CEC.
  542. (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral.
  543. (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral.
  544. @endverbatim
  545. * @{
  546. */
  547. /**
  548. * @brief return the CEC state
  549. * @param hcec: pointer to a CEC_HandleTypeDef structure that contains
  550. * the configuration information for the specified CEC module.
  551. * @retval HAL state
  552. */
  553. HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec)
  554. {
  555. uint32_t temp1 = 0x00U, temp2 = 0x00U;
  556. temp1 = hcec->gState;
  557. temp2 = hcec->RxState;
  558. return (HAL_CEC_StateTypeDef)(temp1 | temp2);
  559. }
  560. /**
  561. * @brief Return the CEC error code
  562. * @param hcec : pointer to a CEC_HandleTypeDef structure that contains
  563. * the configuration information for the specified CEC.
  564. * @retval CEC Error Code
  565. */
  566. uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec)
  567. {
  568. return hcec->ErrorCode;
  569. }
  570. /**
  571. * @}
  572. */
  573. /**
  574. * @}
  575. */
  576. #endif /* STM32F446xx */
  577. #endif /* HAL_CEC_MODULE_ENABLED */
  578. /**
  579. * @}
  580. */
  581. /**
  582. * @}
  583. */
  584. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/