From 343722e3508dbc8d16e62206cd95543de5613fce Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 23 Sep 2020 10:42:03 -0600 Subject: [PATCH] Add hardware keyboard color handling --- .../system76/common/include/board/kbled.h | 7 +++ src/board/system76/common/kbled.c | 54 +++++++++++++++++++ src/board/system76/common/kbscan.c | 12 +++++ 3 files changed, 73 insertions(+) create mode 100644 src/board/system76/common/kbled.c diff --git a/src/board/system76/common/include/board/kbled.h b/src/board/system76/common/include/board/kbled.h index 7e82832..afa76fe 100644 --- a/src/board/system76/common/include/board/kbled.h +++ b/src/board/system76/common/include/board/kbled.h @@ -5,10 +5,17 @@ #include +// Must be specified by board void kbled_init(void); void kbled_reset(void); uint8_t kbled_get(void); void kbled_set(uint8_t level); void kbled_set_color(uint32_t color); +// Provided by common code +void kbled_hotkey_color(void); +void kbled_hotkey_down(void); +void kbled_hotkey_up(void); +void kbled_hotkey_toggle(void); + #endif // _BOARD_KBLED_H diff --git a/src/board/system76/common/kbled.c b/src/board/system76/common/kbled.c new file mode 100644 index 0000000..1e36e18 --- /dev/null +++ b/src/board/system76/common/kbled.c @@ -0,0 +1,54 @@ +#include +#include + +static int LEVEL_I = 1; +static const uint8_t __code LEVELS[] = { + 48, + 72, + 96, + 144, + 192, + 255 +}; + +static int COLOR_I = 0; +static const uint32_t __code COLORS[] = { + 0xFFFFFF, + 0x0000FF, + 0xFF0000, + 0xFF00FF, + 0x00FF00, + 0x00FFFF, + 0xFFFF00 +}; + +void kbled_hotkey_color(void) { + if (COLOR_I < (ARRAY_SIZE(COLORS) - 1)) { + COLOR_I += 1; + } else { + COLOR_I = 0; + } + kbled_set_color(COLORS[COLOR_I]); +} + +void kbled_hotkey_down(void) { + if (LEVEL_I > 0) { + LEVEL_I -= 1; + } + kbled_set(LEVELS[LEVEL_I]); +} + +void kbled_hotkey_up(void) { + if (LEVEL_I < (ARRAY_SIZE(LEVELS) - 1)) { + LEVEL_I += 1; + } + kbled_set(LEVELS[LEVEL_I]); +} + +void kbled_hotkey_toggle(void) { + if (kbled_get() == 0) { + kbled_set(LEVELS[LEVEL_I]); + } else { + kbled_set(0); + } +} diff --git a/src/board/system76/common/kbscan.c b/src/board/system76/common/kbscan.c index f512987..59045a3 100644 --- a/src/board/system76/common/kbscan.c +++ b/src/board/system76/common/kbscan.c @@ -153,6 +153,18 @@ static void hardware_hotkey(uint16_t key) { case K_KBD_BKL: kbled_set(kbled_get() + 1); break; + case K_KBD_COLOR: + if (acpi_ecos != EC_OS_FULL) kbled_hotkey_color(); + break; + case K_KBD_DOWN: + if (acpi_ecos != EC_OS_FULL) kbled_hotkey_down(); + break; + case K_KBD_UP: + if (acpi_ecos != EC_OS_FULL) kbled_hotkey_up(); + break; + case K_KBD_TOGGLE: + if (acpi_ecos != EC_OS_FULL) kbled_hotkey_toggle(); + break; } }