// Interrupt on "pin change" from PB0 to do wakeup on USB // Note: // This interrupt is enable when the USB host enable remotewakeup feature // This interrupt wakeup the CPU if this one is in idle mode static void UI_WAKEUP_HANDLER(void) { sysclk_enable_peripheral_clock(EIC); if(eic_line_interrupt_is_pending(EIC, UI_WAKEUP_EIC_LINE)) { eic_line_clear_interrupt(EIC, UI_WAKEUP_EIC_LINE); ui_disable_asynchronous_interrupt(); // It is a wakeup then send wakeup USB udc_remotewakeup(); // Wakeup, ignore button change until button is back to default state btn_wakeup = true; } sysclk_disable_peripheral_clock(EIC); }
/** * \brief Interrupt handler for interrupt pin change */ static void UI_WAKEUP_HANDLER(void) { if (ui_b_host_mode) { if (uhc_is_suspend()) { ui_disable_asynchronous_interrupt(); /* Wakeup the devices connected */ uhc_resume(); } } else { /* In device mode, wakeup the USB host. */ udc_remotewakeup(); } }
/** * \brief Interrupt handler for interrupt pin change */ static void UI_WAKEUP_HANDLER(void) { sysclk_enable_peripheral_clock(EIC); if (eic_line_interrupt_is_pending(EIC, UI_WAKEUP_EIC_LINE)) { eic_line_clear_interrupt(EIC, UI_WAKEUP_EIC_LINE); if (uhc_is_suspend()) { ui_disable_asynchronous_interrupt(); /* Wakeup host and device */ uhc_resume(); } } sysclk_disable_peripheral_clock(EIC); }
/* Interrupt on "pin change" from RIGHT CLICK to do wakeup on USB * Note: * This interrupt is enable when the USB host enable remotewakeup feature * This interrupt wakeup the CPU if this one is in idle mode */ static void ui_wakeup_handler(uint32_t id, uint32_t mask) { if (RESUME_PIO_ID == id && RESUME_PIO_MASK == mask) { if (ui_b_host_mode) { if (!uhc_is_suspend()) { /* USB is not in suspend mode * Let's interrupt enable. */ return; } ui_disable_asynchronous_interrupt(); /* Wakeup the devices connected */ pmc_wait_wakeup_clocks_restore(uhc_resume); } else { /* In device mode, wakeup the USB host. */ pmc_wait_wakeup_clocks_restore(udc_remotewakeup); } } }
/** * \brief Interrupt handler for interrupt pin change */ static void UI_WAKEUP_HANDLER(void) { sysclk_enable_peripheral_clock(EIC); if (eic_line_interrupt_is_pending(EIC, UI_WAKEUP_EIC_LINE)) { eic_line_clear_interrupt(EIC, UI_WAKEUP_EIC_LINE); if (ui_b_host_mode) { if (!uhc_is_suspend()) { /* USB is not in suspend mode * Let's interrupt enable. */ return; } ui_disable_asynchronous_interrupt(); /* Wakeup the devices connected */ uhc_resume(); } else { /* In device mode, wakeup the USB host. */ udc_remotewakeup(); } } sysclk_disable_peripheral_clock(EIC); }
void ui_usb_enum_event(uhc_device_t *dev, uhc_enum_status_t status) { ui_enum_status = status; if (ui_enum_status == UHC_ENUM_SUCCESS) { switch (dev->speed) { case UHD_SPEED_HIGH: ui_device_speed_blink = 250; break; case UHD_SPEED_FULL: ui_device_speed_blink = 500; break; case UHD_SPEED_LOW: default: ui_device_speed_blink = 1000; break; } /* USB Device CDC connected Open and configure UART and USB CDC ports */ usb_cdc_line_coding_t cfg = { .dwDTERate = CPU_TO_LE32(19200), .bCharFormat = CDC_STOP_BITS_1, .bParityType = CDC_PAR_NONE, .bDataBits = 8, }; uart_open(); uart_config(&cfg); uhi_cdc_open(0, &cfg); } } void ui_usb_wakeup_event(void) { #ifdef USB_HOST_LPM_SUPPORT ui_disable_asynchronous_interrupt(); #endif } void ui_usb_sof_event(void) { #ifdef USB_HOST_LPM_SUPPORT bool b_btn_state; static bool btn_suspend_and_remotewakeup = false; #endif static uint16_t counter_sof = 0; if (ui_enum_status == UHC_ENUM_SUCCESS) { /* Display device enumerated and in active mode */ if (++counter_sof > ui_device_speed_blink) { counter_sof = 0; if (!ui_data_transfer) { LED_Toggle(LED_0_PIN); } } #ifdef USB_HOST_LPM_SUPPORT /* Scan button to enter in suspend mode and remote wakeup */ b_btn_state = !port_pin_get_input_level(BUTTON_0_PIN); if (b_btn_state != btn_suspend_and_remotewakeup) { /* Button have changed */ btn_suspend_and_remotewakeup = b_btn_state; if (b_btn_state) { /* Button has been pressed */ ui_enable_asynchronous_interrupt(); LED_Off(LED_0_PIN); uhc_suspend_lpm(true, HIRD_800_US); return; } } #endif // #ifdef USB_HOST_LPM_SUPPORT } }
void ui_usb_wakeup_event(void) { ui_disable_asynchronous_interrupt(); }
void ui_device_remotewakeup_disable(void) { ui_disable_asynchronous_interrupt(); }
void ui_wakeup_disable(void) { ui_disable_asynchronous_interrupt(); }