Corrections to Keyboard and Mouse combined demos so that all modes (normal, interrupt...
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 19 Mar 2009 15:01:57 +0000 (15:01 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 19 Mar 2009 15:01:57 +0000 (15:01 +0000)
Demos/Keyboard/Descriptors.c
Demos/Keyboard/Keyboard.c
Demos/Keyboard/Keyboard.h
Demos/Mouse/Mouse.c
Demos/Mouse/Mouse.h

index 545f961..1f383ab 100644 (file)
@@ -163,7 +163,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
                        EndpointAddress:        (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_EPNUM),\r
                        Attributes:             EP_TYPE_INTERRUPT,\r
                        EndpointSize:           KEYBOARD_EPSIZE,\r
-                       PollingIntervalMS:      0x02\r
+                       PollingIntervalMS:      0x04\r
                },\r
 \r
        KeyboardLEDsEndpoint:\r
@@ -173,7 +173,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
                        EndpointAddress:        (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_LEDS_EPNUM),\r
                        Attributes:             EP_TYPE_INTERRUPT,\r
                        EndpointSize:           KEYBOARD_EPSIZE,\r
-                       PollingIntervalMS:      0x02\r
+                       PollingIntervalMS:      0x04\r
                }\r
 };\r
 \r
index f506070..a26f357 100644 (file)
@@ -113,6 +113,11 @@ int main(void)
  */\r
 EVENT_HANDLER(USB_Connect)\r
 {\r
+       #if !defined(INTERRUPT_CONTROL_ENDPOINT)\r
+       /* Start USB management task */\r
+       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+       #endif\r
+\r
        /* Indicate USB enumerating */\r
        UpdateStatus(Status_USBEnumerating);\r
 \r
@@ -334,14 +339,10 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
 /** Fills the given HID report data structure with the next HID report to send to the host.\r
  *\r
  *  \param ReportData  Pointer to a HID report data structure to be filled\r
- *\r
- *  \return Boolean true if the new report differs from the last report, false otherwise\r
  */\r
-bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)\r
+void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)\r
 {\r
-       static uint8_t PrevJoyStatus = 0;\r
-       uint8_t        JoyStatus_LCL        = Joystick_GetStatus();\r
-       bool           InputChanged         = false;\r
+       uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
 \r
        /* Clear the report contents */\r
        memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));\r
@@ -358,15 +359,6 @@ bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData)
 \r
        if (JoyStatus_LCL & JOY_PRESS)\r
          ReportData->KeyCode[0] = 0x08; // E\r
-         \r
-       /* Check if the new report is different to the previous report */\r
-       InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL);\r
-\r
-       /* Save the current joystick status for later comparison */\r
-       PrevJoyStatus = JoyStatus_LCL;\r
-\r
-       /* Return whether the new report is different to the previous report or not */\r
-       return InputChanged;\r
 }\r
 \r
 /** Processes a received LED report, and updates the board LEDs states to match.\r
@@ -394,19 +386,25 @@ void ProcessLEDReport(uint8_t LEDReport)
 static inline void SendNextReport(void)\r
 {\r
        USB_KeyboardReport_Data_t KeyboardReportData;\r
-       bool                      SendReport;\r
+       bool                      SendReport = true;\r
        \r
        /* Create the next keyboard report for transmission to the host */\r
-       SendReport = CreateKeyboardReport(&KeyboardReportData);\r
+       CreateKeyboardReport(&KeyboardReportData);\r
        \r
-       /* Check if the idle period is set and has elapsed */\r
-       if (IdleCount && !(IdleMSRemaining))\r
+       /* Check if the idle period is set */\r
+       if (IdleCount)\r
        {\r
-               /* Idle period elapsed, indicate that a report must be sent */\r
-               SendReport = true;\r
-               \r
-               /* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */\r
-               IdleMSRemaining = (IdleCount << 2);\r
+               /* Check if idle period has elapsed */\r
+               if (!(IdleMSRemaining))\r
+               {\r
+                       /* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */\r
+                       IdleMSRemaining = (IdleCount << 2);\r
+               }\r
+               else\r
+               {\r
+                       /* Idle period not elapsed, indicate that a report must not be sent */\r
+                       SendReport = false;                     \r
+               }\r
        }\r
        \r
        /* Select the Keyboard Report Endpoint */\r
index 8b3147c..143ffc6 100644 (file)
                HANDLES_EVENT(USB_UnhandledControlPacket);\r
                \r
        /* Function Prototypes: */\r
-               bool CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);\r
+               void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);\r
                void ProcessLEDReport(uint8_t LEDReport);\r
                static inline void SendNextReport(void);\r
                static inline void ReceiveNextReport(void);\r
index b61850a..c4b7f55 100644 (file)
@@ -113,9 +113,11 @@ int main(void)
  */\r
 EVENT_HANDLER(USB_Connect)\r
 {\r
+       #if !defined(INTERRUPT_CONTROL_ENDPOINT)\r
        /* Start USB management task */\r
        Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
-\r
+       #endif\r
+       \r
        /* Indicate USB enumerating */\r
        UpdateStatus(Status_USBEnumerating);\r
 \r
@@ -307,15 +309,10 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
 /** Fills the given HID report data structure with the next HID report to send to the host.\r
  *\r
  *  \param ReportData  Pointer to a HID report data structure to be filled\r
- *\r
- *  \return Boolean true if the new report differs from the last report, false otherwise\r
  */\r
-bool CreateMouseReport(USB_MouseReport_Data_t* ReportData)\r
+void CreateMouseReport(USB_MouseReport_Data_t* ReportData)\r
 {\r
-       static uint8_t PrevJoyStatus = 0;\r
-       static bool    PrevHWBStatus = false;\r
-       uint8_t        JoyStatus_LCL = Joystick_GetStatus();\r
-       bool           InputChanged  = false;\r
+       uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
        \r
        /* Clear the report contents */\r
        memset(ReportData, 0, sizeof(USB_MouseReport_Data_t));\r
@@ -335,16 +332,6 @@ bool CreateMouseReport(USB_MouseReport_Data_t* ReportData)
          \r
        if (HWB_GetStatus())\r
          ReportData->Button |= (1 << 1);\r
-\r
-       /* Check if the new report is different to the previous report */\r
-       InputChanged = ((uint8_t)(PrevJoyStatus ^ JoyStatus_LCL) | (uint8_t)(HWB_GetStatus() ^ PrevHWBStatus));\r
-\r
-       /* Save the current joystick and HWB status for later comparison */\r
-       PrevJoyStatus = JoyStatus_LCL;\r
-       PrevHWBStatus = HWB_GetStatus();\r
-\r
-       /* Return whether the new report is different to the previous report or not */\r
-       return InputChanged;\r
 }\r
 \r
 /** Sends the next HID report to the host, via the keyboard data endpoint. */\r
index 8723b78..c9854a8 100644 (file)
                HANDLES_EVENT(USB_UnhandledControlPacket);\r
 \r
        /* Function Prototypes: */\r
-               bool CreateMouseReport(USB_MouseReport_Data_t* ReportData);\r
+               void CreateMouseReport(USB_MouseReport_Data_t* ReportData);\r
                void UpdateStatus(uint8_t CurrentStatus);\r
 \r
 #endif\r