aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/KeyboardHostWithParser
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-04-16 08:50:34 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-04-16 08:50:34 +0000
commit8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c (patch)
tree65c37548f19c26de3971639067d6f290095f5843 /Demos/Host/KeyboardHostWithParser
parentef06bfd1c0ef5272c32808e23d0fd60d2d1bca9c (diff)
downloadlufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.tar.gz
lufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.tar.bz2
lufa-8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c.zip
Fixed GenericHIDHost demo report write routine incorrect for control type requests (thanks to Andrei Krainev).
Removed Endpoint_ClearCurrentBank() and Pipe_ClearCurrentBank() in favour of new Endpoint_ClearIN(), Endpoint_ClearOUT(), Endpoint_ClearControlIN(), Endpoint_ClearControlOUT(), Pipe_ClearIN(), Pipe_ClearOUT(), Pipe_ClearControlIN() and Pipe_ClearControlOUT() macros (done to allow for the detection of packets of zero length). Renamed *_ReadWriteAllowed() macros to *_IsReadWriteAllowed() to remain consistent with the rest of the LUFA API. Endpoint_IsSetupReceived() macro has been renamed to Endpoint_IsSETUPReceived(), Endpoint_ClearSetupReceived() macro has been renamed to Endpoint_ClearControlSETUP(), the Pipe_IsSetupSent() macro has been renamed to Pipe_IsSETUPSent() and the Pipe_ClearSetupSent() macro is no longer applicable and should be removed - changes made to compliment the new endpoint and pipe bank management API. Updated all demos, bootloaders and projects to use the new endpoint and pipe management APIs (thanks to Roman Thiel). Updated library doxygen documentation, added groups, changed documentation macro functions to real functions for clarity. Removed old endpoint and pipe aliased read/write/discard routines which did not have an explicit endian specifier for clarity. Removed the ButtLoadTag.h header file, as no one used for its intended purpose anyway.
Diffstat (limited to 'Demos/Host/KeyboardHostWithParser')
-rw-r--r--Demos/Host/KeyboardHostWithParser/ConfigDescriptor.h1
-rw-r--r--Demos/Host/KeyboardHostWithParser/HIDReport.h2
-rw-r--r--Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c141
-rw-r--r--Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.h2
4 files changed, 77 insertions, 69 deletions
diff --git a/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.h b/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.h
index e007a942a..1deff6328 100644
--- a/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.h
+++ b/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.h
@@ -38,7 +38,6 @@
/* Includes: */
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
- #include <LUFA/Drivers/USB/Class/ConfigDescriptor.h> // Configuration Descriptor Parser
#include "HIDReport.h"
diff --git a/Demos/Host/KeyboardHostWithParser/HIDReport.h b/Demos/Host/KeyboardHostWithParser/HIDReport.h
index 7c59138c2..a128b8e97 100644
--- a/Demos/Host/KeyboardHostWithParser/HIDReport.h
+++ b/Demos/Host/KeyboardHostWithParser/HIDReport.h
@@ -37,7 +37,7 @@
#define _HID_REPORT_H_
/* Includes: */
- #include <LUFA/Drivers/USB/Class/HIDParser.h> // HID Class Report Parser
+ #include <LUFA/Drivers/USB/USB.h> // USB Functionality
#include "KeyboardHostWithParser.h"
diff --git a/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c
index d19929d4d..d7d5f9414 100644
--- a/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ b/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c
@@ -36,12 +36,6 @@
#include "KeyboardHostWithParser.h"
-/* Project Tags, for reading out using the ButtLoad project */
-BUTTLOADTAG(ProjName, "LUFA KBD Host App");
-BUTTLOADTAG(BuildTime, __TIME__);
-BUTTLOADTAG(BuildDate, __DATE__);
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);
-
/* Scheduler Task List */
TASK_LIST
{
@@ -270,70 +264,24 @@ TASK(USB_Keyboard_Host)
Pipe_SelectPipe(KEYBOARD_DATAPIPE);
Pipe_Unfreeze();
- /* Check if data has been received from the attached keyboard */
- if (Pipe_ReadWriteAllowed())
+ /* Check to see if a packet has been received */
+ if (Pipe_IsINReceived())
{
- /* Create buffer big enough for the report */
- uint8_t KeyboardReport[Pipe_BytesInPipe()];
+ /* Check if data has been received from the attached keyboard */
+ if (Pipe_IsReadWriteAllowed())
+ {
+ /* Create buffer big enough for the report */
+ uint8_t KeyboardReport[Pipe_BytesInPipe()];
- /* Load in the keyboard report */
- Pipe_Read_Stream_LE(KeyboardReport, Pipe_BytesInPipe());
+ /* Load in the keyboard report */
+ Pipe_Read_Stream_LE(KeyboardReport, Pipe_BytesInPipe());
- /* Clear the IN endpoint, ready for next data packet */
- Pipe_ClearCurrentBank();
-
- /* Check each HID report item in turn, looking for keyboard scan code reports */
- for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)
- {
- /* Create a temporary item pointer to the next report item */
- HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];
-
- /* Check if the current report item is a keyboard scancode */
- if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_KEYBOARD) &&
- (ReportItem->Attributes.BitSize == 8) &&
- (ReportItem->Attributes.Logical.Maximum > 1) &&
- (ReportItem->ItemType == REPORT_ITEM_TYPE_In))
- {
- /* Retrieve the keyboard scancode from the report data retrieved from the device */
- bool FoundData = GetReportItemInfo(KeyboardReport, ReportItem);
-
- /* For multi-report devices - if the requested data was not in the issued report, continue */
- if (!(FoundData))
- continue;
-
- /* Key code is an unsigned char in length, cast to the appropriate type */
- uint8_t KeyCode = (uint8_t)ReportItem->Value;
-
- /* If scancode is non-zero, a key is being pressed */
- if (KeyCode)
- {
- /* Toggle status LED to indicate keypress */
- if (LEDs_GetLEDs() & LEDS_LED2)
- LEDs_TurnOffLEDs(LEDS_LED2);
- else
- LEDs_TurnOnLEDs(LEDS_LED2);
-
- char PressedKey = 0;
-
- /* Convert scancode 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';
-
- /* Print the pressed key character out through the serial port if valid */
- if (PressedKey)
- putchar(PressedKey);
- }
-
- /* Once a scancode is found, stop scanning through the report items */
- break;
- }
+ /* Process the read in keyboard report from the device */
+ ProcessKeyboardReport(KeyboardReport);
}
+
+ /* Clear the IN endpoint, ready for next data packet */
+ Pipe_ClearIN();
}
/* Freeze keyboard data pipe */
@@ -341,3 +289,64 @@ TASK(USB_Keyboard_Host)
break;
}
}
+
+/** Processes a read HID report from an attached keyboard, extracting out elements via the HID parser results
+ * as required and prints pressed characters to the serial port. Each time a key is typed, a board LED is toggled.
+ *
+ * \param KeyboardReport Pointer to a HID report from an attached keyboard device
+ */
+void ProcessKeyboardReport(uint8_t* KeyboardReport)
+{
+ /* Check each HID report item in turn, looking for keyboard scan code reports */
+ for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)
+ {
+ /* Create a temporary item pointer to the next report item */
+ HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];
+
+ /* Check if the current report item is a keyboard scancode */
+ if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_KEYBOARD) &&
+ (ReportItem->Attributes.BitSize == 8) &&
+ (ReportItem->Attributes.Logical.Maximum > 1) &&
+ (ReportItem->ItemType == REPORT_ITEM_TYPE_In))
+ {
+ /* Retrieve the keyboard scancode from the report data retrieved from the device */
+ bool FoundData = GetReportItemInfo(KeyboardReport, ReportItem);
+
+ /* For multi-report devices - if the requested data was not in the issued report, continue */
+ if (!(FoundData))
+ continue;
+
+ /* Key code is an unsigned char in length, cast to the appropriate type */
+ uint8_t KeyCode = (uint8_t)ReportItem->Value;
+
+ /* If scancode is non-zero, a key is being pressed */
+ if (KeyCode)
+ {
+ /* Toggle status LED to indicate keypress */
+ if (LEDs_GetLEDs() & LEDS_LED2)
+ LEDs_TurnOffLEDs(LEDS_LED2);
+ else
+ LEDs_TurnOnLEDs(LEDS_LED2);
+
+ char PressedKey = 0;
+
+ /* Convert scancode 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';
+
+ /* Print the pressed key character out through the serial port if valid */
+ if (PressedKey)
+ putchar(PressedKey);
+ }
+
+ /* Once a scancode is found, stop scanning through the report items */
+ break;
+ }
+ }
+}
diff --git a/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.h b/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.h
index fece67971..112dbfdec 100644
--- a/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.h
+++ b/Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.h
@@ -39,7 +39,6 @@
#include <stdio.h>
#include <LUFA/Version.h> // Library Version Information
- #include <LUFA/Common/ButtLoadTag.h> // PROGMEM tags readable by the ButtLoad project
#include <LUFA/Drivers/Misc/TerminalCodes.h> // ANSI Terminal Escape Codes
#include <LUFA/Drivers/USB/USB.h> // USB Functionality
#include <LUFA/Drivers/AT90USBXXX/Serial_Stream.h> // Serial stream driver
@@ -77,5 +76,6 @@
/* Function Prototypes: */
void UpdateStatus(uint8_t CurrentStatus);
+ void ProcessKeyboardReport(uint8_t* KeyboardReport);
#endif