Documentation improvements - put driver example code into its own section, fix incorr...
[pub/USBasp.git] / Demos / Device / LowLevel / Keyboard / Keyboard.c
index 9d187f8..4e83b51 100644 (file)
@@ -3,7 +3,7 @@
      Copyright (C) Dean Camera, 2010.
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
@@ -129,16 +129,16 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
-/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
- *  control requests that are not handled internally by the USB library (including the HID commands, which are
- *  all issued via the control endpoint), so that they can be handled appropriately for the application.
+/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
+ *  the device from the USB host before passing along unhandled control requests to the library for processing
+ *  internally.
  */
-void EVENT_USB_Device_UnhandledControlRequest(void)
+void EVENT_USB_Device_ControlRequest(void)
 {
        /* Handle HID Class specific requests */
        switch (USB_ControlRequest.bRequest)
        {
-               case REQ_GetReport:
+               case HID_REQ_GetReport:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                USB_KeyboardReport_Data_t KeyboardReportData;
@@ -154,7 +154,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        }
 
                        break;
-               case REQ_SetReport:
+               case HID_REQ_SetReport:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                Endpoint_ClearSETUP();
@@ -177,7 +177,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        }
 
                        break;
-               case REQ_GetProtocol:
+               case HID_REQ_GetProtocol:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                Endpoint_ClearSETUP();
@@ -190,7 +190,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        }
 
                        break;
-               case REQ_SetProtocol:
+               case HID_REQ_SetProtocol:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                Endpoint_ClearSETUP();
@@ -201,7 +201,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        }
 
                        break;
-               case REQ_SetIdle:
+               case HID_REQ_SetIdle:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                Endpoint_ClearSETUP();
@@ -212,7 +212,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        }
 
                        break;
-               case REQ_GetIdle:
+               case HID_REQ_GetIdle:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
                                Endpoint_ClearSETUP();
@@ -251,23 +251,23 @@ void CreateKeyboardReport(USB_KeyboardReport_Data_t* const ReportData)
        memset(ReportData, 0, sizeof(USB_KeyboardReport_Data_t));
 
        /* Make sent key uppercase by indicating that the left shift key is pressed */
-       ReportData->Modifier = KEYBOARD_MODIFER_LEFTSHIFT;
+       ReportData->Modifier = HID_KEYBOARD_MODIFER_LEFTSHIFT;
 
        if (JoyStatus_LCL & JOY_UP)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x04; // A
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_A;
        else if (JoyStatus_LCL & JOY_DOWN)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x05; // B
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_B;
 
        if (JoyStatus_LCL & JOY_LEFT)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x06; // C
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_C;
        else if (JoyStatus_LCL & JOY_RIGHT)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x07; // D
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_D;
 
        if (JoyStatus_LCL & JOY_PRESS)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x08; // E
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_E;
 
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)
-         ReportData->KeyCode[UsedKeyCodes++] = 0x09; // F
+         ReportData->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_F;
 }
 
 /** Processes a received LED report, and updates the board LEDs states to match.
@@ -278,13 +278,13 @@ void ProcessLEDReport(const uint8_t LEDReport)
 {
        uint8_t LEDMask = LEDS_LED2;
 
-       if (LEDReport & KEYBOARD_LED_NUMLOCK)
+       if (LEDReport & HID_KEYBOARD_LED_NUMLOCK)
          LEDMask |= LEDS_LED1;
 
-       if (LEDReport & KEYBOARD_LED_CAPSLOCK)
+       if (LEDReport & HID_KEYBOARD_LED_CAPSLOCK)
          LEDMask |= LEDS_LED3;
 
-       if (LEDReport & KEYBOARD_LED_SCROLLLOCK)
+       if (LEDReport & HID_KEYBOARD_LED_SCROLLLOCK)
          LEDMask |= LEDS_LED4;
 
        /* Set the status LEDs to the current Keyboard LED status */
@@ -305,7 +305,7 @@ void SendNextReport(void)
        SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0);
 
        /* Check if the idle period is set and has elapsed */
-       if ((IdleCount != HID_IDLE_CHANGESONLY) && (!(IdleMSRemaining)))
+       if (IdleCount && (!(IdleMSRemaining)))
        {
                /* Reset the idle time remaining counter */
                IdleMSRemaining = IdleCount;