/** * @brief Changes the selection mode. * @param select_mode: Selection mode * @retval None */ static void AUDIO_ChangeSelectMode(AUDIO_DEMO_SelectMode select_mode) { if(select_mode == AUDIO_SELECT_MENU) { AUDIO_SelectItem(AUDIO_main_menu, 0x00); LCD_LOG_UpdateDisplay(); AudioDemo.state = AUDIO_DEMO_IDLE; AUDIO_PLAYER_Stop(); } else if(select_mode == AUDIO_PLAYBACK_CONTROL) { LCD_ClearTextZone(); AUDIO_SelectItem(AUDIO_main_menu, 0xFF); } AudioSelectMode = select_mode; AudioDemo.select = 0; }
/** * @brief EXTI line detection callbacks. * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { static uint32_t debounce_time = 0; if(GPIO_Pin == MFX_IRQOUT_PIN) { /* The different functionalities of MFX (TS, Joystick, SD detection, etc, ) can be configured in EXTI mode to generate an IRQ on IO transition events. Querying the IO states is based on I2C communication that is not recommended to be called within ISR context to prevent blocking the interrupt. HMI devices such as TS, Joystick, SD detection are relatively slow and heavy processes. So, it is recommended to use polling and interrupt based modes together: the query on IO states in the polling statement is triggered through a flag that is set in the ISR */ /* Here is an example of implementation based on a mix between polling and interrupt mode: On ISR a flag is set (MfxIrqAsserted) and in the main loop, the flag is checked before handling the I2C process*/ MfxIrqReceived = 1; } if(AudioDemo.state == AUDIO_DEMO_PLAYBACK) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } /* Change the selection type */ if(AudioSelectMode == AUDIO_SELECT_MENU) { AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); } else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { AUDIO_PLAYER_Stop(); } } } if(AudioDemo.state == AUDIO_DEMO_IN) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } AudioState = AUDIO_STATE_STOP; } } }
/** * @brief EXTI line detection callbacks. * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { static JOYState_TypeDef JoyState = JOY_NONE; static uint32_t debounce_time = 0; if(GPIO_Pin == GPIO_PIN_8) { /* Get the Joystick State */ JoyState = BSP_JOY_GetState(); /* Clear joystick interrupt pending bits */ BSP_IO_ITClear(); if(AudioSelectMode == AUDIO_SELECT_MENU) { AUDIO_MenuProbeKey(JoyState); switch(JoyState) { case JOY_LEFT: LCD_LOG_ScrollBack(); break; case JOY_RIGHT: LCD_LOG_ScrollForward(); break; default: break; } } else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { AUDIO_PlaybackProbeKey(JoyState); } } if(AudioDemo.state == AUDIO_DEMO_PLAYBACK) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } /* Change the selection type */ if(AudioSelectMode == AUDIO_SELECT_MENU) { AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); } else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { AUDIO_PLAYER_Stop(); } } } if(AudioDemo.state == AUDIO_DEMO_IN) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } AudioState = AUDIO_STATE_STOP; } } }
/** * @brief EXTI line detection callbacks. * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { static uint32_t debounce_time = 0; if(GPIO_Pin == MFX_IRQOUT_PIN) { /* The different functionalities of MFX (TS, Joystick, SD detection, etc. ) can be configured in exti mode to generate an IRQ on given events. The MFX IRQ_OUT pin is unique and common to all functionalities, so if several functionalities are configured in exit mode, the MCU has to enquire MFX about the IRQ source (see BSP_IO_ITGetStatus). Communication with Mfx is done by I2C. Often the sw requires ISRs (irq service routines) to be quick while communication with I2C can be considered relatively long (hundreds of usec depending on I2C clk). Considering that the features for human interaction like TS, Joystick, SD detection don’t need immediate reaction, it is suggested to use POLLING instead of EXTI mode, in order to avoid "blocking I2C communication" on interrupt service routines */ /* Here an example of implementation is proposed: mix between pooling and exit: On ISR a flag is set (MfxIrqReceived), the main loop polls on the flag; Mcu communicates with Mfx only when the flag has been set. This is just an example: the users should choose they strategy depending on their application needs.*/ MfxExtiReceived = 1; } if(AudioDemo.state == AUDIO_DEMO_PLAYBACK) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } /* Change the selection type */ if(AudioSelectMode == AUDIO_SELECT_MENU) { AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); } else if(AudioSelectMode == AUDIO_PLAYBACK_CONTROL) { AUDIO_PLAYER_Stop(); } } } if(AudioDemo.state == AUDIO_DEMO_IN) { if(GPIO_Pin == KEY_BUTTON_PIN) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 50) { debounce_time = HAL_GetTick(); } else { return; } AudioState = AUDIO_STATE_STOP; } } }