apa102.md (2587B)
1 # APA102 Driver {#apa102-driver} 2 3 This driver provides support for APA102 addressable RGB LEDs. They are similar to the [WS2812](ws2812) LEDs, but have increased data and refresh rates. 4 5 ## Usage {#usage} 6 7 In most cases, the APA102 driver code is automatically included if you are using either the [RGBLight](../features/rgblight) or [RGB Matrix](../features/rgb_matrix) feature with the `apa102` driver set, and you would use those APIs instead. 8 9 However, if you need to use the driver standalone, add the following to your `rules.mk`: 10 11 ```make 12 APA102_DRIVER_REQUIRED = yes 13 ``` 14 15 You can then call the APA102 API by including `apa102.h` in your code. 16 17 ## Basic Configuration {#basic-configuration} 18 19 Add the following to your `config.h`: 20 21 |Define |Default |Description | 22 |---------------------------|-------------|------------------------------------------------------------------| 23 |`APA102_DI_PIN` |*Not defined*|The GPIO pin connected to the DI pin of the first LED in the chain| 24 |`APA102_CI_PIN` |*Not defined*|The GPIO pin connected to the CI pin of the first LED in the chain| 25 |`APA102_DEFAULT_BRIGHTNESS`|`31` |The default global brightness level of the LEDs, from 0 to 31 | 26 27 ## API {#api} 28 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. 64 65 --- 66 67 ### `void apa102_flush(void)` {#api-apa102-flush} 68 69 Flush the PWM values to the LED chain. 70 71 --- 72 73 ### `void apa102_set_brightness(uint8_t brightness)` {#api-apa102-set-brightness} 74 75 Set the global brightness. 76 77 #### Arguments {#api-apa102-set-brightness-arguments} 78 79 - `uint8_t brightness` 80 The brightness level to set, from 0 to 31.