Added new EVENT_USB_Device_StartOfFrame() event, controlled by the new USB_Device_Ena...
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 16 Aug 2009 08:51:54 +0000 (08:51 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 16 Aug 2009 08:51:54 +0000 (08:51 +0000)
23 files changed:
Demos/Device/ClassDriver/GenericHID/GenericHID.c
Demos/Device/ClassDriver/GenericHID/GenericHID.h
Demos/Device/ClassDriver/Joystick/Joystick.c
Demos/Device/ClassDriver/Joystick/Joystick.h
Demos/Device/ClassDriver/Keyboard/Keyboard.c
Demos/Device/ClassDriver/Keyboard/Keyboard.h
Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c
Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.h
Demos/Device/ClassDriver/Mouse/Mouse.c
Demos/Device/ClassDriver/Mouse/Mouse.h
Demos/Device/LowLevel/GenericHID/GenericHID.h
Demos/Device/LowLevel/Keyboard/Keyboard.c
Demos/Device/LowLevel/Keyboard/Keyboard.h
Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.h
Demos/Device/LowLevel/Mouse/Mouse.c
Demos/Device/LowLevel/Mouse/Mouse.h
LUFA/Drivers/USB/Class/Device/HID.h
LUFA/Drivers/USB/HighLevel/Events.h
LUFA/Drivers/USB/HighLevel/USBInterrupt.c
LUFA/Drivers/USB/LowLevel/Device.h
LUFA/ManPages/ChangeLog.txt
Projects/Magstripe/Magstripe.c
Projects/Magstripe/Magstripe.h

index 13db6bf..c27558b 100644 (file)
@@ -94,18 +94,12 @@ void SetupHardware(void)
        /* Hardware Initialization */\r
        LEDs_Init();\r
        USB_Init();\r
        /* Hardware Initialization */\r
        LEDs_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
 void EVENT_USB_Device_Connect(void)\r
 {\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
 void EVENT_USB_Device_Connect(void)\r
 {\r
-       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
+       LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);       \r
 }\r
 \r
 /** Event handler for the library USB Disconnection event. */\r
 }\r
 \r
 /** Event handler for the library USB Disconnection event. */\r
@@ -121,6 +115,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
 \r
        if (!(HID_Device_ConfigureEndpoints(&Generic_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
        if (!(HID_Device_ConfigureEndpoints(&Generic_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
@@ -129,8 +125,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Generic_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Generic_HID_Interface);\r
 }\r
 \r
-/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Generic_HID_Interface);\r
 }\r
 {\r
        HID_Device_MillisecondElapsed(&Generic_HID_Interface);\r
 }\r
index 8cf0afc..004daf5 100644 (file)
@@ -40,8 +40,6 @@
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
                #include <avr/power.h>\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
                #include <avr/power.h>\r
-               #include <avr/interrupt.h>\r
-               #include <stdbool.h>\r
                #include <string.h>\r
                \r
                #include "Descriptors.h"\r
                #include <string.h>\r
                \r
                #include "Descriptors.h"\r
@@ -71,6 +69,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
index ea85aad..b18b7eb 100644 (file)
@@ -88,12 +88,6 @@ void SetupHardware(void)
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
@@ -115,6 +109,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
 \r
        if (!(HID_Device_ConfigureEndpoints(&Joystick_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
        if (!(HID_Device_ConfigureEndpoints(&Joystick_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
@@ -123,8 +119,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Joystick_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Joystick_HID_Interface);\r
 }\r
 \r
-/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Joystick_HID_Interface);\r
 }\r
 {\r
        HID_Device_MillisecondElapsed(&Joystick_HID_Interface);\r
 }\r
index 493dfa0..d25ccc1 100644 (file)
@@ -82,6 +82,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
index 6f0bd1d..e609d7a 100644 (file)
@@ -89,12 +89,6 @@ void SetupHardware()
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
@@ -116,6 +110,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
 \r
        if (!(HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
        if (!(HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
@@ -124,8 +120,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);\r
 }\r
 \r
-/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
index 0f7176c..ebd83d5 100644 (file)
@@ -85,6 +85,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
index e219990..5ac5b8d 100644 (file)
@@ -112,12 +112,6 @@ void SetupHardware()
        Joystick_Init();\r
        LEDs_Init();\r
        USB_Init();\r
        Joystick_Init();\r
        LEDs_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
 }\r
 \r
 /** Event handler for the library USB Connection event. */\r
@@ -142,6 +136,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        \r
        if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        \r
        if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
@@ -151,8 +147,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Mouse_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Mouse_HID_Interface);\r
 }\r
 \r
-/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
        HID_Device_MillisecondElapsed(&Mouse_HID_Interface);\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
        HID_Device_MillisecondElapsed(&Mouse_HID_Interface);\r
index 2975641..1f47c3e 100644 (file)
@@ -89,6 +89,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
index 32f8ca6..d54aecf 100644 (file)
@@ -88,12 +88,6 @@ void SetupHardware(void)
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the library USB WakeUp event. */\r
 }\r
 \r
 /** Event handler for the library USB WakeUp event. */\r
@@ -115,6 +109,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
 \r
        if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
        if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface)))\r
          LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Request event. */\r
