Add missing doxygen group terminator to the new CompilerSpecific.h header file.
[pub/USBasp.git] / Demos / Host / ClassDriver / KeyboardHostWithParser / KeyboardHostWithParser.c
index 5f10d8b..d7df58f 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2011.
 
   dean [at] fourwalledcubicle [dot] com
 
   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
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -37,7 +37,7 @@
 #include "KeyboardHostWithParser.h"
 
 /** Processed HID report descriptor items structure, containing information on each HID report element */
 #include "KeyboardHostWithParser.h"
 
 /** Processed HID report descriptor items structure, containing information on each HID report element */
-HID_ReportInfo_t HIDReportInfo;
+static HID_ReportInfo_t HIDReportInfo;
 
 /** LUFA HID Class driver interface configuration and state information. This structure is
  *  passed to all HID Class driver functions, so that multiple instances of the same class
 
 /** LUFA HID Class driver interface configuration and state information. This structure is
  *  passed to all HID Class driver functions, so that multiple instances of the same class
@@ -53,7 +53,7 @@ USB_ClassInfo_HID_Host_t Keyboard_HID_Interface =
                                .DataOUTPipeNumber      = 2,
                                .DataOUTPipeDoubleBank  = false,
 
                                .DataOUTPipeNumber      = 2,
                                .DataOUTPipeDoubleBank  = false,
 
-                               .HIDInterfaceProtocol   = HID_BOOTP_NonBootProtocol,
+                               .HIDInterfaceProtocol   = HID_CSCP_NonBootProtocol,
 
                                .HIDParserData          = &HIDReportInfo
                        },
 
                                .HIDParserData          = &HIDReportInfo
                        },
@@ -152,14 +152,27 @@ int main(void)
                                                                char PressedKey = 0;
 
                                                                /* Convert scan-code to printable character if alphanumeric */
                                                                char PressedKey = 0;
 
                                                                /* Convert scan-code to printable character if alphanumeric */
-                                                               if ((KeyCode >= 0x04) && (KeyCode <= 0x1D))
-                                                                 PressedKey = (KeyCode - 0x04) + 'A';
-                                                               else if ((KeyCode >= 0x1E) && (KeyCode <= 0x27))
-                                                                 PressedKey = (KeyCode - 0x1E) + '0';
-                                                               else if (KeyCode == 0x2C)
-                                                                 PressedKey = ' ';
-                                                               else if (KeyCode == 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) + '1';
+                                                               }
+                                                               else if (KeyCode == HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS)
+                                                               {
+                                                                       PressedKey = '0';
+                                                               }
+                                                               else if (KeyCode == HID_KEYBOARD_SC_SPACE)
+                                                               {
+                                                                       PressedKey = ' ';
+                                                               }
+                                                               else if (KeyCode == HID_KEYBOARD_SC_ENTER)
+                                                               {
+                                                                       PressedKey = '\n';
+                                                               }
 
                                                                /* Print the pressed key character out through the serial port if valid */
                                                                if (PressedKey)
 
                                                                /* Print the pressed key character out through the serial port if valid */
                                                                if (PressedKey)
@@ -191,9 +204,12 @@ void SetupHardware(void)
        clock_prescale_set(clock_div_1);
 
        /* Hardware Initialization */
        clock_prescale_set(clock_div_1);
 
        /* Hardware Initialization */
-       SerialStream_Init(9600, false);
+       Serial_Init(9600, false);
        LEDs_Init();
        USB_Init();
        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
 }
 
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
@@ -225,7 +241,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)
 {
 /** 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);
 
        printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
                                 " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);