Fix key release change detection in polling mode

This commit is contained in:
Ondrej Jirman 2021-06-18 18:28:56 +02:00
parent 93687e1b04
commit c8d8eef090
1 changed files with 30 additions and 26 deletions

View File

@ -80,6 +80,8 @@ void timer1_interupt(void) __interrupt(IRQ_TIMER1)
TF1 = 0; TF1 = 0;
} }
// {{{ Key scanning
// Keyboard has 12 columns and 6 rows directly connected to GPIOs. // Keyboard has 12 columns and 6 rows directly connected to GPIOs.
// //
// C1 P95 // C1 P95
@ -262,6 +264,9 @@ void ext_int_deassert(void)
P1_P9M0 |= BIT(0); P1_P9M0 |= BIT(0);
} }
// }}}
// {{{ I2C
#define I2C_N_REGS 16 #define I2C_N_REGS 16
static uint8_t i2c_transfer = 0x00; static uint8_t i2c_transfer = 0x00;
@ -427,30 +432,29 @@ void main(void)
run_tasks = 0; run_tasks = 0;
#if POLL_INPUT #if POLL_INPUT
// every 10ms we will scan the keyboard keys state and check for changes // every 20ms we will scan the keyboard keys state and check for changes
uint8_t keys[12]; uint8_t keys[12];
uint8_t active_rows = keyscan_scan(keys); uint8_t active_rows = keyscan_scan(keys);
if (active_rows) {
// pressing FN+PINE+F switches to flashing mode (keys 1:2 3:5 5:2, electrically)
if (keys[0] & BIT(2) && keys[2] & BIT(5) && keys[4] & BIT(2)) {
EA = 0;
__asm__("mov r6,#0x5a");
__asm__("mov r7,#0xe7");
__asm__("ljmp 0x0118");
}
// check for changes // pressing FN+PINE+F switches to flashing mode (keys 1:2 3:5 5:2, electrically)
if (!memcmp(i2c_regs + 4, keys, 12)) if (keys[0] & BIT(2) && keys[2] & BIT(5) && keys[4] & BIT(2)) {
continue; EA = 0;
__asm__("mov r6,#0x5a");
// signal interrupt __asm__("mov r7,#0xe7");
memcpy(i2c_regs + 4, keys, 12); __asm__("ljmp 0x0118");
ext_int_assert();
delay_us(100);
ext_int_deassert();
} }
// check for changes
if (!memcmp(i2c_regs + 4, keys, 12))
continue;
// signal interrupt
memcpy(i2c_regs + 4, keys, 12);
ext_int_assert();
delay_us(100);
ext_int_deassert();
#else #else
//XXX: not figured out yet, not tested, not working
if (scan_active) { if (scan_active) {
uint8_t active_rows = keyscan_scan(i2c_regs + 4); uint8_t active_rows = keyscan_scan(i2c_regs + 4);
if (!active_rows) { if (!active_rows) {