Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A5BAC433FE for ; Mon, 17 Oct 2022 20:34:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 04C0C84F96; Mon, 17 Oct 2022 22:31:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MG9NW0P9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3FA3D84F7D; Mon, 17 Oct 2022 22:31:05 +0200 (CEST) Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D3A3A84F41 for ; Mon, 17 Oct 2022 22:30:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x136.google.com with SMTP id l3so6046361ilg.13 for ; Mon, 17 Oct 2022 13:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zueRjmCVSCGgVBGmfQ9G5VIqh5hT5YEIjKcJq5HeH2k=; b=MG9NW0P9lSRGyF9b9h/X2yQuLZHwoofvnOn7sPZQu/If1m9paEDs+7GizZ3QtkmDq2 5TWLHw21PuxlgNrph4VvQx8mwp0moUsrp8avY29abGc7vFjrTJzBFbtNr24S9uPzTNSK k9RwvNGAjVvcB89DrWobPXmt85ivB3ua51VXI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zueRjmCVSCGgVBGmfQ9G5VIqh5hT5YEIjKcJq5HeH2k=; b=v/VOUphWv/hnjYRp2zRPvvh1LU9qIL9hzsfvftw1A9zqixRgS90d6guUh+lpTM6FjC VCx/DAghFTu/BpthkSPvF8TD7qd1LiovxMVJCuf00F2Gghpp8SujcMVvkNkXq/V36ShM uIiFT7Qoij9FcytII4IvriM4/MWi4b7OyWFgdeGIDvgBnXjaw0s0WqAaQAqMUdxgxCjL SvFrva0qtZUCHgk61ENiYdhBtX9ib21UtEdfQaKgJ5uYJ6Uq0fpGvNcGOZ4t/8FV7VeC +0oQS/P7RF711d5+cEeF/ZnSC09dEUi/79dXNbFdQAOxEpWI7JWlEn2ncfmGSyib3EiZ hjYw== X-Gm-Message-State: ACrzQf1QD7vxg4B3O2Hriu2x/QiUwZdIEqkWKW454dpgGjgqjTMB/FA/ NyJ67HVdFgpsvl8GHOdHJ/A4+DaKfjUy7Q== X-Google-Smtp-Source: AMsMyM4XqHL5IK6kdQiQ65mDD3lcJZ7unUFYkjrWQ2bvtXgIBz0ZF1mg2sdjebC8jH+MS23/3hAWXg== X-Received: by 2002:a05:6e02:178a:b0:2fa:825f:6df8 with SMTP id y10-20020a056e02178a00b002fa825f6df8mr5386060ilu.157.1666038630058; Mon, 17 Oct 2022 13:30:30 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:91e:7804:2764:d161]) by smtp.gmail.com with ESMTPSA id j9-20020a926e09000000b002e939413e83sm258071ilc.48.2022.10.17.13.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 13:30:29 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Anatolij Gustschin , Tom Rini , Simon Glass , Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 16/24] menu: Factor out menu-keypress decoding Date: Mon, 17 Oct 2022 14:29:52 -0600 Message-Id: <20221017203000.2207887-17-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221017203000.2207887-1-sjg@chromium.org> References: <20221017203000.2207887-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Move this code into a separate function so that it can be used in the new VBE menu. Signed-off-by: Simon Glass --- 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) { - 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__ */ -- 2.38.0.413.g74048e4d9e-goog