All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] usb: kbd: allow multibyte sequences to be put into ring buffer
Date: Thu, 22 Feb 2018 15:20:57 +0100	[thread overview]
Message-ID: <bba258fd-fd39-0ac6-611d-7b5f4317f5df@denx.de> (raw)
In-Reply-To: <20180222120418.12832-2-xypron.glpk@gmx.de>

On 02/22/2018 01:04 PM, Heinrich Schuchardt wrote:
> The USB keyboard driver provides a ring buffer for key strokes.
> 
> Function keys cannot be encoded as single bytes. Instead xterm control
> sequences have to be put into the ring buffer.

Does it work without xterm or with any other terminal ?

> This preparatory patch changes function usb_kbd_put_queue() to allow adding
> multiple characters at once. If the buffer cannot accommodate the whole
> sequence, it is rejected completely.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  common/usb_kbd.c | 42 +++++++++++++++++++++++++-----------------
>  1 file changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/common/usb_kbd.c b/common/usb_kbd.c
> index 8cbdba6ac2..706cc350a6 100644
> --- a/common/usb_kbd.c
> +++ b/common/usb_kbd.c
> @@ -125,24 +125,32 @@ extern int __maybe_unused net_busy_flag;
>  /* The period of time between two calls of usb_kbd_testc(). */
>  static unsigned long __maybe_unused kbd_testc_tms;
>  
> -/* Puts character in the queue and sets up the in and out pointer. */
> -static void usb_kbd_put_queue(struct usb_kbd_pdata *data, char c)
> +/*
> + * Put characters into ring buffer.
> + *
> + * @data:	private data
> + * @buf		buffer with data to be queued
> + * @count:	number of characters to be queued
> + */
> +static void usb_kbd_put_queue(struct usb_kbd_pdata *data,
> +			      uint8_t *buf, int count)
>  {
> -	if (data->usb_in_pointer == USB_KBD_BUFFER_LEN - 1) {
> -		/* Check for buffer full. */
> -		if (data->usb_out_pointer == 0)
> -			return;
> -
> -		data->usb_in_pointer = 0;
> -	} else {
> -		/* Check for buffer full. */
> -		if (data->usb_in_pointer == data->usb_out_pointer - 1)
> -			return;
> -
> -		data->usb_in_pointer++;
> +	int i, used;
> +
> +	/* Check if buffer holds at least 'count' free slots */
> +	used = data->usb_in_pointer - data->usb_out_pointer;
> +	if (used < 0)
> +		used += USB_KBD_BUFFER_LEN;
> +	if (used + count >= USB_KBD_BUFFER_LEN)
> +		return;
> +
> +	/* Copy to buffer */
> +	for (i = 0; i < count; ++i) {
> +		++data->usb_in_pointer;
> +		if (data->usb_in_pointer == USB_KBD_BUFFER_LEN)
> +			data->usb_in_pointer = 0;
> +		data->usb_kbd_buffer[data->usb_in_pointer] = buf[i];

memcpy() ?

>  	}
> -
> -	data->usb_kbd_buffer[data->usb_in_pointer] = c;
>  }
>  
>  /*
> @@ -237,7 +245,7 @@ static int usb_kbd_translate(struct usb_kbd_pdata *data, unsigned char scancode,
>  	/* Report keycode if any */
>  	if (keycode) {
>  		debug("%c", keycode);
> -		usb_kbd_put_queue(data, keycode);
> +		usb_kbd_put_queue(data, &keycode, 1);
>  	}
>  
>  	return 0;
> 


-- 
Best regards,
Marek Vasut

  reply	other threads:[~2018-02-22 14:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 12:04 [U-Boot] [PATCH 0/2] usb: kbd: implement special keys Heinrich Schuchardt
2018-02-22 12:04 ` [U-Boot] [PATCH 1/2] usb: kbd: allow multibyte sequences to be put into ring buffer Heinrich Schuchardt
2018-02-22 14:20   ` Marek Vasut [this message]
2018-02-22 18:06     ` Heinrich Schuchardt
2018-02-22 19:55       ` Marek Vasut
2018-02-22 20:53         ` Heinrich Schuchardt
2018-02-22 23:02           ` Marek Vasut
2018-02-23  5:50             ` Heinrich Schuchardt
2018-02-23  6:04               ` Marek Vasut
2018-02-23  7:09                 ` Heinrich Schuchardt
2018-02-22 12:04 ` [U-Boot] [PATCH 2/2] usb: kbd: implement special keys Heinrich Schuchardt
2018-02-23 20:59   ` Simon Glass
2018-02-24 11:46     ` Heinrich Schuchardt
2018-03-08 22:04       ` Heinrich Schuchardt
2018-03-19 17:59         ` Simon Glass
2018-03-20  0:12           ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bba258fd-fd39-0ac6-611d-7b5f4317f5df@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.