Porting updates for the UC3B architecture - get UC3B partially enumerating using...
[pub/USBasp.git] / Demos / Host / ClassDriver / KeyboardHost / KeyboardHost.c
index 9b7941e..9b6125e 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2011.
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -50,7 +50,7 @@ USB_ClassInfo_HID_Host_t Keyboard_HID_Interface =
                                .DataOUTPipeNumber      = 2,
                                .DataOUTPipeDoubleBank  = false,
 
-                               .HIDInterfaceProtocol   = HID_BOOTP_KeyboardBootProtocol,
+                               .HIDInterfaceProtocol   = HID_CSCP_KeyboardBootProtocol,
                        },
        };
 
@@ -123,24 +123,33 @@ int main(void)
 
                                        LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);
 
-                                       uint8_t PressedKeyCode = KeyboardReport.KeyCode[0];
+                                       uint8_t KeyCode = KeyboardReport.KeyCode[0];
 
-                                       if (PressedKeyCode)
+                                       if (KeyCode)
                                        {
                                                char PressedKey = 0;
 
                                                LEDs_ToggleLEDs(LEDS_LED2);
 
                                                /* Retrieve pressed key character if alphanumeric */
-                                               if ((PressedKeyCode >= 0x04) && (PressedKeyCode <= 0x1D))
-                                                 PressedKey = (PressedKeyCode - 0x04) + 'A';
-                                               else if ((PressedKeyCode >= 0x1E) && (PressedKeyCode <= 0x27))
-                                                 PressedKey = (PressedKeyCode - 0x1E) + '0';
-                                               else if (PressedKeyCode == 0x2C)
-                                                 PressedKey = ' ';
-                                               else if (PressedKeyCode == 0x28)
-                                                 PressedKey = '\n';
-
+                                               if ((KeyCode >= HID_KEYBOARD_SC_A) && (KeyCode <= HID_KEYBOARD_SC_Z))
+                                               {
+                                                       PressedKey = (KeyCode - HID_KEYBOARD_SC_A) + 'A';
+                                               }
+                                               else if ((KeyCode >= HID_KEYBOARD_SC_1_AND_EXCLAMATION) &
+                                                        (KeyCode <= HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS))
+                                               {
+                                                       PressedKey = (KeyCode - HID_KEYBOARD_SC_1_AND_EXCLAMATION) + '0';
+                                               }
+                                               else if (KeyCode == HID_KEYBOARD_SC_SPACE)
+                                               {
+                                                       PressedKey = ' ';
+                                               }
+                                               else if (KeyCode == HID_KEYBOARD_SC_ENTER)
+                                               {
+                                                       PressedKey = '\n';
+                                               }
+                                               
                                                if (PressedKey)
                                                  putchar(PressedKey);
                                        }
@@ -165,9 +174,12 @@ void SetupHardware(void)
        clock_prescale_set(clock_div_1);
 
        /* Hardware Initialization */
-       SerialStream_Init(9600, false);
+       Serial_Init(9600, false);
        LEDs_Init();
        USB_Init();
+
+       /* Create a stdio stream for the serial port for stdin and stdout */
+       Serial_CreateStream(NULL);
 }
 
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
@@ -199,7 +211,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */
 void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
 {
-       USB_ShutDown();
+       USB_Disable();
 
        printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
                                 " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);