From 644a13c73038335162125a39ffe2882823bdc217 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 17 Apr 2022 22:46:17 +0100 Subject: [PATCH] Add usbdebug command line option and conditionally pause at end of USB scan. If the usbdebug option is present, pause at the end of the USB scan until a key is pressed. Otherwise, if the keyboard=usb option is present and no USB keyboards were discovered, pause for 10 seconds. Otherwise don't pause. --- app/config.c | 2 ++ app/main.c | 2 +- system/keyboard.c | 6 +++--- system/keyboard.h | 2 +- system/usbhcd.c | 12 ++++++++++-- system/usbhcd.h | 5 +++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/config.c b/app/config.c index 5547be4..0c6b430 100644 --- a/app/config.c +++ b/app/config.c @@ -191,6 +191,8 @@ static void parse_option(const char *option, const char *params) smp_enabled = true; } else if (strncmp(option, "trace", 6) == 0) { enable_trace = true; + } else if (strncmp(option, "usbdebug", 9) == 0) { + usb_init_options |= USB_DEBUG; } else if (strncmp(option, "nosm", 5) == 0) { enable_sm = false; } diff --git a/app/main.c b/app/main.c index f7619dd..de8f57a 100644 --- a/app/main.c +++ b/app/main.c @@ -219,7 +219,7 @@ static void global_init(void) config_init(); - keyboard_init(pause_at_start); + keyboard_init(); display_init(); diff --git a/system/keyboard.c b/system/keyboard.c index 0d82085..513b42d 100644 --- a/system/keyboard.c +++ b/system/keyboard.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -// Copyright (C) 2020-2021 Martin Whitaker. +// Copyright (C) 2020-2022 Martin Whitaker. #include @@ -218,10 +218,10 @@ keyboard_types_t keyboard_types = KT_LEGACY | KT_USB; // Public Functions //------------------------------------------------------------------------------ -void keyboard_init(bool pause_at_end) +void keyboard_init(void) { if (keyboard_types & KT_USB) { - find_usb_keyboards(pause_at_end); + find_usb_keyboards(keyboard_types == KT_USB); } } diff --git a/system/keyboard.h b/system/keyboard.h index 049336a..068cc85 100644 --- a/system/keyboard.h +++ b/system/keyboard.h @@ -35,7 +35,7 @@ extern keyboard_types_t keyboard_types; /** * Initialises the keyboard interface. */ -void keyboard_init(bool pause_at_end); +void keyboard_init(void); /** * Checks if a key has been pressed and returns the primary ASCII character diff --git a/system/usbhcd.c b/system/usbhcd.c index 2ecc774..50e50d0 100644 --- a/system/usbhcd.c +++ b/system/usbhcd.c @@ -24,6 +24,8 @@ #define MAX_USB_CONTROLLERS 8 // an arbitrary limit - must match the initialisation of usb_controllers +#define PAUSE_IF_NONE_TIME 10 // seconds + #define MILLISEC 1000 // in microseconds //------------------------------------------------------------------------------ @@ -681,7 +683,7 @@ static void probe_usb_controller(int bus, int dev, int func, hci_type_t controll // Public Functions //------------------------------------------------------------------------------ -void find_usb_keyboards(bool pause_at_end) +void find_usb_keyboards(bool pause_if_none) { clear_screen(); print_usb_info("Scanning for USB keyboards..."); @@ -738,9 +740,15 @@ void find_usb_keyboards(bool pause_at_end) } } - if (pause_at_end) { + if (usb_init_options & USB_DEBUG) { print_usb_info("Press any key to continue..."); while (get_key() == 0) {} + } else if (pause_if_none && num_usb_controllers == 0) { + for (int i = PAUSE_IF_NONE_TIME; i > 0; i--) { + print_usb_info("No USB keyboards found. Continuing in %i second%c ", i, i == 1 ? ' ' : 's'); + sleep(1); + print_row--; // overwrite message + } } } diff --git a/system/usbhcd.h b/system/usbhcd.h index bac4758..cd7441c 100644 --- a/system/usbhcd.h +++ b/system/usbhcd.h @@ -113,7 +113,8 @@ typedef struct usb_hcd_s { typedef enum { USB_DEFAULT_INIT = 0, USB_EXTRA_RESET = 1 << 0, - USB_IGNORE_EHCI = 1 << 1 + USB_IGNORE_EHCI = 1 << 1, + USB_DEBUG = 1 << 2 } usb_init_options_t; /** @@ -266,7 +267,7 @@ bool find_attached_usb_keyboards(const usb_hcd_t *hcd, const usb_hub_t *hub, int * * Used internally by keyboard.c. */ -void find_usb_keyboards(bool pause_at_end); +void find_usb_keyboards(bool pause_if_none); /** * Polls the keyboards discovered by find_usb_keyboards. Consumes and returns