kbled: Add a "step" function for BKL hotkey

Replace the get+set logic with a step function to change the backlight
level for `K_KBD_BKL`.

Keyboards using a DAC have a different set of levels due to the
brightness difference between the keyboards.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-05-19 16:20:20 -06:00
committed by Jeremy Soller
parent 4c9d3197b8
commit 9ac513128a
3 changed files with 25 additions and 2 deletions

View File

@ -26,5 +26,6 @@ void kbled_hotkey_color(void);
void kbled_hotkey_down(void); void kbled_hotkey_down(void);
void kbled_hotkey_up(void); void kbled_hotkey_up(void);
void kbled_hotkey_toggle(void); void kbled_hotkey_toggle(void);
void kbled_hotkey_step(void);
#endif // _BOARD_KBLED_H #endif // _BOARD_KBLED_H

View File

@ -7,14 +7,26 @@ enum KbledKind kbled_kind = KBLED_NONE;
// clang-format off // clang-format off
static uint8_t LEVEL_I = 1; static uint8_t LEVEL_I = 1;
#ifdef KBLED_DAC
// XXX: DAC uses separate levels due to brightness being different.
static const uint8_t __code LEVELS[] = {
0,
128,
144,
168,
192,
255,
};
#else
static const uint8_t __code LEVELS[] = { static const uint8_t __code LEVELS[] = {
48, 48,
72, 72,
96, 96,
144, 144,
192, 192,
255 255,
}; };
#endif
static uint8_t COLOR_I = 0; static uint8_t COLOR_I = 0;
static const uint32_t __code COLORS[] = { static const uint32_t __code COLORS[] = {
@ -58,3 +70,13 @@ void kbled_hotkey_toggle(void) {
kbled_set(0); kbled_set(0);
} }
} }
// Change the backlight level to the next value, cycling through "off".
void kbled_hotkey_step(void) {
if (LEVEL_I < (ARRAY_SIZE(LEVELS) - 1)) {
LEVEL_I += 1;
} else {
LEVEL_I = 0;
}
kbled_set(LEVELS[LEVEL_I]);
}

View File

@ -175,7 +175,7 @@ static void hardware_hotkey(uint16_t key) {
fan_max = !fan_max; fan_max = !fan_max;
break; break;
case K_KBD_BKL: case K_KBD_BKL:
kbled_set(kbled_get() + 1); kbled_hotkey_step();
break; break;
case K_KBD_COLOR: case K_KBD_COLOR:
if (acpi_ecos != EC_OS_FULL) if (acpi_ecos != EC_OS_FULL)