summaryrefslogtreecommitdiff
path: root/quantum/rgblight
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2023-12-05 22:49:14 +1100
committerGitHub <noreply@github.com>2023-12-05 22:49:14 +1100
commit17f36a21bfc340e4715c5849e4d0c537820e7cbe (patch)
tree88a9604026cd94de52eaa34f6a93e2e8d975659e /quantum/rgblight
parent2acb426b8e51acd4ba16475c2132023cbb59b71a (diff)
Rework RGBLight driver system (#22529)
Diffstat (limited to 'quantum/rgblight')
-rw-r--r--quantum/rgblight/rgblight.c33
-rw-r--r--quantum/rgblight/rgblight.h1
-rw-r--r--quantum/rgblight/rgblight_drivers.c20
-rw-r--r--quantum/rgblight/rgblight_drivers.h13
4 files changed, 47 insertions, 20 deletions
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c
index 8ac886d441..8a5240568c 100644
--- a/quantum/rgblight/rgblight.c
+++ b/quantum/rgblight/rgblight.c
@@ -900,12 +900,6 @@ void rgblight_wakeup(void) {
#endif
-__attribute__((weak)) void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
- ws2812_setleds(start_led, num_leds);
-}
-
-#ifndef RGBLIGHT_CUSTOM
-
void rgblight_set(void) {
rgb_led_t *start_led;
uint8_t num_leds = rgblight_ranges.clipping_num_leds;
@@ -915,42 +909,41 @@ void rgblight_set(void) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
-# ifdef RGBW
+#ifdef RGBW
led[i].w = 0;
-# endif
+#endif
}
}
-# ifdef RGBLIGHT_LAYERS
+#ifdef RGBLIGHT_LAYERS
if (rgblight_layers != NULL
-# if !defined(RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF)
+# if !defined(RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF)
&& rgblight_config.enable
-# elif defined(RGBLIGHT_SLEEP)
+# elif defined(RGBLIGHT_SLEEP)
&& !is_suspended
-# endif
+# endif
) {
rgblight_layers_write();
}
-# endif
+#endif
-# ifdef RGBLIGHT_LED_MAP
+#ifdef RGBLIGHT_LED_MAP
rgb_led_t led0[RGBLED_NUM];
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led0[i] = led[pgm_read_byte(&led_map[i])];
}
start_led = led0 + rgblight_ranges.clipping_start_pos;
-# else
+#else
start_led = led + rgblight_ranges.clipping_start_pos;
-# endif
+#endif
-# ifdef RGBW
+#ifdef RGBW
for (uint8_t i = 0; i < num_leds; i++) {
convert_rgb_to_rgbw(&start_led[i]);
}
-# endif
- rgblight_call_driver(start_led, num_leds);
-}
#endif
+ rgblight_driver.setleds(start_led, num_leds);
+}
#ifdef RGBLIGHT_SPLIT
/* for split keyboard master side */
diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h
index a222ab6b9f..d2b8a24b1e 100644
--- a/quantum/rgblight/rgblight.h
+++ b/quantum/rgblight/rgblight.h
@@ -160,6 +160,7 @@ enum RGBLIGHT_EFFECT_MODE {
#include <stdint.h>
#include <stdbool.h>
+#include "rgblight_drivers.h"
#include "progmem.h"
#include "eeconfig.h"
#include "ws2812.h"
diff --git a/quantum/rgblight/rgblight_drivers.c b/quantum/rgblight/rgblight_drivers.c
new file mode 100644
index 0000000000..45b60e1a5f
--- /dev/null
+++ b/quantum/rgblight/rgblight_drivers.c
@@ -0,0 +1,20 @@
+// Copyright 2023 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "rgblight_drivers.h"
+
+#if defined(RGBLIGHT_WS2812)
+# include "ws2812.h"
+
+const rgblight_driver_t rgblight_driver = {
+ .setleds = ws2812_setleds,
+};
+
+#elif defined(RGBLIGHT_APA102)
+# include "apa102.h"
+
+const rgblight_driver_t rgblight_driver = {
+ .setleds = apa102_setleds,
+};
+
+#endif
diff --git a/quantum/rgblight/rgblight_drivers.h b/quantum/rgblight/rgblight_drivers.h
new file mode 100644
index 0000000000..f7125a6f3d
--- /dev/null
+++ b/quantum/rgblight/rgblight_drivers.h
@@ -0,0 +1,13 @@
+// Copyright 2023 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <stdint.h>
+#include "color.h"
+
+typedef struct {
+ void (*setleds)(rgb_led_t *ledarray, uint16_t number_of_leds);
+} rgblight_driver_t;
+
+extern const rgblight_driver_t rgblight_driver;