[PATCH 16/24] menu: Factor out menu-keypress decoding

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Oct 18 00:18:02 CEST 2022


On 10/17/22 22:29, Simon Glass wrote:
> Move this code into a separate function so that it can be used in the new
> VBE menu.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>   common/menu.c  | 48 ++++++++++++++++++++++++++++++------------------
>   include/menu.h | 10 ++++++++++
>   2 files changed, 40 insertions(+), 18 deletions(-)
>
> diff --git a/common/menu.c b/common/menu.c
> index c2e3ec592e3..4606cb7d1b1 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -483,26 +483,11 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
>   	return key;
>   }
>
> -enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
> -				struct cli_ch_state *cch)
> +enum bootmenu_key bootmenu_conv_key(int ichar)
>   {

Please, extract a common library function from
efi_cin_read_key_stroke_ex(). We should avoid code duplication.

Best regards

Heinrich

> -	enum bootmenu_key key = BKEY_NONE;
> -	int c;
> -
> -	c = cli_ch_process(cch, 0);
> -	if (!c) {
> -		while (!c && !tstc()) {
> -			WATCHDOG_RESET();
> -			mdelay(10);
> -			c = cli_ch_process(cch, -ETIMEDOUT);
> -		}
> -		if (!c) {
> -			c = getchar();
> -			c = cli_ch_process(cch, c);
> -		}
> -	}
> +	enum bootmenu_key key;
>
> -	switch (c) {
> +	switch (ichar) {
>   	case '\n':
>   		/* enter key was pressed */
>   		key = BKEY_SELECT;
> @@ -527,7 +512,34 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
>   	case ' ':
>   		key = BKEY_SPACE;
>   		break;
> +	default:
> +		key = BKEY_NONE;
> +		break;
> +	}
> +
> +	return key;
> +}
> +
> +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
> +				struct cli_ch_state *cch)
> +{
> +	enum bootmenu_key key;
> +	int c;
> +
> +	c = cli_ch_process(cch, 0);
> +	if (!c) {
> +		while (!c && !tstc()) {
> +			WATCHDOG_RESET();
> +			mdelay(10);
> +			c = cli_ch_process(cch, -ETIMEDOUT);
> +		}
> +		if (!c) {
> +			c = getchar();
> +			c = cli_ch_process(cch, c);
> +		}
>   	}
>
> +	key = bootmenu_conv_key(c);
> +
>   	return key;
>   }
> diff --git a/include/menu.h b/include/menu.h
> index 3996075a337..1e88141d6bf 100644
> --- a/include/menu.h
> +++ b/include/menu.h
> @@ -53,6 +53,8 @@ enum bootmenu_key {
>   	BKEY_PLUS,
>   	BKEY_MINUS,
>   	BKEY_SPACE,
> +
> +	BKEY_COUNT,
>   };
>
>   /**
> @@ -101,4 +103,12 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
>   enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
>   				struct cli_ch_state *cch);
>
> +/**
> + * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
> + *
> + * @ichar: Keypress to convert (ASCII, including control characters)
> + * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
> + */
> +enum bootmenu_key bootmenu_conv_key(int ichar);
> +
>   #endif /* __MENU_H__ */



More information about the U-Boot mailing list