keyboard stuff
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

APA102: API rework (#23355)

authored by

Ryan and committed by
GitHub
55538b2e c4a74be7

+67 -26
+39 -8
docs/drivers/apa102.md
··· 26 26 27 27 ## API {#api} 28 28 29 - ### `void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds)` 29 + ### `void apa102_init(void)` {#api-apa102-init} 30 + 31 + Initialize the LED driver. This function should be called first. 32 + 33 + --- 34 + 35 + ### `void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue)` {#api-apa102-set-color} 36 + 37 + Set the color of a single LED. This function does not immediately update the LEDs; call `apa102_flush()` after you are finished. 38 + 39 + #### Arguments {#api-apa102-set-color-arguments} 40 + 41 + - `uint16_t index` 42 + The LED index in the APA102 chain. 43 + - `uint8_t red` 44 + The red value to set. 45 + - `uint8_t green` 46 + The green value to set. 47 + - `uint8_t blue` 48 + The blue value to set. 49 + 50 + --- 51 + 52 + ### `void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-apa102-set-color-all} 53 + 54 + Set the color of all LEDs. 55 + 56 + #### Arguments {#api-apa102-set-color-all-arguments} 57 + 58 + - `uint8_t red` 59 + The red value to set. 60 + - `uint8_t green` 61 + The green value to set. 62 + - `uint8_t blue` 63 + The blue value to set. 30 64 31 - Send RGB data to the APA102 LED chain. 65 + --- 32 66 33 - #### Arguments {#api-apa102-setleds-arguments} 67 + ### `void apa102_flush(void)` {#api-apa102-flush} 34 68 35 - - `rgb_led_t *start_led` 36 - A pointer to the LED array. 37 - - `uint16_t num_leds` 38 - The length of the LED array. 69 + Flush the PWM values to the LED chain. 39 70 40 71 --- 41 72 42 - ### `void apa102_set_brightness(uint8_t brightness)` 73 + ### `void apa102_set_brightness(uint8_t brightness)` {#api-apa102-set-brightness} 43 74 44 75 Set the global brightness. 45 76
+17 -6
drivers/led/apa102.c
··· 53 53 io_wait; \ 54 54 } while (0) 55 55 56 - uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS; 56 + rgb_led_t apa102_leds[APA102_LED_COUNT]; 57 + uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS; 57 58 58 59 static void apa102_send_byte(uint8_t byte) { 59 60 APA102_SEND_BIT(byte, 7); ··· 121 122 gpio_set_pin_output(APA102_CI_PIN); 122 123 } 123 124 124 - void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) { 125 - rgb_led_t *end = start_led + num_leds; 125 + void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) { 126 + apa102_leds[index].r = red; 127 + apa102_leds[index].g = green; 128 + apa102_leds[index].b = blue; 129 + } 126 130 131 + void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { 132 + for (uint16_t i = 0; i < APA102_LED_COUNT; i++) { 133 + apa102_set_color(i, red, green, blue); 134 + } 135 + } 136 + 137 + void apa102_flush(void) { 127 138 apa102_start_frame(); 128 - for (rgb_led_t *led = start_led; led < end; led++) { 129 - apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness); 139 + for (uint8_t i = 0; i < APA102_LED_COUNT; i++) { 140 + apa102_send_frame(apa102_leds[i].r, apa102_leds[i].g, apa102_leds[i].b, apa102_led_brightness); 130 141 } 131 - apa102_end_frame(num_leds); 142 + apa102_end_frame(APA102_LED_COUNT); 132 143 } 133 144 134 145 void apa102_set_brightness(uint8_t brightness) {
+3 -12
drivers/led/apa102.h
··· 32 32 #define APA102_MAX_BRIGHTNESS 31 33 33 34 34 void apa102_init(void); 35 - 36 - /* User Interface 37 - * 38 - * Input: 39 - * start_led: An array of GRB data describing the LED colors 40 - * num_leds: The number of LEDs to write 41 - * 42 - * The functions will perform the following actions: 43 - * - Set the data-out pin as output 44 - * - Send out the LED data 45 - */ 46 - void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds); 35 + void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue); 36 + void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue); 37 + void apa102_flush(void); 47 38 48 39 void apa102_set_brightness(uint8_t brightness);
+8
quantum/rgblight/rgblight_drivers.c
··· 14 14 #elif defined(RGBLIGHT_APA102) 15 15 # include "apa102.h" 16 16 17 + // Temporary shim 18 + static void apa102_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) { 19 + for (uint16_t i = 0; i < number_of_leds; i++) { 20 + apa102_set_color(i, ledarray[i].r, ledarray[i].g, ledarray[i].b); 21 + } 22 + apa102_flush(); 23 + } 24 + 17 25 const rgblight_driver_t rgblight_driver = { 18 26 .init = apa102_init, 19 27 .setleds = apa102_setleds,