From f79b11752b9580c2f782da6c2e6d96b871abe258 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 9 Mar 2026 21:30:07 -0600 Subject: [PATCH] kbled: Use defines for PWM DCRs to use Signed-off-by: Tim Crawford --- src/app/main/kbled/rgb_pwm.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/app/main/kbled/rgb_pwm.c b/src/app/main/kbled/rgb_pwm.c index 691ebbfa2..faf05bc7e 100644 --- a/src/app/main/kbled/rgb_pwm.c +++ b/src/app/main/kbled/rgb_pwm.c @@ -4,6 +4,11 @@ #include #include +#define KBLED_BRI DCR0 +#define KBLED_RED DCR5 +#define KBLED_GREEN DCR6 +#define KBLED_BLUE DCR7 + void kbled_init(void) { if (!gpio_get(&RGBKB_DET_N)) { kbled_kind = KBLED_RGB; @@ -22,8 +27,7 @@ void kbled_reset(void) { } uint8_t kbled_get(void) { - // Get PWM for power - return DCR0; + return KBLED_BRI; } uint8_t kbled_max(void) { @@ -31,22 +35,16 @@ uint8_t kbled_max(void) { } void kbled_set(uint8_t level) { - // Set PWM for power - DCR0 = level; + KBLED_BRI = level; } uint32_t kbled_get_color(void) { if (kbled_kind == KBLED_WHITE) return 0xFFFFFF; - // Get PWM of blue component - uint32_t color = (uint32_t)DCR7; - - // Get PWM of green component - color |= ((uint32_t)DCR6) << 8; - - // Get PWM of red component - color |= ((uint32_t)DCR5) << 16; + uint32_t color = (uint32_t)KBLED_BLUE; + color |= ((uint32_t)KBLED_GREEN) << 8; + color |= ((uint32_t)KBLED_RED) << 16; return color; } @@ -55,12 +53,7 @@ void kbled_set_color(uint32_t color) { if (kbled_kind == KBLED_WHITE) color = 0xFFFFFF; - // Set PWM for blue component - DCR7 = (uint8_t)(color); - - // Set PWM for green component - DCR6 = (uint8_t)(color >> 8); - - // Set PWM for red component - DCR5 = (uint8_t)(color >> 16); + KBLED_BLUE = (uint8_t)(color); + KBLED_GREEN = (uint8_t)(color >> 8); + KBLED_RED = (uint8_t)(color >> 16); }