diff options
Diffstat (limited to 'Demos/Host')
4 files changed, 75 insertions, 37 deletions
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) |