diff --git a/src/board/system76/galp3-c/include/board/kbscan.h b/src/board/system76/galp3-c/include/board/kbscan.h index 8fa8cc6..27db45b 100644 --- a/src/board/system76/galp3-c/include/board/kbscan.h +++ b/src/board/system76/galp3-c/include/board/kbscan.h @@ -5,4 +5,6 @@ void kbscan_init(void); +void kbscan_event(void); + #endif // _BOARD_KBSCAN_H diff --git a/src/board/system76/galp3-c/kbscan.c b/src/board/system76/galp3-c/kbscan.c index 2fbbeed..25ef877 100644 --- a/src/board/system76/galp3-c/kbscan.c +++ b/src/board/system76/galp3-c/kbscan.c @@ -1,15 +1,56 @@ +#include + +#include #include void kbscan_init(void) { KSOCTRL = 0x05; KSICTRLR = 0x04; - // Set all outputs to GPIO mode and high - KSOH2 = 0xFF; - KSOH1 = 0xFF; - KSOL = 0xFF; + // Set all outputs to GPIO mode and low + KSOH2 = 0; + KSOH1 = 0; + KSOL = 0; KSOHGCTRL = 0xFF; KSOHGOEN = 0xFF; KSOLGCTRL = 0xFF; KSOLGOEN = 0xFF; } + +void kbscan_event(void) { + static uint8_t last = 0xFF; + uint8_t new = KSI; + if (new != last) { + printf("KSI %02X\n", new); + + int i; + for (i = 0; i <= 15; i++) { + if (i < 8) { + KSOL = ~(1 << i); + KSOH1 = 0xFF; + } else { + KSOL = 0xFF; + KSOH1 = ~(1 << (i - 8)); + } + + // TODO: figure out optimal delay + delay_ms(1); + + uint8_t ksi = KSI; + + printf(" %d: %02X\n", i, ksi); + int j; + for (j = 0; j < 8; j++) { + if (!(ksi & (1 << j))) { + printf(" %d, %d\n", i, j); + } + } + } + + KSOL = 0; + KSOH1 = 0; + + delay_ms(1); + } + last = new; +} diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index 7bfb51f..ddc4077 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -316,6 +316,7 @@ void main(void) { for(;;) { ac_adapter(); power_button(); + kbscan_event(); touchpad_event(&PS2_3); kbc_event(&KBC); pmc_event(&PMC_1);