stm32f4xx_hal_cec.c 23 KB

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