Wait between actions

USB Library ›› Device ›› Keep USB running ››
… visits
Parent Previous Next

A delay sets the pace of your own application; it does not prove that USB data was received. Use short waits that keep the required service running, and check every send result.

Wait between application actions

A keyboard still needs deliberate timing between press/release reports and repeated messages. ISR mode services USB during a delay; it does not automatically create your typing sequence. For an ISR keyboard with VBUS sensing disabled, this helper waits while allowing early exit on loss of readiness:

Proc KeyboardWait(wMilliseconds As Word), Byte

    Result = 0

    While wMilliseconds <> 0

        If USB_Configured = 0 Then ExitProc

        If USB_Suspended = 1 Then ExitProc

        DelayMS 1

        Dec wMilliseconds

    Wend

    If USB_Configured = 0 Then ExitProc

    If USB_Suspended = 1 Then ExitProc

    Result = 1

EndProc

This application helper returns a Byte; it is not a library procedure reporting through USB_Result. No USB_Service() is needed inside it for that ISR/sense-disabled arrangement. With VBUS sensing enabled, add foreground servicing inside the loop. In polling mode, use short serviced delays instead; a long unserviced wait can prevent enumeration or transfers. See HID guide for keyboard press, release and pacing examples. A delay never proves that the host accepted a report—check the send result too.

See also

Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator