Page 1 of 1

Detect Suspend Mode

Posted: Sun Jun 08, 2014 9:10 pm
by AlexDigital
Hi guys,

I have an USB application with the V-USB library and want to detect if the host is in suspend mode.
If it's true, then a LED should turn off. When the host wakes up, the LED should turn on.

In my case, D- is connected to INT0. INT1 is already used by another hardware.

Is there an easy method to do that?

Cheers,
AlexDigital

Re: Detect Suspend Mode

Posted: Wed Jun 11, 2014 9:04 am
by blargg
I've done this in my keyboard converter by putting the CPU to sleep regularly and having it woken by the USB interrupt or a timeout interrupt that fires when the host is suspended and thus doing no USB activity. Something like

Code: Select all

static volatile bool usb_inactive;

ISR(TIMER1_OVF_vect)
{
    usb_inactive = true;
}

void check_inactive()
{
    TCNT1 = -inactive_timeout;
    usb_inactive = false;
    sleep_enable();
    sleep_cpu();
    if ( usb_inactive )
    {
        ...
    }
}


You could use the USB_RESET_HOOK to detect when the host reawakens.