@@ -123,8 +119,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Mouse_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Mouse_HID_Interface);\r
 }\r
 \r
-/** ISR to keep track of each millisecond interrupt, for determining the HID class idle period remaining when set. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Mouse_HID_Interface);\r
 }\r
 {\r
        HID_Device_MillisecondElapsed(&Mouse_HID_Interface);\r
 }\r
index 05b73c0..325bfc5 100644 (file)
@@ -84,6 +84,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
index c036517..da3d4ac 100644 (file)
@@ -40,7 +40,6 @@
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
                #include <avr/power.h>\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
                #include <avr/power.h>\r
-               #include <avr/interrupt.h>\r
                #include <stdbool.h>\r
                #include <string.h>\r
                \r
                #include <stdbool.h>\r
                #include <string.h>\r
                \r
@@ -77,6 +76,7 @@
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                void ProcessGenericHIDReport(uint8_t* DataArray);\r
                void CreateGenericHIDReport(uint8_t* DataArray);\r
 \r
                void ProcessGenericHIDReport(uint8_t* DataArray);\r
                void CreateGenericHIDReport(uint8_t* DataArray);\r
index f8310ab..02f61a5 100644 (file)
@@ -85,12 +85,6 @@ void SetupHardware(void)
        Joystick_Init();\r
        LEDs_Init();\r
        USB_Init();\r
        Joystick_Init();\r
        LEDs_Init();\r
        USB_Init();\r
-       \r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = 0x7D;\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and\r
@@ -137,6 +131,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        {\r
                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        }\r
        {\r
                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        }\r
+       \r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific\r
@@ -248,10 +244,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        }\r
 }\r
 \r
        }\r
 }\r
 \r
-/** ISR for the timer 0 compare vector. This ISR fires once each millisecond, and increments the\r
- *  scheduler elapsed idle period counter when the host has set an idle period.\r
- */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        /* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */\r
        if (IdleMSRemaining)\r
 {\r
        /* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */\r
        if (IdleMSRemaining)\r
index bc478f3..f319ab7 100644 (file)
@@ -40,7 +40,6 @@
        /* Includes: */\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
        /* Includes: */\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
-               #include <avr/interrupt.h>\r
                #include <avr/power.h>\r
                #include <stdbool.h>\r
                #include <string.h>\r
                #include <avr/power.h>\r
                #include <stdbool.h>\r
                #include <string.h>\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);\r
                void ProcessLEDReport(uint8_t LEDReport);\r
 \r
                void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);\r
                void ProcessLEDReport(uint8_t LEDReport);\r
index 37cb7f6..57e152b 100644 (file)
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
                \r
 #endif\r
                \r
 #endif\r
index 48f0461..aa95e9c 100644 (file)
@@ -85,12 +85,6 @@ void SetupHardware(void)
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
        LEDs_Init();\r
        Buttons_Init();\r
        USB_Init();\r
-       \r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = 0x7D;\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and\r
 }\r
 \r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and\r
@@ -129,6 +123,8 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        {\r
                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        }\r
        {\r
                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        }\r
+\r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific\r
@@ -218,10 +214,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        }\r
 }\r
 \r
        }\r
 }\r
 \r
