From 885b246ca91592ba48637a8519dd4fbd576ad38a Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Apr 2021 23:48:58 +1000 Subject: [PATCH] stm32/boardctrl: Show first reset-mode state on LEDs when selecting. Commit 1e297c88989592258965b69cb740039e26c7636c introduced a bug where the very first reset-mode state on the LEDs was not shown, because prior to that commit the first reset-mode state was the same as the initial LED state (green on, others off) and update_reset_mode() was called after setting this initial LED state. This is fixed in this commit by changing the update_reset_mode() loop so that it displays the current reset mode before doing the delay. Signed-off-by: Damien George --- ports/stm32/boardctrl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ports/stm32/boardctrl.c b/ports/stm32/boardctrl.c index ce04914ea9..8cc519d8e9 100644 --- a/ports/stm32/boardctrl.c +++ b/ports/stm32/boardctrl.c @@ -51,20 +51,21 @@ STATIC uint update_reset_mode(uint reset_mode) { // The original method used on the pyboard is appropriate if you have 2 // or more LEDs. #if defined(MICROPY_HW_LED2) - for (uint i = 0; i < 3000; i++) { - if (!switch_get()) { - break; - } - mp_hal_delay_ms(20); - if (i % 30 == 29) { - if (++reset_mode > BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM) { - reset_mode = BOARDCTRL_RESET_MODE_NORMAL; + for (uint i = 0; i < 100; i++) { + led_state(2, reset_mode & 1); + led_state(3, reset_mode & 2); + led_state(4, reset_mode & 4); + for (uint j = 0; j < 30; ++j) { + mp_hal_delay_ms(20); + if (!switch_get()) { + goto select_mode; } - led_state(2, reset_mode & 1); - led_state(3, reset_mode & 2); - led_state(4, reset_mode & 4); + } + if (++reset_mode > BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM) { + reset_mode = BOARDCTRL_RESET_MODE_NORMAL; } } + select_mode: // flash the selected reset mode for (uint i = 0; i < 6; i++) { led_state(2, 0);