/** * @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) { if(BSP_IO_ITGetStatus(JOY_SEL_PIN) != 0) { /* SEL is used to pause and resume the audio playback */ if (PressCount == 1) { /* Resume playing Wave status */ PauseResumeStatus = RESUME_STATUS; PressCount = 0; } else { /* Pause playing Wave status */ PauseResumeStatus = PAUSE_STATUS; PressCount = 1; } } else if(BSP_IO_ITGetStatus(JOY_UP_PIN) != 0) { /* UP is used to increment the volume of the audio playback */ volume ++; if (volume > 100) { volume = 100; } VolumeChange = 1; } else if(BSP_IO_ITGetStatus(JOY_DOWN_PIN) != 0) { /* DOWN is used to decrement the volume of the audio playback */ volume --; if ((int8_t)volume < 50) { volume = 50; } VolumeChange = 1; } else if(BSP_IO_ITGetStatus(JOY_RIGHT_PIN) != 0) { /* Audio change output: speaker only */ UserOutputMode = OUTPUT_DEVICE_SPEAKER; } else if(BSP_IO_ITGetStatus(JOY_LEFT_PIN) != 0) { /* Audio change output: headset only */ UserOutputMode = OUTPUT_DEVICE_HEADPHONE; } /* Clear IO Expander IT */ BSP_IO_ITClear(JOY_ALL_PINS); }
/** * @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) { /* Get the IT status register value */ if(BSP_IO_ITGetStatus(MII_INT_PIN)) { ethernetif_set_link(&gnetif); } BSP_IO_ITClear(); }
/** * @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) { if (GPIO_Pin == GPIO_PIN_8) { /* Get the IT status register value */ if(BSP_IO_ITGetStatus(MII_INT_PIN)) { osSemaphoreRelease(Netif_LinkSemaphore); } } }
/** * @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) { if (GPIO_Pin == MFX_IRQOUT_PIN) { /* Get the IT status register value */ if(BSP_IO_ITGetStatus(MII_INT_PIN)) { /* ethernetif_notify_conn_changed(&gnetif);; */ } BSP_IO_ITClear(); } }
/** * @brief Joystick Exti demo * @param None * @retval None */ void Joystick_exti_demo (void) { uint8_t status = 0; uint32_t ITstatus = 0; Joystick_SetHint(1); status = BSP_JOY_Init(JOY_MODE_EXTI); if (status != IO_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Joystick cannot be initialized", CENTER_MODE); } if (status == IO_OK) { Joystick_SetCursorPosition(); } while (1) /* pull for USER button in GPIO mode */ { if (status == IO_OK) { if (MfxExtiReceived == 1) { MfxExtiReceived = 0; ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS); if (ITstatus) { /* Get the Joystick State */ JoyState = BSP_JOY_GetState(); Joystick_SetCursorPosition(); } BSP_IO_ITClear(); /* poll if joystick is still pressed until it is released*/ while ( BSP_JOY_GetState() != JOY_NONE) { Joystick_SetCursorPosition(); HAL_Delay(5); } } } if(CheckForUserInput() > 0) { return; } HAL_Delay(5); } }
/** * @brief Gets the touch screen interrupt status. * @retval TS_IRQ_PENDING if touchscreen IRQ is pending, TS_NO_IRQ_PENDING when no IRQ TS is pending. */ uint8_t BSP_TS_ITGetStatus(void) { uint8_t itStatus = TS_NO_IRQ_PENDING; /* By default no IRQ TS pending */ uint32_t mfx_irq_status = 0; /* No MFX IRQ by default */ /* Check status of MFX_IO14 in particular which is the Touch Screen INT pin active low */ mfx_irq_status = BSP_IO_ITGetStatus(TS_INT_PIN); if(mfx_irq_status != 0) /* Note : returned mfx_irq_status = 0x4000 == (1<<TS_INT_PIN) == (1<<14) */ { /* This is Touch Screen INT case : so this is a new touch available that produced the IRQ EXTI */ itStatus = TS_IRQ_PENDING; } /* Return the TS IT status */ return (itStatus); }
/** * @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) { if (GPIO_Pin == GPIO_PIN_8) { /* Get the IT status register value */ if(BSP_IO_ITGetStatus(MII_INT_PIN)) { ethernetif_set_link(&gnetif); } BSP_IO_ITClear(); } else if (GPIO_Pin == GPIO_PIN_13) { /*connect to tcp server */ udp_echoclient_send(); } }
/** * @brief SD Demo exti detection * @param None * @retval None */ void SD_exti_demo (void) { uint32_t ITstatus = 0; SD_main_test(); if(BSP_SD_IsDetected() != SD_PRESENT) { BSP_SD_Init(); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Not Connected", LEFT_MODE); } else { BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(20, BSP_LCD_GetYSize()-30, (uint8_t *)"SD Connected ", LEFT_MODE); } BSP_SD_ITConfig(); while (1) { if (MfxExtiReceived == 1) { MfxExtiReceived = 0; ITstatus = BSP_IO_ITGetStatus(SD_DETECT_PIN); if (ITstatus) { SD_Detection(); } BSP_IO_ITClear(); } if(CheckForUserInput() > 0) { BSP_SD_DeInit(); return; } } }
/** * @brief User task * @param pvParameters not used * @retval None */ static void MSC_MenuThread(void const *argument) { uint32_t ITstatus = 0; for(;;) { if(osSemaphoreWait(MenuEvent, 100) == osOK) { switch(msc_demo.state) { case MSC_DEMO_IDLE: MSC_SelectItem(MSC_main_menu, 0); msc_demo.state = MSC_DEMO_WAIT; msc_demo.select = 0; osSemaphoreRelease(MenuEvent); break; case MSC_DEMO_WAIT: MSC_SelectItem(MSC_main_menu, msc_demo.select & 0x7F); /* Handle select item */ if(msc_demo.select & 0x80) { switch(msc_demo.select & 0x7F) { case 0: msc_demo.state = MSC_DEMO_FILE_OPERATIONS; osSemaphoreRelease(MenuEvent); break; case 1: msc_demo.state = MSC_DEMO_EXPLORER; osSemaphoreRelease(MenuEvent); break; case 2: msc_demo.state = MSC_REENUMERATE; osSemaphoreRelease(MenuEvent); break; default: break; } } break; case MSC_DEMO_FILE_OPERATIONS: /* Read and Write File Here */ if(Appli_state == APPLICATION_READY) { MSC_File_Operations(); } msc_demo.state = MSC_DEMO_WAIT; break; case MSC_DEMO_EXPLORER: /* Display disk content */ if(Appli_state == APPLICATION_READY) { Explore_Disk("0:/", 1); } msc_demo.state = MSC_DEMO_WAIT; break; case MSC_REENUMERATE: /* Force MSC Device to re-enumerate */ USBH_ReEnumerate(&hUSBHost); msc_demo.state = MSC_DEMO_WAIT; break; default: break; } msc_demo.select &= 0x7F; } if (osJoySemaphore != NULL) { if(osSemaphoreWait(osJoySemaphore , 0) == osOK) { ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS); if (ITstatus) { Joystick_MscMenu(); /* Clear joystick interrupt pending bits */ BSP_IO_ITClear(); } } } } }
/** * @brief Manages AUDIO Menu Process. * @param None * @retval None */ void AUDIO_MenuProcess(void) { uint32_t ITstatus = 0; AUDIO_ErrorTypeDef status; static uint32_t debounce_time = 0; if(appli_state == APPLICATION_READY) { switch(AudioDemo.state) { case AUDIO_DEMO_IDLE: AUDIO_SelectItem(AUDIO_main_menu, 0); if(AUDIO_ShowWavFiles() > 0) { LCD_ErrLog("There is no WAV file on the USB Key.\n"); AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } AudioDemo.select = 0; BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(17, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down"); BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Use [Joystick Up/Down] to scroll Audio Playback and Record menu"); break; case AUDIO_DEMO_WAIT: if(AudioDemo.select != PrevSelect) { PrevSelect = AudioDemo.select; AUDIO_SelectItem(AUDIO_main_menu, AudioDemo.select & 0x7F); /* Handle select item */ if(AudioDemo.select & 0x80) { switch(AudioDemo.select & 0x7F) { case 0: AudioDemo.state = AUDIO_DEMO_EXPLORE; break; case 1: /* Display HMI messages */ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(17 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(18 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder "); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Set PLAYBACK state and start playing 1st file */ AudioState = AUDIO_STATE_IDLE; AudioDemo.state = AUDIO_DEMO_PLAYBACK; AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); break; case 2: /* Display HMI messages */ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(14 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(15 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(16 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(17 ,(uint8_t *)" "); BSP_LCD_DisplayStringAtLine(18 ,(uint8_t *)"Use [User Key] To Stop and return from player/recorder "); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Set PLAYBACK state and start playing 1st file */ AudioState = AUDIO_STATE_IDLE; AudioDemo.state = AUDIO_DEMO_IN; AUDIO_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); break; default: break; } } } break; case AUDIO_DEMO_EXPLORE: if(appli_state == APPLICATION_READY) { if(AUDIO_ShowWavFiles() > 0) { LCD_ErrLog("There is no WAV file on the USB Key.\n"); AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } else { AudioDemo.state = AUDIO_DEMO_WAIT; } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_PLAYBACK: if(appli_state == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; if(AUDIO_PLAYER_Start(0) == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } else { BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_DisplayStringAtLine(10, (uint8_t *)"[ UP ] : Volume +"); BSP_LCD_DisplayStringAtLine(11, (uint8_t *)"[ DOWN ] : Volume -"); BSP_LCD_DisplayStringAtLine(12, (uint8_t *)"[ LEFT ] : Previous"); BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"[ RIGHT ] : Next"); BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"[ SEL ] : Pause/Resume"); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); } } else /* Not idle */ { if(AUDIO_PLAYER_Process() == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; case AUDIO_DEMO_IN: if(appli_state == APPLICATION_READY) { if(AudioState == AUDIO_STATE_IDLE) { /* Start Playing */ AudioState = AUDIO_STATE_INIT; /* Configure the audio recorder: sampling frequency, bits-depth, number of channels */ if(AUDIO_REC_Start() == AUDIO_ERROR_IO) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } else { BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_DisplayStringAtLine(11, (uint8_t *)"[ UP ] : Volume +"); BSP_LCD_DisplayStringAtLine(12, (uint8_t *)"[ DOWN ] : Volume -"); BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"[ SEL ] : Pause/Resume"); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); } } else /* Not idle */ { status = AUDIO_REC_Process(); if((status == AUDIO_ERROR_IO) || (status == AUDIO_ERROR_EOF)) { AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); AudioDemo.state = AUDIO_DEMO_IDLE; } } } else { AudioDemo.state = AUDIO_DEMO_WAIT; } break; default: break; } } if(appli_state == APPLICATION_DISCONNECT) { appli_state = APPLICATION_IDLE; AUDIO_ChangeSelectMode(AUDIO_SELECT_MENU); BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); } AudioDemo.select &= 0x7F; if (MfxIrqReceived == 1) { MfxIrqReceived = 0; ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS); if (ITstatus) { /* Prevent debounce effect for user key */ if((HAL_GetTick() - debounce_time) > 200) { debounce_time = HAL_GetTick(); Joystick_AudioMenu(); } /* Clear joystick interrupt pending bits */ BSP_IO_ITClear(); } } }
/** * @brief SDRAM Demo * @param None * @retval None */ void IOE_GPIO_demo (void) { uint32_t ioe_irq_pending_status, ioe_gpio_status; uint32_t lcd_line = 85; uint8_t test_result = IOE_GPIO_TEST_PASSED; uint8_t all_test_fail = 1; GPIO_PinState mcu_pin_state; IOE_GPIO_SetHint(); /* Enable the Leds */ BSP_IO_Init(); BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_On(LED1); BSP_LED_On(LED2); BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); /* TEST IO_MODE_OUPUT mode */ /* ---------------------------------- */ /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */ SetMcuGpioToBeConnectedToMfxGPO(); test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OUTPUT); BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_SET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } BSP_IO_WritePin(MFX_CONNECTET_PIN, BSP_IO_PIN_RESET); HAL_Delay(1); mcu_pin_state = HAL_GPIO_ReadPin (MCU_GPIO_PORT, MCU_GPIO_PIN); if (mcu_pin_state) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_OUTPUT: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_INPUT mode */ /* ---------------------------------- */ /* SetUp a GPIO to be connected to one of the MFX GPIOS via a wire */ SetMcuGpioToBeConnectedToMfxGPI(); test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_INPUT); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_gpio_status = BSP_IO_ReadPin (MFX_CONNECTET_PIN); if (ioe_gpio_status) { test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_INPUT: PASSED", LEFT_MODE); all_test_fail = 0; } SetMcuGpioToBeConnectedToMfxGPI(); /* TEST IO_MODE_IT_HIGH_LEVEL mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_HIGH_LEVEL_PD); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_HIGH_LEVEL: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_LOW_LEVEL mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_LOW_LEVEL_PU); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_Delay(1); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_LOW_LEVEL: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_RISING_EDGE mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_RISING_EDGE_PD); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_RISING_EDGE: PASSED", LEFT_MODE); all_test_fail = 0; } /* TEST IO_MODE_IT_FALLING_EDGE mode */ /* ---------------------------------- */ test_result = IOE_GPIO_TEST_PASSED; BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_OFF); HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); BSP_IO_ITClear(); /* BSP_IO_ConfigPin(MFXIO_PIN_6, IO_MODE_INPUT); */ BSP_IO_ConfigPin(MFX_CONNECTET_PIN, IO_MODE_IT_FALLING_EDGE_PU); /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_SET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_FAILED; } else { test_result |= IOE_GPIO_TEST_PASSED; } HAL_GPIO_WritePin(MCU_GPIO_PORT, MCU_GPIO_PIN, GPIO_PIN_RESET); HAL_Delay(1); ioe_irq_pending_status = BSP_IO_ITGetStatus(MFX_CONNECTET_PIN); if (ioe_irq_pending_status) { BSP_IO_ITClear(); test_result |= IOE_GPIO_TEST_PASSED; } else { test_result |= IOE_GPIO_TEST_FAILED; } lcd_line += 15; if (test_result) { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: FAILED", LEFT_MODE); } else { BSP_LCD_DisplayStringAt(20, lcd_line, (uint8_t *)"IOE IO_MODE_IT_FALLING_EDGE: PASSED", LEFT_MODE); all_test_fail = 0; } if (all_test_fail) { BSP_LCD_DisplayStringAt(20, lcd_line + 20, (uint8_t *)" all IOE tests FAILED !!!", LEFT_MODE); BSP_LCD_DisplayStringAt(15, lcd_line + 40, (uint8_t *)"Are you sure that MCU_PB4 pin is connected ", LEFT_MODE); BSP_LCD_DisplayStringAt(15, lcd_line + 55, (uint8_t *)"to TP9 probe with a wire on the board ??", LEFT_MODE); } /* We just want to test the good functioning of pending bit and ack on the IOE */ HAL_NVIC_EnableIRQ((IRQn_Type)(MFX_IRQOUT_EXTI_IRQn)); while (1) { if(CheckForUserInput() > 0) { return; } } }
/** * @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) { uint32_t ITstatus = 0; JOYState_TypeDef JoyState = JOY_NONE; if(GPIO_Pin == TAMPER_BUTTON_PIN) { /* Toggle GREEN LED1 */ BSP_LED_Toggle(LED1); DestinationAddress = MyFollowerAddress1; TxSize = 0x0; /* no payload, ping only */ StartSending = 1; } if(GPIO_Pin == MFX_IRQOUT_PIN) /* Interrupt received from MFX */ { /* 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 */ ITstatus = BSP_IO_ITGetStatus(JOY_ALL_PINS); if (ITstatus) /* Checks if interrupt comes from joystick */ { /* Get the Joystick State */ JoyState = BSP_JOY_GetState(); if(JoyState == JOY_UP) { /* Toggle RED LED3 */ BSP_LED_Toggle(LED3); } if(JoyState == JOY_DOWN) { /* Toggle BLUE LED4 */ BSP_LED_Toggle(LED4); #if defined (DEVICE_1) DestinationAddress = MyFollowerAddress2; #elif defined (DEVICE_2) DestinationAddress = MyFollowerAddress1; #endif /* DEVICE_1 */ TxSize = 0x0; /* no payload, ping only */ StartSending = 1; } if(JoyState == JOY_SEL) { /* Toggle ORANGE LED2 */ BSP_LED_Toggle(LED2); DestinationAddress = 0xF; /* broadcast message indicator */ TxSize = 0x0; /* no payload, ping only */ StartSending = 1; } } BSP_IO_ITClear(); } }