
23/54
AN1886 - APPLICATION NOTE
HID device using Feature reports
, HidD_GetFeature,
and
Input reports,
ReadFile.
All of these routines ex-
pect data buffers to include an extra header byte that is used to specify what type of report is being trans-
ferred. The application defines a helper structure called
REPORT_BUF
that puts this extra report ID byte
in front of an
MCU_CMD
structure.
REPORT_BUF
structures are then passed to and from
WriteFile
and
HidD_GetFeature
calls.
The size chosen for the Feature and Output reports (64 bytes) is arbitrary. A larger size improves efficien-
cy for large transfers: there is less overhead per block of command data. However, with large reports,
there are more wasted bytes for smaller command structures.
Note: LCD mirror data is passed to the application from the firmware as 8-byte Input reports with no higher
level structure defined on top.
SUSPEND Mode and RESUME Mode Handling Mechanism
Since version 2.0_XP (December 2003), the USB demo supports SUSPEND mode. The suspend mode
handling mechanism uses the following code for service code, found in the USB interrupt service routine,
and requires the
SUSPND
interrupt to have been enabled.
if (SUSPND) // Handle suspend interrupt
{
SUSPND = 0; // keep USB logic functional
GoOnSuspend = 1; // set global flag
UIEN &= ~uSUSPNDIE; // disable INT
TF2 = 1; // Activate execution of the rest of USB ISR
}
If
USBSuspend
is detected (a constant idle state on the USB lines for more than 3ms), then the
SUSPND
flag is set. Setting this bit stops the clock to USB, and causes the USB module to enter Suspend mode.
Because this event can be serviced at some other place in the code, with the auxiliary bit (
GoOnSuspend
)
set and the
SUSPND
flag cleared, another mechanism to reach the still functional USB part is used (albeit
not in the next interrupt after this source has been enabled). Afterwards, when the application has more
time, the physical suspension of the device is possible.
The
GoOnSuspend
event is checked in the subsequent auxiliary USB service routine when it is possible:
// The following 3 lines can be deleted if you don’t plan to use Suspend
if (GoOnSuspend) //Service USB INT Suspend
{
OnUSBSuspend();
}
The default handler, for this event, performs the physical suspend task, and is located in
main.c
, and is
shown in
APPENDIX J.
.
This default handler, in the USB demonstration program:
–
writes information to the display, announcing the start of the Suspend mode
–
disables all interrupts, except USB
–
enables the USB Resume interrupt source
–
enters the Idle mode of the μPSD (
PCON |
= 1).
In this state, no instructions are executed, and the μPSD waits for any enabled interrupt. When a USB
interrupt is detected, the μPSD continues execution, by restoration of the USB part, by clearing the
SUS-
PND
and
RESUMF
bits, restoring and enabling other previous interrupts, and clearing the display.