diff options
author | Ryan <[email protected]> | 2024-06-13 22:19:45 +1000 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-13 22:19:45 +1000 |
commit | 55538b2e1e743ec1a209e61880d52bb5d2156669 (patch) | |
tree | 22914c451f5d816470a159f28befd75585bfbceb /drivers | |
parent | c4a74be7f02ec64033638e93a49924df20fb2e57 (diff) | |
download | qmk_firmware-55538b2e1e743ec1a209e61880d52bb5d2156669.tar.gz qmk_firmware-55538b2e1e743ec1a209e61880d52bb5d2156669.zip |
APA102: API rework (#23355)
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/led/apa102.c | 23 | ||||
-rw-r--r-- | drivers/led/apa102.h | 15 |
2 files changed, 20 insertions, 18 deletions
diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c index b171b07b12..0cf0ecb401 100644 --- a/drivers/led/apa102.c +++ b/drivers/led/apa102.c @@ -53,7 +53,8 @@ io_wait; \ } while (0) -uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS; +rgb_led_t apa102_leds[APA102_LED_COUNT]; +uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS; static void apa102_send_byte(uint8_t byte) { APA102_SEND_BIT(byte, 7); @@ -121,14 +122,24 @@ void apa102_init(void) { gpio_set_pin_output(APA102_CI_PIN); } -void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) { - rgb_led_t *end = start_led + num_leds; +void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) { + apa102_leds[index].r = red; + apa102_leds[index].g = green; + apa102_leds[index].b = blue; +} + +void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + for (uint16_t i = 0; i < APA102_LED_COUNT; i++) { + apa102_set_color(i, red, green, blue); + } +} +void apa102_flush(void) { apa102_start_frame(); - for (rgb_led_t *led = start_led; led < end; led++) { - apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness); + for (uint8_t i = 0; i < APA102_LED_COUNT; i++) { + apa102_send_frame(apa102_leds[i].r, apa102_leds[i].g, apa102_leds[i].b, apa102_led_brightness); } - apa102_end_frame(num_leds); + apa102_end_frame(APA102_LED_COUNT); } void apa102_set_brightness(uint8_t brightness) { diff --git a/drivers/led/apa102.h b/drivers/led/apa102.h index 5e2f78658b..42f1344f0c 100644 --- a/drivers/led/apa102.h +++ b/drivers/led/apa102.h @@ -32,17 +32,8 @@ #define APA102_MAX_BRIGHTNESS 31 void apa102_init(void); - -/* User Interface - * - * Input: - * start_led: An array of GRB data describing the LED colors - * num_leds: The number of LEDs to write - * - * The functions will perform the following actions: - * - Set the data-out pin as output - * - Send out the LED data - */ -void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds); +void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue); +void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void apa102_flush(void); void apa102_set_brightness(uint8_t brightness); |