PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/STM32F0xx_StdPeriph_Lib_V1.0.0/Utilities/STM32_EVAL/STM320518_EVAL/stm320518_eval_cec.c

https://github.com/rurume/stm32-test
C | 2044 lines | 1316 code | 336 blank | 392 comment | 358 complexity | 1d98fcf6242b29116aa9cd8372328463 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. ******************************************************************************
  3. * @file stm320518_eval_cec.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 20-April-2012
  7. * @brief This file provides all the STM320518-EVAL HDMI-CEC firmware functions.
  8. *
  9. * ===================================================================
  10. * Notes:
  11. * - This driver runs only on the STM320518-EVAL RevB
  12. * ===================================================================
  13. *
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  18. *
  19. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  20. * You may not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at:
  22. *
  23. * http://www.st.com/software_license_agreement_liberty_v2
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an "AS IS" BASIS,
  27. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm320518_eval_cec.h"
  35. /** @addtogroup Utilities
  36. * @{
  37. */
  38. /** @addtogroup STM32_EVAL
  39. * @{
  40. */
  41. /** @addtogroup STM320518_EVAL
  42. * @{
  43. */
  44. /** @defgroup STM320518_EVAL_CEC
  45. * @brief This file includes the CEC Stack driver for HDMI-CEC Module
  46. * of STM320518-EVAL board.
  47. * @{
  48. */
  49. /** @defgroup STM320518_EVAL_CEC_Private_Types
  50. * @{
  51. */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup STM320518_EVAL_CEC_Private_Defines
  56. * @{
  57. */
  58. /* Uncomment the define to use the LSE as a source clock */
  59. /* #define LSE_SOURCE_CLK */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup STM320518_EVAL_CEC_Private_Macros
  64. * @{
  65. */
  66. /**
  67. * @}
  68. */
  69. /** @defgroup STM320518_EVAL_CEC_Private_Variables
  70. * @{
  71. */
  72. __IO uint32_t ReceivedFrame = 0;
  73. __IO uint32_t SendFrame = 0;
  74. uint32_t BufferCount = 0, TxCounter = 0, RxCounter = 0;
  75. __IO uint8_t BufferPointer[15];
  76. __IO uint32_t ReceiveStatus = 0;
  77. __IO uint32_t SendStatus = 0;
  78. __IO uint8_t TransErrorCode = 0;
  79. uint8_t MyLogicalAddress = 0;
  80. uint16_t MyPhysicalAddress = 0;
  81. __IO uint8_t DeviceType = 0;
  82. #ifdef HDMI_CEC_USE_DDC
  83. uint8_t pBuffer[256];
  84. __IO uint16_t NumByteToRead = 255;
  85. #endif
  86. __IO uint8_t CECDevicesNumber = 0;
  87. HDMI_CEC_Message HDMI_CEC_TX_MessageStructPrivate;
  88. HDMI_CEC_Message HDMI_CEC_RX_MessageStructPrivate;
  89. HDMI_CEC_Message HDMI_CEC_TX_MessageStructure;
  90. __IO uint8_t FeatureOpcode = 0;
  91. __IO uint8_t AbortReason = 0;
  92. __IO uint8_t DeviceCount = 0;
  93. HDMI_CEC_Map HDMI_CEC_MapStruct;
  94. HDMI_CEC_Map HDMI_CEC_DeviceMap[14];
  95. /* CEC follower addresses */
  96. uint8_t* HDMI_CEC_Follower_String[13][2] =
  97. {
  98. {(uint8_t *)" TV ", (uint8_t *)"0"},
  99. {(uint8_t *)" Recording Device 1 ", (uint8_t *)"0"},
  100. {(uint8_t *)" Recording Device 2 ", (uint8_t *)"0"},
  101. {(uint8_t *)" Tuner 1 ", (uint8_t *)"0"},
  102. {(uint8_t *)" Playback Device 1 ", (uint8_t *)"0"},
  103. {(uint8_t *)" Audio System ", (uint8_t *)"0"},
  104. {(uint8_t *)" Tuner 2 ", (uint8_t *)"0"},
  105. {(uint8_t *)" Tuner 3 ", (uint8_t *)"0"},
  106. {(uint8_t *)" Playback Device 2 ", (uint8_t *)"0"},
  107. {(uint8_t *)" Recording Device 3 ", (uint8_t *)"0"},
  108. {(uint8_t *)" Tuner 4 ", (uint8_t *)"0"},
  109. {(uint8_t *)" Playback Device 3 ", (uint8_t *)"0"},
  110. {(uint8_t *)" Broadcast ", (uint8_t *)"1"}
  111. };
  112. /* EDID & CEA861 Extension */
  113. const uint8_t EDID_Structure[256] =
  114. {
  115. /*-------------------------- Block0: 128Bytes ------------------------------*/
  116. /* Header */
  117. 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
  118. /* Vendor & Product Identification */
  119. 0x4C, 0x2D, 0x57, 0x03, 0x00, 0x00, 0x00, 0x00, 0x22, 0x11,
  120. /* EDID Structure Version & Revision */
  121. 0x01, 0x03,
  122. /* Basic Display Parameters & Features */
  123. 0x80, 0x10, 0x09, 0x78, 0x0A,
  124. /* Color Characteristics */
  125. 0x1D, 0xED, 0xA7, 0x53, 0x34, 0xAC, 0x25, 0x12, 0x47, 0x4A,
  126. /* Established Timings */
  127. 0x20, 0x00, 0x00,
  128. /* Standard Timings */
  129. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  130. 0x01, 0x01, 0x01,
  131. /* Byte Data Blocks*/
  132. 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45, 0x00, 0xA0,
  133. 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
  134. 0x6E, 0x28, 0x55, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00,
  135. 0xFD, 0x00, 0x17, 0x3D, 0x1A, 0x44, 0x17, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20,
  136. 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53, 0x41, 0x4D, 0x53, 0x55, 0x4E,
  137. 0x47, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
  138. /* Extension Block Count */
  139. 0x01,
  140. /* Checksum C */
  141. 0xF3,
  142. /* ------------------------ Block1: 128Bytes------------------------------- */
  143. /* Refer to CEA 861 Standard for definitions */
  144. /* CEA 861 EXTENSION Block – Version 3 */
  145. 0x02, 0x03,
  146. /* Byte number within this block where the 18-byte DTDs begin */
  147. 0x21,
  148. /* Number of DTDs present */
  149. 0x00,
  150. /* Start of Data Block Collection */
  151. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  152. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153. /* IEEE Registration Identifier */
  154. 0x03, 0x0C, 0x00,
  155. /* Vendor Specific Data: Physical Address */
  156. 0x10, 0x00,
  157. /* Byte Data Blocks */
  158. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  159. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  164. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165. 0x00, 0x00, 0x00, 0x00, 0x00
  166. };
  167. /**
  168. * @}
  169. */
  170. /** @defgroup STM320518_EVAL_CEC_Private_Function_Prototypes
  171. * @{
  172. */
  173. static HDMI_CEC_Error SinkPhysicalAddressDiscovery(void);
  174. static HDMI_CEC_Error SourcePhysicalAddressDiscovery(void);
  175. static HDMI_CEC_Error LogicalAddressAllocation(void);
  176. /**
  177. * @}
  178. */
  179. /** @defgroup STM320518_EVAL_CEC_Private_Functions
  180. * @{
  181. */
  182. /**
  183. * @brief Initializes the HDMI CEC.
  184. * @param None
  185. * @retval HDMI_CEC_Error: CEC Error code
  186. */
  187. HDMI_CEC_Error HDMI_CEC_Init(void)
  188. {
  189. GPIO_InitTypeDef GPIO_InitStructure;
  190. CEC_InitTypeDef CEC_InitStructure;
  191. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  192. uint8_t sendcount = 0;
  193. uint32_t idx = 0;
  194. #ifdef LSE_SOURCE_CLK
  195. /* LSE */
  196. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  197. PWR_BackupAccessCmd(ENABLE);
  198. RCC_LSEConfig(RCC_LSE_ON);
  199. while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  200. {}
  201. RCC_CECCLKConfig(RCC_CECCLK_LSE);
  202. #endif
  203. for(idx=0; idx<12; idx++)
  204. {
  205. HDMI_CEC_Follower_String[idx][1] = (uint8_t *)"0";
  206. }
  207. /* Enable CEC and PWR clocks */
  208. RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC | RCC_APB1Periph_PWR, ENABLE);
  209. /* Enable CEC_LINE_GPIO clocks */
  210. RCC_AHBPeriphClockCmd(HDMI_CEC_LINE_GPIO_CLK, ENABLE);
  211. /* Configure CEC_LINE_GPIO as Output open drain */
  212. GPIO_InitStructure.GPIO_Pin = HDMI_CEC_LINE_PIN;
  213. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  214. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  215. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  216. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  217. GPIO_Init(HDMI_CEC_LINE_GPIO_PORT, &GPIO_InitStructure);
  218. GPIO_PinAFConfig(HDMI_CEC_LINE_GPIO_PORT, GPIO_PinSource10, GPIO_AF_0);
  219. /* CEC DeInit */
  220. CEC_DeInit();
  221. /* Configure CEC */
  222. CEC_InitStructure.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard;
  223. CEC_InitStructure.CEC_RxTolerance = CEC_RxTolerance_Standard;
  224. CEC_InitStructure.CEC_StopReception = CEC_StopReception_Off;
  225. CEC_InitStructure.CEC_BitRisingError = CEC_BitRisingError_Off;
  226. CEC_InitStructure.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off;
  227. CEC_InitStructure.CEC_BRDNoGen = CEC_BRDNoGen_Off;
  228. CEC_InitStructure.CEC_SFTOption = CEC_SFTOption_Off;
  229. CEC_Init(&CEC_InitStructure);
  230. /* Disable Listen Mode */
  231. CEC_ListenModeCmd(DISABLE);
  232. /* Enable CEC */
  233. CEC_Cmd(ENABLE);
  234. if (HDMI_CEC_ROOT == 0x1)
  235. {
  236. /* Logical Address Allocation */
  237. sendcount = 0;
  238. errorstatus = LogicalAddressAllocation();
  239. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  240. {
  241. sendcount++;
  242. errorstatus = LogicalAddressAllocation();
  243. }
  244. if (errorstatus != HDMI_CEC_OK)
  245. {
  246. /* Device Unregistered */
  247. return(errorstatus);
  248. }
  249. HDMI_CEC_CheckConnectedDevices();
  250. /* Set the CEC initiator address */
  251. CEC_OwnAddressConfig(MyLogicalAddress);
  252. /* Sink Physical Address discovery */
  253. errorstatus = SinkPhysicalAddressDiscovery();
  254. if (errorstatus != HDMI_CEC_OK)
  255. {
  256. /* Device not connected (Physical Address lost) */
  257. return(errorstatus);
  258. }
  259. }
  260. else
  261. {
  262. /* Source Physical Address discovery */
  263. errorstatus = SourcePhysicalAddressDiscovery();
  264. if (errorstatus != HDMI_CEC_OK)
  265. {
  266. /* Device not connected (Physical Address lost) */
  267. return(errorstatus);
  268. }
  269. /* Logical Address Allocation */
  270. sendcount = 0;
  271. errorstatus = LogicalAddressAllocation();
  272. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  273. {
  274. sendcount++;
  275. errorstatus = LogicalAddressAllocation();
  276. }
  277. if (errorstatus != HDMI_CEC_OK)
  278. {
  279. /* Device Unregistered */
  280. return(errorstatus);
  281. }
  282. HDMI_CEC_CheckConnectedDevices();
  283. /* Set the CEC initiator address */
  284. CEC_OwnAddressConfig(MyLogicalAddress);
  285. }
  286. /* Activate CEC interrupts associated to the set of TX flags */
  287. CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE);
  288. /* Activate CEC interrupts associated to the set of RX flags */
  289. CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE);
  290. /* Activate CEC interrupts associated to the set of TX error */
  291. CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_TXUDR|CEC_IT_ARBLST,ENABLE);
  292. /* Activate CEC interrupts associated to the set of RX error */
  293. CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE|CEC_IT_RXOVR,ENABLE);
  294. /* Report physical address */
  295. errorstatus = HDMI_CEC_ReportPhysicalAddress();
  296. sendcount = 0;
  297. RxCounter = 0;
  298. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  299. {
  300. sendcount++;
  301. errorstatus = HDMI_CEC_ReportPhysicalAddress();
  302. }
  303. if (errorstatus != HDMI_CEC_OK)
  304. {
  305. /* Device Unregistred */
  306. return(errorstatus);
  307. }
  308. return errorstatus;
  309. }
  310. /**
  311. * @brief Transmit message by taking data from typedef struct CEC_Meassage
  312. * @param CEC_TX_MessageStructure: pointer to an CEC_Message structure that contains
  313. * the message to be sent.
  314. * @retval HDMI_CEC_Error: CEC Error code
  315. */
  316. HDMI_CEC_Error HDMI_CEC_TransmitMessage(HDMI_CEC_Message *HDMI_CEC_TX_MessageStructure)
  317. {
  318. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  319. __IO uint32_t count = 0, j = 0;
  320. SendFrame = 0;
  321. SendStatus = 0;
  322. TxCounter = 0;
  323. BufferCount = 0;
  324. HDMI_CEC_TX_MessageStructPrivate = *HDMI_CEC_TX_MessageStructure;
  325. /* Initialize BufferPointer */
  326. for (j = 0; j < 15; j++)
  327. {
  328. BufferPointer[j] = 0;
  329. }
  330. BufferPointer[0] = HDMI_CEC_TX_MessageStructPrivate.Opcode;
  331. for (BufferCount = 1; BufferCount < HDMI_CEC_TX_MessageStructPrivate.TxMessageLength + 1; BufferCount++)
  332. {
  333. BufferPointer[BufferCount] = HDMI_CEC_TX_MessageStructPrivate.Operande[BufferCount - 1];
  334. }
  335. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  336. /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */
  337. CEC_SendData(HDMI_CEC_TX_MessageStructPrivate.Header);
  338. /* Initiate Message Transmission */
  339. CEC_StartOfMessage();
  340. while ((SendFrame == 0) && (count < HDMI_CEC_TIMEOUT_VALUE))
  341. {
  342. count++;
  343. }
  344. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  345. {
  346. errorstatus = HDMI_CEC_TIMEOUT;
  347. return(errorstatus);
  348. }
  349. if (SendStatus == 0)
  350. {
  351. errorstatus = (HDMI_CEC_Error) TransErrorCode;
  352. }
  353. return errorstatus;
  354. }
  355. /**
  356. * @brief Get the ISR register status.
  357. * @param None
  358. * @retval HDMI_CEC_Error: CEC Error code
  359. */
  360. HDMI_CEC_Error HDMI_CEC_GetErrorStatus (void)
  361. {
  362. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  363. /* RX Overrun error case*/
  364. if (CEC_GetFlagStatus(CEC_FLAG_RXOVR) != RESET)
  365. {
  366. errorstatus = HDMI_CEC_RX_OVERRUN;
  367. CEC_ClearFlag(CEC_FLAG_RXOVR);
  368. }
  369. /* Bit Rising error case */
  370. if (CEC_GetFlagStatus(CEC_FLAG_BRE) != RESET)
  371. {
  372. errorstatus = HDMI_CEC_RX_BIT_RISING;
  373. CEC_ClearFlag(CEC_FLAG_BRE);
  374. }
  375. /* Short Bit Period error case */
  376. if (CEC_GetFlagStatus(CEC_FLAG_SBPE) != RESET)
  377. {
  378. errorstatus = HDMI_CEC_RX_SHORT_BIT_PERIOD;
  379. CEC_ClearFlag(CEC_FLAG_SBPE);
  380. }
  381. /* Long Bit Period error case */
  382. if (CEC_GetFlagStatus(CEC_FLAG_LBPE) != RESET)
  383. {
  384. errorstatus = HDMI_CEC_RX_LONG_BIT_PERIOD;
  385. CEC_ClearFlag(CEC_FLAG_LBPE);
  386. }
  387. /* RX Acknowledge error case */
  388. if (CEC_GetFlagStatus(CEC_FLAG_RXACKE) != RESET)
  389. {
  390. errorstatus = HDMI_CEC_RX_ACKNOWLEDGE;
  391. CEC_ClearFlag(CEC_FLAG_RXACKE);
  392. }
  393. /* Arbitration Lost error case */
  394. if (CEC_GetFlagStatus(CEC_FLAG_ARBLST) != RESET)
  395. {
  396. errorstatus = HDMI_CEC_ARBITRATION_LOST;
  397. CEC_ClearFlag(CEC_FLAG_ARBLST);
  398. }
  399. /* TX underrun error case */
  400. if (CEC_GetFlagStatus(CEC_FLAG_TXUDR) != RESET)
  401. {
  402. errorstatus = HDMI_CEC_TX_UNDERRUN;
  403. CEC_ClearFlag(CEC_FLAG_TXUDR);
  404. }
  405. /* TX error case */
  406. if (CEC_GetFlagStatus(CEC_FLAG_TXERR) != RESET)
  407. {
  408. errorstatus = HDMI_CEC_TX_ERROR;
  409. CEC_ClearFlag(CEC_FLAG_TXERR);
  410. }
  411. /* TX Acknowledge error case */
  412. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  413. {
  414. errorstatus = HDMI_CEC_TX_ACKNOWLEDGE;
  415. CEC_ClearFlag(CEC_FLAG_TXACKE);
  416. }
  417. return errorstatus;
  418. }
  419. /**
  420. * @brief Allows to process all the interrupts that are high.
  421. * @param None
  422. * @retval None
  423. */
  424. void HDMI_CEC_ProcessIRQSrc(void)
  425. {
  426. /********************** Reception *******************************************/
  427. /* Check if a reception error occured */
  428. if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR))
  429. {
  430. /* Set receive status bit (Error) */
  431. ReceiveStatus = 0;
  432. ReceivedFrame = 1;
  433. CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR);
  434. RxCounter = 0;
  435. }
  436. if (CEC_GetITStatus(CEC_IT_RXBR))
  437. {
  438. /* Check if the byte received is a Header */
  439. if (RxCounter == 0)
  440. {
  441. HDMI_CEC_RX_MessageStructPrivate.Header = CEC_ReceiveData();
  442. RxCounter ++;
  443. }
  444. else if(RxCounter == 1) /* Receive opcode in the reception buffer */
  445. {
  446. HDMI_CEC_RX_MessageStructPrivate.Opcode = CEC_ReceiveData();
  447. RxCounter++;
  448. }
  449. else /* Receive each byte except header and opcode in the reception buffer */
  450. {
  451. HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-2] = CEC_ReceiveData();
  452. RxCounter++;
  453. }
  454. CEC_ClearITPendingBit(CEC_IT_RXBR);
  455. }
  456. /* Check if the byte received is the last one of the message */
  457. if (CEC_GetITStatus(CEC_IT_RXEND))
  458. {
  459. if (RxCounter == 1)
  460. {
  461. HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter-1;
  462. }
  463. else
  464. {
  465. HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter-2;
  466. ReceivedFrame = 1;
  467. }
  468. /* Set the receive status */
  469. ReceiveStatus = SUCCESS;
  470. RxCounter = 0;
  471. /* Clear all reception flags */
  472. CEC_ClearITPendingBit(CEC_IT_RXEND);
  473. }
  474. /********************** Transmission ****************************************/
  475. /* Check if a transmission error occurred */
  476. if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST))
  477. {
  478. TransErrorCode = HDMI_CEC_GetErrorStatus();
  479. CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST);
  480. SendFrame = 1;
  481. SendStatus = 0;
  482. TxCounter = 0;
  483. }
  484. /* Check if end of message bit is set in the data to be transmitted */
  485. if (CEC_GetITStatus(CEC_IT_TXEND))
  486. {
  487. CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR);
  488. SendFrame = 1;
  489. SendStatus = SUCCESS;
  490. }
  491. /* Check if data byte has been sent */
  492. else if (CEC_GetITStatus(CEC_IT_TXBR))
  493. {
  494. /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */
  495. if (TxCounter == (HDMI_CEC_TX_MessageStructPrivate.TxMessageLength))
  496. {
  497. CEC_EndOfMessage();
  498. CEC_SendData(BufferPointer[TxCounter++]);
  499. }
  500. else
  501. {
  502. /* Put the byte in the TX Buffer */
  503. CEC_SendData(BufferPointer[TxCounter++]);
  504. }
  505. CEC_ClearITPendingBit(CEC_IT_TXBR);
  506. }
  507. }
  508. /**
  509. * @brief Report physical address to all other devices thus allowing any
  510. device to create a map of the network.
  511. * @param None
  512. * @retval HDMI_CEC_Error: CEC Error code.
  513. */
  514. HDMI_CEC_Error HDMI_CEC_ReportPhysicalAddress(void)
  515. {
  516. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  517. HDMI_CEC_Message HDMI_CEC_TX_Message;
  518. HDMI_CEC_TX_Message.Header = ((MyLogicalAddress << 4) | 0xF);
  519. HDMI_CEC_TX_Message.Opcode = HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS;
  520. HDMI_CEC_TX_Message.Operande[0] = MyPhysicalAddress >> 8;
  521. HDMI_CEC_TX_Message.Operande[1] = MyPhysicalAddress & 0xFF;
  522. HDMI_CEC_TX_Message.Operande[2] = DeviceType;
  523. HDMI_CEC_TX_Message.TxMessageLength = 0x03;
  524. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_Message);
  525. return errorstatus;
  526. }
  527. /**
  528. * @brief Handle CEC command receive callback.
  529. * @note When receiving the STANDBY Opcode command, the system is entered in
  530. * Stop mode and when wakeup, the PLL is configured as system clock and
  531. * the HSI is selected as PLL source.
  532. * @param None
  533. * @retval None
  534. */
  535. void HDMI_CEC_CommandCallBack(void)
  536. {
  537. uint8_t i = 0, sendcount = 0;
  538. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  539. ErrorStatus HSEStartUpStatus;
  540. switch (HDMI_CEC_RX_MessageStructPrivate.Opcode)
  541. {
  542. case HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
  543. HDMI_CEC_MapStruct.PhysicalAddress_A = HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4;
  544. HDMI_CEC_MapStruct.PhysicalAddress_B = HDMI_CEC_RX_MessageStructPrivate.Operande[1] & 0x0F;
  545. HDMI_CEC_MapStruct.PhysicalAddress_C = HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4;
  546. HDMI_CEC_MapStruct.PhysicalAddress_D = HDMI_CEC_RX_MessageStructPrivate.Operande[0] & 0x0F;
  547. HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
  548. HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
  549. HDMI_CEC_DeviceMap[DeviceCount] = HDMI_CEC_MapStruct;
  550. HDMI_CEC_Follower_String[(HDMI_CEC_DeviceMap[DeviceCount].LogicalAddress)][1] = (uint8_t *)"1";
  551. DeviceCount++;
  552. break;
  553. case HDMI_CEC_OPCODE_STANDBY:
  554. /* Request to enter Stop mode */
  555. PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
  556. /* Enable HSE */
  557. RCC_HSEConfig(RCC_HSE_ON);
  558. /* Wait till HSE is ready */
  559. HSEStartUpStatus = RCC_WaitForHSEStartUp();
  560. if (HSEStartUpStatus == SUCCESS)
  561. {
  562. /* Enable PLL */
  563. RCC_PLLCmd(ENABLE);
  564. /* Wait till PLL is ready */
  565. while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  566. {}
  567. /* Select PLL as system clock source */
  568. RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
  569. /* Wait till PLL is used as system clock source */
  570. while (RCC_GetSYSCLKSource() != 0x08)
  571. {}
  572. }
  573. break;
  574. case HDMI_CEC_OPCODE_GET_CEC_VERSION:
  575. /* Send the Used CEC version */
  576. HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
  577. HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_CEC_VERSION;
  578. HDMI_CEC_TX_MessageStructPrivate.Operande[0] = HDMI_CEC_VERSION; /* CEC Version */
  579. HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x01;
  580. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  581. /* Retransmit message until 5 time */
  582. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  583. {
  584. sendcount++;
  585. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  586. }
  587. break;
  588. case HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
  589. /* Send the Physical address */
  590. errorstatus = HDMI_CEC_ReportPhysicalAddress();
  591. sendcount = 0;
  592. /* Retransmit message until 5 time */
  593. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  594. {
  595. sendcount++;
  596. errorstatus = HDMI_CEC_ReportPhysicalAddress();
  597. }
  598. break;
  599. case HDMI_CEC_OPCODE_FEATURE_ABORT:
  600. /* The device doesn't support the requested message type, or that it cannot
  601. execute it at the present time. */
  602. FeatureOpcode = HDMI_CEC_RX_MessageStructPrivate.Operande[0];
  603. AbortReason = HDMI_CEC_RX_MessageStructPrivate.Operande[1];
  604. break;
  605. case HDMI_CEC_OPCODE_GIVE_OSD_NAME:
  606. /* Send the OSD name = STM320518 CEC */
  607. HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
  608. HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_SET_OSD_NAME;
  609. /* STM320518 */
  610. HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x53;
  611. HDMI_CEC_TX_MessageStructPrivate.Operande[1] = 0x54;
  612. HDMI_CEC_TX_MessageStructPrivate.Operande[2] = 0x4D;
  613. HDMI_CEC_TX_MessageStructPrivate.Operande[3] = 0x33;
  614. HDMI_CEC_TX_MessageStructPrivate.Operande[4] = 0x32;
  615. HDMI_CEC_TX_MessageStructPrivate.Operande[5] = 0x30;
  616. HDMI_CEC_TX_MessageStructPrivate.Operande[6] = 0x35;
  617. HDMI_CEC_TX_MessageStructPrivate.Operande[7] = 0x31;
  618. HDMI_CEC_TX_MessageStructPrivate.Operande[8] = 0x38;
  619. HDMI_CEC_TX_MessageStructPrivate.Operande[9] = 0x20;
  620. /* CEC */
  621. HDMI_CEC_TX_MessageStructPrivate.Operande[10] = 0x43;
  622. HDMI_CEC_TX_MessageStructPrivate.Operande[11] = 0x45;
  623. HDMI_CEC_TX_MessageStructPrivate.Operande[12] = 0x43;
  624. HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 13;
  625. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  626. sendcount = 0;
  627. /* Retransmit message until 5 time */
  628. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  629. {
  630. sendcount++;
  631. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  632. }
  633. break;
  634. case HDMI_CEC_OPCODE_ROUTING_CHANGE:
  635. for (i = 0;i < 0x14;i++)
  636. {
  637. if ((HDMI_CEC_DeviceMap[i].PhysicalAddress_A == HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4) &&
  638. (HDMI_CEC_DeviceMap[i].PhysicalAddress_B == HDMI_CEC_RX_MessageStructPrivate.Operande[1]&0x0F) &&
  639. (HDMI_CEC_DeviceMap[i].PhysicalAddress_C == HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4) &&
  640. (HDMI_CEC_DeviceMap[i].PhysicalAddress_D == (HDMI_CEC_RX_MessageStructPrivate.Operande[0]&0x0F)))
  641. {
  642. HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
  643. HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
  644. HDMI_CEC_DeviceMap[i] = HDMI_CEC_MapStruct;
  645. }
  646. }
  647. break;
  648. default:
  649. /* Send Abort feature */
  650. HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
  651. HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_FEATURE_ABORT;
  652. HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x02; /* Defines command to be performed */
  653. HDMI_CEC_TX_MessageStructPrivate.Operande[1] = HDMI_CEC_REFUSED; /* Reason for abort feature */
  654. HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x02;
  655. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  656. sendcount = 0;
  657. /* Retransmit message until 5 time */
  658. while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
  659. {
  660. sendcount++;
  661. errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
  662. }
  663. break;
  664. }
  665. }
  666. /**
  667. * @brief Check the connected CEC devices.
  668. * @param None
  669. * @retval HDMI_CEC_Error
  670. */
  671. HDMI_CEC_Error HDMI_CEC_CheckConnectedDevices(void)
  672. {
  673. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  674. uint32_t count = 0, i = 1;
  675. /*------------------------------- TV device --------------------------------*/
  676. CEC_EndOfMessage();
  677. CEC_SendData((MyLogicalAddress << 4) | 0x0);
  678. /* Start of message */
  679. CEC_StartOfMessage();
  680. /* Wait till the header message is sent */
  681. while (count < HDMI_CEC_TIMEOUT_VALUE)
  682. {
  683. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  684. {
  685. errorstatus = HDMI_CEC_GetErrorStatus();
  686. CEC_ClearFlag( CEC_FLAG_TXACKE);
  687. break;
  688. }
  689. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  690. {
  691. errorstatus = HDMI_CEC_OK;
  692. break;
  693. }
  694. count++;
  695. }
  696. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  697. {
  698. errorstatus = HDMI_CEC_TIMEOUT;
  699. return(errorstatus);
  700. }
  701. if (errorstatus == HDMI_CEC_OK)
  702. {
  703. HDMI_CEC_Follower_String[0][1] = (uint8_t *)"1";
  704. i++;
  705. errorstatus = HDMI_CEC_OK;
  706. }
  707. /* Clear CEC ISR register */
  708. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  709. /*---------------------------- Recording device 1 --------------------------*/
  710. CEC_EndOfMessage();
  711. CEC_SendData((MyLogicalAddress << 4)|0x1);
  712. /* Start of message */
  713. CEC_StartOfMessage();
  714. /* Wait till the header message is sent */
  715. while (count < HDMI_CEC_TIMEOUT_VALUE)
  716. {
  717. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  718. {
  719. errorstatus = HDMI_CEC_GetErrorStatus();
  720. CEC_ClearFlag( CEC_FLAG_TXACKE);
  721. break;
  722. }
  723. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  724. {
  725. errorstatus = HDMI_CEC_OK;
  726. break;
  727. }
  728. count++;
  729. }
  730. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  731. {
  732. errorstatus = HDMI_CEC_TIMEOUT;
  733. return(errorstatus);
  734. }
  735. if (errorstatus == HDMI_CEC_OK)
  736. {
  737. HDMI_CEC_Follower_String[1][1] = (uint8_t *)"1";
  738. i++;
  739. errorstatus = HDMI_CEC_OK;
  740. }
  741. /* Clear CEC ISR register */
  742. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  743. /*---------------------------- Recording device 2 --------------------------*/
  744. CEC_EndOfMessage();
  745. CEC_SendData((MyLogicalAddress << 4) | 0x2);
  746. /* Start of message */
  747. CEC_StartOfMessage();
  748. /* Wait till the header message is sent */
  749. while (count < HDMI_CEC_TIMEOUT_VALUE)
  750. {
  751. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  752. {
  753. errorstatus = HDMI_CEC_GetErrorStatus();
  754. CEC_ClearFlag( CEC_FLAG_TXACKE);
  755. break;
  756. }
  757. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  758. {
  759. errorstatus = HDMI_CEC_OK;
  760. break;
  761. }
  762. count++;
  763. }
  764. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  765. {
  766. errorstatus = HDMI_CEC_TIMEOUT;
  767. return(errorstatus);
  768. }
  769. if (errorstatus == HDMI_CEC_OK)
  770. {
  771. HDMI_CEC_Follower_String[2][1] = (uint8_t *)"1";
  772. i++;
  773. errorstatus = HDMI_CEC_OK;
  774. }
  775. /* Clear CEC ISR register */
  776. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  777. /*------------------------------ Tuner 1 -----------------------------------*/
  778. CEC_EndOfMessage();
  779. CEC_SendData((MyLogicalAddress << 4) | 0x3);
  780. /* Start of message */
  781. CEC_StartOfMessage();
  782. /* Wait till the header message is sent */
  783. while (count < HDMI_CEC_TIMEOUT_VALUE)
  784. {
  785. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  786. {
  787. errorstatus = HDMI_CEC_GetErrorStatus();
  788. CEC_ClearFlag( CEC_FLAG_TXACKE);
  789. break;
  790. }
  791. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  792. {
  793. errorstatus = HDMI_CEC_OK;
  794. break;
  795. }
  796. count++;
  797. }
  798. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  799. {
  800. errorstatus = HDMI_CEC_TIMEOUT;
  801. return(errorstatus);
  802. }
  803. if (errorstatus == HDMI_CEC_OK)
  804. {
  805. HDMI_CEC_Follower_String[3][1] = (uint8_t *)"1";
  806. i++;
  807. errorstatus = HDMI_CEC_OK;
  808. }
  809. /* Clear CEC ISR register */
  810. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  811. /*---------------------------- Playback device 1 ---------------------------*/
  812. CEC_EndOfMessage();
  813. CEC_SendData((MyLogicalAddress << 4) | 0x4);
  814. /* Start of message */
  815. CEC_StartOfMessage();
  816. /* Wait till the header message is sent */
  817. while (count < HDMI_CEC_TIMEOUT_VALUE)
  818. {
  819. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  820. {
  821. errorstatus = HDMI_CEC_GetErrorStatus();
  822. CEC_ClearFlag(CEC_FLAG_TXACKE);
  823. break;
  824. }
  825. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  826. {
  827. errorstatus = HDMI_CEC_OK;
  828. break;
  829. }
  830. count++;
  831. }
  832. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  833. {
  834. errorstatus = HDMI_CEC_TIMEOUT;
  835. return(errorstatus);
  836. }
  837. if (errorstatus == HDMI_CEC_OK)
  838. {
  839. HDMI_CEC_Follower_String[4][1] = (uint8_t *)"1";
  840. i++;
  841. errorstatus = HDMI_CEC_OK;
  842. }
  843. /* Clear CEC ISR register */
  844. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  845. /*-------------------------------- Audio system ----------------------------*/
  846. CEC_EndOfMessage();
  847. CEC_SendData((MyLogicalAddress << 4) | 0x5);
  848. /* Start of message */
  849. CEC_StartOfMessage();
  850. /* Wait till the header message is sent */
  851. while (count < HDMI_CEC_TIMEOUT_VALUE)
  852. {
  853. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  854. {
  855. errorstatus = HDMI_CEC_GetErrorStatus();
  856. CEC_ClearFlag(CEC_FLAG_TXACKE);
  857. break;
  858. }
  859. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  860. {
  861. errorstatus = HDMI_CEC_OK;
  862. break;
  863. }
  864. count++;
  865. }
  866. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  867. {
  868. errorstatus = HDMI_CEC_TIMEOUT;
  869. return(errorstatus);
  870. }
  871. if (errorstatus == HDMI_CEC_OK)
  872. {
  873. HDMI_CEC_Follower_String[5][1] = (uint8_t *)"1";
  874. i++;
  875. errorstatus = HDMI_CEC_OK;
  876. }
  877. /* Clear CEC ISR register */
  878. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  879. /*--------------------------------- Tuner 2 --------------------------------*/
  880. CEC_EndOfMessage();
  881. CEC_SendData((MyLogicalAddress << 4) | 0x6);
  882. /* Start of message */
  883. CEC_StartOfMessage();
  884. /* Wait till the header message is sent */
  885. while (count < HDMI_CEC_TIMEOUT_VALUE)
  886. {
  887. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  888. {
  889. errorstatus = HDMI_CEC_GetErrorStatus();
  890. CEC_ClearFlag(CEC_FLAG_TXACKE);
  891. break;
  892. }
  893. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  894. {
  895. errorstatus = HDMI_CEC_OK;
  896. break;
  897. }
  898. count++;
  899. }
  900. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  901. {
  902. errorstatus = HDMI_CEC_TIMEOUT;
  903. return(errorstatus);
  904. }
  905. if (errorstatus == HDMI_CEC_OK)
  906. {
  907. HDMI_CEC_Follower_String[6][1] = (uint8_t *)"1";
  908. i++;
  909. errorstatus = HDMI_CEC_OK;
  910. }
  911. /* Clear CEC ISR register */
  912. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  913. /*--------------------------------- Tuner 3 --------------------------------*/
  914. CEC_EndOfMessage();
  915. CEC_SendData((MyLogicalAddress << 4) | 0x7);
  916. /* Start of message */
  917. CEC_StartOfMessage();
  918. /* Wait till the header message is sent */
  919. while (count < HDMI_CEC_TIMEOUT_VALUE)
  920. {
  921. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  922. {
  923. errorstatus = HDMI_CEC_GetErrorStatus();
  924. CEC_ClearFlag(CEC_FLAG_TXACKE);
  925. break;
  926. }
  927. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  928. {
  929. errorstatus = HDMI_CEC_OK;
  930. break;
  931. }
  932. count++;
  933. }
  934. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  935. {
  936. errorstatus = HDMI_CEC_TIMEOUT;
  937. return(errorstatus);
  938. }
  939. if (errorstatus == HDMI_CEC_OK)
  940. {
  941. HDMI_CEC_Follower_String[7][1] = (uint8_t *)"1";
  942. i++;
  943. errorstatus = HDMI_CEC_OK;
  944. }
  945. /* Clear CEC ISR register */
  946. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  947. /*---------------------------- Playback device 2 ---------------------------*/
  948. CEC_EndOfMessage();
  949. CEC_SendData((MyLogicalAddress << 4) | 0x8);
  950. /* Start of message */
  951. CEC_StartOfMessage();
  952. /* Wait till the header message is sent */
  953. while(count < HDMI_CEC_TIMEOUT_VALUE)
  954. {
  955. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  956. {
  957. errorstatus = HDMI_CEC_GetErrorStatus();
  958. CEC_ClearFlag(CEC_FLAG_TXACKE);
  959. break;
  960. }
  961. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  962. {
  963. errorstatus = HDMI_CEC_OK;
  964. break;
  965. }
  966. count++;
  967. }
  968. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  969. {
  970. errorstatus = HDMI_CEC_TIMEOUT;
  971. return(errorstatus);
  972. }
  973. if (errorstatus == HDMI_CEC_OK)
  974. {
  975. HDMI_CEC_Follower_String[8][1] = (uint8_t *)"1";
  976. i++;
  977. errorstatus = HDMI_CEC_OK;
  978. }
  979. /* Clear CEC ISR register */
  980. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  981. /*---------------------------- Recording device 3 --------------------------*/
  982. CEC_EndOfMessage();
  983. CEC_SendData((MyLogicalAddress << 4) | 0x9);
  984. /* Start of message */
  985. CEC_StartOfMessage();
  986. /* Wait till the header message is sent */
  987. while(count < HDMI_CEC_TIMEOUT_VALUE)
  988. {
  989. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  990. {
  991. errorstatus = HDMI_CEC_GetErrorStatus();
  992. CEC_ClearFlag(CEC_FLAG_TXACKE);
  993. break;
  994. }
  995. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  996. {
  997. errorstatus = HDMI_CEC_OK;
  998. break;
  999. }
  1000. count++;
  1001. }
  1002. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1003. {
  1004. errorstatus = HDMI_CEC_TIMEOUT;
  1005. return(errorstatus);
  1006. }
  1007. if (errorstatus == HDMI_CEC_OK)
  1008. {
  1009. HDMI_CEC_Follower_String[9][1] = (uint8_t *)"1";
  1010. i++;
  1011. errorstatus = HDMI_CEC_OK;
  1012. }
  1013. /* Clear CEC ISR register */
  1014. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  1015. /*-------------------------------- Tuner 4 ---------------------------------*/
  1016. CEC_EndOfMessage();
  1017. CEC_SendData((MyLogicalAddress << 4) | 0xA);
  1018. /* Start of message */
  1019. CEC_StartOfMessage();
  1020. /* Wait till the header message is sent */
  1021. while (count < HDMI_CEC_TIMEOUT_VALUE)
  1022. {
  1023. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  1024. {
  1025. errorstatus = HDMI_CEC_GetErrorStatus();
  1026. CEC_ClearFlag(CEC_FLAG_TXACKE);
  1027. break;
  1028. }
  1029. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1030. {
  1031. errorstatus = HDMI_CEC_OK;
  1032. break;
  1033. }
  1034. count++;
  1035. }
  1036. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1037. {
  1038. errorstatus = HDMI_CEC_TIMEOUT;
  1039. return(errorstatus);
  1040. }
  1041. if (errorstatus == HDMI_CEC_OK)
  1042. {
  1043. HDMI_CEC_Follower_String[10][1] = (uint8_t *)"1";
  1044. i++;
  1045. errorstatus = HDMI_CEC_OK;
  1046. }
  1047. /* Clear CEC ISR register */
  1048. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  1049. /*---------------------------- Playback device 3 ---------------------------*/
  1050. CEC_EndOfMessage();
  1051. CEC_SendData((MyLogicalAddress << 4) | 0xB);
  1052. /* Start of message */
  1053. CEC_StartOfMessage();
  1054. /* Wait till the header message is sent */
  1055. while(count < HDMI_CEC_TIMEOUT_VALUE)
  1056. {
  1057. if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
  1058. {
  1059. errorstatus = HDMI_CEC_GetErrorStatus();
  1060. CEC_ClearFlag(CEC_FLAG_TXACKE);
  1061. break;
  1062. }
  1063. else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1064. {
  1065. errorstatus = HDMI_CEC_OK;
  1066. break;
  1067. }
  1068. count++;
  1069. }
  1070. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1071. {
  1072. errorstatus = HDMI_CEC_TIMEOUT;
  1073. return(errorstatus);
  1074. }
  1075. if (errorstatus == HDMI_CEC_OK)
  1076. {
  1077. HDMI_CEC_Follower_String[11][1] = (uint8_t *)"1";
  1078. i++;
  1079. errorstatus = HDMI_CEC_OK;
  1080. }
  1081. /* Clear CEC ISR register */
  1082. CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
  1083. CECDevicesNumber = i - 1;
  1084. return errorstatus;
  1085. }
  1086. /**
  1087. * @brief Sink Physical address discovery.
  1088. * @param None
  1089. * @retval HDMI_CEC_Error: CEC Error code.
  1090. */
  1091. static HDMI_CEC_Error SinkPhysicalAddressDiscovery(void)
  1092. {
  1093. uint32_t DataNum=0;
  1094. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  1095. uint32_t i = 0;
  1096. I2C_InitTypeDef I2C_InitStructure;
  1097. GPIO_InitTypeDef GPIO_InitStructure;
  1098. /*------------------------------ Physical address discovery ----------------*/
  1099. /* if HDMI_CEC_ROOT == 0x1*/
  1100. MyPhysicalAddress = 0x0000;
  1101. /* The HDMI-CEC here is configured as sink or as a repeater. The configuration
  1102. of the +5V power signal and the HPD should be well configured.
  1103. Implement here the EDID Structure to be sent to the HDMI source.
  1104. For more details please refer to the HDMI specification.
  1105. The EDID structure should be sent to the device source using the DDC Channel
  1106. and using the HPD signal. */
  1107. /* Enable CEC_I2C clocks */
  1108. RCC_APB1PeriphClockCmd(HDMI_CEC_SINK_I2C_CLK, ENABLE);
  1109. /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */
  1110. RCC_AHBPeriphClockCmd(HDMI_CEC_SINK_I2C_GPIO_CLK | HDMI_CEC_HPD_SINK_GPIO_CLK, ENABLE);
  1111. I2C_DeInit(HDMI_CEC_SINK_I2C);
  1112. GPIO_PinAFConfig(HDMI_CEC_SINK_I2C_GPIO_PORT, HDMI_CEC_SINK_I2C_SCL_PIN_SOURCE, GPIO_AF_1);
  1113. GPIO_PinAFConfig(HDMI_CEC_SINK_I2C_GPIO_PORT, HDMI_CEC_SINK_I2C_SDA_PIN_SOURCE, GPIO_AF_1);
  1114. /* Set PF6/PF7 as OD AF - I2C2_SCL/I2C2_SDA of Source*/
  1115. GPIO_InitStructure.GPIO_Pin = HDMI_CEC_SINK_I2C_SDA_PIN | HDMI_CEC_SINK_I2C_SCL_PIN;
  1116. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  1117. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  1118. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  1119. GPIO_Init(HDMI_CEC_SINK_I2C_GPIO_PORT, &GPIO_InitStructure);
  1120. /* Set PA11 as PP - HPD */
  1121. GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_SINK_PIN;
  1122. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  1123. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  1124. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  1125. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  1126. GPIO_Init(HDMI_CEC_HPD_SINK_GPIO_PORT, &GPIO_InitStructure);
  1127. RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
  1128. HDMI_CEC_SINK_I2C->CR1 &= (uint16_t)(~I2C_CR1_NOSTRETCH);
  1129. I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  1130. I2C_InitStructure.I2C_Timing = HDMI_CEC_I2C_TIMING;
  1131. I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
  1132. /* Initialize the I2C_DigitalFilter member */
  1133. I2C_InitStructure.I2C_DigitalFilter = 0x00;
  1134. I2C_InitStructure.I2C_OwnAddress1 = HDMI_CEC_I2C_SLAVE_ADDRESS7;
  1135. I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  1136. I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  1137. I2C_Init(HDMI_CEC_SINK_I2C, &I2C_InitStructure);
  1138. /* Set the Hot plug detect signal */
  1139. HDMI_CEC_HPD_HIGH();
  1140. /* The HDMI-CEC here is configured as source or as a repeater. The configuration
  1141. of the +5V power signal and the HPD should be well configured.
  1142. The source should wait for HPD and then read the EDID structure. */
  1143. while(GPIO_ReadInputDataBit(HDMI_CEC_HPD_SINK_GPIO_PORT, HDMI_CEC_HPD_SINK_PIN) == RESET)
  1144. {
  1145. }
  1146. /* Wait for 100 ms after HPD was received */
  1147. for(i = 0; i <0x5FFFFF; i++)
  1148. {
  1149. }
  1150. /* Enable HDMI_CEC_SINK_I2C */
  1151. I2C_Cmd(HDMI_CEC_SINK_I2C, ENABLE);
  1152. /* Wait until ADDR is set */
  1153. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_ADDR));
  1154. /* Clear ADDR flag */
  1155. HDMI_CEC_SINK_I2C->ICR = I2C_ICR_ADDRCF;
  1156. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_RXNE));
  1157. HDMI_CEC_SINK_I2C->RXDR;
  1158. /* Wait until ADDR is set */
  1159. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_ADDR));
  1160. /* Clear ADDR flag */
  1161. HDMI_CEC_SINK_I2C->ICR = I2C_ICR_ADDRCF;
  1162. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_TXIS));
  1163. while (DataNum != 256)
  1164. {
  1165. if (HDMI_CEC_SINK_I2C->ISR & I2C_ISR_TXIS)
  1166. {
  1167. /* Write data to TXDR */
  1168. HDMI_CEC_SINK_I2C->TXDR = (uint8_t)(EDID_Structure[DataNum++]);
  1169. }
  1170. }
  1171. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_STOPF));
  1172. while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_NACKF));
  1173. /* Clear STOPF and NACKF flag */
  1174. HDMI_CEC_SINK_I2C->ICR = ( I2C_ICR_STOPCF | I2C_ICR_NACKCF) ;
  1175. return errorstatus;
  1176. }
  1177. /**
  1178. * @brief Source Physical address discovery.
  1179. * @param None
  1180. * @retval HDMI_CEC_Error: CEC Error code.
  1181. */
  1182. static HDMI_CEC_Error SourcePhysicalAddressDiscovery(void)
  1183. {
  1184. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  1185. #ifdef HDMI_CEC_USE_DDC
  1186. uint32_t DataNum=0;
  1187. GPIO_InitTypeDef GPIO_InitStructure;
  1188. I2C_InitTypeDef I2C_InitStructure;
  1189. /* Enable CEC_I2C clocks */
  1190. RCC_APB1PeriphClockCmd(HDMI_CEC_I2C_CLK, ENABLE);
  1191. /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */
  1192. RCC_AHBPeriphClockCmd(HDMI_CEC_I2C_GPIO_CLK | HDMI_CEC_HPD_SOURCE_GPIO_CLK, ENABLE);
  1193. GPIO_PinAFConfig(HDMI_CEC_I2C_GPIO_PORT,HDMI_CEC_I2C_SCL_PIN_SOURCE,GPIO_AF_1);
  1194. GPIO_PinAFConfig(HDMI_CEC_I2C_GPIO_PORT,HDMI_CEC_I2C_SDA_PIN_SOURCE,GPIO_AF_1);
  1195. /* Configure CEC_I2C_SCL_PIN and CEC_I2C_SDA_PIN as Output open drain */
  1196. GPIO_InitStructure.GPIO_Pin = HDMI_CEC_I2C_SCL_PIN | HDMI_CEC_I2C_SDA_PIN;
  1197. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  1198. GPIO_Init(HDMI_CEC_I2C_GPIO_PORT, &GPIO_InitStructure);
  1199. /* This configuration is only when the HDMI CEC is configured as source.
  1200. The HDMI source has to provide the +5V Power signal to the sink.
  1201. Then, the source will wait for HPD signal to be asserted from the sink.
  1202. Once the HPD signal is detected the source shall read the EDID structure
  1203. through the DDC channel. */
  1204. /* Configure CEC_HPD_GPIO as Input pull down */
  1205. GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_SOURCE_PIN;
  1206. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  1207. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  1208. GPIO_Init(HDMI_CEC_HPD_SOURCE_GPIO_PORT, &GPIO_InitStructure);
  1209. /* I2C configuration */
  1210. I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  1211. I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
  1212. I2C_InitStructure.I2C_DigitalFilter = 0x00;
  1213. I2C_InitStructure.I2C_OwnAddress1 = 0x00;
  1214. I2C_InitStructure.I2C_Ack =I2C_Ack_Enable;
  1215. I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  1216. I2C_InitStructure.I2C_Timing = HDMI_CEC_I2C_TIMING;
  1217. /* I2C configuration */
  1218. I2C_Init(HDMI_CEC_I2C, &I2C_InitStructure);
  1219. /* I2C Peripheral Enable */
  1220. I2C_Cmd(HDMI_CEC_I2C, ENABLE);
  1221. /* Configure slave address, nbytes, reload and generate start */
  1222. HDMI_CEC_I2C->CR2 = (uint32_t)(0xA0) | (uint32_t)(1 << 16) | I2C_CR2_START ;
  1223. /* Wait until TXIS is set */
  1224. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TXIS));
  1225. /* Send memory address */
  1226. HDMI_CEC_I2C->TXDR = (uint8_t)(0x00);
  1227. /* Wait until TC is set */
  1228. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TC));
  1229. /* Update CR2 : set Nbytes and reload */
  1230. HDMI_CEC_I2C->CR2 = (uint32_t)(0xA0) | I2C_CR2_RD_WRN | I2C_CR2_START | (uint32_t)(255 << 16) | I2C_CR2_RELOAD;
  1231. /* Wait until all data are received */
  1232. while (DataNum != 255)
  1233. {
  1234. /* Wait until RXNE flag is set */
  1235. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_RXNE));
  1236. /* Read data from RXDR */
  1237. pBuffer[DataNum]= (uint8_t)HDMI_CEC_I2C->RXDR;
  1238. /* Update number of received data */
  1239. DataNum++;
  1240. }
  1241. /* Wait until TCR flag is set */
  1242. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TCR));
  1243. /* Update CR2 : set Nbytes and end mode */
  1244. HDMI_CEC_I2C->CR2 = (uint32_t)(1 << 16) | I2C_CR2_AUTOEND;
  1245. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_RXNE));
  1246. /* Read data from RXDR */
  1247. pBuffer[DataNum]= (uint8_t)HDMI_CEC_I2C->RXDR;
  1248. /* Wait until STOPF flag is set */
  1249. while (!(HDMI_CEC_I2C->ISR & I2C_ISR_STOPF));
  1250. /* Clear STOPF flag */
  1251. HDMI_CEC_I2C->ICR = I2C_ICR_STOPCF;
  1252. MyPhysicalAddress = ((pBuffer[158] << 8) | pBuffer[159]);
  1253. #else
  1254. MyPhysicalAddress = 0x1000;
  1255. #endif
  1256. return errorstatus;
  1257. }
  1258. /**
  1259. * @brief Allocate the logical address.
  1260. * @param None
  1261. * @retval HDMI_CEC_Error: CEC Error code.
  1262. */
  1263. static HDMI_CEC_Error LogicalAddressAllocation(void)
  1264. {
  1265. HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
  1266. uint32_t count = 0;
  1267. /*------------------ Logical address allocation ----------------------------*/
  1268. /* Get the device type */
  1269. /* Device type = CEC_TV */
  1270. if (DeviceType == HDMI_CEC_TV)
  1271. {
  1272. if (HDMI_CEC_ROOT)
  1273. {
  1274. MyLogicalAddress = 0x00;
  1275. }
  1276. else
  1277. {
  1278. CEC_OwnAddressConfig(0xE); /* Own address = 0xE */
  1279. CEC_EndOfMessage();
  1280. CEC_SendData(0xEE);
  1281. /* Start of message */
  1282. CEC_StartOfMessage();
  1283. /* Wait till the header message is sent */
  1284. while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
  1285. {
  1286. if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1287. {
  1288. break;
  1289. }
  1290. count++;
  1291. }
  1292. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1293. {
  1294. errorstatus = HDMI_CEC_TIMEOUT;
  1295. return(errorstatus);
  1296. }
  1297. errorstatus = HDMI_CEC_GetErrorStatus();
  1298. if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
  1299. {
  1300. MyLogicalAddress = 0x0E;
  1301. errorstatus = HDMI_CEC_OK;
  1302. }
  1303. else if (errorstatus == HDMI_CEC_OK)
  1304. {
  1305. MyLogicalAddress = 0x0F;
  1306. errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
  1307. }
  1308. }
  1309. /* Clear CEC ISR register */
  1310. CEC_ClearFlag(CEC_FLAG_TXEND);
  1311. }
  1312. /* Device type = CEC_RECORDING */
  1313. if (DeviceType == HDMI_CEC_RECORDING)
  1314. {
  1315. CEC_OwnAddressConfig(0x1); /* Own address = 0x1 */
  1316. CEC_EndOfMessage();
  1317. CEC_SendData(0x11);
  1318. /* Start of message */
  1319. CEC_StartOfMessage();
  1320. /* Wait till the header message is sent */
  1321. while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
  1322. {
  1323. if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1324. {
  1325. break;
  1326. }
  1327. count++;
  1328. }
  1329. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1330. {
  1331. errorstatus = HDMI_CEC_TIMEOUT;
  1332. return(errorstatus);
  1333. }
  1334. errorstatus = HDMI_CEC_GetErrorStatus();
  1335. if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
  1336. {
  1337. MyLogicalAddress = 0x01;
  1338. errorstatus = HDMI_CEC_OK;
  1339. }
  1340. else if (errorstatus == HDMI_CEC_OK)
  1341. {
  1342. /* Clear CEC ISR register */
  1343. CEC_ClearFlag(CEC_FLAG_TXEND|CEC_FLAG_TXACKE|CEC_FLAG_TXBR);
  1344. /* Clear the OAR */
  1345. CEC_OwnAddressClear();
  1346. CEC_OwnAddressConfig(0x2); /* Own address = 0x2 */
  1347. CEC_EndOfMessage();
  1348. CEC_SendData(0x22);
  1349. /* Start of message */
  1350. CEC_StartOfMessage();
  1351. count = 0;
  1352. /* Wait till the header message is sent */
  1353. while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
  1354. {
  1355. if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1356. {
  1357. break;
  1358. }
  1359. count++;
  1360. }
  1361. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1362. {
  1363. errorstatus = HDMI_CEC_TIMEOUT;
  1364. return(errorstatus);
  1365. }
  1366. errorstatus = HDMI_CEC_GetErrorStatus();
  1367. if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
  1368. {
  1369. MyLogicalAddress = 0x02;
  1370. errorstatus = HDMI_CEC_OK;
  1371. }
  1372. else if (errorstatus == HDMI_CEC_OK)
  1373. {
  1374. /* Clear CEC ISR register */
  1375. CEC_ClearFlag( CEC_FLAG_TXEND);
  1376. CEC_OwnAddressClear();
  1377. CEC_OwnAddressConfig(0x9); /* Own address = 0x9 */
  1378. CEC_EndOfMessage();
  1379. CEC_SendData(0x99);
  1380. /* Start of message */
  1381. CEC_StartOfMessage();
  1382. count = 0;
  1383. /* Wait till the header message is sent */
  1384. while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
  1385. {
  1386. if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
  1387. {
  1388. break;
  1389. }
  1390. count++;
  1391. }
  1392. if (count >= HDMI_CEC_TIMEOUT_VALUE)
  1393. {
  1394. errorstatus = HDMI_CEC_TIMEOUT;
  1395. return(errorstatus);
  1396. }
  1397. errorstatus = HDMI_CEC_GetErrorStatus();
  1398. if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
  1399. {
  1400. MyLogicalAddress = 0x09;
  1401. errorstatus = HDMI_CEC_OK;
  1402. }
  1403. else if (errorstatus == HDMI_CEC_OK)
  1404. {
  1405. MyLogicalAddress = 0x0F;
  1406. errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
  1407. }
  1408. }
  1409. }
  1410. /* Clear CEC ISR register */
  1411. CEC_ClearFlag(CEC_FLAG_TXEND|CEC_FLAG_TXACKE|CEC_FLAG_TXBR);
  1412. }
  1413. /* Device type = CEC_TUNER */
  1414. if (DeviceTyp

Large files files are truncated, but you can click here to view the full file