diff mbox series

[U-Boot,1/2] usb: kbd: simplify coding for arrow keys

Message ID 20190616214339.26535-2-xypron.glpk@gmx.de
State Superseded, archived
Delegated to: Marek Vasut
Headers show
Series usb: kbd: implement special keys | expand

Commit Message

Heinrich Schuchardt June 16, 2019, 9:43 p.m. UTC
Avoid duplicate translation of arrow key codes.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 common/usb_kbd.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

--
2.20.1

Comments

Simon Glass June 24, 2019, 1:56 p.m. UTC | #1
On Sun, 16 Jun 2019 at 22:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Avoid duplicate translation of arrow key codes.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  common/usb_kbd.c | 31 +++++++++----------------------
>  1 file changed, 9 insertions(+), 22 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

We should really have a test for this input stuff...
Heinrich Schuchardt June 24, 2019, 5:36 p.m. UTC | #2
On 6/24/19 3:56 PM, Simon Glass wrote:
> On Sun, 16 Jun 2019 at 22:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> Avoid duplicate translation of arrow key codes.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>>   common/usb_kbd.c | 31 +++++++++----------------------
>>   1 file changed, 9 insertions(+), 22 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> We should really have a test for this input stuff...
>

We already have.

For low level analysis:

=> conitrace
Waiting for your input
To terminate type 'x'
61
1b 5b 32 30 7e

For a higher level view:

=> setenv efi_selftest extended text input
=> bootefi selftest
Executing 'extended text input'
Waiting for your input
To terminate type 'CTRL+x'
Unicode char 100 ('d'), scan code 0 (Null)
Unicode char 0 (Null), scan code 19 (+FN 9)
Unicode char 0 (Null), scan code 19 (SHIFT+FN 9)

Regards

Heinrich
Simon Glass June 24, 2019, 6:49 p.m. UTC | #3
Hi Heinrich,

On Mon, 24 Jun 2019 at 11:36, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 6/24/19 3:56 PM, Simon Glass wrote:
> > On Sun, 16 Jun 2019 at 22:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>
> >> Avoid duplicate translation of arrow key codes.
> >>
> >> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> >> ---
> >>   common/usb_kbd.c | 31 +++++++++----------------------
> >>   1 file changed, 9 insertions(+), 22 deletions(-)
> >
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> >
> > We should really have a test for this input stuff...
> >
>
> We already have.
>
> For low level analysis:
>
> => conitrace
> Waiting for your input
> To terminate type 'x'
> 61
> 1b 5b 32 30 7e
>
> For a higher level view:
>
> => setenv efi_selftest extended text input
> => bootefi selftest
> Executing 'extended text input'
> Waiting for your input
> To terminate type 'CTRL+x'
> Unicode char 100 ('d'), scan code 0 (Null)
> Unicode char 0 (Null), scan code 19 (+FN 9)
> Unicode char 0 (Null), scan code 19 (SHIFT+FN 9)

I mean automated test :-)

Regards,
Simon
Heinrich Schuchardt Aug. 9, 2019, 9:36 p.m. UTC | #4
On 6/24/19 8:49 PM, Simon Glass wrote:
> Hi Heinrich,
>
> On Mon, 24 Jun 2019 at 11:36, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 6/24/19 3:56 PM, Simon Glass wrote:
>>> On Sun, 16 Jun 2019 at 22:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>>>
>>>> Avoid duplicate translation of arrow key codes.
>>>>
>>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>>> ---
>>>>    common/usb_kbd.c | 31 +++++++++----------------------
>>>>    1 file changed, 9 insertions(+), 22 deletions(-)
>>>
>>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>>
>>> We should really have a test for this input stuff...
>>>
>>
>> We already have.
>>
>> For low level analysis:
>>
>> => conitrace
>> Waiting for your input
>> To terminate type 'x'
>> 61
>> 1b 5b 32 30 7e
>>
>> For a higher level view:
>>
>> => setenv efi_selftest extended text input
>> => bootefi selftest
>> Executing 'extended text input'
>> Waiting for your input
>> To terminate type 'CTRL+x'
>> Unicode char 100 ('d'), scan code 0 (Null)
>> Unicode char 0 (Null), scan code 19 (+FN 9)
>> Unicode char 0 (Null), scan code 19 (SHIFT+FN 9)
>
> I mean automated test :-)
>
> Regards,
> Simon

Hello Simon,

drivers/usb/emul/sandbox_keyb.c seems to bypass the driver in
common/usb_keyb.c instead of emulating a USB keyboard.

Shouldn't it pass keyboard scan codes to common/usb_keyb.c?

Would you know how to get this fixed? Then I can add the additional
keyboard scan codes.

Best regards

Heinrich
Simon Glass Aug. 13, 2019, 9:34 a.m. UTC | #5
Hi Heinrich,

On Fri, 9 Aug 2019 at 15:36, Heinrich Schuchardt <xypron.debian@gmx.de> wrote:
>
> On 6/24/19 8:49 PM, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Mon, 24 Jun 2019 at 11:36, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>
> >> On 6/24/19 3:56 PM, Simon Glass wrote:
> >>> On Sun, 16 Jun 2019 at 22:44, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>>>
> >>>> Avoid duplicate translation of arrow key codes.
> >>>>
> >>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> >>>> ---
> >>>>    common/usb_kbd.c | 31 +++++++++----------------------
> >>>>    1 file changed, 9 insertions(+), 22 deletions(-)
> >>>
> >>> Reviewed-by: Simon Glass <sjg@chromium.org>
> >>>
> >>> We should really have a test for this input stuff...
> >>>
> >>
> >> We already have.
> >>
> >> For low level analysis:
> >>
> >> => conitrace
> >> Waiting for your input
> >> To terminate type 'x'
> >> 61
> >> 1b 5b 32 30 7e
> >>
> >> For a higher level view:
> >>
> >> => setenv efi_selftest extended text input
> >> => bootefi selftest
> >> Executing 'extended text input'
> >> Waiting for your input
> >> To terminate type 'CTRL+x'
> >> Unicode char 100 ('d'), scan code 0 (Null)
> >> Unicode char 0 (Null), scan code 19 (+FN 9)
> >> Unicode char 0 (Null), scan code 19 (SHIFT+FN 9)
> >
> > I mean automated test :-)
> >
> > Regards,
> > Simon
>
> Hello Simon,
>
> drivers/usb/emul/sandbox_keyb.c seems to bypass the driver in
> common/usb_keyb.c instead of emulating a USB keyboard.
>
> Shouldn't it pass keyboard scan codes to common/usb_keyb.c?
>
> Would you know how to get this fixed? Then I can add the additional
> keyboard scan codes.

Well it looks like you have figured this out.

Regards,
Simon
diff mbox series

Patch

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;