aboutsummaryrefslogtreecommitdiffstats
path: root/Demos
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-10-28 23:11:49 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-10-28 23:11:49 +0000
commitb8dfa976ce796ede92dfefa6a39eb0a3b08acdce (patch)
tree8144660271140732a299511aa31159c12239ee55 /Demos
parent2d49c09b384375298a4995b79c4b29e8d9390cd6 (diff)
downloadlufa-b8dfa976ce796ede92dfefa6a39eb0a3b08acdce.tar.gz
lufa-b8dfa976ce796ede92dfefa6a39eb0a3b08acdce.tar.bz2
lufa-b8dfa976ce796ede92dfefa6a39eb0a3b08acdce.zip
Added standard keyboard HID report scancode defines (thanks to László Monda).
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Device/ClassDriver/Keyboard/Keyboard.c12
-rw-r--r--Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c10
-rw-r--r--Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c12
-rw-r--r--Demos/Device/LowLevel/Keyboard/Keyboard.c12
-rw-r--r--Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c10
-rw-r--r--Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c31
-rw-r--r--Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c25
-rw-r--r--Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c29
-rw-r--r--Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c27
9 files changed, 103 insertions, 65 deletions
diff --git a/Demos/Device/ClassDriver/Keyboard/Keyboard.c b/Demos/Device/ClassDriver/Keyboard/Keyboard.c
index d17b238ef..34dee99d0 100644
--- a/Demos/Device/ClassDriver/Keyboard/Keyboard.c
+++ b/Demos/Device/ClassDriver/Keyboard/Keyboard.c
@@ -149,20 +149,20 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
uint8_t UsedKeyCodes = 0;
if (JoyStatus_LCL & JOY_UP)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x04; // A
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_A;
else if (JoyStatus_LCL & JOY_DOWN)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x05; // B
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_B;
if (JoyStatus_LCL & JOY_LEFT)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x06; // C
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_C;
else if (JoyStatus_LCL & JOY_RIGHT)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x07; // D
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_D;
if (JoyStatus_LCL & JOY_PRESS)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x08; // E
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_E;
if (ButtonStatus_LCL & BUTTONS_BUTTON1)
- KeyboardReport->KeyCode[UsedKeyCodes++] = 0x09; // F
+ KeyboardReport->KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_F;
if (UsedKeyCodes)
KeyboardReport->Modifier = HID_KEYBOARD_MODIFER_LEFTSHIFT;
diff --git a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c
index 245bf0755..61f22d2ab 100644
--- a/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c
+++ b/Demos/Device/ClassDriver/KeyboardMouse/KeyboardMouse.c
@@ -185,17 +185,17 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
KeyboardReport->Modifier = HID_KEYBOARD_MODIFER_LEFTSHIFT;
if (JoyStatus_LCL & JOY_UP)
- KeyboardReport->KeyCode[0] = 0x04; // A
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_A;
else if (JoyStatus_LCL & JOY_DOWN)
- KeyboardReport->KeyCode[0] = 0x05; // B
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_B;
if (JoyStatus_LCL & JOY_LEFT)
- KeyboardReport->KeyCode[0] = 0x06; // C
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_C;
else if (JoyStatus_LCL & JOY_RIGHT)
- KeyboardReport->KeyCode[0] = 0x07; // D
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_D;
if (JoyStatus_LCL & JOY_PRESS)
- KeyboardReport->KeyCode[0] = 0x08; // E
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_E;
*ReportSize = sizeof(USB_KeyboardReport_Data_t);
return false;
diff --git a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
index a81b4d969..7c5411033 100644
--- a/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
+++ b/Demos/Device/ClassDriver/MassStorageKeyboard/MassStorageKeyboard.c
@@ -198,20 +198,20 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
KeyboardReport->Modifier = HID_KEYBOARD_MODIFER_LEFTSHIFT;
if (JoyStatus_LCL & JOY_UP)
- KeyboardReport->KeyCode[0] = 0x04; // A
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_A;
else if (JoyStatus_LCL & JOY_DOWN)
- KeyboardReport->KeyCode[0] = 0x05; // B
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_B;
if (JoyStatus_LCL & JOY_LEFT)
- KeyboardReport->KeyCode[0] = 0x06; // C
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_C;
else if (JoyStatus_LCL & JOY_RIGHT)
- KeyboardReport->KeyCode[0] = 0x07; // D
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_D;
if (JoyStatus_LCL & JOY_PRESS)
- KeyboardReport->KeyCode[0] = 0x08; // E
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_E;
if (ButtonStatus_LCL & BUTTONS_BUTTON1)
- KeyboardReport->KeyCode[0] = 0x09; // F
+ KeyboardReport->KeyCode[0] = HID_KEYBOARD_SC_F;
*ReportSize = sizeof(USB_KeyboardReport_Data_t);
return false;
diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.c b/Demos/Device/LowLevel/Keyboard/Keyboard.c
index e490f517b..a8149a935 100644
--- a/Demos/Device/LowLevel/Keyboard/Keyboard.c
+++ b/Demos/Device/LowLevel/Keyboard/Keyboard.c
@@ -254,20 +254,20 @@ void CreateKeyboardReport(USB_KeyboardReport_Data_t* const ReportData)
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.
diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
index 9b0c9ab7b..c54bb158f 100644
--- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
+++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
@@ -222,17 +222,17 @@ void Keyboard_HID_Task(void)
KeyboardReportData.Modifier = HID_KEYBOARD_MODIFER_LEFTSHIFT;
if (JoyStatus_LCL & JOY_UP)
- KeyboardReportData.KeyCode[0] = 0x04; // A
+ KeyboardReportData.KeyCode[0] = HID_KEYBOARD_SC_A;
else if (JoyStatus_LCL & JOY_DOWN)
- KeyboardReportData.KeyCode[0] = 0x05; // B
+ KeyboardReportData.KeyCode[0] = HID_KEYBOARD_SC_B;
if (JoyStatus_LCL & JOY_LEFT)
- KeyboardReportData.KeyCode[0] = 0x06; // C
+ KeyboardReportData.KeyCode[0] = HID_KEYBOARD_SC_C;
else if (JoyStatus_LCL & JOY_RIGHT)
- KeyboardReportData.KeyCode[0] = 0x07; // D
+ KeyboardReportData.KeyCode[0] = HID_KEYBOARD_SC_D;
if (JoyStatus_LCL & JOY_PRESS)
- KeyboardReportData.KeyCode[0] = 0x08; // E
+ KeyboardReportData.KeyCode[0] = HID_KEYBOARD_SC_E;
}
/* Select the Keyboard Report Endpoint */
diff --git a/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c b/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
index 1d9b2c0ff..2101ae803 100644
--- a/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
+++ b/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
@@ -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);
}
diff --git a/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
index 3ef4640c6..6e7ee6c6a 100644
--- a/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ b/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
@@ -152,14 +152,23 @@ int main(void)
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) + '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)
diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
index f6946fbdd..c35a9034f 100644
--- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
+++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
@@ -154,8 +154,10 @@ void ReadNextReport(void)
/* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */
LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);
+ uint8_t KeyCode = KeyboardReport.KeyCode[0];
+
/* Check if a key has been pressed */
- if (KeyboardReport.KeyCode)
+ if (KeyCode)
{
/* Toggle status LED to indicate keypress */
LEDs_ToggleLEDs(LEDS_LED2);
@@ -163,14 +165,23 @@ void ReadNextReport(void)
char PressedKey = 0;
/* Retrieve pressed key character if alphanumeric */
- if ((KeyboardReport.KeyCode[0] >= 0x04) && (KeyboardReport.KeyCode[0] <= 0x1D))
- PressedKey = (KeyboardReport.KeyCode[0] - 0x04) + 'A';
- else if ((KeyboardReport.KeyCode[0] >= 0x1E) && (KeyboardReport.KeyCode[0] <= 0x27))
- PressedKey = (KeyboardReport.KeyCode[0] - 0x1E) + '0';
- else if (KeyboardReport.KeyCode[0] == 0x2C)
- PressedKey = ' ';
- else if (KeyboardReport.KeyCode[0] == 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';
+ }
/* Print the pressed key character out through the serial port if valid */
if (PressedKey)
diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
index 3cd0f4407..064407a62 100644
--- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
@@ -278,15 +278,24 @@ void ProcessKeyboardReport(uint8_t* KeyboardReport)
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';
+ /* Retrieve pressed key character if alphanumeric */
+ 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';
+ }
/* Print the pressed key character out through the serial port if valid */
if (PressedKey)