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

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Oct 10 21:36:55 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>
---
v3:
	no change
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 d178af248a..7510a210be 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -75,15 +75,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!
@@ -214,10 +205,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];
@@ -245,19 +232,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.23.0



More information about the U-Boot mailing list