From 47e3489141ada6aaede7ee5884c6481507fa87b1 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 9 Feb 2025 12:47:19 -0500 Subject: [PATCH] fix cold bootup keyboard issue on the f256k KBD_OPTICAL (0xf01dc0) is only "valid" on F256K2 hardware. i would assume that this value is unknown on non-F256K2 hardware, thus sometimes you might read some garbage value from here perhaps? what i observed on my f256k was that always on cold bootup (that is, booting from flash) the keyboard would never work. hitting reset or booting from a ram build would not exhibit the same problem. sometimes (somewhat more rarely) kbd_init() would lock up at some point, presumably when it was trying to initialize/scan the non-existent optical keyboard. so far this also *seems* to resolve intermittent issues with reads to the SD card on my f256k locking up. best not to read from those new F256K2 registers on non-K2 devices! --- src/dev/kbd_f256k.c | 10 ++++++++++ src/include/features.h | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/dev/kbd_f256k.c b/src/dev/kbd_f256k.c index 7547439..e4ad17a 100644 --- a/src/dev/kbd_f256k.c +++ b/src/dev/kbd_f256k.c @@ -14,6 +14,7 @@ #include #include +#include "features.h" #include "interrupt.h" #include "log.h" #include "ring_buffer.h" @@ -330,11 +331,20 @@ bool kbd_break() { * */ short kbd_sc_init() { + // NOTE: Reading from the new optical keyboard IO registers on non-F256K2 + // devices causes odd and sometimes intermittent issues not limited to + // the keyboard not working at all right after a cold bootup from flash. + // Possibly this can be addressed with future FPGA updates for + // non-F256K2 devices, but for now we want to avoid this situation. +#if HAS_OPTICAL_KBD_SUPPORT if (KBD_OPTICAL->status & KBD_OPT_STAT_MECH) { is_optical = false; } else { is_optical = true; } +#else + is_optical = false; +#endif // Initialize VIA0 -- we'll just read from PB7 via0->ddra = 0x00; diff --git a/src/include/features.h b/src/include/features.h index ee92b5e..630e2f5 100644 --- a/src/include/features.h +++ b/src/include/features.h @@ -46,6 +46,10 @@ #define HAS_IEC 1 #endif +#if MODEL == MODEL_FOENIX_F256K2 || MODEL == MODEL_FOENIX_F256K2E + #define HAS_OPTICAL_KBD_SUPPORT 1 +#endif + /* Defaults -----------------------------------------------------------------*/ @@ -93,4 +97,8 @@ #define HAS_IEC 0 #endif -#endif \ No newline at end of file +#ifndef HAS_OPTICAL_KBD_SUPPORT + #define HAS_OPTICAL_KBD_SUPPORT 0 +#endif + +#endif