Fix demos based on the device mode HID class driver, as well as the driver itself...
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 31 Jul 2009 03:22:08 +0000 (03:22 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 31 Jul 2009 03:22:08 +0000 (03:22 +0000)
14 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
LUFA/Drivers/USB/Class/Device/HID.c
LUFA/Drivers/USB/Class/Device/HID.h
Projects/Magstripe/Magstripe.c
Projects/Magstripe/Magstripe.h

index 4315723..9db30ce 100644 (file)
@@ -36,6 +36,9 @@
 \r
 #include "GenericHID.h"\r
 \r
 \r
 #include "GenericHID.h"\r
 \r
+/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevHIDReportBuffer[GENERIC_REPORT_SIZE];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -48,6 +51,9 @@ USB_ClassInfo_HID_Device_t Generic_HID_Interface =
 \r
                                .ReportINEndpointNumber  = GENERIC_IN_EPNUM,\r
                                .ReportINEndpointSize    = GENERIC_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = GENERIC_IN_EPNUM,\r
                                .ReportINEndpointSize    = GENERIC_EPSIZE,\r
+                               \r
+                               .PrevReportINBuffer      = PrevHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevHIDReportBuffer),\r
                        },\r
        };\r
 \r
                        },\r
        };\r
 \r
@@ -126,14 +132,17 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes written in the report (or zero if no report is to be sent\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        // Create generic HID report here\r
        \r
 {\r
        // Create generic HID report here\r
        \r
-       return 0;\r
+       *ReportSize = 0;\r
+       return true;\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
index 6d5de71..50a92ec 100644 (file)
@@ -72,9 +72,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                            void* ReportData);\r
-               void     CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
-                                                             const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
                \r
 #endif\r
                \r
 #endif\r
index ffd167e..f4dc32d 100644 (file)
@@ -36,6 +36,9 @@
 \r
 #include "Joystick.h"\r
 \r
 \r
 #include "Joystick.h"\r
 \r
+/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevJoystickHIDReportBuffer[sizeof(USB_JoystickReport_Data_t)];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -48,6 +51,9 @@ USB_ClassInfo_HID_Device_t Joystick_HID_Interface =
 \r
                                .ReportINEndpointNumber  = JOYSTICK_EPNUM,\r
                                .ReportINEndpointSize    = JOYSTICK_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = JOYSTICK_EPNUM,\r
                                .ReportINEndpointSize    = JOYSTICK_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevJoystickHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevJoystickHIDReportBuffer),\r
                        },\r
        };\r
 \r
                        },\r
        };\r
 \r
@@ -128,10 +134,12 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes written in the report (or zero if no report is to be sent\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;\r
        \r
 {\r
        USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;\r
        \r
@@ -154,7 +162,8 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          JoystickReport->Button |= (1 << 0);\r
          \r
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          JoystickReport->Button |= (1 << 0);\r
          \r
-       return sizeof(USB_JoystickReport_Data_t);\r
+       *ReportSize = sizeof(USB_JoystickReport_Data_t);\r
+       return false;\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
index 0f35fcc..764de17 100644 (file)
@@ -83,9 +83,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateNextHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                                void* ReportData);\r
-               void     CALLBACK_HID_Device_ProcessReceivedHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, const uint8_t ReportID, \r
-                                                                     const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
 \r
 #endif\r
 \r
 #endif\r
index fb19d02..040aec4 100644 (file)
@@ -37,6 +37,9 @@
 \r
 #include "Keyboard.h"\r
 \r
 \r
 #include "Keyboard.h"\r
 \r
+/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -49,6 +52,9 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
 \r
                                .ReportINEndpointNumber  = KEYBOARD_EPNUM,\r
                                .ReportINEndpointSize    = KEYBOARD_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = KEYBOARD_EPNUM,\r
                                .ReportINEndpointSize    = KEYBOARD_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevKeyboardHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevKeyboardHIDReportBuffer),\r
                        },\r
     };\r
 \r
                        },\r
     };\r
 \r
