stm32100b_eval_cec.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32100b_eval_cec.c
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the STM32100B-EVAL HDMI-CEC firmware functions.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32100b_eval_cec.h"
00023 
00024 /** @addtogroup Utilities
00025   * @{
00026   */
00027 
00028 /** @addtogroup STM32_EVAL
00029   * @{
00030   */ 
00031 
00032 /** @addtogroup STM32100B_EVAL
00033   * @{
00034   */
00035   
00036 /** @defgroup STM32100B_EVAL_CEC
00037   * @brief This file includes the CEC Stack driver for HDMI-CEC Module
00038   *        of STM32100B-EVAL board.
00039   * @{
00040   */
00041 
00042 /** @defgroup STM32100B_EVAL_CEC_Private_Types
00043   * @{
00044   */
00045 
00046 /**
00047   * @}
00048   */
00049 
00050 /** @defgroup STM32100B_EVAL_CEC_Private_Defines
00051   * @{
00052   */
00053 
00054 
00055 /**
00056   * @}
00057   */
00058 
00059 /** @defgroup STM32100B_EVAL_CEC_Private_Macros
00060   * @{
00061   */
00062 /**
00063   * @}
00064   */
00065 
00066 /** @defgroup STM32100B_EVAL_CEC_Private_Variables
00067   * @{
00068   */
00069 
00070 __IO uint32_t ReceivedFrame = 0;
00071 __IO uint32_t SendFrame = 0;
00072 __IO uint32_t BufferCount = 0, TxCounter = 0, RxCounter = 0;
00073 __IO uint8_t BufferPointer[15];
00074 __IO uint32_t ReceiveStatus = 0;
00075 __IO uint32_t SendStatus = 0;
00076 __IO uint8_t TransErrorCode = 0;
00077 __IO uint8_t RecepErrorCode = 0;
00078 __IO uint8_t MyLogicalAddress = 0;
00079 __IO uint16_t MyPhysicalAddress = 0;
00080 __IO uint8_t DeviceType = 0;
00081 #ifdef HDMI_CEC_USE_DDC
00082 __IO uint8_t pBuffer[256];
00083 __IO uint16_t NumByteToRead = 255;
00084 #endif
00085 __IO uint8_t CECDevicesNumber = 0;
00086 
00087 HDMI_CEC_Message HDMI_CEC_TX_MessageStructPrivate;
00088 HDMI_CEC_Message HDMI_CEC_RX_MessageStructPrivate;
00089 HDMI_CEC_Message HDMI_CEC_TX_MessageStructure;
00090 
00091 __IO uint8_t FeatureOpcode = 0;
00092 __IO uint8_t AbortReason = 0;
00093 __IO uint8_t DeviceCount = 0;
00094 
00095 HDMI_CEC_Map HDMI_CEC_MapStruct;
00096 HDMI_CEC_Map HDMI_CEC_DeviceMap[14];
00097 
00098 /* CEC follower addresses */
00099 uint8_t* HDMI_CEC_Follower_String[13][2] =
00100   {
00101     {"         TV         ", "0"},
00102     {"Recording Device 1  ", "0"},
00103     {"Recording Device 2  ", "0"},
00104     {"    Tuner 1         ", "0"},
00105     {" Playback Device 1  ", "0"},
00106     {"   Audio System     ", "0"},
00107     {"    Tuner 2         ", "0"},
00108     {"    Tuner 3         ", "0"},
00109     {" Playback Device 2  ", "0"},
00110     {"Recording Device 3  ", "0"},
00111     {"      Tuner 4       ", "0"},
00112     {" Playback Device 3  ", "0"},
00113     {"     Broadcast      ", "1"}
00114   };
00115 
00116 /**
00117   * @}
00118   */
00119 
00120 
00121 /** @defgroup STM32100B_EVAL_CEC_Private_Function_Prototypes
00122   * @{
00123   */
00124 static HDMI_CEC_Error PhysicalAddressDiscovery(void);
00125 static HDMI_CEC_Error LogicalAddressAllocation(void);
00126 
00127 
00128 /**
00129   * @}
00130   */
00131 
00132 
00133 /** @defgroup STM32100B_EVAL_CEC_Private_Functions
00134   * @{
00135   */
00136 
00137 /**
00138   * @brief  Initializes the HDMI CEC.
00139   * @param  None
00140   * @retval HDMI_CEC_Error: CEC Error code
00141   */
00142 HDMI_CEC_Error HDMI_CEC_Init(void)
00143 {
00144   GPIO_InitTypeDef GPIO_InitStructure;
00145   CEC_InitTypeDef CEC_InitStructure;
00146   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00147   uint8_t sendcount = 0;
00148 
00149 #ifdef HDMI_CEC_USE_DDC
00150   I2C_InitTypeDef  I2C_InitStructure;
00151   /* Enable CEC_I2C clocks */
00152   RCC_APB1PeriphClockCmd(HDMI_CEC_I2C_CLK, ENABLE);
00153 
00154   /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */
00155   RCC_APB2PeriphClockCmd(HDMI_CEC_I2C_GPIO_CLK | HDMI_CEC_HPD_GPIO_CLK, ENABLE);
00156 #endif
00157 
00158   /* Enable CEC clocks */
00159   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC, ENABLE);
00160 
00161   /* Enable CEC_LINE_GPIO clocks */
00162   RCC_APB2PeriphClockCmd(HDMI_CEC_LINE_GPIO_CLK, ENABLE);
00163 
00164   /* Configure CEC_LINE_GPIO as Output open drain */
00165   GPIO_InitStructure.GPIO_Pin = HDMI_CEC_LINE_PIN;
00166   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00167   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00168   GPIO_Init(HDMI_CEC_LINE_GPIO_PORT, &GPIO_InitStructure);
00169 
00170 #ifdef HDMI_CEC_USE_DDC
00171   /* Configure CEC_I2C_SCL_PIN and CEC_I2C_SDA_PIN  as Output open drain */
00172   GPIO_InitStructure.GPIO_Pin = HDMI_CEC_I2C_SCL_PIN | HDMI_CEC_I2C_SDA_PIN;
00173   GPIO_Init(HDMI_CEC_I2C_GPIO_PORT, &GPIO_InitStructure);
00174 
00175 /* This configuration is only when the HDMI CEC is configured as source.
00176    The HDMI source has to provide the +5V Power signal to the sink. 
00177    On STM32100B-EVAL borad, you have to solder the SB4 Solder bridge.
00178    Then, the source will wait for HPD signal to be asserted from the sink.
00179    Once the HPD signal is detected the source shall read the EDID structure 
00180    throuhgh the DDC channel. */
00181   /* Configure CEC_HPD_GPIO as Input pull down */
00182   GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_PIN;
00183   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
00184   GPIO_Init(HDMI_CEC_HPD_GPIO_PORT, &GPIO_InitStructure);
00185 
00186 
00187 /* This configuration is only when the HDMI CEC is configured as sink.
00188    The HDMI sink has to wait for the +5V Power signal from the source. 
00189    On STM32100B-EVAL borad, SB4 Solder bridge should be open (default configuration).
00190    Then, the sink will assert the HPD signal to inform the source that the EDID
00191    is ready for read through DDC channel. In this implementation, the EDID structure
00192    is not implemented. */
00193 /*  GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_PIN;
00194   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00195   GPIO_Init(HDMI_CEC_HPD_GPIO_PORT, &GPIO_InitStructure);
00196 
00197   HDMI_CEC_HPD_HIGH(); // Set the Hot plug detect signal */
00198   
00199   /* Enable CEC_I2C */
00200   I2C_Cmd(HDMI_CEC_I2C, ENABLE);
00201 
00202   /* I2C configuration */
00203   I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
00204   I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
00205   I2C_InitStructure.I2C_OwnAddress1 = HDMI_CEC_I2C_SLAVE_ADDRESS7;
00206   I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
00207   I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
00208   I2C_InitStructure.I2C_ClockSpeed = HDMI_CEC_I2C_CLOCK_SPEED;
00209   I2C_Init(HDMI_CEC_I2C, &I2C_InitStructure);
00210 #endif
00211 
00212   /* Physical Address discovery */
00213   errorstatus = PhysicalAddressDiscovery();
00214 
00215   if (errorstatus != HDMI_CEC_OK)
00216   {
00217     /* Device not connected (Physical Address lost) */
00218     return(errorstatus);
00219   }
00220 
00221 
00222   /* CEC DeInit */
00223   CEC_DeInit();
00224 
00225   /* Configure CEC */
00226   CEC_InitStructure.CEC_BitTimingMode = CEC_BitTimingStdMode;
00227   CEC_InitStructure.CEC_BitPeriodMode = CEC_BitPeriodStdMode;
00228   CEC_Init(&CEC_InitStructure);
00229 
00230   /* Set Prescaler value for APB1 clock = 24MHz */
00231   CEC_SetPrescaler(0x4AF);
00232 
00233   /* Enable CEC */
00234   CEC_Cmd(ENABLE);
00235 
00236   /* Logical Address Allocation */
00237   sendcount = 0;
00238   errorstatus = LogicalAddressAllocation();
00239 
00240   while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00241   {
00242     sendcount++;
00243     errorstatus = LogicalAddressAllocation();
00244   }
00245 
00246   if (errorstatus != HDMI_CEC_OK)
00247   {
00248     /* Device Unregistred */
00249     return(errorstatus);
00250   }
00251 
00252   HDMI_CEC_CheckConnectedDevices();
00253   
00254   /* Set the CEC initiator address */
00255   CEC_OwnAddressConfig(MyLogicalAddress);
00256 
00257   /* Activate CEC interrupts associated to the set of RBTF,RERR, TBTF, TERR flags */
00258   CEC_ITConfig(ENABLE);
00259 
00260   /* Report physical address*/
00261   errorstatus = HDMI_CEC_ReportPhysicalAddress();
00262   sendcount = 0;
00263 
00264   while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00265   {
00266     sendcount++;
00267     errorstatus = HDMI_CEC_ReportPhysicalAddress();
00268   }
00269 
00270   if (errorstatus != HDMI_CEC_OK)
00271   {
00272     /* Device Unregistred */
00273     return(errorstatus);
00274   }
00275 
00276   return errorstatus;
00277 }
00278 
00279 /**
00280   * @brief  Transmit message by taking  data from typedef struct CEC_Meassage
00281   * @param  CEC_TX_MessageStructure: pointer to an CEC_Message structure that contains
00282   *         the message to be sent.
00283   * @retval HDMI_CEC_Error: CEC Error code
00284   */
00285 HDMI_CEC_Error HDMI_CEC_TransmitMessage(HDMI_CEC_Message *HDMI_CEC_TX_MessageStructure)
00286 {
00287   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00288   __IO uint32_t count = 0, j = 0;
00289 
00290   SendFrame = 0;
00291   SendStatus = 0;
00292   TxCounter = 0;
00293   BufferCount = 0;
00294 
00295   HDMI_CEC_TX_MessageStructPrivate =  *HDMI_CEC_TX_MessageStructure;
00296 
00297   /* Initialize BufferPointer */
00298   for (j = 0; j < 15; j++)
00299   {
00300     BufferPointer[j] = 0;
00301   }
00302 
00303   BufferPointer[0] =  HDMI_CEC_TX_MessageStructPrivate.Opcode;
00304 
00305   for (BufferCount = 1; BufferCount < HDMI_CEC_TX_MessageStructPrivate.TxMessageLength + 1; BufferCount++)
00306   {
00307     BufferPointer[BufferCount] =  HDMI_CEC_TX_MessageStructPrivate.Operande[BufferCount-1];
00308   }
00309 
00310   CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
00311 
00312   /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */
00313   CEC_SendDataByte(HDMI_CEC_TX_MessageStructPrivate.Header);
00314 
00315   /* Initiate Message Transmission */
00316   CEC_StartOfMessage();
00317 
00318   while ((SendFrame == 0) && (count < HDMI_CEC_TIMEOUT_VALUE))
00319   {
00320     count++;
00321   }
00322   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00323   {
00324     errorstatus = HDMI_CEC_TIMEOUT;
00325     return(errorstatus);
00326   }
00327 
00328   if (SendStatus == 0)
00329   {
00330     errorstatus = (HDMI_CEC_Error) TransErrorCode;
00331   }
00332 
00333   return errorstatus;
00334 }
00335 
00336 
00337 /**
00338   * @brief  Get the ESR register status.
00339   * @param  None
00340   * @retval HDMI_CEC_Error: CEC Error code
00341   */
00342 HDMI_CEC_Error HDMI_CEC_GetErrorStatus (void)
00343 {
00344   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00345 
00346   /* Bit timing error case*/
00347   if (CEC_GetFlagStatus(CEC_FLAG_BTE) != RESET)
00348   {
00349     errorstatus = HDMI_CEC_BIT_TIMING;
00350   }
00351   /* Bit period error case */
00352   if (CEC_GetFlagStatus(CEC_FLAG_BPE) != RESET)
00353   {
00354     errorstatus = HDMI_CEC_BIT_PERIOD;
00355   }
00356   /* Recieve error case */
00357   if (CEC_GetFlagStatus(CEC_FLAG_RBTFE) != RESET)
00358   {
00359     errorstatus = HDMI_CEC_RX_BLOCK_FINISHED;
00360   }
00361   /* Start bit error case*/
00362   if (CEC_GetFlagStatus(CEC_FLAG_SBE) != RESET)
00363   {
00364     errorstatus = HDMI_CEC_START_BIT;
00365   }
00366   /* Acknowledge error case*/
00367   if (CEC_GetFlagStatus(CEC_FLAG_ACKE) != RESET)
00368   {
00369     errorstatus = HDMI_CEC_BLOCK_ACKNOWLEDGE;
00370   }
00371   /* Line error case */
00372   if (CEC_GetFlagStatus(CEC_FLAG_LINE) != RESET)
00373   {
00374     errorstatus = HDMI_CEC_LINE;
00375   }
00376   /* Transfert error case*/
00377   if (CEC_GetFlagStatus(CEC_FLAG_TBTFE) != RESET)
00378   {
00379     errorstatus = HDMI_CEC_TX_BLOCK_FINISHED;
00380   }
00381   /* Clear All errors */
00382   CEC_ClearFlag(CEC_FLAG_RERR);
00383   CEC_ClearFlag(CEC_FLAG_TERR);
00384   return errorstatus;
00385 }
00386 
00387 /**
00388   * @brief  Allows to process all the interrupts that are high.
00389   * @param  None
00390   * @retval None
00391   */
00392 void HDMI_CEC_ProcessIRQSrc(void)
00393 {
00394   /********************** Reception *********************************************/
00395   /* Check if a reception error occured */
00396   if (CEC_GetFlagStatus(CEC_FLAG_RERR))
00397   {
00398     /* Set receive status bit (Error) */
00399     ReceiveStatus  = 0;
00400     ReceivedFrame  = 1;
00401     RecepErrorCode = HDMI_CEC_GetErrorStatus();
00402     CEC_ClearFlag(CEC_FLAG_RERR | CEC_FLAG_RSOM | CEC_FLAG_REOM  | CEC_FLAG_RBTF);
00403   }
00404   else if (CEC_GetFlagStatus(CEC_FLAG_RBTF))
00405   {
00406     /* Check if the byte received is the last one of the message */
00407     if (CEC_GetFlagStatus(CEC_FLAG_REOM))
00408     {
00409       HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-1] = CEC_ReceiveDataByte();
00410       HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter;
00411       ReceiveStatus = SUCCESS;
00412       ReceivedFrame = 1;
00413     }
00414     /* Check if the byte received is a Header */
00415     else if (CEC_GetFlagStatus(CEC_FLAG_RSOM))
00416     {
00417       ReceiveStatus = 0;
00418       HDMI_CEC_RX_MessageStructPrivate.Header = CEC_ReceiveDataByte();
00419       RxCounter = 0;
00420     }
00421     /* Receive each byte except header in the reception buffer */
00422     else
00423     {
00424       if (RxCounter != 0)
00425       {
00426         HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-1] = CEC_ReceiveDataByte();
00427         RxCounter++;
00428       }
00429       else
00430       {
00431         HDMI_CEC_RX_MessageStructPrivate.Opcode = CEC_ReceiveDataByte();
00432         RxCounter++;
00433       }
00434       
00435     }
00436     /* Clear all reception flags */
00437     CEC_ClearFlag(CEC_FLAG_RSOM | CEC_FLAG_REOM  | CEC_FLAG_RBTF);
00438   }
00439 
00440   /********************** Transmission ******************************************/
00441   /* Check if a transmission error occured */
00442   if (CEC_GetFlagStatus(CEC_FLAG_TERR))
00443   {
00444     TransErrorCode = HDMI_CEC_GetErrorStatus();
00445     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
00446     SendFrame = 1;
00447     SendStatus = 0;
00448   }
00449   /* Check if end of message bit is set in the data to be transmitted */
00450   else if (CEC_GetFlagStatus(CEC_FLAG_TEOM))
00451   {
00452     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_RBTF);
00453     CEC_EndOfMessageCmd(DISABLE);
00454     SendFrame = 1;
00455     SendStatus = SUCCESS;
00456   }
00457   /* Check if data byte has been sent */
00458   else if (CEC_GetFlagStatus(CEC_FLAG_TBTRF))
00459   {
00460     /* Set EOM bit if the byte to be transmitted is the last one of the TransmitBuffer */
00461     if (TxCounter == (HDMI_CEC_TX_MessageStructPrivate.TxMessageLength))
00462     {
00463       CEC_SendDataByte(BufferPointer[TxCounter]);
00464       TxCounter++;
00465       CEC_ClearFlag(CEC_FLAG_TBTRF);
00466       CEC_EndOfMessageCmd(ENABLE);
00467     }
00468     else
00469     {
00470       /* Put the byte in the TX Buffer */
00471       CEC_SendDataByte(BufferPointer[TxCounter]);
00472       TxCounter++;
00473       CEC_ClearFlag(CEC_FLAG_TBTRF);
00474     }
00475   }
00476 }
00477 
00478 /**
00479   * @brief  Report physical address to all other devices thus allowing any
00480             device to create a map of the network.
00481   * @param  None
00482   * @retval HDMI_CEC_Error: CEC Error code.
00483   */
00484 HDMI_CEC_Error HDMI_CEC_ReportPhysicalAddress(void)
00485 {
00486   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00487   HDMI_CEC_Message HDMI_CEC_TX_Message;
00488 
00489   HDMI_CEC_TX_Message.Header = ((MyLogicalAddress << 4) | 0xF);
00490   HDMI_CEC_TX_Message.Opcode = HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS;
00491   HDMI_CEC_TX_Message.Operande[0] = MyPhysicalAddress >> 8;
00492   HDMI_CEC_TX_Message.Operande[1] = MyPhysicalAddress & 0xFF;
00493   HDMI_CEC_TX_Message.Operande[2] = DeviceType;
00494   HDMI_CEC_TX_Message.TxMessageLength = 0x03;
00495 
00496   errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_Message);
00497 
00498   return  errorstatus;
00499 }
00500 
00501 /**
00502   * @brief  Handle CEC command receive callback.
00503   *         When receiving the STANDBY Opcode commande, the system is entred in
00504   *         Stop mode and when wakeup, the PLL is configured as system clock and
00505   *         the HSI is selected as PLL source.      
00506   * @param  None
00507   * @retval None
00508   */
00509 void HDMI_CEC_CommandCallBack(void)
00510 {
00511   uint8_t i = 0, sendcount = 0;
00512   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00513   EXTI_InitTypeDef EXTI_InitStructure;
00514 
00515   switch (HDMI_CEC_RX_MessageStructPrivate.Opcode)
00516   {
00517     case HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
00518       HDMI_CEC_MapStruct.PhysicalAddress_A = HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4;
00519       HDMI_CEC_MapStruct.PhysicalAddress_B = HDMI_CEC_RX_MessageStructPrivate.Operande[1] & 0x0F;
00520       HDMI_CEC_MapStruct.PhysicalAddress_C = HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4;
00521       HDMI_CEC_MapStruct.PhysicalAddress_D = HDMI_CEC_RX_MessageStructPrivate.Operande[0] & 0x0F;
00522       HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
00523       HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
00524       HDMI_CEC_DeviceMap[DeviceCount] = HDMI_CEC_MapStruct;
00525       HDMI_CEC_Follower_String[(HDMI_CEC_DeviceMap[DeviceCount].LogicalAddress)][1] = "1";
00526       DeviceCount++;
00527       break;
00528 
00529     case HDMI_CEC_OPCODE_STANDBY:
00530       /* CEC Line */
00531       GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
00532       /* Configure the CEC Line as EXTI Line on Falling Edge */
00533       EXTI_ClearITPendingBit(EXTI_Line8);
00534       EXTI_InitStructure.EXTI_Line = EXTI_Line8;
00535       EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00536       EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
00537       EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00538       EXTI_Init(&EXTI_InitStructure);
00539       /* Request to enter Stop mode */
00540       PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
00541 
00542       /* Disable the CEC EXTI Line */
00543       EXTI_InitStructure.EXTI_LineCmd = DISABLE;
00544       EXTI_Init(&EXTI_InitStructure);
00545       /* Configure the PLL Source */
00546       RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);
00547 
00548       /* Enable PLL */ 
00549       RCC_PLLCmd(ENABLE);
00550 
00551       /* Wait till PLL is ready */
00552       while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00553       {
00554       }
00555 
00556       /* Select PLL as system clock source */
00557       RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00558 
00559       /* Wait till PLL is used as system clock source */
00560       while(RCC_GetSYSCLKSource() != 0x08)
00561       {
00562       }
00563       break;
00564 
00565     case HDMI_CEC_OPCODE_GET_CEC_VERSION:
00566       /* Send the Used CEC version */
00567       HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
00568       HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_CEC_VERSION;
00569       HDMI_CEC_TX_MessageStructPrivate.Operande[0] = HDMI_CEC_VERSION; /* CEC Version */
00570       HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x01;
00571       errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00572 
00573       /* Retransmit message until 5 time */
00574       while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00575       {
00576         sendcount++;
00577         errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00578       }
00579       break;
00580 
00581     case HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
00582       /* Send the Physical address */
00583       errorstatus = HDMI_CEC_ReportPhysicalAddress();
00584       sendcount = 0;
00585       /* Retransmit message until 5 time */
00586       while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00587       {
00588         sendcount++;
00589         errorstatus = HDMI_CEC_ReportPhysicalAddress();
00590       }
00591       break;
00592 
00593     case HDMI_CEC_OPCODE_FEATURE_ABORT:
00594       /* The device doesn't support the requested message type, or that it cannot
00595       execute it at the present time. */
00596       FeatureOpcode = HDMI_CEC_RX_MessageStructPrivate.Operande[0];
00597       AbortReason = HDMI_CEC_RX_MessageStructPrivate.Operande[1];
00598       break;
00599 
00600     case HDMI_CEC_OPCODE_GIVE_OSD_NAME:
00601       /* Send the OSD name = STM32100B CEC*/
00602       HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
00603       HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_SET_OSD_NAME;
00604       /* STM32100B*/
00605       HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x53;
00606       HDMI_CEC_TX_MessageStructPrivate.Operande[1] = 0x54;
00607       HDMI_CEC_TX_MessageStructPrivate.Operande[2] = 0x4D;
00608       HDMI_CEC_TX_MessageStructPrivate.Operande[3] = 0x33;
00609       HDMI_CEC_TX_MessageStructPrivate.Operande[4] = 0x32;
00610       HDMI_CEC_TX_MessageStructPrivate.Operande[5] = 0x31;
00611       HDMI_CEC_TX_MessageStructPrivate.Operande[6] = 0x30;
00612       HDMI_CEC_TX_MessageStructPrivate.Operande[7] = 0x30;
00613       HDMI_CEC_TX_MessageStructPrivate.Operande[8] = 0x42;
00614       HDMI_CEC_TX_MessageStructPrivate.Operande[9] = 0x20;
00615       /* CEC */
00616       HDMI_CEC_TX_MessageStructPrivate.Operande[10] = 0x43;
00617       HDMI_CEC_TX_MessageStructPrivate.Operande[11] = 0x45;
00618       HDMI_CEC_TX_MessageStructPrivate.Operande[12] = 0x43;
00619       HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 13;
00620       errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00621       sendcount = 0;
00622       /* Retransmit message until 5 time */
00623       while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00624       {
00625         sendcount++;
00626         errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00627       }
00628       break;
00629 
00630     case HDMI_CEC_OPCODE_ROUTING_CHANGE:
00631       for (i = 0;i < 0x14;i++)
00632       {
00633         if ((HDMI_CEC_DeviceMap[i].PhysicalAddress_A == HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4) &&
00634             (HDMI_CEC_DeviceMap[i].PhysicalAddress_B == HDMI_CEC_RX_MessageStructPrivate.Operande[1]&0x0F) &&
00635             (HDMI_CEC_DeviceMap[i].PhysicalAddress_C == HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4) &&
00636             (HDMI_CEC_DeviceMap[i].PhysicalAddress_D == HDMI_CEC_RX_MessageStructPrivate.Operande[0]&0x0F))
00637         {
00638           HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
00639           HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
00640           HDMI_CEC_DeviceMap[i] = HDMI_CEC_MapStruct;
00641         }
00642       }
00643       break;
00644 
00645     default:
00646       /* Send Abort feature*/
00647       HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
00648       HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_FEATURE_ABORT;
00649       HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x02; /* defines command to be performed */
00650       HDMI_CEC_TX_MessageStructPrivate.Operande[1] = HDMI_CEC_REFUSED; /* Reason for abort feature */
00651       HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x02;
00652       errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00653       sendcount = 0;
00654       /* Retransmit message until 5 time */
00655       while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
00656       {
00657         sendcount++;
00658         errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
00659       }
00660       break;
00661 
00662   }
00663 }
00664 
00665 /**
00666   * @brief  Check the connected CEC devices.
00667   * @param  None
00668   * @retval HDMI_CEC_Error
00669   */
00670 HDMI_CEC_Error HDMI_CEC_CheckConnectedDevices(void)
00671 {
00672   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
00673   uint32_t count = 0, i = 1;
00674  
00675   /*----------------------------- TV device  ---------------------------*/
00676   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00677 
00678   CEC_EndOfMessageCmd(ENABLE);
00679 
00680   CEC_SendDataByte((MyLogicalAddress << 4) | 0x0);
00681 
00682   /* Start of message */
00683   CEC_StartOfMessage();
00684 
00685   /* Wait till the header message is sent */
00686   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00687   {
00688     count++;
00689   }
00690 
00691   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00692   {
00693     errorstatus = HDMI_CEC_TIMEOUT;
00694     return(errorstatus);
00695   }
00696 
00697   errorstatus = HDMI_CEC_GetErrorStatus();
00698 
00699   if (errorstatus == HDMI_CEC_OK)
00700   {
00701     HDMI_CEC_Follower_String[0][1] = "1";
00702     i++;
00703     errorstatus = HDMI_CEC_OK;
00704   }
00705 
00706   /* Clear CEC CSR register */
00707   CEC_ClearFlag(CEC_FLAG_TBTRF);
00708   CEC_EndOfMessageCmd(DISABLE);
00709 
00710   /*----------------------------- Recording device 1 ---------------------------*/
00711   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00712 
00713   CEC_EndOfMessageCmd(ENABLE);
00714 
00715   CEC_SendDataByte((MyLogicalAddress << 4) | 0x1);
00716 
00717   /* Start of message */
00718   CEC_StartOfMessage();
00719 
00720   /* Wait till the header message is sent */
00721   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00722   {
00723     count++;
00724   }
00725 
00726   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00727   {
00728     errorstatus = HDMI_CEC_TIMEOUT;
00729     return(errorstatus);
00730   }
00731 
00732   errorstatus = HDMI_CEC_GetErrorStatus();
00733 
00734   if (errorstatus == HDMI_CEC_OK)
00735   {
00736     HDMI_CEC_Follower_String[1][1] = "1";
00737     i++;
00738     errorstatus = HDMI_CEC_OK;
00739   }
00740 
00741   /* Clear CEC CSR register */
00742   CEC_ClearFlag(CEC_FLAG_TBTRF);
00743   CEC_EndOfMessageCmd(DISABLE);
00744   /*----------------------------- Recording device 2 ---------------------------*/
00745   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00746 
00747   CEC_EndOfMessageCmd(ENABLE);
00748 
00749   CEC_SendDataByte((MyLogicalAddress << 4) | 0x2);
00750 
00751   /* Start of message */
00752   CEC_StartOfMessage();
00753 
00754   /* Wait till the header message is sent */
00755   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00756   {
00757     count++;
00758   }
00759 
00760   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00761   {
00762     errorstatus = HDMI_CEC_TIMEOUT;
00763     return(errorstatus);
00764   }
00765 
00766   errorstatus = HDMI_CEC_GetErrorStatus();
00767 
00768   if (errorstatus == HDMI_CEC_OK)
00769   {
00770     HDMI_CEC_Follower_String[2][1] = "1";
00771     i++;
00772     errorstatus = HDMI_CEC_OK;
00773   }
00774 
00775   /* Clear CEC CSR register */
00776   CEC_ClearFlag(CEC_FLAG_TBTRF);
00777   CEC_EndOfMessageCmd(DISABLE);
00778 
00779   /*----------------------------- Tuner 1 ---------------------------*/
00780   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00781 
00782   CEC_EndOfMessageCmd(ENABLE);
00783 
00784   CEC_SendDataByte((MyLogicalAddress << 4) | 0x3);
00785 
00786   /* Start of message */
00787   CEC_StartOfMessage();
00788 
00789   /* Wait till the header message is sent */
00790   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00791   {
00792     count++;
00793   }
00794 
00795   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00796   {
00797     errorstatus = HDMI_CEC_TIMEOUT;
00798     return(errorstatus);
00799   }
00800 
00801   errorstatus = HDMI_CEC_GetErrorStatus();
00802 
00803   if (errorstatus == HDMI_CEC_OK)
00804   {
00805     HDMI_CEC_Follower_String[3][1] = "1";
00806     i++;
00807     errorstatus = HDMI_CEC_OK;
00808   }
00809   /* Clear CEC CSR register */
00810   CEC_ClearFlag(CEC_FLAG_TBTRF);
00811   CEC_EndOfMessageCmd(DISABLE);
00812   /*----------------------------- Playback device 1 ---------------------------*/
00813   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00814 
00815   CEC_EndOfMessageCmd(ENABLE);
00816 
00817   CEC_SendDataByte((MyLogicalAddress << 4) | 0x4);
00818 
00819   /* Start of message */
00820   CEC_StartOfMessage();
00821 
00822   /* Wait till the header message is sent */
00823   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00824   {
00825     count++;
00826   }
00827 
00828   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00829   {
00830     errorstatus = HDMI_CEC_TIMEOUT;
00831     return(errorstatus);
00832   }
00833 
00834   errorstatus = HDMI_CEC_GetErrorStatus();
00835 
00836   if (errorstatus == HDMI_CEC_OK)
00837   {
00838     HDMI_CEC_Follower_String[4][1] = "1";
00839     i++;
00840     errorstatus = HDMI_CEC_OK;
00841   }
00842   /* Clear CEC CSR register */
00843   CEC_ClearFlag(CEC_FLAG_TBTRF);
00844   CEC_EndOfMessageCmd(DISABLE);
00845 
00846   /*----------------------------- Audio system ---------------------------*/
00847   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00848 
00849   CEC_EndOfMessageCmd(ENABLE);
00850 
00851   CEC_SendDataByte((MyLogicalAddress << 4) | 0x5);
00852 
00853   /* Start of message */
00854   CEC_StartOfMessage();
00855 
00856   /* Wait till the header message is sent */
00857   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00858   {
00859     count++;
00860   }
00861 
00862   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00863   {
00864     errorstatus = HDMI_CEC_TIMEOUT;
00865     return(errorstatus);
00866   }
00867 
00868   errorstatus = HDMI_CEC_GetErrorStatus();
00869 
00870   if (errorstatus == HDMI_CEC_OK)
00871   {
00872     HDMI_CEC_Follower_String[5][1] = "1";
00873     i++;
00874     errorstatus = HDMI_CEC_OK;
00875   }
00876   /* Clear CEC CSR register */
00877   CEC_ClearFlag(CEC_FLAG_TBTRF);
00878   CEC_EndOfMessageCmd(DISABLE);
00879 
00880   /*----------------------------- Tuner 2 ---------------------------*/
00881   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00882 
00883   CEC_EndOfMessageCmd(ENABLE);
00884 
00885   CEC_SendDataByte((MyLogicalAddress << 4) | 0x6);
00886 
00887   /* Start of message */
00888   CEC_StartOfMessage();
00889 
00890   /* Wait till the header message is sent */
00891   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00892   {
00893     count++;
00894   }
00895 
00896   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00897   {
00898     errorstatus = HDMI_CEC_TIMEOUT;
00899     return(errorstatus);
00900   }
00901 
00902   errorstatus = HDMI_CEC_GetErrorStatus();
00903 
00904   if (errorstatus == HDMI_CEC_OK)
00905   {
00906     HDMI_CEC_Follower_String[6][1] = "1";
00907     i++;
00908     errorstatus = HDMI_CEC_OK;
00909   }
00910   /* Clear CEC CSR register */
00911   CEC_ClearFlag(CEC_FLAG_TBTRF);
00912   CEC_EndOfMessageCmd(DISABLE);
00913 
00914   /*----------------------------- Tuner 3 ---------------------------*/
00915   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00916 
00917   CEC_EndOfMessageCmd(ENABLE);
00918 
00919   CEC_SendDataByte((MyLogicalAddress << 4) | 0x7);
00920 
00921   /* Start of message */
00922   CEC_StartOfMessage();
00923 
00924   /* Wait till the header message is sent */
00925   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00926   {
00927     count++;
00928   }
00929 
00930   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00931   {
00932     errorstatus = HDMI_CEC_TIMEOUT;
00933     return(errorstatus);
00934   }
00935 
00936   errorstatus = HDMI_CEC_GetErrorStatus();
00937 
00938   if (errorstatus == HDMI_CEC_OK)
00939   {
00940     HDMI_CEC_Follower_String[7][1] = "1";
00941     i++;
00942     errorstatus = HDMI_CEC_OK;
00943   }
00944   /* Clear CEC CSR register */
00945   CEC_ClearFlag(CEC_FLAG_TBTRF);
00946   CEC_EndOfMessageCmd(DISABLE);
00947 
00948   /*----------------------------- Playback device 2 ---------------------------*/
00949   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00950 
00951   CEC_EndOfMessageCmd(ENABLE);
00952 
00953   CEC_SendDataByte((MyLogicalAddress << 4) | 0x8);
00954 
00955   /* Start of message */
00956   CEC_StartOfMessage();
00957 
00958   /* Wait till the header message is sent */
00959   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00960   {
00961     count++;
00962   }
00963 
00964   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00965   {
00966     errorstatus = HDMI_CEC_TIMEOUT;
00967     return(errorstatus);
00968   }
00969 
00970   errorstatus = HDMI_CEC_GetErrorStatus();
00971 
00972   if (errorstatus == HDMI_CEC_OK)
00973   {
00974     HDMI_CEC_Follower_String[8][1] = "1";
00975     i++;
00976     errorstatus = HDMI_CEC_OK;
00977   }
00978   /* Clear CEC CSR register */
00979   CEC_ClearFlag(CEC_FLAG_TBTRF);
00980   CEC_EndOfMessageCmd(DISABLE);
00981 
00982   /*----------------------------- Recording device 3 ---------------------------*/
00983   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
00984 
00985   CEC_EndOfMessageCmd(ENABLE);
00986 
00987   CEC_SendDataByte((MyLogicalAddress << 4) | 0x9);
00988 
00989   /* Start of message */
00990   CEC_StartOfMessage();
00991 
00992   /* Wait till the header message is sent */
00993   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
00994   {
00995     count++;
00996   }
00997 
00998   if (count >= HDMI_CEC_TIMEOUT_VALUE)
00999   {
01000     errorstatus = HDMI_CEC_TIMEOUT;
01001     return(errorstatus);
01002   }
01003 
01004   errorstatus = HDMI_CEC_GetErrorStatus();
01005 
01006   if (errorstatus == HDMI_CEC_OK)
01007   {
01008     HDMI_CEC_Follower_String[9][1] = "1";
01009     i++;
01010     errorstatus = HDMI_CEC_OK;
01011   }
01012   /* Clear CEC CSR register */
01013   CEC_ClearFlag(CEC_FLAG_TBTRF);
01014   CEC_EndOfMessageCmd(DISABLE);
01015   /*----------------------------- Tuner 4 ---------------------------*/
01016   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
01017 
01018   CEC_EndOfMessageCmd(ENABLE);
01019 
01020   CEC_SendDataByte((MyLogicalAddress << 4) | 0xA);
01021 
01022   /* Start of message */
01023   CEC_StartOfMessage();
01024 
01025   /* Wait till the header message is sent */
01026   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01027   {
01028     count++;
01029   }
01030 
01031   if (count >= HDMI_CEC_TIMEOUT_VALUE)
01032   {
01033     errorstatus = HDMI_CEC_TIMEOUT;
01034     return(errorstatus);
01035   }
01036 
01037   errorstatus = HDMI_CEC_GetErrorStatus();
01038 
01039   if (errorstatus == HDMI_CEC_OK)
01040   {
01041     HDMI_CEC_Follower_String[10][1] = "1";
01042     i++;
01043     errorstatus = HDMI_CEC_OK;
01044   }
01045   /* Clear CEC CSR register */
01046   CEC_ClearFlag(CEC_FLAG_TBTRF);
01047   CEC_EndOfMessageCmd(DISABLE);
01048   /*----------------------------- Playback device 3 ---------------------------*/
01049   CEC_OwnAddressConfig(MyLogicalAddress); /* Own address = MyLogicalAddress */
01050 
01051   CEC_EndOfMessageCmd(ENABLE);
01052 
01053   CEC_SendDataByte((MyLogicalAddress << 4) | 0xB);
01054 
01055   /* Start of message */
01056   CEC_StartOfMessage();
01057 
01058   /* Wait till the header message is sent */
01059   while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01060   {
01061     count++;
01062   }
01063 
01064   if (count >= HDMI_CEC_TIMEOUT_VALUE)
01065   {
01066     errorstatus = HDMI_CEC_TIMEOUT;
01067     return(errorstatus);
01068   }
01069 
01070   errorstatus = HDMI_CEC_GetErrorStatus();
01071 
01072   if (errorstatus == HDMI_CEC_OK)
01073   {
01074     HDMI_CEC_Follower_String[11][1] = "1";
01075     i++;
01076     errorstatus = HDMI_CEC_OK;
01077   }
01078   /* Clear CEC CSR register */
01079   CEC_ClearFlag(CEC_FLAG_TBTRF);
01080   CEC_EndOfMessageCmd(DISABLE);
01081 
01082   CECDevicesNumber = i - 1;
01083 
01084   return errorstatus;
01085 }
01086 
01087 /**
01088   * @brief  Physical address discovery.
01089   * @param  None
01090   * @retval HDMI_CEC_Error: CEC Error code.
01091   */
01092 static HDMI_CEC_Error PhysicalAddressDiscovery(void)
01093 {
01094   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
01095 #ifdef HDMI_CEC_USE_DDC
01096   uint32_t index = 0, i = 0;
01097 #endif
01098 
01099   /*------------------------------ Physical address discovery -----------------*/
01100   if (HDMI_CEC_ROOT == 0x1)
01101   {
01102     MyPhysicalAddress = 0x0000;
01103     /* The HDMI-CEC here is configured as sink or as a repeater. The configuration
01104        of the +5V power signal and the HPD should be well configured.
01105        Implement here the EDID Structure to be sent to the HDMI source.
01106        For more details please refer to the HDMI specification. 
01107        The EDID structure should be sent to the device source using the DDC Channel
01108        and using the HPD signal. */
01109   }
01110   else
01111   {
01112   
01113 #ifdef HDMI_CEC_USE_DDC  
01114     /* The HDMI-CEC here is configured as source or as a repeater. The configuration
01115        of the +5V power signal and the HPD should be well configured.
01116        The source should wait for HPD and then read the EDID structure. */
01117     while(GPIO_ReadInputDataBit(HDMI_CEC_HPD_GPIO_PORT, HDMI_CEC_HPD_PIN) == RESET)
01118     {
01119     }
01120     /* Wait for 100 ms after HPD was received */
01121     for(i = 0; i < 0x5FFFF; i++)
01122     {
01123     }
01124 
01125     /* Return the physical address using the I2C  by reading the 2 bytes 24 and
01126       25 form the EDID */
01127     /* Read the EDID Block 0 and EDID Block 1 at address 0xA0 */
01128     /*!< While the bus is busy */
01129     while(I2C_GetFlagStatus(HDMI_CEC_I2C, I2C_FLAG_BUSY))
01130     {
01131     }
01132   
01133     /*!< Send START condition */
01134     I2C_GenerateSTART(HDMI_CEC_I2C, ENABLE);
01135   
01136     /*!< Test on EV5 and clear it */
01137     while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_MODE_SELECT))
01138     {
01139     }
01140    
01141     /*!< Send EEPROM address for write */
01142     I2C_Send7bitAddress(HDMI_CEC_I2C, 0xA0, I2C_Direction_Transmitter);
01143  
01144 
01145     /*!< Test on EV6 and clear it */
01146     while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
01147     {
01148     }
01149 
01150     /*!< Send the EEPROM's internal address to read from: Only one byte address */
01151     I2C_SendData(HDMI_CEC_I2C, 0x00);  
01152 
01153     /*!< Test on EV8 and clear it */
01154     while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
01155     {
01156     }
01157   
01158     /*!< Send STRAT condition a second time */  
01159     I2C_GenerateSTART(HDMI_CEC_I2C, ENABLE);
01160   
01161     /*!< Test on EV5 and clear it */
01162     while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_MODE_SELECT))
01163     {
01164     }
01165   
01166     /*!< Send EEPROM address for read */
01167     I2C_Send7bitAddress(HDMI_CEC_I2C, 0xA1, I2C_Direction_Receiver);
01168   
01169     /*!< Test on EV6 and clear it */
01170     while(!I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
01171     {
01172     }
01173 
01174     /* While there is data to be read */
01175     while (NumByteToRead-- > 1)
01176     {
01177       while(I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
01178       {
01179       }
01180       for(i = 0; i < 0xFFF; i++)
01181       {
01182       }
01183       pBuffer[index++] = I2C_ReceiveData(HDMI_CEC_I2C);
01184     }
01185 
01186     /* Disable Acknowledgement */
01187     I2C_AcknowledgeConfig(HDMI_CEC_I2C, DISABLE);
01188 
01189     /* Send STOP Condition */
01190     I2C_GenerateSTOP(HDMI_CEC_I2C, ENABLE);
01191 
01192     while(I2C_CheckEvent(HDMI_CEC_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED));
01193     pBuffer[index] = I2C_ReceiveData(HDMI_CEC_I2C);
01194 
01195     /* Enable Acknowledgement to be ready for another reception */
01196     I2C_AcknowledgeConfig(HDMI_CEC_I2C, ENABLE);
01197     MyPhysicalAddress = ((pBuffer[138] << 8) | pBuffer[137]);
01198 #else
01199     MyPhysicalAddress = 0x1000;
01200 #endif
01201   }
01202 
01203   return errorstatus;
01204 }
01205 /**
01206   * @brief  Allocate the logical address.
01207   * @param  None
01208   * @retval HDMI_CEC_Error: CEC Error code.
01209   */
01210 static HDMI_CEC_Error LogicalAddressAllocation(void)
01211 {
01212   HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
01213   uint32_t count = 0;
01214 
01215   /*------------------ Logical address allocation -----------------------------*/
01216   /* Get the device type */
01217   /* Device type = CEC_TV */
01218   if (DeviceType == HDMI_CEC_TV)
01219   {
01220     if (HDMI_CEC_ROOT)
01221     {
01222       MyLogicalAddress = 0x00;
01223     }
01224     else
01225     {
01226       CEC_OwnAddressConfig(0xE); /* Own address = 0xE */
01227 
01228       CEC_EndOfMessageCmd(ENABLE);
01229 
01230       CEC_SendDataByte(0xEE);
01231 
01232       /* Start of message */
01233       CEC_StartOfMessage();
01234 
01235       /* Wait till the polling message is sent */
01236       while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01237       {
01238         count++;
01239       }
01240 
01241       if (count >= HDMI_CEC_TIMEOUT_VALUE)
01242       {
01243         errorstatus = HDMI_CEC_TIMEOUT;
01244         return(errorstatus);
01245       }
01246 
01247       errorstatus = HDMI_CEC_GetErrorStatus();
01248 
01249       if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01250       {
01251         MyLogicalAddress = 0x0E;
01252         errorstatus = HDMI_CEC_OK;
01253       }
01254       else if (errorstatus == HDMI_CEC_OK)
01255       {
01256         MyLogicalAddress = 0x0F;
01257         errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
01258       }
01259     }
01260     /* Clear CEC CSR register */
01261     CEC_ClearFlag(CEC_FLAG_TBTRF);
01262     CEC_EndOfMessageCmd(DISABLE);
01263   }
01264 
01265   /* Device type = CEC_RECORDING */
01266   if (DeviceType == HDMI_CEC_RECORDING)
01267   {
01268     CEC_OwnAddressConfig(0x1); /* Own address = 0x1 */
01269 
01270     CEC_EndOfMessageCmd(ENABLE);
01271 
01272     CEC_SendDataByte(0x11);
01273 
01274     /* Start of message */
01275     CEC_StartOfMessage();
01276 
01277     /* Wait till the header message is sent */
01278     while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01279     {
01280       count++;
01281     }
01282 
01283     if (count >= HDMI_CEC_TIMEOUT_VALUE)
01284     {
01285       errorstatus = HDMI_CEC_TIMEOUT;
01286       return(errorstatus);
01287     }
01288 
01289     errorstatus = HDMI_CEC_GetErrorStatus();
01290 
01291     if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01292     {
01293       MyLogicalAddress = 0x01;
01294       errorstatus = HDMI_CEC_OK;
01295     }
01296     else if (errorstatus == HDMI_CEC_OK)
01297     {
01298       /* Clear CEC CSR register */
01299       CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01300 
01301       CEC_EndOfMessageCmd(DISABLE);
01302 
01303       CEC_OwnAddressConfig(0x2); /* Own address = 0x2 */
01304 
01305       CEC_EndOfMessageCmd(ENABLE);
01306 
01307       CEC_SendDataByte(0x22);
01308 
01309       /* Start of message */
01310       CEC_StartOfMessage();
01311 
01312       count = 0;
01313 
01314       /* Wait till the header message is sent */
01315       while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01316       {
01317         count++;
01318       }
01319 
01320       if (count >= HDMI_CEC_TIMEOUT_VALUE)
01321       {
01322         errorstatus = HDMI_CEC_TIMEOUT;
01323         return(errorstatus);
01324       }
01325       errorstatus = HDMI_CEC_GetErrorStatus();
01326 
01327       if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01328       {
01329         MyLogicalAddress = 0x02;
01330         errorstatus = HDMI_CEC_OK;
01331       }
01332       else if (errorstatus == HDMI_CEC_OK)
01333       {
01334         /* Clear CEC CSR register */
01335         CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01336 
01337         CEC_EndOfMessageCmd(DISABLE);
01338 
01339         CEC_OwnAddressConfig(0x9); /* Own address = 0x9 */
01340 
01341         CEC_EndOfMessageCmd(ENABLE);
01342 
01343         CEC_SendDataByte(0x99);
01344 
01345         /* Start of message */
01346         CEC_StartOfMessage();
01347 
01348         count = 0;
01349 
01350         /* Wait till the header message is sent */
01351         while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01352         {
01353           count++;
01354         }
01355 
01356         if (count >= HDMI_CEC_TIMEOUT_VALUE)
01357         {
01358           errorstatus = HDMI_CEC_TIMEOUT;
01359           return(errorstatus);
01360         }
01361         errorstatus = HDMI_CEC_GetErrorStatus();
01362 
01363         if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01364         {
01365           MyLogicalAddress = 0x09;
01366           errorstatus = HDMI_CEC_OK;
01367         }
01368         else if (errorstatus == HDMI_CEC_OK)
01369         {
01370           MyLogicalAddress = 0x0F;
01371           errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
01372         }
01373       }
01374     }
01375     /* Clear CEC CSR register */
01376     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01377     CEC_EndOfMessageCmd(DISABLE);
01378   }
01379 
01380   /* Device type = CEC_TUNER */
01381   if (DeviceType == HDMI_CEC_TUNER)
01382   {
01383     CEC_OwnAddressConfig(0x3); /* Own address = 0x3 */
01384 
01385     CEC_EndOfMessageCmd(ENABLE);
01386 
01387     CEC_SendDataByte(0x33);
01388 
01389     /* Start of message */
01390     CEC_StartOfMessage();
01391 
01392     count = 0;
01393 
01394     /* Wait till the header message is sent */
01395     while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01396     {
01397       count++;
01398     }
01399 
01400     if (count >= HDMI_CEC_TIMEOUT_VALUE)
01401     {
01402       errorstatus = HDMI_CEC_TIMEOUT;
01403       return(errorstatus);
01404     }
01405     errorstatus = HDMI_CEC_GetErrorStatus();
01406 
01407     if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01408     {
01409       MyLogicalAddress = 0x03;
01410       errorstatus = HDMI_CEC_OK;
01411     }
01412     else if (errorstatus == HDMI_CEC_OK)
01413     {
01414       /* Clear CEC CSR register */
01415       CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01416 
01417       CEC_EndOfMessageCmd(DISABLE);
01418 
01419       CEC_OwnAddressConfig(0x6); /* Own address = 0x6 */
01420 
01421       CEC_EndOfMessageCmd(ENABLE);
01422 
01423       CEC_SendDataByte(0x66);
01424 
01425       /* Start of message */
01426       CEC_StartOfMessage();
01427 
01428       count = 0;
01429 
01430       /* Wait till the header message is sent */
01431       while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01432       {
01433         count++;
01434       }
01435 
01436       if (count >= HDMI_CEC_TIMEOUT_VALUE)
01437       {
01438         errorstatus = HDMI_CEC_TIMEOUT;
01439         return(errorstatus);
01440       }
01441       errorstatus = HDMI_CEC_GetErrorStatus();
01442 
01443       if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01444       {
01445         MyLogicalAddress = 0x06;
01446         errorstatus = HDMI_CEC_OK;
01447       }
01448       else if (errorstatus == HDMI_CEC_OK)
01449       {
01450         /* Clear CEC CSR register */
01451         CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01452 
01453         CEC_EndOfMessageCmd(DISABLE);
01454 
01455         CEC_OwnAddressConfig(0x7); /* Own address = 0x7 */
01456 
01457         CEC_EndOfMessageCmd(ENABLE);
01458 
01459         CEC_SendDataByte(0x77);
01460 
01461         /* Start of message */
01462         CEC_StartOfMessage();
01463 
01464         count = 0;
01465 
01466         /* Wait till the header message is sent */
01467         while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01468         {
01469           count++;
01470         }
01471 
01472         if (count >= HDMI_CEC_TIMEOUT_VALUE)
01473         {
01474           errorstatus = HDMI_CEC_TIMEOUT;
01475           return(errorstatus);
01476         }
01477         errorstatus = HDMI_CEC_GetErrorStatus();
01478 
01479         if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01480         {
01481           MyLogicalAddress = 0x07;
01482           errorstatus = HDMI_CEC_OK;
01483         }
01484         else if (errorstatus == HDMI_CEC_OK)
01485         {
01486           /* Clear CEC CSR register */
01487           CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01488 
01489           CEC_EndOfMessageCmd(DISABLE);
01490 
01491           CEC_OwnAddressConfig(0xA); /* Own address = 0xA */
01492 
01493           CEC_EndOfMessageCmd(ENABLE);
01494 
01495           CEC_SendDataByte(0xAA);
01496 
01497           /* Start of message */
01498           CEC_StartOfMessage();
01499 
01500           count = 0;
01501 
01502           /* Wait till the header message is sent */
01503           while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01504           {
01505             count++;
01506           }
01507 
01508           if (count >= HDMI_CEC_TIMEOUT_VALUE)
01509           {
01510             errorstatus = HDMI_CEC_TIMEOUT;
01511             return(errorstatus);
01512           }
01513           errorstatus = HDMI_CEC_GetErrorStatus();
01514 
01515           if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01516           {
01517             MyLogicalAddress = 0x0A;
01518             errorstatus = HDMI_CEC_OK;
01519           }
01520           else if (errorstatus == HDMI_CEC_OK)
01521           {
01522             MyLogicalAddress = 0x0F;
01523             errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
01524           }
01525         }
01526       }
01527     }
01528     /* Clear CEC CSR register */
01529     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01530     CEC_EndOfMessageCmd(DISABLE);
01531   }
01532 
01533   /* Device type = CEC_PLAYBACK */
01534   if (DeviceType == HDMI_CEC_PLAYBACK)
01535   {
01536     CEC_OwnAddressConfig(0x4); /* Own address = 0x4 */
01537 
01538     CEC_EndOfMessageCmd(ENABLE);
01539 
01540     CEC_SendDataByte(0x44);
01541 
01542     /* Start of message */
01543     CEC_StartOfMessage();
01544 
01545     count = 0;
01546 
01547     /* Wait till the header message is sent */
01548     while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01549     {
01550       count++;
01551     }
01552 
01553     if (count >= HDMI_CEC_TIMEOUT_VALUE)
01554     {
01555       errorstatus = HDMI_CEC_TIMEOUT;
01556       return(errorstatus);
01557     }
01558 
01559     errorstatus = HDMI_CEC_GetErrorStatus();
01560 
01561     if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01562     {
01563       MyLogicalAddress = 0x04;
01564       errorstatus = HDMI_CEC_OK;
01565     }
01566     else if (errorstatus == HDMI_CEC_OK)
01567     {
01568       /* Clear CEC CSR register */
01569       CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01570 
01571       CEC_EndOfMessageCmd(DISABLE);
01572 
01573       CEC_OwnAddressConfig(0x8); /* Own address = 0x8 */
01574 
01575       CEC_EndOfMessageCmd(ENABLE);
01576 
01577       CEC_SendDataByte(0x88);
01578 
01579       /* Start of message */
01580       CEC_StartOfMessage();
01581 
01582       count = 0;
01583 
01584       /* Wait till the header message is sent */
01585       while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01586       {
01587         count++;
01588       }
01589 
01590       if (count >= HDMI_CEC_TIMEOUT_VALUE)
01591       {
01592         errorstatus = HDMI_CEC_TIMEOUT;
01593         return(errorstatus);
01594       }
01595       errorstatus = HDMI_CEC_GetErrorStatus();
01596 
01597       if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01598       {
01599         MyLogicalAddress = 0x08;
01600         errorstatus = HDMI_CEC_OK;
01601       }
01602       else if (errorstatus == HDMI_CEC_OK)
01603       {
01604         /* Clear CEC CSR register */
01605         CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01606 
01607         CEC_EndOfMessageCmd(DISABLE);
01608 
01609         CEC_OwnAddressConfig(0xB); /* Own address = 0xBB */
01610 
01611         CEC_EndOfMessageCmd(ENABLE);
01612 
01613         CEC_SendDataByte(0xBB);
01614 
01615         /* Start of message */
01616         CEC_StartOfMessage();
01617 
01618         count = 0;
01619 
01620         /* Wait till the header message is sent */
01621         while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01622         {
01623           count++;
01624         }
01625 
01626         if (count >= HDMI_CEC_TIMEOUT_VALUE)
01627         {
01628           errorstatus = HDMI_CEC_TIMEOUT;
01629           return(errorstatus);
01630         }
01631 
01632         errorstatus = HDMI_CEC_GetErrorStatus();
01633 
01634         if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01635         {
01636           MyLogicalAddress = 0x0B;
01637           errorstatus = HDMI_CEC_OK;
01638         }
01639         else if (errorstatus == HDMI_CEC_OK)
01640         {
01641           MyLogicalAddress = 0x0F;
01642           errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
01643         }
01644       }
01645     }
01646 
01647     /* Clear CEC CSR register */
01648     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01649     CEC_EndOfMessageCmd(DISABLE);
01650   }
01651 
01652   /* Device type = CEC Audio System */
01653   if (DeviceType == HDMI_CEC_AUDIOSYSTEM)
01654   {
01655     CEC_OwnAddressConfig(0x5); /* Own address = 0x5 */
01656 
01657     CEC_EndOfMessageCmd(ENABLE);
01658 
01659     CEC_SendDataByte(0x55);
01660 
01661     /* Start of message */
01662     CEC_StartOfMessage();
01663 
01664     count = 0;
01665 
01666     /* Wait till the header message is sent */
01667     while ((CEC_GetFlagStatus(CEC_FLAG_TBTRF) == RESET) && (CEC_GetFlagStatus(CEC_FLAG_TERR) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
01668     {
01669       count++;
01670     }
01671 
01672     if (count >= HDMI_CEC_TIMEOUT_VALUE)
01673     {
01674       errorstatus = HDMI_CEC_TIMEOUT;
01675       return(errorstatus);
01676     }
01677 
01678     errorstatus = HDMI_CEC_GetErrorStatus();
01679 
01680     if (errorstatus == HDMI_CEC_BLOCK_ACKNOWLEDGE)
01681     {
01682       MyLogicalAddress = 0x05;
01683       errorstatus = HDMI_CEC_OK;
01684     }
01685     else if (errorstatus == HDMI_CEC_OK)
01686     {
01687       MyLogicalAddress = 0x0F;
01688       errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
01689     }
01690 
01691     /* Clear CEC CSR register */
01692     CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR);
01693     CEC_EndOfMessageCmd(DISABLE);
01694   }
01695 
01696   return errorstatus;
01697 }
01698 
01699 /**
01700   * @}
01701   */
01702 
01703 /**
01704   * @}
01705   */
01706 
01707 /**
01708   * @}
01709   */
01710 
01711 /**
01712   * @}
01713   */
01714 
01715 /**
01716   * @}
01717   */  
01718 
01719 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
01720 
01721 
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32