mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-27 11:06:37 +06:00
APA102: API rework (#23355)
This commit is contained in:
parent
c4a74be7f0
commit
55538b2e1e
|
@ -26,20 +26,51 @@ Add the following to your `config.h`:
|
||||||
|
|
||||||
## API {#api}
|
## API {#api}
|
||||||
|
|
||||||
### `void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds)`
|
### `void apa102_init(void)` {#api-apa102-init}
|
||||||
|
|
||||||
Send RGB data to the APA102 LED chain.
|
Initialize the LED driver. This function should be called first.
|
||||||
|
|
||||||
#### Arguments {#api-apa102-setleds-arguments}
|
|
||||||
|
|
||||||
- `rgb_led_t *start_led`
|
|
||||||
A pointer to the LED array.
|
|
||||||
- `uint16_t num_leds`
|
|
||||||
The length of the LED array.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### `void apa102_set_brightness(uint8_t brightness)`
|
### `void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue)` {#api-apa102-set-color}
|
||||||
|
|
||||||
|
Set the color of a single LED. This function does not immediately update the LEDs; call `apa102_flush()` after you are finished.
|
||||||
|
|
||||||
|
#### Arguments {#api-apa102-set-color-arguments}
|
||||||
|
|
||||||
|
- `uint16_t index`
|
||||||
|
The LED index in the APA102 chain.
|
||||||
|
- `uint8_t red`
|
||||||
|
The red value to set.
|
||||||
|
- `uint8_t green`
|
||||||
|
The green value to set.
|
||||||
|
- `uint8_t blue`
|
||||||
|
The blue value to set.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-apa102-set-color-all}
|
||||||
|
|
||||||
|
Set the color of all LEDs.
|
||||||
|
|
||||||
|
#### Arguments {#api-apa102-set-color-all-arguments}
|
||||||
|
|
||||||
|
- `uint8_t red`
|
||||||
|
The red value to set.
|
||||||
|
- `uint8_t green`
|
||||||
|
The green value to set.
|
||||||
|
- `uint8_t blue`
|
||||||
|
The blue value to set.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `void apa102_flush(void)` {#api-apa102-flush}
|
||||||
|
|
||||||
|
Flush the PWM values to the LED chain.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### `void apa102_set_brightness(uint8_t brightness)` {#api-apa102-set-brightness}
|
||||||
|
|
||||||
Set the global brightness.
|
Set the global brightness.
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@
|
||||||
io_wait; \
|
io_wait; \
|
||||||
} while (0)
|
} 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) {
|
static void apa102_send_byte(uint8_t byte) {
|
||||||
APA102_SEND_BIT(byte, 7);
|
APA102_SEND_BIT(byte, 7);
|
||||||
|
@ -121,14 +122,24 @@ void apa102_init(void) {
|
||||||
gpio_set_pin_output(APA102_CI_PIN);
|
gpio_set_pin_output(APA102_CI_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
rgb_led_t *end = start_led + num_leds;
|
apa102_leds[index].r = red;
|
||||||
|
apa102_leds[index].g = green;
|
||||||
|
apa102_leds[index].b = blue;
|
||||||
|
}
|
||||||
|
|
||||||
apa102_start_frame();
|
void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
|
||||||
for (rgb_led_t *led = start_led; led < end; led++) {
|
for (uint16_t i = 0; i < APA102_LED_COUNT; i++) {
|
||||||
apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
|
apa102_set_color(i, red, green, blue);
|
||||||
}
|
}
|
||||||
apa102_end_frame(num_leds);
|
}
|
||||||
|
|
||||||
|
void apa102_flush(void) {
|
||||||
|
apa102_start_frame();
|
||||||
|
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(APA102_LED_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void apa102_set_brightness(uint8_t brightness) {
|
void apa102_set_brightness(uint8_t brightness) {
|
||||||
|
|
|
@ -32,17 +32,8 @@
|
||||||
#define APA102_MAX_BRIGHTNESS 31
|
#define APA102_MAX_BRIGHTNESS 31
|
||||||
|
|
||||||
void apa102_init(void);
|
void apa102_init(void);
|
||||||
|
void apa102_set_color(uint16_t index, uint8_t red, uint8_t green, uint8_t blue);
|
||||||
/* User Interface
|
void apa102_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||||
*
|
void apa102_flush(void);
|
||||||
* 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_brightness(uint8_t brightness);
|
void apa102_set_brightness(uint8_t brightness);
|
||||||
|
|
|
@ -14,6 +14,14 @@ const rgblight_driver_t rgblight_driver = {
|
||||||
#elif defined(RGBLIGHT_APA102)
|
#elif defined(RGBLIGHT_APA102)
|
||||||
# include "apa102.h"
|
# include "apa102.h"
|
||||||
|
|
||||||
|
// Temporary shim
|
||||||
|
static void apa102_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {
|
||||||
|
for (uint16_t i = 0; i < number_of_leds; i++) {
|
||||||
|
apa102_set_color(i, ledarray[i].r, ledarray[i].g, ledarray[i].b);
|
||||||
|
}
|
||||||
|
apa102_flush();
|
||||||
|
}
|
||||||
|
|
||||||
const rgblight_driver_t rgblight_driver = {
|
const rgblight_driver_t rgblight_driver = {
|
||||||
.init = apa102_init,
|
.init = apa102_init,
|
||||||
.setleds = apa102_setleds,
|
.setleds = apa102_setleds,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user