@@ -129,10 +135,12 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes written in the report (or zero if no report is to be sent\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
        \r
 {\r
        USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
        \r
@@ -154,8 +162,9 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
          \r
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          KeyboardReport->KeyCode[0] = 0x09; // F\r
          \r
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          KeyboardReport->KeyCode[0] = 0x09; // F\r
-         \r
-       return sizeof(USB_KeyboardReport_Data_t);\r
+       \r
+       *ReportSize = sizeof(USB_KeyboardReport_Data_t);\r
+       return false;\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
index 52b07ce..4a28d20 100644 (file)
@@ -86,9 +86,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                            void* ReportData);\r
-               void     CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
-                                                             const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
 \r
 #endif\r
 \r
 #endif\r
index 418ccba..abaf380 100644 (file)
 \r
 #include "KeyboardMouse.h"\r
 \r
 \r
 #include "KeyboardMouse.h"\r
 \r
+/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];\r
+\r
+/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another. This is for the keyboard HID\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another. This is for the keyboard HID\r
@@ -50,6 +56,9 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
 \r
                                .ReportINEndpointNumber  = KEYBOARD_IN_EPNUM,\r
                                .ReportINEndpointSize    = HID_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = KEYBOARD_IN_EPNUM,\r
                                .ReportINEndpointSize    = HID_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevKeyboardHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevKeyboardHIDReportBuffer),\r
                        },\r
        };\r
        \r
                        },\r
        };\r
        \r
@@ -66,6 +75,9 @@ USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
 \r
                                .ReportINEndpointNumber  = MOUSE_IN_EPNUM,\r
                                .ReportINEndpointSize    = HID_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = MOUSE_IN_EPNUM,\r
                                .ReportINEndpointSize    = HID_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevMouseHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevMouseHIDReportBuffer),\r
                        },              \r
        };\r
 \r
                        },              \r
        };\r
 \r
@@ -151,10 +163,12 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes written in the report (or zero if no report is to be sent\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        uint8_t JoyStatus_LCL    = Joystick_GetStatus();\r
        uint8_t ButtonStatus_LCL = Buttons_GetStatus();\r
 {\r
        uint8_t JoyStatus_LCL    = Joystick_GetStatus();\r
        uint8_t ButtonStatus_LCL = Buttons_GetStatus();\r
@@ -179,8 +193,9 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
 \r
                if (JoyStatus_LCL & JOY_PRESS)\r
                  KeyboardReport->KeyCode[0] = 0x08; // E\r
 \r
                if (JoyStatus_LCL & JOY_PRESS)\r
                  KeyboardReport->KeyCode[0] = 0x08; // E\r
-                 \r
-               return sizeof(USB_KeyboardReport_Data_t);\r
+               \r
+               *ReportSize = sizeof(USB_KeyboardReport_Data_t);\r
+               return false;\r
        }\r
        else\r
        {\r
        }\r
        else\r
        {\r
@@ -203,7 +218,8 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
                if (JoyStatus_LCL & JOY_PRESS)\r
                  MouseReport->Button  = (1 << 0);\r
                \r
                if (JoyStatus_LCL & JOY_PRESS)\r
                  MouseReport->Button  = (1 << 0);\r
                \r
-               return sizeof(USB_MouseReport_Data_t);          \r
+               *ReportSize = sizeof(USB_MouseReport_Data_t);\r
+               return true;            \r
        }\r
 }\r
 \r
        }\r
 }\r
 \r
index a04051b..15532c8 100644 (file)
@@ -90,9 +90,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                            void* ReportData);\r
-               void     CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
-                                                             const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
                \r
 #endif\r
                \r
 #endif\r
index 51021c0..08e87e6 100644 (file)
@@ -36,6 +36,9 @@
 \r
 #include "Mouse.h"\r
 \r
 \r
 #include "Mouse.h"\r
 \r
+/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -48,6 +51,9 @@ USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
 \r
                                .ReportINEndpointNumber  = MOUSE_EPNUM,\r
                                .ReportINEndpointSize    = MOUSE_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = MOUSE_EPNUM,\r
                                .ReportINEndpointSize    = MOUSE_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevMouseHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevMouseHIDReportBuffer),\r
                        },\r
        };\r
 \r
                        },\r
        };\r
 \r
