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!
This commit is contained in:
Gered 2025-02-09 12:47:19 -05:00
parent e16eaca30c
commit 47e3489141
2 changed files with 19 additions and 1 deletions

View file

@ -14,6 +14,7 @@
#include <stdint.h>
#include <stdio.h>
#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;

View file

@ -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
#ifndef HAS_OPTICAL_KBD_SUPPORT
#define HAS_OPTICAL_KBD_SUPPORT 0
#endif
#endif