From 7f62e15f559bde36f5dd9088647b5a8b25733ddd Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 15 Jun 2025 18:36:30 +0800 Subject: [PATCH] sd_boot: move readboot logic to bootloader. --- .../pico_multi_booter/sd_boot/i2ckbd/i2ckbd.c | 22 ------------------- .../pico_multi_booter/sd_boot/i2ckbd/i2ckbd.h | 1 - Code/pico_multi_booter/sd_boot/main.c | 21 ++++++++++++++++++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.c b/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.c index f90c3b5..1b32456 100644 --- a/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.c +++ b/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.c @@ -83,25 +83,3 @@ int read_battery() { } return -1; } - -int read_bootmode() { - int retval; - unsigned char msg[2]; - msg[0] = 0x0e; // REG_ID_BOOT - - if (i2c_inited == 0) return -1; - - retval = i2c_write_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, msg, 1, false, 500000); - if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) { - DEBUG_PRINT("Boot I2C write err\n"); - return -1; - } - sleep_ms(16); - retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) msg, 2, false, 500000); - if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT || msg[0] != 0x0e) { - DEBUG_PRINT("Boot I2C read err\n"); - return -1; - } - - return msg[1]; -} diff --git a/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.h b/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.h index dabb8d5..479608c 100644 --- a/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.h +++ b/Code/pico_multi_booter/sd_boot/i2ckbd/i2ckbd.h @@ -16,7 +16,6 @@ void init_i2c_kbd(); int read_i2c_kbd(); int read_battery(); -int read_bootmode(); #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitClear(value, bit) ((value) &= ~(1 << (bit))) diff --git a/Code/pico_multi_booter/sd_boot/main.c b/Code/pico_multi_booter/sd_boot/main.c index 445bb73..20f0d5c 100644 --- a/Code/pico_multi_booter/sd_boot/main.c +++ b/Code/pico_multi_booter/sd_boot/main.c @@ -314,6 +314,27 @@ void final_selection_callback(const char *path) load_firmware_by_path(path); } +int read_bootmode() +{ + int key = keypad_get_key(); + int _x; + DEBUG_PRINT("read_bootmode key = %d\n", key); + while((_x = keypad_get_key()) > 0) { + // drain the keypad input buffer + DEBUG_PRINT("read_bootmode subsequent key = %d\n", _x); + } + int bootmode = 0; // Default boot mode + if (key == KEY_ARROW_UP) + { + bootmode = 1; // SD card boot mode + } + else if (key == KEY_ARROW_DOWN) + { + bootmode = 2; // Firmware update mode + } + return bootmode; +} + int main() { uint32_t cur_time,last_time=0;