-/** ISR for the timer 0 compare vector. This ISR fires once each millisecond, and increments the\r
- *  scheduler elapsed idle period counter when the host has set an idle period.\r
- */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        /* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */\r
        if (IdleMSRemaining)\r
 {\r
        /* One millisecond has elapsed, decrement the idle time remaining counter if it has not already elapsed */\r
        if (IdleMSRemaining)\r
index b244ffa..698fe47 100644 (file)
@@ -39,7 +39,6 @@
        /* Includes: */\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
        /* Includes: */\r
                #include <avr/io.h>\r
                #include <avr/wdt.h>\r
-               #include <avr/interrupt.h>\r
                #include <avr/power.h>\r
                #include <stdbool.h>\r
                #include <string.h>\r
                #include <avr/power.h>\r
                #include <stdbool.h>\r
                #include <string.h>\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                void EVENT_USB_Device_Disconnect(void);\r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                void CreateMouseReport(USB_MouseReport_Data_t* ReportData);\r
 \r
 \r
                void CreateMouseReport(USB_MouseReport_Data_t* ReportData);\r
 \r
index 0c141e6..d995c09 100644 (file)
                        void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);\r
                        \r
                        /** Indicates that a millisecond of idle time has elapsed on the given HID interface, and the interface's idle count should be\r
                        void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo);\r
                        \r
                        /** Indicates that a millisecond of idle time has elapsed on the given HID interface, and the interface's idle count should be\r
-                        *  decremented. This should be called once per millisecond so that hardware key-repeats function correctly.\r
+                        *  decremented. This should be called once per millisecond so that hardware key-repeats function correctly. It is recommended\r
+                        *  that this be called by the \ref EVENT_USB_Device_StartOfFrame() event, once SOF events have been enabled via\r
+                        *  \ref USB_Device_EnableSOFEvents();.\r
                         *\r
                         *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.\r
                         */\r
                         *\r
                         *  \param[in,out] HIDInterfaceInfo  Pointer to a structure containing a HID Class configuration and state.\r
                         */\r
index 1e63831..4ed6537 100644 (file)
                         *        \ref Group_USBManagement documentation).\r
                         */\r
                        void EVENT_USB_Device_Reset(void);\r
                         *        \ref Group_USBManagement documentation).\r
                         */\r
                        void EVENT_USB_Device_Reset(void);\r
