Add hardware keyboard color handling

This commit is contained in:
Jeremy Soller 2020-09-23 10:42:03 -06:00 committed by Jeremy Soller
parent 480e05d12b
commit 343722e350
3 changed files with 73 additions and 0 deletions

View File

@ -5,10 +5,17 @@
#include <stdint.h>
// 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

View File

@ -0,0 +1,54 @@
#include <board/kbled.h>
#include <common/macro.h>
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);
}
}

View File

@ -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;
}
}