diff --git a/Production/firmware/mai_pico.uf2 b/Production/firmware/mai_pico.uf2 index 3ef5b1b..645a294 100644 Binary files a/Production/firmware/mai_pico.uf2 and b/Production/firmware/mai_pico.uf2 differ diff --git a/firmware/src/button.c b/firmware/src/button.c index bd6d7b9..a2b6168 100644 --- a/firmware/src/button.c +++ b/firmware/src/button.c @@ -42,10 +42,19 @@ void button_init() } } +static inline bool button_pressed(int id) +{ + bool reading = gpio_get(gpio_real[id]); + bool active_level = id < 8 ? mai_cfg->tweak.main_button_active_high : + mai_cfg->tweak.aux_button_active_high; + + return reading == active_level; +} + bool button_is_stuck() { for (int i = 0; i < BUTTON_NUM; i++) { - if (!gpio_get(gpio_real[i])) { + if (button_pressed(i)) { return true; } } @@ -83,7 +92,7 @@ void button_update() uint16_t buttons = 0; for (int i = BUTTON_NUM - 1; i >= 0; i--) { - bool sw_pressed = !gpio_get(gpio_real[i]); + bool sw_pressed = button_pressed(i); if (now >= sw_freeze_time[i]) { if (sw_pressed != sw_val[i]) { diff --git a/firmware/src/commands.c b/firmware/src/commands.c index f076e3d..e00464d 100644 --- a/firmware/src/commands.c +++ b/firmware/src/commands.c @@ -61,7 +61,7 @@ static void disp_hid() { printf("[HID]\n"); const char *nkro[] = {"off", "key1", "key2"}; - printf(" Joy: %s, NKRO: %s\n", mai_cfg->hid.joy ? "on" : "off", + printf(" Joy: %s, NKRO: %s\n", mai_cfg->hid.joy ? "ON" : "OFF", mai_cfg->hid.nkro <= 2 ? nkro[mai_cfg->hid.nkro] : "key1"); if (mai_runtime.key_stuck) { printf(" !!! Button stuck, force JOY only !!!\n"); @@ -71,9 +71,9 @@ static void disp_hid() static void disp_aime() { printf("[AIME]\n"); - printf(" NFC Module: %s\n", nfc_module_name()); - printf(" Virtual AIC: %s\n", mai_cfg->aime.virtual_aic ? "ON" : "OFF"); - printf(" Mode: %d\n", mai_cfg->aime.mode); + printf(" NFC Module: %s\n", nfc_module_name()); + printf(" Virtual AIC: %s\n", mai_cfg->aime.virtual_aic ? "ON" : "OFF"); + printf(" Protocol Mode: %d\n", mai_cfg->aime.mode); } static void disp_gpio() @@ -102,48 +102,57 @@ static void disp_touch() } } +static void disp_tweak() +{ + printf("[Tweak]\n"); + printf(" Main Buttons Active-High: %s\n", + mai_cfg->tweak.main_button_active_high ? "ON" : "OFF"); + printf(" Aux Buttons Active-High: %s\n", + mai_cfg->tweak.aux_button_active_high ? "ON" : "OFF"); +} + +#define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0])) + void handle_display(int argc, char *argv[]) { - const char *usage = "Usage: display [rgb|sense|hid|gpio|aime]\n"; + const char *usage = "Usage: display [rgb|sense|hid|gpio|touch|aime|tweak]\n"; if (argc > 1) { printf(usage); return; } + const char *choices[] = {"rgb", "sense", "hid", "gpio", "touch", "aime", "tweak"}; + static void (*disp_funcs[])() = { + disp_rgb, + disp_sense, + disp_hid, + disp_gpio, + disp_touch, + disp_aime, + disp_tweak, + }; + + static_assert(ARRAYSIZE(choices) == ARRAYSIZE(disp_funcs), + "Choices and disp_funcs arrays must have the same number of elements"); + if (argc == 0) { - disp_rgb(); - disp_sense(); - disp_hid(); - disp_gpio(); - disp_touch(); - disp_aime(); + for (int i = 0; i < ARRAYSIZE(disp_funcs); i++) { + disp_funcs[i](); + } return; } - const char *choices[] = {"rgb", "sense", "hid", "gpio", "touch", "aime"}; - switch (cli_match_prefix(choices, 6, argv[0])) { - case 0: - disp_rgb(); - break; - case 1: - disp_sense(); - break; - case 2: - disp_hid(); - break; - case 3: - disp_gpio(); - break; - case 4: - disp_touch(); - break; - case 5: - disp_aime(); - break; - default: - printf(usage); - break; + int choice = cli_match_prefix(choices, ARRAYSIZE(choices), argv[0]); + if (choice < 0) { + printf(usage); + return; } + + if (choice > ARRAYSIZE(disp_funcs)) { + return; + } + + disp_funcs[choice](); } static void handle_rgb(int argc, char *argv[]) @@ -593,6 +602,42 @@ static void handle_aime(int argc, char *argv[]) } } +static void handle_tweak(int argc, char *argv[]) +{ + const char *usage = "Usage: tweak