Fixed Mouse and Keyboard device demos not acting in accordance with the HID specification for idle periods (thanks to Brian Dickman).
Removed support for endpoint/pipe non-control interrupts; these did not act in the way users expected, and had many subtle issues.
This commit is contained in:
parent
ea74397095
commit
958a1b4e2b
23 changed files with 98 additions and 470 deletions
|
@ -43,9 +43,7 @@ TASK_LIST
|
|||
{ .Task = USB_USBTask , .TaskStatus = TASK_STOP },
|
||||
#endif
|
||||
|
||||
#if !defined(INTERRUPT_DATA_ENDPOINT)
|
||||
{ .Task = USB_Mouse_Report , .TaskStatus = TASK_STOP },
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Global Variables */
|
||||
|
@ -57,7 +55,7 @@ bool UsingReportProtocol = true;
|
|||
/** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
|
||||
* for either the entire idle duration, or until the report status changes (e.g. the user moves the mouse).
|
||||
*/
|
||||
uint8_t IdleCount = 0;
|
||||
uint16_t IdleCount = HID_IDLE_CHANGESONLY;
|
||||
|
||||
/** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
|
||||
* milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
|
||||
|
@ -140,9 +138,7 @@ EVENT_HANDLER(USB_Reset)
|
|||
EVENT_HANDLER(USB_Disconnect)
|
||||
{
|
||||
/* Stop running mouse reporting and USB management tasks */
|
||||
#if !defined(INTERRUPT_DATA_ENDPOINT)
|
||||
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_STOP);
|
||||
#endif
|
||||
|
||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);
|
||||
|
@ -162,18 +158,11 @@ EVENT_HANDLER(USB_ConfigurationChanged)
|
|||
ENDPOINT_DIR_IN, MOUSE_EPSIZE,
|
||||
ENDPOINT_BANK_SINGLE);
|
||||
|
||||
#if defined(INTERRUPT_DATA_ENDPOINT)
|
||||
/* Enable the endpoint IN interrupt ISR for the report endpoint */
|
||||
USB_INT_Enable(ENDPOINT_INT_IN);
|
||||
#endif
|
||||
|
||||
/* Indicate USB connected and ready */
|
||||
UpdateStatus(Status_USBReady);
|
||||
|
||||
#if !defined(INTERRUPT_DATA_ENDPOINT)
|
||||
/* Start running mouse reporting task */
|
||||
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_RUN);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
|
||||
|
@ -311,34 +300,36 @@ void CreateMouseReport(USB_MouseReport_Data_t* ReportData)
|
|||
}
|
||||
|
||||
/** Sends the next HID report to the host, via the keyboard data endpoint. */
|
||||
static inline void SendNextReport(void)
|
||||
void SendNextReport(void)
|
||||
{
|
||||
static USB_MouseReport_Data_t PrevMouseReportData;
|
||||
USB_MouseReport_Data_t MouseReportData;
|
||||
bool SendReport = true;
|
||||
bool SendReport;
|
||||
|
||||
/* Create the next mouse report for transmission to the host */
|
||||
CreateMouseReport(&MouseReportData);
|
||||
|
||||
/* Check if the idle period is set*/
|
||||
if (IdleCount)
|
||||
{
|
||||
/* Determine if the idle period has elapsed */
|
||||
if (!(IdleMSRemaining))
|
||||
{
|
||||
/* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */
|
||||
IdleMSRemaining = (IdleCount << 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Idle period not elapsed, indicate that a report must not be sent unless the report has changed */
|
||||
SendReport = (memcmp(&PrevMouseReportData, &MouseReportData, sizeof(USB_MouseReport_Data_t)) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check to see if the report data has changed - if so a report MUST be sent */
|
||||
SendReport = (memcmp(&PrevMouseReportData, &MouseReportData, sizeof(USB_MouseReport_Data_t)) != 0);
|
||||
|
||||
/* Override the check if the Y or X values are non-zero - we want continuous movement while the joystick
|
||||
* is being held down (via continuous reports), otherwise the cursor will only move once per joystick toggle */
|
||||
if ((MouseReportData.Y != 0) || (MouseReportData.X != 0))
|
||||
SendReport = true;
|
||||
|
||||
/* Save the current report data for later comparison to check for changes */
|
||||
PrevMouseReportData = MouseReportData;
|
||||
|
||||
/* Check if the idle period is set and has elapsed */
|
||||
if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
|
||||
{
|
||||
/* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */
|
||||
IdleMSRemaining = (IdleCount << 2);
|
||||
|
||||
/* Idle period is set and has elapsed, must send a report to the host */
|
||||
SendReport = true;
|
||||
}
|
||||
|
||||
/* Select the Mouse Report Endpoint */
|
||||
Endpoint_SelectEndpoint(MOUSE_EPNUM);
|
||||
|
||||
|
@ -380,7 +371,6 @@ void UpdateStatus(uint8_t CurrentStatus)
|
|||
LEDs_SetAllLEDs(LEDMask);
|
||||
}
|
||||
|
||||
#if !defined(INTERRUPT_DATA_ENDPOINT)
|
||||
/** Task to manage HID report generation and transmission to the host, when in report mode. */
|
||||
TASK(USB_Mouse_Report)
|
||||
{
|
||||
|
@ -391,8 +381,8 @@ TASK(USB_Mouse_Report)
|
|||
SendNextReport();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
/** ISR for the general Pipe/Endpoint interrupt vector. This ISR fires when an endpoint's status changes (such as
|
||||
* a packet has been received) on an endpoint with its corresponding ISR enabling bits set. This is used to send
|
||||
* HID packets to the host each time the HID interrupt endpoints polling period elapses, as managed by the USB
|
||||
|
@ -401,36 +391,20 @@ TASK(USB_Mouse_Report)
|
|||
*/
|
||||
ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
|
||||
{
|
||||
#if defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||
/* Save previously selected endpoint before selecting a new endpoint */
|
||||
uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
|
||||
|
||||
/* Check if the control endpoint has received a request */
|
||||
if (Endpoint_HasEndpointInterrupted(ENDPOINT_CONTROLEP))
|
||||
{
|
||||
/* Clear the endpoint interrupt */
|
||||
Endpoint_ClearEndpointInterrupt(ENDPOINT_CONTROLEP);
|
||||
|
||||
/* Process the control request */
|
||||
USB_USBTask();
|
||||
|
||||
/* Handshake the endpoint setup interrupt - must be after the call to USB_USBTask() */
|
||||
USB_INT_Clear(ENDPOINT_INT_SETUP);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INTERRUPT_DATA_ENDPOINT)
|
||||
/* Check if mouse endpoint has interrupted */
|
||||
if (Endpoint_HasEndpointInterrupted(MOUSE_EPNUM))
|
||||
{
|
||||
/* Select the Mouse Report Endpoint */
|
||||
Endpoint_SelectEndpoint(MOUSE_EPNUM);
|
||||
|
||||
/* Clear the endpoint IN interrupt flag */
|
||||
USB_INT_Clear(ENDPOINT_INT_IN);
|
||||
|
||||
/* Clear the Mouse Report endpoint interrupt and select the endpoint */
|
||||
Endpoint_ClearEndpointInterrupt(MOUSE_EPNUM);
|
||||
|
||||
/* Send the next mouse report to the host */
|
||||
SendNextReport();
|
||||
}
|
||||
#endif
|
||||
/* Restore previously selected endpoint */
|
||||
Endpoint_SelectEndpoint(PrevSelectedEndpoint);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue