diff --git a/src/board/system76/common/include/board/kbc.h b/src/board/system76/common/include/board/kbc.h index dbf7141..c74bbcf 100644 --- a/src/board/system76/common/include/board/kbc.h +++ b/src/board/system76/common/include/board/kbc.h @@ -7,8 +7,6 @@ #include -extern bool kbc_first; -extern bool kbc_second; extern uint8_t kbc_leds; void kbc_init(void); diff --git a/src/board/system76/common/include/board/touchpad.h b/src/board/system76/common/include/board/touchpad.h deleted file mode 100644 index a5f258c..0000000 --- a/src/board/system76/common/include/board/touchpad.h +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#ifndef _BOARD_TOUCHPAD_H -#define _BOARD_TOUCHPAD_H - -void touchpad_event(void); - -#endif // _BOARD_TOUCHPAD_H diff --git a/src/board/system76/common/kbc.c b/src/board/system76/common/kbc.c index 612f285..950ef9f 100644 --- a/src/board/system76/common/kbc.c +++ b/src/board/system76/common/kbc.c @@ -25,9 +25,9 @@ void kbc_init(void) { #define KBC_TIMEOUT 10000 // Enable first port - TODO -bool kbc_first = false; +static bool kbc_first = false; // Enable second port - TODO -bool kbc_second = false; +static bool kbc_second = false; // Translate from scancode set 2 to scancode set 1 // for basically no good reason static bool kbc_translate = true; @@ -406,6 +406,20 @@ static void kbc_on_output_empty(struct Kbc * kbc) { void kbc_event(struct Kbc * kbc) { uint8_t sts; + // Read from touchpad when possible + if (kbc_second) { + *(PS2_TOUCHPAD.control) = 0x07; + if (state == KBC_STATE_NORMAL) { + uint8_t sts = *(PS2_TOUCHPAD.status); + *(PS2_TOUCHPAD.status) = sts; + if (sts & BIT(3)) { + state = KBC_STATE_TOUCHPAD; + } + } + } else { + ps2_reset(&PS2_TOUCHPAD); + } + // Read command/data while available sts = kbc_status(kbc); if (sts & KBC_STS_IBF) { diff --git a/src/board/system76/common/main.c b/src/board/system76/common/main.c index 5d5c35f..80a3151 100644 --- a/src/board/system76/common/main.c +++ b/src/board/system76/common/main.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -93,7 +92,7 @@ void main(void) { uint32_t last_time = 0; for(main_cycle = 0; ; main_cycle++) { - switch (main_cycle % 5) { + switch (main_cycle % 3) { case 0: // Handle power states power_event(); @@ -108,14 +107,6 @@ void main(void) { } break; case 2: - // Passes through touchpad packets - touchpad_event(); - break; - case 3: - // Checks for keyboard/mouse packets from host - kbc_event(&KBC); - break; - case 4: // Handle lid close/open lid_event(); break; @@ -143,6 +134,8 @@ void main(void) { // Board-specific events board_event(); + // Checks for keyboard/mouse packets from host + kbc_event(&KBC); // Handles ACPI communication pmc_event(&PMC_1); // AP/EC communication over SMFI diff --git a/src/board/system76/common/touchpad.c b/src/board/system76/common/touchpad.c deleted file mode 100644 index f772d18..0000000 --- a/src/board/system76/common/touchpad.c +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include -#include -#include - -void touchpad_event(void) { - if (kbc_second) { - *(PS2_TOUCHPAD.control) = 0x07; - } else { - ps2_reset(&PS2_TOUCHPAD); - } - - uint8_t status = *(PS2_TOUCHPAD.status); - *(PS2_TOUCHPAD.status) = status; - if (status & (1 << 3)) { - uint8_t data = *(PS2_TOUCHPAD.data); - TRACE("touchpad: %02X\n", data); - kbc_mouse(&KBC, data, 1000); - } -}