Add new HID_Device_MillisecondElapsed() function to the HID device Class driver, to move the burden of managing the Idle period of each instance to the library and not the user application.

Dean Camera 16 years ago
parent 7227e133a9
commit 7df6b9563c

@ -78,11 +78,6 @@ USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface =
.NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM,
.NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
};
/** Main program entry point. This routine contains the overall program flow, including initial

@ -118,8 +118,7 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Generic_HID_Interface.State.IdleMSRemaining)
Generic_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Generic_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.

@ -120,8 +120,7 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Joystick_HID_Interface.State.IdleMSRemaining)
Joystick_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Joystick_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.

@ -121,8 +121,7 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Keyboard_HID_Interface.State.IdleMSRemaining)
Keyboard_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.

@ -66,12 +66,7 @@ USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
.ReportINEndpointNumber = MOUSE_IN_EPNUM,
.ReportINEndpointSize = HID_EPSIZE,
},
.State =
{
// Leave all state values to their defaults
}
},
};
/** Main program entry point. This routine contains the overall program flow, including initial
@ -147,11 +142,8 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Keyboard_HID_Interface.State.IdleMSRemaining)
Keyboard_HID_Interface.State.IdleMSRemaining--;
if (Mouse_HID_Interface.State.IdleMSRemaining)
Mouse_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.

@ -120,8 +120,7 @@ void EVENT_USB_UnhandledControlPacket(void)
/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Mouse_HID_Interface.State.IdleMSRemaining)
Mouse_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
}
/** HID class driver callback function for the creation of HID reports to the host.

@ -184,4 +184,10 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo)
}
}
void HID_Device_MillisecondElapsed(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo)
{
if (HIDInterfaceInfo->State.IdleMSRemaining)
HIDInterfaceInfo->State.IdleMSRemaining--;
}
#endif

@ -121,6 +121,13 @@
*/
void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
/** Indicates that a millisecond of idle time has elapsed on the given HID interface, and the interface's idle count should be
* decremented. This should be called once per millisecond so that hardware key-repeats function correctly.
*
* \param[in,out] HIDInterfaceInfo Pointer to a structure containing a HID Class configuration and state.
*/
void HID_Device_MillisecondElapsed(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);
/** HID class driver callback for the user creation of a HID input report. This callback may fire in response to either
* HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback the
* user is responsible for the creation of the next HID input report to be sent to the host.

@ -153,8 +153,7 @@ void EVENT_USB_UnhandledControlPacket(void)
/** Timer 0 CTC ISR, firing once each millisecond to keep track of elapsed idle time in the HID interface. */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
if (Keyboard_HID_Interface.State.IdleMSRemaining)
Keyboard_HID_Interface.State.IdleMSRemaining--;
HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);
}
/** HID Class driver callback function for the creation of a HID report for the host.

Loading…
Cancel
Save