Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM32100E_EVAL/stm32100e_eval_cec.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32100e_eval_cec.c | |
4 * @author MCD Application Team | |
5 * @version V4.5.0 | |
6 * @date 07-March-2011 | |
7 * @brief This file provides all the STM32100E-EVAL HDMI-CEC firmware functions. | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
17 * | |
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
19 ****************************************************************************** | |
20 */ | |
21 | |
22 /* Includes ------------------------------------------------------------------*/ | |
23 #include "stm32100e_eval_cec.h" | |
24 | |
25 /** @addtogroup Utilities | |
26 * @{ | |
27 */ | |
28 | |
29 /** @addtogroup STM32_EVAL | |
30 * @{ | |
31 */ | |
32 | |
33 /** @addtogroup STM32100E_EVAL | |
34 * @{ | |
35 */ | |
36 | |
37 /** @defgroup STM32100E_EVAL_CEC | |
38 * @brief This file includes the CEC Stack driver for HDMI-CEC Module | |
39 * of STM32100E-EVAL board. | |
40 * @{ | |
41 */ | |
42 | |
43 /** @defgroup STM32100E_EVAL_CEC_Private_Types | |
44 * @{ | |
45 */ | |
46 | |
47 /** | |
48 * @} | |
49 */ | |
50 | |
51 /** @defgroup STM32100E_EVAL_CEC_Private_Defines | |
52 * @{ | |
53 */ | |
54 | |
55 | |
56 /** | |
57 * @} | |
58 */ | |
59 | |
60 /** @defgroup STM32100E_EVAL_CEC_Private_Macros | |
61 * @{ | |
62 */ | |
63 /** | |
64 * @} | |
65 */ | |
66 | |
67 /** @defgroup STM32100E_EVAL_CEC_Private_Variables | |
68 * @{ | |
69 */ | |
70 | |
71 __IO uint32_t ReceivedFrame = 0; | |
72 __IO uint32_t SendFrame = 0; | |
73 __IO uint32_t BufferCount = 0, TxCounter = 0, RxCounter = 0; | |
74 __IO uint8_t BufferPointer[15]; | |
75 __IO uint32_t ReceiveStatus = 0; | |
76 __IO uint32_t SendStatus = 0; | |
77 __IO uint8_t TransErrorCode = 0; | |
78 __IO uint8_t RecepErrorCode = 0; | |
79 __IO uint8_t MyLogicalAddress = 0; | |
80 __IO uint16_t MyPhysicalAddress = 0; | |
81 __IO uint8_t DeviceType = 0; | |
82 #ifdef HDMI_CEC_USE_DDC | |
83 __IO uint8_t pBuffer[256]; | |
84 __IO uint16_t NumByteToRead = 255; | |
85 #endif | |
86 __IO uint8_t CECDevicesNumber = 0; | |
87 | |
88 HDMI_CEC_Message HDMI_CEC_TX_MessageStructPrivate; | |
89 HDMI_CEC_Message HDMI_CEC_RX_MessageStructPrivate; | |
90 HDMI_CEC_Message HDMI_CEC_TX_MessageStructure; | |
91 | |
92 __IO uint8_t FeatureOpcode = 0; | |
93 __IO uint8_t AbortReason = 0; | |
94 __IO uint8_t DeviceCount = 0; | |
95 | |
96 HDMI_CEC_Map HDMI_CEC_MapStruct; | |
97 HDMI_CEC_Map HDMI_CEC_DeviceMap[14]; | |
98 | |
99 /* CEC follower addresses */ | |
100 uint8_t* HDMI_CEC_Follower_String[13][2] = | |
101 { | |
102 {(uint8_t*)" TV ", (uint8_t*)"0"}, | |
103 {(uint8_t*)"Recording Device 1 ", (uint8_t*)"0"}, | |
104 {(uint8_t*)"Recording Device 2 ", (uint8_t*)"0"}, | |
105 {(uint8_t*)" Tuner 1 ", (uint8_t*)"0"}, | |
106 {(uint8_t*)" Playback Device 1 ", (uint8_t*)"0"}, | |
107 {(uint8_t*)" Audio System ", (uint8_t*)"0"}, | |
108 {(uint8_t*)" Tuner 2 ", (uint8_t*)"0"}, | |
109 {(uint8_t*)" Tuner 3 ", (uint8_t*)"0"}, | |
110 {(uint8_t*)" Playback Device 2 ", (uint8_t*)"0"}, | |
111 {(uint8_t*)"Recording Device 3 ", (uint8_t*)"0"}, | |
112 {(uint8_t*)" Tuner 4 ", (uint8_t*)"0"}, | |
113 {(uint8_t*)" Playback Device 3 ", (uint8_t*)"0"}, | |
114 {(uint8_t*)" Broadcast ", (uint8_t*)"1"} | |
115 }; | |
116 | |
117 /** | |
118 * @} | |
119 */ | |
120 | |
121 | |
122 /** @defgroup STM32100E_EVAL_CEC_Private_Function_Prototypes | |
123 * @{ | |
124 */ | |
125 static HDMI_CEC_Error PhysicalAddressDiscovery(void); | |
126 static HDMI_CEC_Error LogicalAddressAllocation(void); | |
127 | |
128 | |
129 /** | |
130 * @} | |
131 */ | |
132 | |
133 | |
134 /** @defgroup STM32100E_EVAL_CEC_Private_Functions | |
135 * @{ | |
136 */ | |
137 | |
138 /** | |
139 * @brief Initializes the HDMI CEC. | |
140 * @param None | |
141 * @retval HDMI_CEC_Error: CEC Error code | |
142 */ | |
143 HDMI_CEC_Error HDMI_CEC_Init(void) | |
144 { | |
145 GPIO_InitTypeDef GPIO_InitStructure; | |
146 CEC_InitTypeDef CEC_InitStructure; | |
147 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
148 uint8_t sendcount = 0; | |
149 | |
150 #ifdef HDMI_CEC_USE_DDC | |
151 I2C_InitTypeDef I2C_InitStructure; | |
152 /* Enable CEC_I2C clocks */ | |
153 RCC_APB1PeriphClockCmd(HDMI_CEC_I2C_CLK, ENABLE); | |
154 | |
155 /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */ | |
156 RCC_APB2PeriphClockCmd(HDMI_CEC_I2C_GPIO_CLK | HDMI_CEC_HPD_GPIO_CLK, ENABLE); | |
157 #endif | |
158 | |
159 /* Enable CEC clocks */ | |
160 RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC, ENABLE); | |
161 | |
162 /* Enable CEC_LINE_GPIO clocks */ | |
163 RCC_APB2PeriphClockCmd(HDMI_CEC_LINE_GPIO_CLK, ENABLE); | |
164 | |
165 /* Configure CEC_LINE_GPIO as Output open drain */ | |
166 GPIO_InitStructure.GPIO_Pin = HDMI_CEC_LINE_PIN; | |
167 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
168 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; | |
169 GPIO_Init(HDMI_CEC_LINE_GPIO_PORT, &GPIO_InitStructure); | |
170 | |
171 #ifdef HDMI_CEC_USE_DDC | |
172 /* Configure CEC_I2C_SCL_PIN and CEC_I2C_SDA_PIN as Output open drain */ | |
173 GPIO_InitStructure.GPIO_Pin = HDMI_CEC_I2C_SCL_PIN | HDMI_CEC_I2C_SDA_PIN; | |
174 GPIO_Init(HDMI_CEC_I2C_GPIO_PORT, &GPIO_InitStructure); | |
175 | |
176 /* This configuration is only when the HDMI CEC is configured as source. | |
177 The HDMI source has to provide the +5V Power signal to the sink. | |
178 On STM32100E-EVAL borad, you have to solder the SB4 Solder bridge. | |
179 Then, the source will wait for HPD signal to be asserted from the sink. | |
180 Once the HPD signal is detected the source shall read the EDID structure | |
181 throuhgh the DDC channel. */ | |
182 /* Configure CEC_HPD_GPIO as Input pull down */ | |
183 GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_PIN; | |
184 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; | |
185 GPIO_Init(HDMI_CEC_HPD_GPIO_PORT, &GPIO_InitStructure); | |
186 | |
187 | |
188 /* This configuration is only when the HDMI CEC is configured as sink. | |
189 The HDMI sink has to wait for the +5V Power signal from the source. | |
190 On STM32100E-EVAL borad, SB4 Solder bridge should be open (default configuration). | |
191 Then, the sink will assert the HPD signal to inform the source that the EDID | |
192 is ready for read through DDC channel. In this implementation, the EDID structure | |
193 is not implemented. */ | |
194 /* GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_PIN; | |
195 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
196 GPIO_Init(HDMI_CEC_HPD_GPIO_PORT, &GPIO_InitStructure); | |
197 | |
198 HDMI_CEC_HPD_HIGH(); // Set the Hot plug detect signal */ | |
199 | |
200 /* Enable CEC_I2C */ | |
201 I2C_Cmd(HDMI_CEC_I2C, ENABLE); | |
202 | |
203 /* I2C configuration */ | |
204 I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; | |
205 I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; | |
206 I2C_InitStructure.I2C_OwnAddress1 = HDMI_CEC_I2C_SLAVE_ADDRESS7; | |
207 I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; | |
208 I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; | |
209 I2C_InitStructure.I2C_ClockSpeed = HDMI_CEC_I2C_CLOCK_SPEED; | |
210 I2C_Init(HDMI_CEC_I2C, &I2C_InitStructure); | |
211 #endif | |
212 | |
213 /* Physical Address discovery */ | |
214 errorstatus = PhysicalAddressDiscovery(); | |
215 | |
216 if (errorstatus != HDMI_CEC_OK) | |
217 { | |
218 /* Device not connected (Physical Address lost) */ | |
219 return(errorstatus); | |
220 } | |
221 | |
222 | |
223 /* CEC DeInit */ | |
224 CEC_DeInit(); | |
225 | |
226 /* Configure CEC */ | |
227 CEC_InitStructure.CEC_BitTimingMode = CEC_BitTimingStdMode; | |
228 CEC_InitStructure.CEC_BitPeriodMode = CEC_BitPeriodStdMode; | |
229 CEC_Init(&CEC_InitStructure); | |
230 | |
231 /* Set Prescaler value for APB1 clock = 24MHz */ | |
232 CEC_SetPrescaler(0x4AF); | |
233 | |
234 /* Enable CEC */ | |
235 CEC_Cmd(ENABLE); | |
236 | |
237 /* Logical Address Allocation */ | |
238 sendcount = 0; | |
239 errorstatus = LogicalAddressAllocation(); | |
240 | |
241 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
242 { | |
243 sendcount++; | |
244 errorstatus = LogicalAddressAllocation(); | |
245 } | |
246 | |
247 if (errorstatus != HDMI_CEC_OK) | |
248 { | |
249 /* Device Unregistred */ | |
250 return(errorstatus); | |
251 } | |
252 | |
253 HDMI_CEC_CheckConnectedDevices(); | |
254 | |
255 /* Set the CEC initiator address */ | |
256 CEC_OwnAddressConfig(MyLogicalAddress); | |
257 | |
258 /* Activate CEC interrupts associated to the set of RBTF,RERR, TBTF, TERR flags */ | |
259 CEC_ITConfig(ENABLE); | |
260 | |
261 /* Report physical address*/ | |
262 errorstatus = HDMI_CEC_ReportPhysicalAddress(); | |
263 sendcount = 0; | |
264 | |
265 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
266 { | |
267 sendcount++; | |
268 errorstatus = HDMI_CEC_ReportPhysicalAddress(); | |
269 } | |
270 | |
271 if (errorstatus != HDMI_CEC_OK) | |
272 { | |
273 /* Device Unregistred */ | |
274 return(errorstatus); | |
275 } | |
276 | |
277 return errorstatus; | |
278 } | |
279 | |
280 /** | |
281 * @brief Transmit message by taking data from typedef struct CEC_Meassage | |
282 * @param CEC_TX_MessageStructure: pointer to an CEC_Message structure that contains | |
283 * the message to be sent. | |
284 * @retval HDMI_CEC_Error: CEC Error code | |
285 */ | |
286 HDMI_CEC_Error HDMI_CEC_TransmitMessage(HDMI_CEC_Message *HDMI_CEC_TX_MessageStructure) | |
287 { | |
288 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
289 __IO uint32_t count = 0, j = 0; | |
290 | |
291 SendFrame = 0; | |
292 SendStatus = 0; | |
293 TxCounter = 0; | |
294 BufferCount = 0; | |
295 | |
296 HDMI_CEC_TX_MessageStructPrivate = *HDMI_CEC_TX_MessageStructure; | |
297 | |
298 /* Initialize BufferPointer */ | |
299 for (j = 0; j < 15; j++) | |
300 { | |
301 BufferPointer[j] = 0; | |
302 } | |
303 | |
304 BufferPointer[0] = HDMI_CEC_TX_MessageStructPrivate.Opcode; | |
305 | |
306 for (BufferCount = 1; BufferCount < HDMI_CEC_TX_MessageStructPrivate.TxMessageLength + 1; BufferCount++) | |
307 { | |
308 BufferPointer[BufferCount] = HDMI_CEC_TX_MessageStructPrivate.Operande[BufferCount-1]; | |
309 } | |
310 | |
311 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
312 | |
313 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ | |
314 CEC_SendDataByte(HDMI_CEC_TX_MessageStructPrivate.Header); | |
315 | |
316 /* Initiate Message Transmission */ | |
317 CEC_StartOfMessage(); | |
318 | |
319 while ((SendFrame == 0) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
320 { | |
321 count++; | |
322 } | |
323 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
324 { | |
325 errorstatus = HDMI_CEC_TIMEOUT; | |
326 return(errorstatus); | |
327 } | |
328 | |
329 if (SendStatus == 0) | |
330 { | |
331 errorstatus = (HDMI_CEC_Error) TransErrorCode; | |
332 } | |
333 | |
334 return errorstatus; | |
335 } | |
336 | |
337 | |
338 /** | |
339 * @brief Get the ESR register status. | |
340 * @param None | |
341 * @retval HDMI_CEC_Error: CEC Error code | |
342 */ | |
343 HDMI_CEC_Error HDMI_CEC_GetErrorStatus (void) | |
344 { | |
345 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
346 | |
347 /* Bit timing error case*/ | |
348 if (CEC_GetFlagStatus(CEC_FLAG_BTE) != RESET) | |
349 { | |
350 errorstatus = HDMI_CEC_BIT_TIMING; | |
351 } | |
352 /* Bit period error case */ | |
353 if (CEC_GetFlagStatus(CEC_FLAG_BPE) != RESET) | |
354 { | |
355 errorstatus = HDMI_CEC_BIT_PERIOD; | |
356 } | |
357 /* Recieve error case */ | |
358 if (CEC_GetFlagStatus(CEC_FLAG_RBTFE) != RESET) | |
359 { | |
360 errorstatus = HDMI_CEC_RX_BLOCK_FINISHED; | |
361 } | |
362 /* Start bit error case*/ | |
363 if (CEC_GetFlagStatus(CEC_FLAG_SBE) != RESET) | |
364 { | |
365 errorstatus = HDMI_CEC_START_BIT; | |
366 } | |
367 /* Acknowledge error case*/ | |
368 if (CEC_GetFlagStatus(CEC_FLAG_ACKE) != RESET) | |
369 { | |
370 errorstatus = HDMI_CEC_BLOCK_ACKNOWLEDGE; | |
371 } | |
372 /* Line error case */ | |
373 if (CEC_GetFlagStatus(CEC_FLAG_LINE) != RESET) | |
374 { | |
375 errorstatus = HDMI_CEC_LINE; | |
376 } | |
377 /* Transfert error case*/ | |
378 if (CEC_GetFlagStatus(CEC_FLAG_TBTFE) != RESET) | |
379 { | |
380 errorstatus = HDMI_CEC_TX_BLOCK_FINISHED; | |
381 } | |
382 /* Clear All errors */ | |
383 CEC_ClearFlag(CEC_FLAG_RERR); | |
384 CEC_ClearFlag(CEC_FLAG_TERR); | |
385 return errorstatus; | |
386 } | |
387 | |
388 /** | |
389 * @brief Allows to process all the interrupts that are high. | |
390 * @param None | |
391 * @retval None | |
392 */ | |
393 void HDMI_CEC_ProcessIRQSrc(void) | |
394 { | |
395 /********************** Reception *********************************************/ | |
396 /* Check if a reception error occured */ | |
397 if (CEC_GetFlagStatus(CEC_FLAG_RERR)) | |
398 { | |
399 /* Set receive status bit (Error) */ | |
400 ReceiveStatus = 0; | |
401 ReceivedFrame = 1; | |
402 RecepErrorCode = HDMI_CEC_GetErrorStatus(); | |
403 CEC_ClearFlag(CEC_FLAG_RERR | CEC_FLAG_RSOM | CEC_FLAG_REOM | CEC_FLAG_RBTF); | |
404 } | |
405 else if (CEC_GetFlagStatus(CEC_FLAG_RBTF)) | |
406 { | |
407 /* Check if the byte received is the last one of the message */ | |
408 if (CEC_GetFlagStatus(CEC_FLAG_REOM)) | |
409 { | |
410 HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-1] = CEC_ReceiveDataByte(); | |
411 HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter; | |
412 ReceiveStatus = SUCCESS; | |
413 ReceivedFrame = 1; | |
414 } | |
415 /* Check if the byte received is a Header */ | |
416 else if (CEC_GetFlagStatus(CEC_FLAG_RSOM)) | |
417 { | |
418 ReceiveStatus = 0; | |
419 HDMI_CEC_RX_MessageStructPrivate.Header = CEC_ReceiveDataByte(); | |
420 RxCounter = 0; | |
421 } | |
422 /* Receive each byte except header in the reception buffer */ | |
423 else | |
424 { | |
425 if (RxCounter != 0) | |
426 { | |
427 HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-1] = CEC_ReceiveDataByte(); | |
428 RxCounter++; | |
429 } | |
430 else | |
431 { | |
432 HDMI_CEC_RX_MessageStructPrivate.Opcode = CEC_ReceiveDataByte(); | |
433 RxCounter++; | |
434 } | |
435 | |
436 } | |
437 /* Clear all reception flags */ | |
438 CEC_ClearFlag(CEC_FLAG_RSOM | CEC_FLAG_REOM | CEC_FLAG_RBTF); | |
439 } | |
440 | |
441 /********************** Transmission ******************************************/ | |
442 /* Check if a transmission error occured */ | |
443 if (CEC_GetFlagStatus(CEC_FLAG_TERR)) | |
444 { | |
445 TransErrorCode = HDMI_CEC_GetErrorStatus(); | |
446 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
447 SendFrame = 1; | |
448 SendStatus = 0; | |
449 } | |
450 /* Check if end of message bit is set in the data to be transmitted */ | |
451 else if (CEC_GetFlagStatus(CEC_FLAG_TEOM)) | |
452 { | |
453 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_RBTF); | |
454 CEC_EndOfMessageCmd(DISABLE); | |
455 SendFrame = 1; | |
456 SendStatus = SUCCESS; | |
457 } | |
458 /* Check if data byte has been sent */ | |
459 else if (CEC_GetFlagStatus(CEC_FLAG_TBTRF)) | |
460 { | |
461 /* Set EOM bit if the byte to be transmitted is the last one of the TransmitBuffer */ | |
462 if (TxCounter == (HDMI_CEC_TX_MessageStructPrivate.TxMessageLength)) | |
463 { | |
464 CEC_SendDataByte(BufferPointer[TxCounter]); | |
465 TxCounter++; | |
466 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
467 CEC_EndOfMessageCmd(ENABLE); | |
468 } | |
469 else | |
470 { | |
471 /* Put the byte in the TX Buffer */ | |
472 CEC_SendDataByte(BufferPointer[TxCounter]); | |
473 TxCounter++; | |
474 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
475 } | |
476 } | |
477 } | |
478 | |
479 /** | |
480 * @brief Report physical address to all other devices thus allowing any | |
481 device to create a map of the network. | |
482 * @param None | |
483 * @retval HDMI_CEC_Error: CEC Error code. | |
484 */ | |
485 HDMI_CEC_Error HDMI_CEC_ReportPhysicalAddress(void) | |
486 { | |
487 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
488 HDMI_CEC_Message HDMI_CEC_TX_Message; | |
489 | |
490 HDMI_CEC_TX_Message.Header = ((MyLogicalAddress << 4) | 0xF); | |
491 HDMI_CEC_TX_Message.Opcode = HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS; | |
492 HDMI_CEC_TX_Message.Operande[0] = MyPhysicalAddress >> 8; | |
493 HDMI_CEC_TX_Message.Operande[1] = MyPhysicalAddress & 0xFF; | |
494 HDMI_CEC_TX_Message.Operande[2] = DeviceType; | |
495 HDMI_CEC_TX_Message.TxMessageLength = 0x03; | |
496 | |
497 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_Message); | |
498 | |
499 return errorstatus; | |
500 } | |
501 | |
502 /** | |
503 * @brief Handle CEC command receive callback. | |
504 * When receiving the STANDBY Opcode commande, the system is entred in | |
505 * Stop mode and when wakeup, the PLL is configured as system clock and | |
506 * the HSI is selected as PLL source. | |
507 * @param None | |
508 * @retval None | |
509 */ | |
510 void HDMI_CEC_CommandCallBack(void) | |
511 { | |
512 uint8_t i = 0, sendcount = 0; | |
513 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
514 EXTI_InitTypeDef EXTI_InitStructure; | |
515 | |
516 switch (HDMI_CEC_RX_MessageStructPrivate.Opcode) | |
517 { | |
518 case HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: | |
519 HDMI_CEC_MapStruct.PhysicalAddress_A = HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4; | |
520 HDMI_CEC_MapStruct.PhysicalAddress_B = HDMI_CEC_RX_MessageStructPrivate.Operande[1] & 0x0F; | |
521 HDMI_CEC_MapStruct.PhysicalAddress_C = HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4; | |
522 HDMI_CEC_MapStruct.PhysicalAddress_D = HDMI_CEC_RX_MessageStructPrivate.Operande[0] & 0x0F; | |
523 HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F; | |
524 HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2]; | |
525 HDMI_CEC_DeviceMap[DeviceCount] = HDMI_CEC_MapStruct; | |
526 HDMI_CEC_Follower_String[(HDMI_CEC_DeviceMap[DeviceCount].LogicalAddress)][1] = (uint8_t*)"1"; | |
527 DeviceCount++; | |
528 break; | |
529 | |
530 case HDMI_CEC_OPCODE_STANDBY: | |
531 /* CEC Line */ | |
532 GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8); | |
533 /* Configure the CEC Line as EXTI Line on Falling Edge */ | |
534 EXTI_ClearITPendingBit(EXTI_Line8); | |
535 EXTI_InitStructure.EXTI_Line = EXTI_Line8; | |
536 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; | |
537 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; | |
538 EXTI_InitStructure.EXTI_LineCmd = ENABLE; | |
539 EXTI_Init(&EXTI_InitStructure); | |
540 /* Request to enter Stop mode */ | |
541 PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); | |
542 | |
543 /* Disable the CEC EXTI Line */ | |
544 EXTI_InitStructure.EXTI_LineCmd = DISABLE; | |
545 EXTI_Init(&EXTI_InitStructure); | |
546 /* Configure the PLL Source */ | |
547 RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6); | |
548 | |
549 /* Enable PLL */ | |
550 RCC_PLLCmd(ENABLE); | |
551 | |
552 /* Wait till PLL is ready */ | |
553 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) | |
554 { | |
555 } | |
556 | |
557 /* Select PLL as system clock source */ | |
558 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); | |
559 | |
560 /* Wait till PLL is used as system clock source */ | |
561 while(RCC_GetSYSCLKSource() != 0x08) | |
562 { | |
563 } | |
564 break; | |
565 | |
566 case HDMI_CEC_OPCODE_GET_CEC_VERSION: | |
567 /* Send the Used CEC version */ | |
568 HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4); | |
569 HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_CEC_VERSION; | |
570 HDMI_CEC_TX_MessageStructPrivate.Operande[0] = HDMI_CEC_VERSION; /* CEC Version */ | |
571 HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x01; | |
572 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
573 | |
574 /* Retransmit message until 5 time */ | |
575 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
576 { | |
577 sendcount++; | |
578 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
579 } | |
580 break; | |
581 | |
582 case HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
583 /* Send the Physical address */ | |
584 errorstatus = HDMI_CEC_ReportPhysicalAddress(); | |
585 sendcount = 0; | |
586 /* Retransmit message until 5 time */ | |
587 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
588 { | |
589 sendcount++; | |
590 errorstatus = HDMI_CEC_ReportPhysicalAddress(); | |
591 } | |
592 break; | |
593 | |
594 case HDMI_CEC_OPCODE_FEATURE_ABORT: | |
595 /* The device doesn't support the requested message type, or that it cannot | |
596 execute it at the present time. */ | |
597 FeatureOpcode = HDMI_CEC_RX_MessageStructPrivate.Operande[0]; | |
598 AbortReason = HDMI_CEC_RX_MessageStructPrivate.Operande[1]; | |
599 break; | |
600 | |
601 case HDMI_CEC_OPCODE_GIVE_OSD_NAME: | |
602 /* Send the OSD name = STM32100E CEC*/ | |
603 HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4); | |
604 HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_SET_OSD_NAME; | |
605 /* STM32100E*/ | |
606 HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x53; | |
607 HDMI_CEC_TX_MessageStructPrivate.Operande[1] = 0x54; | |
608 HDMI_CEC_TX_MessageStructPrivate.Operande[2] = 0x4D; | |
609 HDMI_CEC_TX_MessageStructPrivate.Operande[3] = 0x33; | |
610 HDMI_CEC_TX_MessageStructPrivate.Operande[4] = 0x32; | |
611 HDMI_CEC_TX_MessageStructPrivate.Operande[5] = 0x31; | |
612 HDMI_CEC_TX_MessageStructPrivate.Operande[6] = 0x30; | |
613 HDMI_CEC_TX_MessageStructPrivate.Operande[7] = 0x30; | |
614 HDMI_CEC_TX_MessageStructPrivate.Operande[8] = 0x45; | |
615 HDMI_CEC_TX_MessageStructPrivate.Operande[9] = 0x20; | |
616 /* CEC */ | |
617 HDMI_CEC_TX_MessageStructPrivate.Operande[10] = 0x43; | |
618 HDMI_CEC_TX_MessageStructPrivate.Operande[11] = 0x45; | |
619 HDMI_CEC_TX_MessageStructPrivate.Operande[12] = 0x43; | |
620 HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 13; | |
621 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
622 sendcount = 0; | |
623 /* Retransmit message until 5 time */ | |
624 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
625 { | |
626 sendcount++; | |
627 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
628 } | |
629 break; | |
630 | |
631 case HDMI_CEC_OPCODE_ROUTING_CHANGE: | |
632 for (i = 0;i < 0x14;i++) | |
633 { | |
634 if ((HDMI_CEC_DeviceMap[i].PhysicalAddress_A == HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4) && | |
635 (HDMI_CEC_DeviceMap[i].PhysicalAddress_B == HDMI_CEC_RX_MessageStructPrivate.Operande[1]&0x0F) && | |
636 (HDMI_CEC_DeviceMap[i].PhysicalAddress_C == HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4) && | |
637 (HDMI_CEC_DeviceMap[i].PhysicalAddress_D == HDMI_CEC_RX_MessageStructPrivate.Operande[0]&0x0F)) | |
638 { | |
639 HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F; | |
640 HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2]; | |
641 HDMI_CEC_DeviceMap[i] = HDMI_CEC_MapStruct; | |
642 } | |
643 } | |
644 break; | |
645 | |
646 default: | |
647 /* Send Abort feature*/ | |
648 HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4); | |
649 HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_FEATURE_ABORT; | |
650 HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x02; /* defines command to be performed */ | |
651 HDMI_CEC_TX_MessageStructPrivate.Operande[1] = HDMI_CEC_REFUSED; /* Reason for abort feature */ | |
652 HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x02; | |
653 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
654 sendcount = 0; | |
655 /* Retransmit message until 5 time */ | |
656 while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5) | |
657 { | |
658 sendcount++; | |
659 errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate); | |
660 } | |
661 break; | |
662 | |
663 } | |
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 | |
676 /*----------------------------- TV device ---------------------------*/ | |
677 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
678 | |
679 CEC_EndOfMessageCmd(ENABLE); | |
680 | |
681 CEC_SendDataByte((MyLogicalAddress << 4) | 0x0); | |
682 | |
683 /* Start of message */ | |
684 CEC_StartOfMessage(); | |
685 | |
686 /* Wait till the header message is sent */ | |
687 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
688 { | |
689 count++; | |
690 } | |
691 | |
692 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
693 { | |
694 errorstatus = HDMI_CEC_TIMEOUT; | |
695 return(errorstatus); | |
696 } | |
697 | |
698 errorstatus = HDMI_CEC_GetErrorStatus(); | |
699 | |
700 if (errorstatus == HDMI_CEC_OK) | |
701 { | |
702 HDMI_CEC_Follower_String[0][1] = (uint8_t*)"1"; | |
703 i++; | |
704 errorstatus = HDMI_CEC_OK; | |
705 } | |
706 | |
707 /* Clear CEC CSR register */ | |
708 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
709 CEC_EndOfMessageCmd(DISABLE); | |
710 | |
711 /*----------------------------- Recording device 1 ---------------------------*/ | |
712 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
713 | |
714 CEC_EndOfMessageCmd(ENABLE); | |
715 | |
716 CEC_SendDataByte((MyLogicalAddress << 4) | 0x1); | |
717 | |
718 /* Start of message */ | |
719 CEC_StartOfMessage(); | |
720 | |
721 /* Wait till the header message is sent */ | |
722 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
723 { | |
724 count++; | |
725 } | |
726 | |
727 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
728 { | |
729 errorstatus = HDMI_CEC_TIMEOUT; | |
730 return(errorstatus); | |
731 } | |
732 | |
733 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 | |
742 /* Clear CEC CSR register */ | |
743 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
744 CEC_EndOfMessageCmd(DISABLE); | |
745 /*----------------------------- Recording device 2 ---------------------------*/ | |
746 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
747 | |
748 CEC_EndOfMessageCmd(ENABLE); | |
749 | |
750 CEC_SendDataByte((MyLogicalAddress << 4) | 0x2); | |
751 | |
752 /* Start of message */ | |
753 CEC_StartOfMessage(); | |
754 | |
755 /* Wait till the header message is sent */ | |
756 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
757 { | |
758 count++; | |
759 } | |
760 | |
761 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
762 { | |
763 errorstatus = HDMI_CEC_TIMEOUT; | |
764 return(errorstatus); | |
765 } | |
766 | |
767 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 | |
776 /* Clear CEC CSR register */ | |
777 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
778 CEC_EndOfMessageCmd(DISABLE); | |
779 | |
780 /*----------------------------- Tuner 1 ---------------------------*/ | |
781 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
782 | |
783 CEC_EndOfMessageCmd(ENABLE); | |
784 | |
785 CEC_SendDataByte((MyLogicalAddress << 4) | 0x3); | |
786 | |
787 /* Start of message */ | |
788 CEC_StartOfMessage(); | |
789 | |
790 /* Wait till the header message is sent */ | |
791 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
792 { | |
793 count++; | |
794 } | |
795 | |
796 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
797 { | |
798 errorstatus = HDMI_CEC_TIMEOUT; | |
799 return(errorstatus); | |
800 } | |
801 | |
802 errorstatus = HDMI_CEC_GetErrorStatus(); | |
803 | |
804 if (errorstatus == HDMI_CEC_OK) | |
805 { | |
806 HDMI_CEC_Follower_String[3][1] = (uint8_t *)"1"; | |
807 i++; | |
808 errorstatus = HDMI_CEC_OK; | |
809 } | |
810 /* Clear CEC CSR register */ | |
811 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
812 CEC_EndOfMessageCmd(DISABLE); | |
813 /*----------------------------- Playback device 1 ---------------------------*/ | |
814 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
815 | |
816 CEC_EndOfMessageCmd(ENABLE); | |
817 | |
818 CEC_SendDataByte((MyLogicalAddress << 4) | 0x4); | |
819 | |
820 /* Start of message */ | |
821 CEC_StartOfMessage(); | |
822 | |
823 /* Wait till the header message is sent */ | |
824 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
825 { | |
826 count++; | |
827 } | |
828 | |
829 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
830 { | |
831 errorstatus = HDMI_CEC_TIMEOUT; | |
832 return(errorstatus); | |
833 } | |
834 | |
835 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
844 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
845 CEC_EndOfMessageCmd(DISABLE); | |
846 | |
847 /*----------------------------- Audio system ---------------------------*/ | |
848 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
849 | |
850 CEC_EndOfMessageCmd(ENABLE); | |
851 | |
852 CEC_SendDataByte((MyLogicalAddress << 4) | 0x5); | |
853 | |
854 /* Start of message */ | |
855 CEC_StartOfMessage(); | |
856 | |
857 /* Wait till the header message is sent */ | |
858 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
859 { | |
860 count++; | |
861 } | |
862 | |
863 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
864 { | |
865 errorstatus = HDMI_CEC_TIMEOUT; | |
866 return(errorstatus); | |
867 } | |
868 | |
869 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
878 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
879 CEC_EndOfMessageCmd(DISABLE); | |
880 | |
881 /*----------------------------- Tuner 2 ---------------------------*/ | |
882 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
883 | |
884 CEC_EndOfMessageCmd(ENABLE); | |
885 | |
886 CEC_SendDataByte((MyLogicalAddress << 4) | 0x6); | |
887 | |
888 /* Start of message */ | |
889 CEC_StartOfMessage(); | |
890 | |
891 /* Wait till the header message is sent */ | |
892 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
893 { | |
894 count++; | |
895 } | |
896 | |
897 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
898 { | |
899 errorstatus = HDMI_CEC_TIMEOUT; | |
900 return(errorstatus); | |
901 } | |
902 | |
903 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
912 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
913 CEC_EndOfMessageCmd(DISABLE); | |
914 | |
915 /*----------------------------- Tuner 3 ---------------------------*/ | |
916 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
917 | |
918 CEC_EndOfMessageCmd(ENABLE); | |
919 | |
920 CEC_SendDataByte((MyLogicalAddress << 4) | 0x7); | |
921 | |
922 /* Start of message */ | |
923 CEC_StartOfMessage(); | |
924 | |
925 /* Wait till the header message is sent */ | |
926 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
927 { | |
928 count++; | |
929 } | |
930 | |
931 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
932 { | |
933 errorstatus = HDMI_CEC_TIMEOUT; | |
934 return(errorstatus); | |
935 } | |
936 | |
937 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
946 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
947 CEC_EndOfMessageCmd(DISABLE); | |
948 | |
949 /*----------------------------- Playback device 2 ---------------------------*/ | |
950 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
951 | |
952 CEC_EndOfMessageCmd(ENABLE); | |
953 | |
954 CEC_SendDataByte((MyLogicalAddress << 4) | 0x8); | |
955 | |
956 /* Start of message */ | |
957 CEC_StartOfMessage(); | |
958 | |
959 /* Wait till the header message is sent */ | |
960 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
961 { | |
962 count++; | |
963 } | |
964 | |
965 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
966 { | |
967 errorstatus = HDMI_CEC_TIMEOUT; | |
968 return(errorstatus); | |
969 } | |
970 | |
971 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
980 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
981 CEC_EndOfMessageCmd(DISABLE); | |
982 | |
983 /*----------------------------- Recording device 3 ---------------------------*/ | |
984 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
985 | |
986 CEC_EndOfMessageCmd(ENABLE); | |
987 | |
988 CEC_SendDataByte((MyLogicalAddress << 4) | 0x9); | |
989 | |
990 /* Start of message */ | |
991 CEC_StartOfMessage(); | |
992 | |
993 /* Wait till the header message is sent */ | |
994 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
995 { | |
996 count++; | |
997 } | |
998 | |
999 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1000 { | |
1001 errorstatus = HDMI_CEC_TIMEOUT; | |
1002 return(errorstatus); | |
1003 } | |
1004 | |
1005 errorstatus = HDMI_CEC_GetErrorStatus(); | |
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 CSR register */ | |
1014 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
1015 CEC_EndOfMessageCmd(DISABLE); | |
1016 /*----------------------------- Tuner 4 ---------------------------*/ | |
1017 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
1018 | |
1019 CEC_EndOfMessageCmd(ENABLE); | |
1020 | |
1021 CEC_SendDataByte((MyLogicalAddress << 4) | 0xA); | |
1022 | |
1023 /* Start of message */ | |
1024 CEC_StartOfMessage(); | |
1025 | |
1026 /* Wait till the header message is sent */ | |
1027 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1028 { | |
1029 count++; | |
1030 } | |
1031 | |
1032 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1033 { | |
1034 errorstatus = HDMI_CEC_TIMEOUT; | |
1035 return(errorstatus); | |
1036 } | |
1037 | |
1038 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1039 | |
1040 if (errorstatus == HDMI_CEC_OK) | |
1041 { | |
1042 HDMI_CEC_Follower_String[10][1] = (uint8_t *)"1"; | |
1043 i++; | |
1044 errorstatus = HDMI_CEC_OK; | |
1045 } | |
1046 /* Clear CEC CSR register */ | |
1047 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
1048 CEC_EndOfMessageCmd(DISABLE); | |
1049 /*----------------------------- Playback device 3 ---------------------------*/ | |
1050 CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */ | |
1051 | |
1052 CEC_EndOfMessageCmd(ENABLE); | |
1053 | |
1054 CEC_SendDataByte((MyLogicalAddress << 4) | 0xB); | |
1055 | |
1056 /* Start of message */ | |
1057 CEC_StartOfMessage(); | |
1058 | |
1059 /* Wait till the header message is sent */ | |
1060 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1061 { | |
1062 count++; | |
1063 } | |
1064 | |
1065 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1066 { | |
1067 errorstatus = HDMI_CEC_TIMEOUT; | |
1068 return(errorstatus); | |
1069 } | |
1070 | |
1071 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1072 | |
1073 if (errorstatus == HDMI_CEC_OK) | |
1074 { | |
1075 HDMI_CEC_Follower_String[11][1] = (uint8_t *)"1"; | |
1076 i++; | |
1077 errorstatus = HDMI_CEC_OK; | |
1078 } | |
1079 /* Clear CEC CSR register */ | |
1080 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
1081 CEC_EndOfMessageCmd(DISABLE); | |
1082 | |
1083 CECDevicesNumber = i - 1; | |
1084 | |
1085 return errorstatus; | |
1086 } | |
1087 | |
1088 /** | |
1089 * @brief Physical address discovery. | |
1090 * @param None | |
1091 * @retval HDMI_CEC_Error: CEC Error code. | |
1092 */ | |
1093 static HDMI_CEC_Error PhysicalAddressDiscovery(void) | |
1094 { | |
1095 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
1096 #ifdef HDMI_CEC_USE_DDC | |
1097 uint32_t index = 0, i = 0; | |
1098 #endif | |
1099 | |
1100 /*------------------------------ Physical address discovery -----------------*/ | |
1101 if (HDMI_CEC_ROOT == 0x1) | |
1102 { | |
1103 MyPhysicalAddress = 0x0000; | |
1104 /* The HDMI-CEC here is configured as sink or as a repeater. The configuration | |
1105 of the +5V power signal and the HPD should be well configured. | |
1106 Implement here the EDID Structure to be sent to the HDMI source. | |
1107 For more details please refer to the HDMI specification. | |
1108 The EDID structure should be sent to the device source using the DDC Channel | |
1109 and using the HPD signal. */ | |
1110 } | |
1111 else | |
1112 { | |
1113 | |
1114 #ifdef HDMI_CEC_USE_DDC | |
1115 /* The HDMI-CEC here is configured as source or as a repeater. The configuration | |
1116 of the +5V power signal and the HPD should be well configured. | |
1117 The source should wait for HPD and then read the EDID structure. */ | |
1118 while(GPIO_ReadInputDataBit(HDMI_CEC_HPD_GPIO_PORT, HDMI_CEC_HPD_PIN) == RESET) | |
1119 { | |
1120 } | |
1121 /* Wait for 100 ms after HPD was received */ | |
1122 for(i = 0; i < 0x5FFFF; i++) | |
1123 { | |
1124 } | |
1125 | |
1126 /* Return the physical address using the I2C by reading the 2 bytes 24 and | |
1127 25 form the EDID */ | |
1128 /* Read the EDID Block 0 and EDID Block 1 at address 0xA0 */ | |
1129 /*!< While the bus is busy */ | |
1130 while(I2C_GetFlagStatus(HDMI_CEC_I2C, I2C_FLAG_BUSY)) | |
1131 { | |
1132 } | |
1133 | |
1134 /*!< Send START condition */ | |
1135 I2C_GenerateSTART(HDMI_CEC_I2C, ENABLE); | |
1136 | |
1137 /*!< Test on EV5 and clear it */ | |
1138 while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_MODE_SELECT)) | |
1139 { | |
1140 } | |
1141 | |
1142 /*!< Send EEPROM address for write */ | |
1143 I2C_Send7bitAddress(HDMI_CEC_I2C, 0xA0, I2C_Direction_Transmitter); | |
1144 | |
1145 | |
1146 /*!< Test on EV6 and clear it */ | |
1147 while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) | |
1148 { | |
1149 } | |
1150 | |
1151 /*!< Send the EEPROM's internal address to read from: Only one byte address */ | |
1152 I2C_SendData(HDMI_CEC_I2C, 0x00); | |
1153 | |
1154 /*!< Test on EV8 and clear it */ | |
1155 while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) | |
1156 { | |
1157 } | |
1158 | |
1159 /*!< Send STRAT condition a second time */ | |
1160 I2C_GenerateSTART(HDMI_CEC_I2C, ENABLE); | |
1161 | |
1162 /*!< Test on EV5 and clear it */ | |
1163 while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_MODE_SELECT)) | |
1164 { | |
1165 } | |
1166 | |
1167 /*!< Send EEPROM address for read */ | |
1168 I2C_Send7bitAddress(HDMI_CEC_I2C, 0xA1, I2C_Direction_Receiver); | |
1169 | |
1170 /*!< Test on EV6 and clear it */ | |
1171 while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) | |
1172 { | |
1173 } | |
1174 | |
1175 /* While there is data to be read */ | |
1176 while (NumByteToRead-- > 1) | |
1177 { | |
1178 while(I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)) | |
1179 { | |
1180 } | |
1181 for(i = 0; i < 0xFFF; i++) | |
1182 { | |
1183 } | |
1184 pBuffer[index++] = I2C_ReceiveData(HDMI_CEC_I2C); | |
1185 } | |
1186 | |
1187 /* Disable Acknowledgement */ | |
1188 I2C_AcknowledgeConfig(HDMI_CEC_I2C, DISABLE); | |
1189 | |
1190 /* Send STOP Condition */ | |
1191 I2C_GenerateSTOP(HDMI_CEC_I2C, ENABLE); | |
1192 | |
1193 while(I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)); | |
1194 pBuffer[index] = I2C_ReceiveData(HDMI_CEC_I2C); | |
1195 | |
1196 /* Enable Acknowledgement to be ready for another reception */ | |
1197 I2C_AcknowledgeConfig(HDMI_CEC_I2C, ENABLE); | |
1198 MyPhysicalAddress = ((pBuffer[138] << 8) | pBuffer[137]); | |
1199 #else | |
1200 MyPhysicalAddress = 0x1000; | |
1201 #endif | |
1202 } | |
1203 | |
1204 return errorstatus; | |
1205 } | |
1206 /** | |
1207 * @brief Allocate the logical address. | |
1208 * @param None | |
1209 * @retval HDMI_CEC_Error: CEC Error code. | |
1210 */ | |
1211 static HDMI_CEC_Error LogicalAddressAllocation(void) | |
1212 { | |
1213 HDMI_CEC_Error errorstatus = HDMI_CEC_OK; | |
1214 uint32_t count = 0; | |
1215 | |
1216 /*------------------ Logical address allocation -----------------------------*/ | |
1217 /* Get the device type */ | |
1218 /* Device type = CEC_TV */ | |
1219 if (DeviceType == HDMI_CEC_TV) | |
1220 { | |
1221 if (HDMI_CEC_ROOT) | |
1222 { | |
1223 MyLogicalAddress = 0x00; | |
1224 } | |
1225 else | |
1226 { | |
1227 CEC_OwnAddressConfig(0xE); /* Own address = 0xE */ | |
1228 | |
1229 CEC_EndOfMessageCmd(ENABLE); | |
1230 | |
1231 CEC_SendDataByte(0xEE); | |
1232 | |
1233 /* Start of message */ | |
1234 CEC_StartOfMessage(); | |
1235 | |
1236 /* Wait till the polling message is sent */ | |
1237 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1238 { | |
1239 count++; | |
1240 } | |
1241 | |
1242 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1243 { | |
1244 errorstatus = HDMI_CEC_TIMEOUT; | |
1245 return(errorstatus); | |
1246 } | |
1247 | |
1248 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1249 | |
1250 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1251 { | |
1252 MyLogicalAddress = 0x0E; | |
1253 errorstatus = HDMI_CEC_OK; | |
1254 } | |
1255 else if (errorstatus == HDMI_CEC_OK) | |
1256 { | |
1257 MyLogicalAddress = 0x0F; | |
1258 errorstatus = HDMI_CEC_DEVICE_UNREGISTRED; | |
1259 } | |
1260 } | |
1261 /* Clear CEC CSR register */ | |
1262 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
1263 CEC_EndOfMessageCmd(DISABLE); | |
1264 } | |
1265 | |
1266 /* Device type = CEC_RECORDING */ | |
1267 if (DeviceType == HDMI_CEC_RECORDING) | |
1268 { | |
1269 CEC_OwnAddressConfig(0x1); /* Own address = 0x1 */ | |
1270 | |
1271 CEC_EndOfMessageCmd(ENABLE); | |
1272 | |
1273 CEC_SendDataByte(0x11); | |
1274 | |
1275 /* Start of message */ | |
1276 CEC_StartOfMessage(); | |
1277 | |
1278 /* Wait till the header message is sent */ | |
1279 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1280 { | |
1281 count++; | |
1282 } | |
1283 | |
1284 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1285 { | |
1286 errorstatus = HDMI_CEC_TIMEOUT; | |
1287 return(errorstatus); | |
1288 } | |
1289 | |
1290 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1291 | |
1292 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1293 { | |
1294 MyLogicalAddress = 0x01; | |
1295 errorstatus = HDMI_CEC_OK; | |
1296 } | |
1297 else if (errorstatus == HDMI_CEC_OK) | |
1298 { | |
1299 /* Clear CEC CSR register */ | |
1300 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1301 | |
1302 CEC_EndOfMessageCmd(DISABLE); | |
1303 | |
1304 CEC_OwnAddressConfig(0x2); /* Own address = 0x2 */ | |
1305 | |
1306 CEC_EndOfMessageCmd(ENABLE); | |
1307 | |
1308 CEC_SendDataByte(0x22); | |
1309 | |
1310 /* Start of message */ | |
1311 CEC_StartOfMessage(); | |
1312 | |
1313 count = 0; | |
1314 | |
1315 /* Wait till the header message is sent */ | |
1316 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1317 { | |
1318 count++; | |
1319 } | |
1320 | |
1321 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1322 { | |
1323 errorstatus = HDMI_CEC_TIMEOUT; | |
1324 return(errorstatus); | |
1325 } | |
1326 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1327 | |
1328 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1329 { | |
1330 MyLogicalAddress = 0x02; | |
1331 errorstatus = HDMI_CEC_OK; | |
1332 } | |
1333 else if (errorstatus == HDMI_CEC_OK) | |
1334 { | |
1335 /* Clear CEC CSR register */ | |
1336 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1337 | |
1338 CEC_EndOfMessageCmd(DISABLE); | |
1339 | |
1340 CEC_OwnAddressConfig(0x9); /* Own address = 0x9 */ | |
1341 | |
1342 CEC_EndOfMessageCmd(ENABLE); | |
1343 | |
1344 CEC_SendDataByte(0x99); | |
1345 | |
1346 /* Start of message */ | |
1347 CEC_StartOfMessage(); | |
1348 | |
1349 count = 0; | |
1350 | |
1351 /* Wait till the header message is sent */ | |
1352 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1353 { | |
1354 count++; | |
1355 } | |
1356 | |
1357 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1358 { | |
1359 errorstatus = HDMI_CEC_TIMEOUT; | |
1360 return(errorstatus); | |
1361 } | |
1362 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1363 | |
1364 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1365 { | |
1366 MyLogicalAddress = 0x09; | |
1367 errorstatus = HDMI_CEC_OK; | |
1368 } | |
1369 else if (errorstatus == HDMI_CEC_OK) | |
1370 { | |
1371 MyLogicalAddress = 0x0F; | |
1372 errorstatus = HDMI_CEC_DEVICE_UNREGISTRED; | |
1373 } | |
1374 } | |
1375 } | |
1376 /* Clear CEC CSR register */ | |
1377 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1378 CEC_EndOfMessageCmd(DISABLE); | |
1379 } | |
1380 | |
1381 /* Device type = CEC_TUNER */ | |
1382 if (DeviceType == HDMI_CEC_TUNER) | |
1383 { | |
1384 CEC_OwnAddressConfig(0x3); /* Own address = 0x3 */ | |
1385 | |
1386 CEC_EndOfMessageCmd(ENABLE); | |
1387 | |
1388 CEC_SendDataByte(0x33); | |
1389 | |
1390 /* Start of message */ | |
1391 CEC_StartOfMessage(); | |
1392 | |
1393 count = 0; | |
1394 | |
1395 /* Wait till the header message is sent */ | |
1396 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1397 { | |
1398 count++; | |
1399 } | |
1400 | |
1401 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1402 { | |
1403 errorstatus = HDMI_CEC_TIMEOUT; | |
1404 return(errorstatus); | |
1405 } | |
1406 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1407 | |
1408 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1409 { | |
1410 MyLogicalAddress = 0x03; | |
1411 errorstatus = HDMI_CEC_OK; | |
1412 } | |
1413 else if (errorstatus == HDMI_CEC_OK) | |
1414 { | |
1415 /* Clear CEC CSR register */ | |
1416 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1417 | |
1418 CEC_EndOfMessageCmd(DISABLE); | |
1419 | |
1420 CEC_OwnAddressConfig(0x6); /* Own address = 0x6 */ | |
1421 | |
1422 CEC_EndOfMessageCmd(ENABLE); | |
1423 | |
1424 CEC_SendDataByte(0x66); | |
1425 | |
1426 /* Start of message */ | |
1427 CEC_StartOfMessage(); | |
1428 | |
1429 count = 0; | |
1430 | |
1431 /* Wait till the header message is sent */ | |
1432 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1433 { | |
1434 count++; | |
1435 } | |
1436 | |
1437 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1438 { | |
1439 errorstatus = HDMI_CEC_TIMEOUT; | |
1440 return(errorstatus); | |
1441 } | |
1442 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1443 | |
1444 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1445 { | |
1446 MyLogicalAddress = 0x06; | |
1447 errorstatus = HDMI_CEC_OK; | |
1448 } | |
1449 else if (errorstatus == HDMI_CEC_OK) | |
1450 { | |
1451 /* Clear CEC CSR register */ | |
1452 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1453 | |
1454 CEC_EndOfMessageCmd(DISABLE); | |
1455 | |
1456 CEC_OwnAddressConfig(0x7); /* Own address = 0x7 */ | |
1457 | |
1458 CEC_EndOfMessageCmd(ENABLE); | |
1459 | |
1460 CEC_SendDataByte(0x77); | |
1461 | |
1462 /* Start of message */ | |
1463 CEC_StartOfMessage(); | |
1464 | |
1465 count = 0; | |
1466 | |
1467 /* Wait till the header message is sent */ | |
1468 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1469 { | |
1470 count++; | |
1471 } | |
1472 | |
1473 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1474 { | |
1475 errorstatus = HDMI_CEC_TIMEOUT; | |
1476 return(errorstatus); | |
1477 } | |
1478 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1479 | |
1480 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1481 { | |
1482 MyLogicalAddress = 0x07; | |
1483 errorstatus = HDMI_CEC_OK; | |
1484 } | |
1485 else if (errorstatus == HDMI_CEC_OK) | |
1486 { | |
1487 /* Clear CEC CSR register */ | |
1488 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1489 | |
1490 CEC_EndOfMessageCmd(DISABLE); | |
1491 | |
1492 CEC_OwnAddressConfig(0xA); /* Own address = 0xA */ | |
1493 | |
1494 CEC_EndOfMessageCmd(ENABLE); | |
1495 | |
1496 CEC_SendDataByte(0xAA); | |
1497 | |
1498 /* Start of message */ | |
1499 CEC_StartOfMessage(); | |
1500 | |
1501 count = 0; | |
1502 | |
1503 /* Wait till the header message is sent */ | |
1504 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1505 { | |
1506 count++; | |
1507 } | |
1508 | |
1509 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1510 { | |
1511 errorstatus = HDMI_CEC_TIMEOUT; | |
1512 return(errorstatus); | |
1513 } | |
1514 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1515 | |
1516 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1517 { | |
1518 MyLogicalAddress = 0x0A; | |
1519 errorstatus = HDMI_CEC_OK; | |
1520 } | |
1521 else if (errorstatus == HDMI_CEC_OK) | |
1522 { | |
1523 MyLogicalAddress = 0x0F; | |
1524 errorstatus = HDMI_CEC_DEVICE_UNREGISTRED; | |
1525 } | |
1526 } | |
1527 } | |
1528 } | |
1529 /* Clear CEC CSR register */ | |
1530 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1531 CEC_EndOfMessageCmd(DISABLE); | |
1532 } | |
1533 | |
1534 /* Device type = CEC_PLAYBACK */ | |
1535 if (DeviceType == HDMI_CEC_PLAYBACK) | |
1536 { | |
1537 CEC_OwnAddressConfig(0x4); /* Own address = 0x4 */ | |
1538 | |
1539 CEC_EndOfMessageCmd(ENABLE); | |
1540 | |
1541 CEC_SendDataByte(0x44); | |
1542 | |
1543 /* Start of message */ | |
1544 CEC_StartOfMessage(); | |
1545 | |
1546 count = 0; | |
1547 | |
1548 /* Wait till the header message is sent */ | |
1549 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1550 { | |
1551 count++; | |
1552 } | |
1553 | |
1554 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1555 { | |
1556 errorstatus = HDMI_CEC_TIMEOUT; | |
1557 return(errorstatus); | |
1558 } | |
1559 | |
1560 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1561 | |
1562 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1563 { | |
1564 MyLogicalAddress = 0x04; | |
1565 errorstatus = HDMI_CEC_OK; | |
1566 } | |
1567 else if (errorstatus == HDMI_CEC_OK) | |
1568 { | |
1569 /* Clear CEC CSR register */ | |
1570 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1571 | |
1572 CEC_EndOfMessageCmd(DISABLE); | |
1573 | |
1574 CEC_OwnAddressConfig(0x8); /* Own address = 0x8 */ | |
1575 | |
1576 CEC_EndOfMessageCmd(ENABLE); | |
1577 | |
1578 CEC_SendDataByte(0x88); | |
1579 | |
1580 /* Start of message */ | |
1581 CEC_StartOfMessage(); | |
1582 | |
1583 count = 0; | |
1584 | |
1585 /* Wait till the header message is sent */ | |
1586 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1587 { | |
1588 count++; | |
1589 } | |
1590 | |
1591 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1592 { | |
1593 errorstatus = HDMI_CEC_TIMEOUT; | |
1594 return(errorstatus); | |
1595 } | |
1596 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1597 | |
1598 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1599 { | |
1600 MyLogicalAddress = 0x08; | |
1601 errorstatus = HDMI_CEC_OK; | |
1602 } | |
1603 else if (errorstatus == HDMI_CEC_OK) | |
1604 { | |
1605 /* Clear CEC CSR register */ | |
1606 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1607 | |
1608 CEC_EndOfMessageCmd(DISABLE); | |
1609 | |
1610 CEC_OwnAddressConfig(0xB); /* Own address = 0xBB */ | |
1611 | |
1612 CEC_EndOfMessageCmd(ENABLE); | |
1613 | |
1614 CEC_SendDataByte(0xBB); | |
1615 | |
1616 /* Start of message */ | |
1617 CEC_StartOfMessage(); | |
1618 | |
1619 count = 0; | |
1620 | |
1621 /* Wait till the header message is sent */ | |
1622 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1623 { | |
1624 count++; | |
1625 } | |
1626 | |
1627 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1628 { | |
1629 errorstatus = HDMI_CEC_TIMEOUT; | |
1630 return(errorstatus); | |
1631 } | |
1632 | |
1633 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1634 | |
1635 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1636 { | |
1637 MyLogicalAddress = 0x0B; | |
1638 errorstatus = HDMI_CEC_OK; | |
1639 } | |
1640 else if (errorstatus == HDMI_CEC_OK) | |
1641 { | |
1642 MyLogicalAddress = 0x0F; | |
1643 errorstatus = HDMI_CEC_DEVICE_UNREGISTRED; | |
1644 } | |
1645 } | |
1646 } | |
1647 | |
1648 /* Clear CEC CSR register */ | |
1649 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1650 CEC_EndOfMessageCmd(DISABLE); | |
1651 } | |
1652 | |
1653 /* Device type = CEC Audio System */ | |
1654 if (DeviceType == HDMI_CEC_AUDIOSYSTEM) | |
1655 { | |
1656 CEC_OwnAddressConfig(0x5); /* Own address = 0x5 */ | |
1657 | |
1658 CEC_EndOfMessageCmd(ENABLE); | |
1659 | |
1660 CEC_SendDataByte(0x55); | |
1661 | |
1662 /* Start of message */ | |
1663 CEC_StartOfMessage(); | |
1664 | |
1665 count = 0; | |
1666 | |
1667 /* Wait till the header message is sent */ | |
1668 while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE)) | |
1669 { | |
1670 count++; | |
1671 } | |
1672 | |
1673 if (count >= HDMI_CEC_TIMEOUT_VALUE) | |
1674 { | |
1675 errorstatus = HDMI_CEC_TIMEOUT; | |
1676 return(errorstatus); | |
1677 } | |
1678 | |
1679 errorstatus = HDMI_CEC_GetErrorStatus(); | |
1680 | |
1681 if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE) | |
1682 { | |
1683 MyLogicalAddress = 0x05; | |
1684 errorstatus = HDMI_CEC_OK; | |
1685 } | |
1686 else if (errorstatus == HDMI_CEC_OK) | |
1687 { | |
1688 MyLogicalAddress = 0x0F; | |
1689 errorstatus = HDMI_CEC_DEVICE_UNREGISTRED; | |
1690 } | |
1691 | |
1692 /* Clear CEC CSR register */ | |
1693 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
1694 CEC_EndOfMessageCmd(DISABLE); | |
1695 } | |
1696 | |
1697 return errorstatus; | |
1698 } | |
1699 | |
1700 /** | |
1701 * @} | |
1702 */ | |
1703 | |
1704 /** | |
1705 * @} | |
1706 */ | |
1707 | |
1708 /** | |
1709 * @} | |
1710 */ | |
1711 | |
1712 /** | |
1713 * @} | |
1714 */ | |
1715 | |
1716 /** | |
1717 * @} | |
1718 */ | |
1719 | |
1720 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ | |
1721 | |
1722 |