@@ -128,10 +134,12 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes written in the report (or zero if no report is to be sent\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData;\r
                \r
 {\r
        USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData;\r
                \r
@@ -154,7 +162,8 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          MouseReport->Button |= (1 << 1);\r
        \r
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          MouseReport->Button |= (1 << 1);\r
        \r
-       return sizeof(USB_MouseReport_Data_t);\r
+       *ReportSize = sizeof(USB_MouseReport_Data_t);\r
+       return true;\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
 }\r
 \r
 /** HID class driver callback function for the processing of HID reports from the host.\r
index f134d92..57e4a69 100644 (file)
@@ -85,9 +85,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                            void* ReportData);\r
-               void     CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
-                                                             const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
 \r
 #endif\r
 \r
 #endif\r
index eef15f2..fbb45ac 100644 (file)
@@ -51,15 +51,15 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* const HIDInterf
                        {\r
                                Endpoint_ClearSETUP();  \r
 \r
                        {\r
                                Endpoint_ClearSETUP();  \r
 \r
-                               uint8_t  ReportINData[HID_MAX_REPORT_SIZE];\r
                                uint16_t ReportINSize;\r
                                uint8_t  ReportID = (USB_ControlRequest.wValue & 0xFF);\r
 \r
                                uint16_t ReportINSize;\r
                                uint8_t  ReportID = (USB_ControlRequest.wValue & 0xFF);\r
 \r
-                               memset(ReportINData, 0, sizeof(ReportINData));\r
+                               memset(HIDInterfaceInfo->Config.PrevReportINBuffer, 0, HIDInterfaceInfo->Config.PrevReportINBufferSize);\r
                                \r
                                \r
-                               ReportINSize = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData);\r
+                               CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID,\r
+                                                                   HIDInterfaceInfo->Config.PrevReportINBuffer, &ReportINSize);\r
 \r
 \r
-                               Endpoint_Write_Control_Stream_LE(ReportINData, ReportINSize);\r
+                               Endpoint_Write_Control_Stream_LE(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize);\r
                                Endpoint_ClearOUT();\r
                        }\r
                \r
                                Endpoint_ClearOUT();\r
                        }\r
                \r
@@ -157,20 +157,20 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo)
        \r
        if (Endpoint_IsReadWriteAllowed())\r
        {\r
        \r
        if (Endpoint_IsReadWriteAllowed())\r
        {\r
-               uint8_t  ReportINData[HID_MAX_REPORT_SIZE];\r
+               uint8_t  ReportINData[HIDInterfaceInfo->Config.PrevReportINBufferSize];\r
                uint8_t  ReportID = 0;\r
                uint16_t ReportINSize;\r
 \r
                memset(ReportINData, 0, sizeof(ReportINData));\r
 \r
                uint8_t  ReportID = 0;\r
                uint16_t ReportINSize;\r
 \r
                memset(ReportINData, 0, sizeof(ReportINData));\r
 \r
-               ReportINSize  = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData);\r
+               bool ForceSend = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData, &ReportINSize);\r
 \r
 \r
-               bool StatesChanged     = (memcmp(ReportINData, HIDInterfaceInfo->State.PreviousReportINData, ReportINSize) != 0);\r
+               bool StatesChanged     = (memcmp(ReportINData, HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize) != 0);\r
                bool IdlePeriodElapsed = (HIDInterfaceInfo->State.IdleCount && !(HIDInterfaceInfo->State.IdleMSRemaining));\r
                \r
                bool IdlePeriodElapsed = (HIDInterfaceInfo->State.IdleCount && !(HIDInterfaceInfo->State.IdleMSRemaining));\r
                \r
-               memcpy(HIDInterfaceInfo->State.PreviousReportINData, ReportINData, ReportINSize);\r
+               memcpy(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINData, ReportINSize);\r
 \r
 \r
-               if (ReportINSize && (StatesChanged || IdlePeriodElapsed))\r
+               if (ReportINSize && (ForceSend || StatesChanged || IdlePeriodElapsed))\r
                {\r
                        HIDInterfaceInfo->State.IdleMSRemaining = HIDInterfaceInfo->State.IdleCount;\r
 \r
                {\r
                        HIDInterfaceInfo->State.IdleMSRemaining = HIDInterfaceInfo->State.IdleCount;\r
 \r
index 06456cf..b8ca479 100644 (file)
                #endif\r
 \r
        /* Public Interface - May be used in end-application: */\r
                #endif\r
 \r
        /* Public Interface - May be used in end-application: */\r
-               /* Macros: */\r
-                       #if !defined(HID_MAX_REPORT_SIZE)\r
-                               /** Maximum size of an IN report which can be generated by the device and sent to the host, in bytes.\r
-                                *\r
-                                *  \note If larger reports than the default specified here are to be generated by the device, this\r
-                                *        value can be overridden by defining this token to the required value in the project makefile\r
-                                *        and passing it to the compiler via the -D switch.\r
-                                */\r
-                               #define HID_MAX_REPORT_SIZE     16\r
-                       #endif\r
-       \r
                /* Type Defines: */\r
                        /** Class state structure. An instance of this structure should be made for each HID interface\r
                         *  within the user application, and passed to each of the HID class driver functions as the\r
                /* Type Defines: */\r
                        /** Class state structure. An instance of this structure should be made for each HID interface\r
                         *  within the user application, and passed to each of the HID class driver functions as the\r
 \r
                                        uint8_t  ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */\r
                                        uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */                                  \r
 \r
                                        uint8_t  ReportINEndpointNumber; /**< Endpoint number of the HID interface's IN report endpoint */\r
                                        uint16_t ReportINEndpointSize; /**< Size in bytes of the HID interface's IN report endpoint */                                  \r
+                                       \r
+                                       void*    PrevReportINBuffer; /** Pointer to a buffer where the previously created HID input report can be\r
+                                                                     *  stored by the driver, for comparison purposes to detect report changes that\r
+                                                                     *  must be sent immediately to the host. This should point to a buffer big enough\r
+                                                                     *  to hold the largest HID input report sent from the HID interface.\r
+                                                                     */\r
+                                       uint8_t  PrevReportINBufferSize; /** Size in bytes of the given input report buffer. This is used to create a\r
+                                                                         *  second buffer of the same size within the driver so that subsequent reports\r
+                                                                         *  can be compared.\r
+                                                                         */\r
                                } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
                                           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
                                           */                                                                            \r
                                } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
                                           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
                                           */                                                                            \r
