[U-Boot] [PATCH v2 1/5] usb: kbd: simplify coding for arrow keys

Heinrich Schuchardt xypron.glpk at gmx.de
Sat Aug 10 09:24:15 UTC 2019


Avoid duplicate translation of arrow key codes.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
v2
	no change
---
 common/usb_kbd.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index cc99c6be07..232d278e13 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -74,15 +74,6 @@ static const unsigned char usb_kbd_num_keypad[] = {
 	'.', 0, 0, 0, '='
 };

-/*
- * map arrow keys to ^F/^B ^N/^P, can't really use the proper
- * ANSI sequence for arrow keys because the queuing code breaks
- * when a single keypress expands to 3 queue elements
- */
-static const unsigned char usb_kbd_arrow[] = {
-	0x6, 0x2, 0xe, 0x10
-};
-
 /*
  * NOTE: It's important for the NUM, CAPS, SCROLL-lock bits to be in this
  *       order. See usb_kbd_setled() function!
@@ -213,10 +204,6 @@ static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode,
 			keycode = usb_kbd_numkey[scancode - 0x1e];
 	}

-	/* Arrow keys */
-	if ((scancode >= 0x4f) && (scancode <= 0x52))
-		keycode = usb_kbd_arrow[scancode - 0x4f];
-
 	/* Numeric keypad */
 	if ((scancode >= 0x54) && (scancode <= 0x67))
 		keycode = usb_kbd_num_keypad[scancode - 0x54];
@@ -244,19 +231,19 @@ static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode,
 	if (keycode)
 		debug("%c", keycode);

-	switch (keycode) {
-	case 0x0e:					/* Down arrow key */
-		usb_kbd_put_sequence(data, "\e[B");
-		break;
-	case 0x10:					/* Up arrow key */
-		usb_kbd_put_sequence(data, "\e[A");
-		break;
-	case 0x06:					/* Right arrow key */
+	switch (scancode) {
+	case 0x4f:					/* Right arrow key */
 		usb_kbd_put_sequence(data, "\e[C");
 		break;
-	case 0x02:					/* Left arrow key */
+	case 0x50:					/* Left arrow key */
 		usb_kbd_put_sequence(data, "\e[D");
 		break;
+	case 0x51:					/* Down arrow key */
+		usb_kbd_put_sequence(data, "\e[B");
+		break;
+	case 0x52:					/* Up arrow key */
+		usb_kbd_put_sequence(data, "\e[A");
+		break;
 	default:
 		usb_kbd_put_queue(data, keycode);
 		break;
--
2.20.1



More information about the U-Boot mailing list