+\r
+                       /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB\r
+                        *  frame, once per millisecond, and is synchronised to the USB bus. This can be used as an accurate\r
+                        *  millisecond timer source when the USB bus is enumerated in device mode to a USB host.\r
+                        *\r
+                        *  This event is not normally active - it must be manually enabled and disabled via the\r
+                        *  \ref USB_Device_EnableSOFEvents() and \ref USB_Device_DisableSOFEvents() commands after enumeration.\r
+                        *\r
+                        *  \note This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see\r
+                        *        \ref Group_USBManagement documentation).\r
+                        */\r
+                       void EVENT_USB_Device_StartOfFrame(void);\r
                #endif\r
                \r
        /* Private Interface - For use in library only: */\r
                #endif\r
                \r
        /* Private Interface - For use in library only: */\r
                                        void EVENT_USB_Device_Suspend(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                        void EVENT_USB_Device_WakeUp(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                        void EVENT_USB_Device_Reset(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                        void EVENT_USB_Device_Suspend(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                        void EVENT_USB_Device_WakeUp(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                        void EVENT_USB_Device_Reset(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
+                                       void EVENT_USB_Device_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);\r
                                #endif\r
                        #endif\r
        #endif\r
                                #endif\r
                        #endif\r
        #endif\r
index 00fe7d1..a8083c9 100644 (file)
@@ -153,6 +153,13 @@ ISR(USB_GEN_vect, ISR_BLOCK)
 \r
                EVENT_USB_Device_Reset();\r
        }\r
 \r
                EVENT_USB_Device_Reset();\r
        }\r
+       \r
+       if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))\r
+       {\r
+               USB_INT_Clear(USB_INT_SOFI);\r
+               \r
+               EVENT_USB_Device_StartOfFrame();\r
+       }\r
        #endif\r
        \r
        #if defined(USB_CAN_BE_HOST)\r
        #endif\r
        \r
        #if defined(USB_CAN_BE_HOST)\r
index d66def4..f107407 100644 (file)
                                 *  \return Boolean true if the USB communications have been suspended by the host, false otherwise.\r
                                 */\r
                                static inline bool USB_Device_IsUSBSuspended(void);\r
                                 *  \return Boolean true if the USB communications have been suspended by the host, false otherwise.\r
                                 */\r
                                static inline bool USB_Device_IsUSBSuspended(void);\r
+                               \r
+                               /** Enables the device mode Start Of Frame events. When enabled, this causes the\r
+                                *  \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronised to the USB bus,\r
+                                *  at the start of each USB frame when enumerated in device mode.\r
+                                */\r
+                               static inline bool USB_Device_EnableSOFEvents(void);\r
+                               \r
+                               /** Disables the device mode Start Of Frame events. When disabled, this stop the firing of the\r
+                                *  \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.\r
+                                */\r
+                               static inline bool USB_Device_DisableSOFEvents(void);\r
                        #else\r
                                #define USB_Device_SendRemoteWakeup()   MACROS{ UDCON |= (1 << RMWKUP); }MACROE\r
 \r
                                #define USB_Device_IsRemoteWakeupSent()       ((UDCON &  (1 << RMWKUP)) ? false : true)\r
 \r
                                #define USB_Device_IsUSBSuspended()           ((UDINT &  (1 << SUSPI)) ? true : false)\r
                        #else\r
                                #define USB_Device_SendRemoteWakeup()   MACROS{ UDCON |= (1 << RMWKUP); }MACROE\r
 \r
                                #define USB_Device_IsRemoteWakeupSent()       ((UDCON &  (1 << RMWKUP)) ? false : true)\r
 \r
                                #define USB_Device_IsUSBSuspended()           ((UDINT &  (1 << SUSPI)) ? true : false)\r
+                               \r
+                               #define USB_Device_EnableSOFEvents()    MACROS{ USB_INT_Enable(USB_INT_SOFI); }MACROE\r
+\r
+                               #define USB_Device_DisableSOFEvents()   MACROS{ USB_INT_Disable(USB_INT_SOFI); }MACROE\r
                        #endif\r
                        \r
                /* Type Defines: */\r
                        #endif\r
                        \r
                /* Type Defines: */\r
index fd65221..de2fa81 100644 (file)
@@ -11,6 +11,8 @@
   *  <b>New:</b>\r
   *  - Added new host class drivers and matching demos to the library for rapid application development\r
   *  - Added flag to the HID report parser to indicate if a device has multiple reports\r
   *  <b>New:</b>\r
   *  - Added new host class drivers and matching demos to the library for rapid application development\r
   *  - Added flag to the HID report parser to indicate if a device has multiple reports\r
+  *  - Added new EVENT_USB_Device_StartOfFrame() event, controlled by the new USB_Device_EnableSOFEvents() and\r
+  *    USB_Device_DisableSOFEvents() macros to give bus-synchronised millisecond interrupts when in USB device mode\r
   *  \r
   *  <b>Changed:</b>\r
   *  - SetIdle requests to the HID device driver with a 0 idle period (send changes only) now only affect the requested\r
   *  \r
   *  <b>Changed:</b>\r
   *  - SetIdle requests to the HID device driver with a 0 idle period (send changes only) now only affect the requested\r
index 5be3449..3ea5052 100644 (file)
@@ -99,12 +99,6 @@ void SetupHardware(void)
        /* Hardware Initialization */\r
        Magstripe_Init();\r
        USB_Init();\r
        /* Hardware Initialization */\r
        Magstripe_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Determines if a card has been inserted, and if so reads in each track's contents into the bit buffers\r
 }\r
 \r
 /** Determines if a card has been inserted, and if so reads in each track's contents into the bit buffers\r
@@ -148,6 +142,8 @@ void ReadMagstripeData(void)
 void EVENT_USB_Device_ConfigurationChanged(void)\r
 {\r
        HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);\r
 void EVENT_USB_Device_ConfigurationChanged(void)\r
 {\r
        HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);\r
+       \r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Packet event. */\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Packet event. */\r
@@ -156,8 +152,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);\r
 }\r
 \r
        HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);\r
 }\r
 \r
-/** Timer 0 CTC ISR, firing once each millisecond to keep track of elapsed idle time in the HID interface. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
index 7cbda83..aabf6ac 100644 (file)
@@ -84,6 +84,7 @@
                \r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
                \r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
+               void EVENT_USB_Device_StartOfFrame(void);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r
 \r
                bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
                                                  void* ReportData, uint16_t* ReportSize);\r