@@ -89,8 +88,6 @@
                                        uint16_t IdleCount; /**< Report idle period, in mS, set by the host */\r
                                        uint16_t IdleMSRemaining; /**< Total number of mS remaining before the idle period elapsed - this should be\r
                                                                                           *   decremented by the user application if non-zero each millisecond */      \r
                                        uint16_t IdleCount; /**< Report idle period, in mS, set by the host */\r
                                        uint16_t IdleMSRemaining; /**< Total number of mS remaining before the idle period elapsed - this should be\r
                                                                                           *   decremented by the user application if non-zero each millisecond */      \r
-\r
-                                       uint8_t PreviousReportINData[HID_MAX_REPORT_SIZE]; /**< Previously generated report from the HID interface */\r
                                } State; /**< State data for the USB class interface within the device. All elements in this section\r
                                          *   are reset to their defaults when the interface is enumerated.\r
                                          */\r
                                } State; /**< State data for the USB class interface within the device. All elements in this section\r
                                          *   are reset to their defaults when the interface is enumerated.\r
                                          */\r
                         *                 be set to the report ID of the generated HID input report. If multiple reports are not sent via the\r
                         *                 given HID interface, this parameter should be ignored.\r
                         *  \param[out] ReportData  Pointer to a buffer where the generated HID report should be stored.\r
                         *                 be set to the report ID of the generated HID input report. If multiple reports are not sent via the\r
                         *                 given HID interface, this parameter should be ignored.\r
                         *  \param[out] ReportData  Pointer to a buffer where the generated HID report should be stored.\r
