/** * @brief Main program * @param None * @retval None */ int main(void) { /* This sample code shows how to use STM32F4xx CEC HAL API to transmit and * receive data. The device is set in waiting to receive mode and sends * messages when the evaluation board buttons are pushed by the user */ /* STM32F4xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* -1- Initialize LEDs mounted on EVAL board */ /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* -2- Configure User push-button in Interrupt mode */ /* button-triggered interruptions initialization */ BSP_PB_Init(BUTTON_TAMPER,BUTTON_MODE_EXTI); /* -3- Configure Joystick Selection push-button in Interrupt mode */ BSP_JOY_Init(JOY_MODE_EXTI); /* CEC device initialization */ #if defined (DEVICE_1) LogicalAddress = DEVICE_ADDRESS_1; DestinationAddress = DEVICE_ADDRESS_2; /* follower address */ #elif defined (DEVICE_2) LogicalAddress = DEVICE_ADDRESS_2; DestinationAddress = DEVICE_ADDRESS_1; /* follower address */ #elif defined (DEVICE_3) LogicalAddress = DEVICE_ADDRESS_3; DestinationAddress = DEVICE_ADDRESS_1; /* follower address */ #endif /* -4- CEC configuration (transfer will take place in Interrupt mode) */ hcec.Instance = CEC; /* Deinitialize CEC to reinitialize from scratch */ HAL_CEC_DeInit(&hcec); /* IP configuration */ CEC_Config(&hcec); /* -5- CEC transfer general variables initialization */ ReceivedFrame = 0; StartSending = 0; NbOfReceivedBytes = 0; CEC_FlushRxBuffer(); /* Test start */ /* Enter infinite reception loop: the CEC device is set in * waiting to receive mode. * The CEC "background" state is HAL_CEC_STATE_STANDBY_RX. * Upon any message reception or transmission, the CEC * comes back to that state. * It is up to the user to define exit conditions in modifying * accordingly the RX, TX or Error callback functions. */ HAL_CEC_Receive_IT(&hcec, (uint8_t *)&Tab_Rx); while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY) { /* if no reception has occurred and no error has been detected, * transmit a message if the user has pushed a button */ if( (StartSending == 1) && (ReceivedFrame == 0)) { HAL_CEC_Transmit_IT(&hcec, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize); /* loop until TX ends or TX error reported */ while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_STANDBY_RX); StartSending = 0; } /* if a frame has been received */ if (ReceivedFrame == 1) { if (Tab_Rx[1] == 0x44) /* Test on the opcode value */ { /* Receive command is equal to Volume Up(Button Up) */ if (Tab_Rx[2] == 0x41) /* Test on the operand value */ { BSP_LED_On(LED1); BSP_LED_On(LED2); BSP_LED_On(LED3); BSP_LED_On(LED4); } else if (Tab_Rx[2] == 0x42) /* Receive command is equal to Volume Down(Button Down) */ { BSP_LED_Off(LED1); BSP_LED_Off(LED2); BSP_LED_Off(LED3); BSP_LED_Off(LED4); } } else if (Tab_Rx[1] == 0x46) /* Test on the opcode value */ { BSP_LED_On(LED1); BSP_LED_On(LED2); BSP_LED_Off(LED3); BSP_LED_Off(LED4); } else if (Tab_Rx[1] == 0x9F) /* Test on the opcode value */ { BSP_LED_Off(LED1); BSP_LED_Off(LED2); BSP_LED_On(LED3); BSP_LED_On(LED4); } ReceivedFrame = 0; } else if (ReceivedFrame == 2) /* means CEC error detected */ { /* Turn on LED3 */ BSP_LED_On(LED3); ReceivedFrame = 0; } } /* while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY) */ return 0; }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* This sample code shows how to use STM32F7xx CEC HAL API to transmit and * receive data. The device is set in waiting to receive mode and sends * messages when the evaluation board buttons are pushed by the user */ /* Configure the MPU attributes as Write Through */ MPU_Config(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); /* STM32F7xx HAL library initialization: - Configure the Flash ART accelerator - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 200 MHz MHz */ SystemClock_Config(); /*##-1- Initialize the SDRAM ##############################################*/ BSP_SDRAM_Init(); /*##-2- Initialize the LCD #################################################*/ BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Select the LCD Foreground layer */ BSP_LCD_SelectLayer(1); /* Display test description on screen */ CEC_SetHint(); /* -2- Configure touch screen */ BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); BSP_TS_ITConfig(); /* Touch screen interrupt configuration and enable */ /* -3- CEC configuration (transfer will take place in Interrupt mode) */ #if defined (DEVICE_1) DestinationAddress = DEVICE_ADDRESS_2; /* follower address */ #elif defined (DEVICE_2) DestinationAddress = DEVICE_ADDRESS_1; /* follower address */ #endif hcec.Instance = CEC; /* Deinitialize CEC to reinitialize from scratch */ HAL_CEC_DeInit(&hcec); /* IP configuration */ CEC_Config(&hcec); /* -4- CEC transfer general variables initialization */ ReceivedFrame = 0; StartSending = 0; NbOfReceivedBytes = 0; CEC_FlushRxBuffer(); /* Test start */ /* Enter infinite reception loop: the CEC device is set in * waiting to receive mode. * The CEC "background" state is HAL_CEC_STATE_STANDBY_RX. * Upon any message reception or transmission, the CEC * comes back to that state. * It is up to the user to define exit conditions in modifying * accordingly the RX, TX or Error callback functions. */ HAL_CEC_Receive_IT(&hcec, (uint8_t *)&Tab_Rx); while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY) { /* if no reception has occurred and no error has been detected, * transmit a message if the user has pushed a button */ if( (StartSending == 1) && (ReceivedFrame == 0)) { HAL_CEC_Transmit_IT(&hcec, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize); /* loop until TX ends or TX error reported */ while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_STANDBY_RX); StartSending = 0; } /* if a frame has been received */ if (ReceivedFrame == 1) { if (Tab_Rx[1] == 0x44) /* Test on the opcode value */ { /* Receive command is equal to Command 1 */ if (Tab_Rx[2] == 0x41) /* Test on the operand value */ { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)" Received opcode 44, operand 41 ", CENTER_MODE); } else if (Tab_Rx[2] == 0x42) /* Receive command is equal to Command 2 */ { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)" Received opcode 44, operand 42 ", CENTER_MODE); } } else if (Tab_Rx[1] == 0x46) /* Test on the opcode value */ { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_ORANGE); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)" Received opcode 46 ", CENTER_MODE); } else if (Tab_Rx[1] == 0x9F) /* Test on the opcode value */ { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_DARKMAGENTA); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+30, (uint8_t *)" Received opcode 9F ", CENTER_MODE); } ReceivedFrame = 0; } else if (ReceivedFrame == 2) /* means CEC error detected */ { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()/2)+45, (uint8_t *)" CEC Error ", CENTER_MODE); ReceivedFrame = 0; } } /* while (HAL_CEC_GetState(&hcec) != HAL_CEC_STATE_READY) */ return 0; }