picocalc_keyboard: add bootmode register

This commit is contained in:
Yatao Li 2025-06-15 02:50:35 +08:00
parent 44615ce5d2
commit a690686270
5 changed files with 30 additions and 0 deletions

View File

@ -58,6 +58,10 @@ enum key_state
#define KEY_F9 0x89
#define KEY_F10 0x90
#define BOOTMODE_DEFAULT 0x00 // normal boot mode
#define BOOTMODE_SDCARD 0x01 // sdcard multiboot: loads .bin to FLASH+200K
#define BOOTMODE_FWUPDATE 0x02 // enter BOOTSEL to upload .uf2 firmware
typedef void (*key_callback)(char, enum key_state);
typedef void (*lock_callback)(bool, bool);
@ -66,6 +70,7 @@ void keyboard_set_key_callback(key_callback callback);
void keyboard_set_lock_callback(lock_callback callback);
bool keyboard_get_capslock(void);
bool keyboard_get_numlock(void);
uint8_t keyboard_get_bootmode(void);
void keyboard_init(void);
#define NUM_OF_COLS 8

View File

@ -78,6 +78,8 @@ static struct {
bool numlock_changed;
bool numlock;
uint8_t bootmode;
} self;
void output_string(char*str){
@ -423,6 +425,11 @@ bool keyboard_get_numlock(void)
return self.numlock;
}
uint8_t keyboard_get_bootmode(void)
{
return self.bootmode;
}
void keyboard_init(void)
{
struct port_config port_init;
@ -431,6 +438,8 @@ void keyboard_init(void)
for (int i = 0; i < MOD_LAST; ++i)
self.mods[i] = false;
self.bootmode = BOOTMODE_DEFAULT;
// Rows
port_init.direction = PORT_PIN_DIR_INPUT;
port_init.input_pull = PORT_PIN_PULL_UP;
@ -449,5 +458,13 @@ void keyboard_init(void)
port_init.input_pull = PORT_PIN_PULL_UP;
for(uint32_t i = 0; i < NUM_OF_BTNS; ++i)
port_pin_set_config(btn_pins[i], &port_init);
//B12=left,B11=down [FWUPDATE],B10=up [SDCARD-MULTIBOOT],B9=right
if (port_pin_get_input_level(btn_pins[10]) == 0) {
self.bootmode = BOOTMODE_FWUPDATE;
}
if (port_pin_get_input_level(btn_pins[9]) == 0) {
self.bootmode = BOOTMODE_SDCARD;
}
#endif
}

View File

@ -168,6 +168,11 @@ void receiveEvent(int howMany) {
write_buffer[1] = js_bits;
write_buffer_len = 2;
}break;
case REG_ID_BOOT:{
write_buffer[0] = reg;
write_buffer[1] = keyboard_get_bootmode();
write_buffer_len = 2;
}break;
default: {
write_buffer[0] = 0;
write_buffer[1] = 0;

View File

@ -19,6 +19,7 @@ enum reg_id
REG_ID_BAT = 0x0b,// battery
REG_ID_C64_MTX = 0x0c,// read c64 matrix
REG_ID_C64_JS = 0x0d, // joystick io bits
REG_ID_BOOT = 0x0e, // boot mode (see keyboard.h)
REG_ID_LAST,
};

View File

@ -1,4 +1,5 @@
#include "reg.h"
#include "keyboard.h"
static uint8_t regs[REG_ID_LAST];
@ -42,4 +43,5 @@ void reg_init(void)
regs[REG_ID_BKL] = 255;//100%duty
regs[REG_ID_BK2] = 0;
regs[REG_ID_BAT] = 0; //default .no battery ,no charging
regs[REG_ID_BOOT] = BOOTMODE_DEFAULT;
}