+                        *  \param[out] ReportSize  Number of bytes in the generated input report, or zero if no report is to be sent\r
                         *\r
                         *\r
-                        *  \return  Number of bytes in the generated input report, or zero if no report is to be sent\r
+                        *  \return Boolean true to force the sending of the report even if it is identical to the previous report and still within\r
+                        *          the idle period (useful for devices which report relative movement), false otherwise\r
                         */\r
                         */\r
-                       uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo, uint8_t* ReportID, void* ReportData);\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
                        /** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to\r
                         *  either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback\r
                         *  the user is responsible for the processing of the received HID output report from the host.\r
                        /** HID class driver callback for the user processing of a received HID input report. This callback may fire in response to\r
                         *  either HID class control requests from the host, or by the normal HID endpoint polling procedure. Inside this callback\r
                         *  the user is responsible for the processing of the received HID output report from the host.\r
index 6d463d6..f0fd8a7 100644 (file)
@@ -45,6 +45,9 @@ BitBuffer_t TrackDataBuffers[TOTAL_TRACKS];
 /** Pointer to the current track buffer being sent to the host. */\r
 BitBuffer_t* CurrentTrackBuffer = &TrackDataBuffers[TOTAL_TRACKS];\r
 \r
 /** Pointer to the current track buffer being sent to the host. */\r
 BitBuffer_t* CurrentTrackBuffer = &TrackDataBuffers[TOTAL_TRACKS];\r
 \r
+/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */\r
+uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];\r
+\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
 /** LUFA HID Class driver interface configuration and state information. This structure is\r
  *  passed to all HID Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another.\r
@@ -57,6 +60,9 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
 \r
                                .ReportINEndpointNumber  = KEYBOARD_EPNUM,\r
                                .ReportINEndpointSize    = KEYBOARD_EPSIZE,\r
 \r
                                .ReportINEndpointNumber  = KEYBOARD_EPNUM,\r
                                .ReportINEndpointSize    = KEYBOARD_EPSIZE,\r
+\r
+                               .PrevReportINBuffer      = PrevKeyboardHIDReportBuffer,\r
+                               .PrevReportINBufferSize  = sizeof(PrevKeyboardHIDReportBuffer),\r
                        },\r
        };\r
 \r
                        },\r
        };\r
 \r
@@ -156,15 +162,17 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
 \r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
 \r
-/** HID Class driver callback function for the creation of a HID report for the host.\r
+/** HID class driver callback function for the creation of HID reports to the host.\r
  *\r
  *\r
- *  \param[in] HIDInterfaceInfo  Pointer to the HID interface structure for the HID interface being referenced\r
- *  \param[in,out] ReportID      Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
- *  \param[out] ReportData       Pointer to the preallocated report buffer where the created report should be stored\r
+ *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
+ *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
+ *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
+ *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *\r
- *  \return Number of bytes in the created report\r
+ *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
  */\r
-uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData)\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
        USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
 \r
 {\r
        USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
 \r
@@ -190,7 +198,8 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H
                KeyboardReport->KeyCode = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0;\r
        }\r
        \r
                KeyboardReport->KeyCode = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0;\r
        }\r
        \r
-       return sizeof(USB_KeyboardReport_Data_t);\r
+       *ReportSize = sizeof(USB_KeyboardReport_Data_t);\r
+       return false;\r
 }\r
 \r
 /** HID Class driver callback function for the processing of a received HID report from the host.\r
 }\r
 \r
 /** HID Class driver callback function for the processing of a received HID report from the host.\r
index 4e0aac9..279e3db 100644 (file)
@@ -85,9 +85,9 @@
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
-               uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                                            void* ReportData);\r
-               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID,\r
-                                                  const void* ReportData, const uint16_t ReportSize);\r
+               bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
+                                                 void* ReportData, uint16_t* ReportSize);\r
+               void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, \r
+                                                         const void* ReportData, const uint16_t ReportSize);\r
                                                                                                                  \r
 #endif\r
                                                                                                                  \r
 #endif\r