mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 09:01:24 +02:00
Add LED compatibility for other boards.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void led_driver_init();
|
extern void led_driver_init();
|
||||||
extern void led_driver_color(uint8_t, float);
|
extern void led_driver_color(uint8_t, uint32_t, float);
|
||||||
|
|
||||||
static uint32_t led_mode = MODE_NOT_MOUNTED;
|
static uint32_t led_mode = MODE_NOT_MOUNTED;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ void led_blinking_task() {
|
|||||||
#ifdef PICO_DEFAULT_LED_PIN_INVERTED
|
#ifdef PICO_DEFAULT_LED_PIN_INVERTED
|
||||||
state = !state;
|
state = !state;
|
||||||
#endif
|
#endif
|
||||||
uint32_t led_max_brightness = (led_mode & LED_BTNESS_MASK) >> LED_BTNESS_SHIFT;
|
uint32_t led_brightness = (led_mode & LED_BTNESS_MASK) >> LED_BTNESS_SHIFT;
|
||||||
uint32_t led_color = (led_mode & LED_COLOR_MASK) >> LED_COLOR_SHIFT;
|
uint32_t led_color = (led_mode & LED_COLOR_MASK) >> LED_COLOR_SHIFT;
|
||||||
uint32_t led_off = (led_mode & LED_OFF_MASK) >> LED_OFF_SHIFT;
|
uint32_t led_off = (led_mode & LED_OFF_MASK) >> LED_OFF_SHIFT;
|
||||||
uint32_t led_on = (led_mode & LED_ON_MASK) >> LED_ON_SHIFT;
|
uint32_t led_on = (led_mode & LED_ON_MASK) >> LED_ON_SHIFT;
|
||||||
@@ -64,9 +64,8 @@ void led_blinking_task() {
|
|||||||
// maybe quick return if progress didn't changed much ?
|
// maybe quick return if progress didn't changed much ?
|
||||||
|
|
||||||
// current one from 0 - 1
|
// current one from 0 - 1
|
||||||
float led_brightness = ((float)led_max_brightness / MAX_BTNESS) * progress;
|
|
||||||
|
|
||||||
led_driver_color(led_color, led_brightness);
|
led_driver_color(led_color, led_brightness, progress);
|
||||||
|
|
||||||
if (board_millis() >= stop_ms){
|
if (board_millis() >= stop_ms){
|
||||||
start_ms = stop_ms;
|
start_ms = stop_ms;
|
||||||
@@ -78,7 +77,7 @@ void led_blinking_task() {
|
|||||||
|
|
||||||
void led_off_all() {
|
void led_off_all() {
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
led_driver_color(LED_COLOR_OFF, 0);
|
led_driver_color(LED_COLOR_OFF, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ void led_driver_init() {
|
|||||||
cyw43_arch_init();
|
cyw43_arch_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color(uint8_t color, float brightness) {
|
void led_driver_color(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, color != LED_COLOR_OFF);
|
(void)led_brightness;
|
||||||
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, progress >= 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,8 +45,19 @@ void led_driver_init() {
|
|||||||
neopixel = neopixel_Init(1, gpio);
|
neopixel = neopixel_Init(1, gpio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color(uint8_t color, float brightness) {
|
void led_driver_color(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
neopixel_SetPixel(neopixel, &pixel[color], 1);
|
static tNeopixel spx = {.index = 0, .rgb = 0};
|
||||||
|
float brightness = ((float)led_brightness / MAX_BTNESS) * progress;
|
||||||
|
uint32_t pixel_color = pixel[color].rgb;
|
||||||
|
uint8_t r = (pixel_color >> 16) & 0xFF;
|
||||||
|
uint8_t g = (pixel_color >> 8) & 0xFF;
|
||||||
|
uint8_t b = (pixel_color) & 0xFF;
|
||||||
|
|
||||||
|
r = (uint8_t)(r * brightness);
|
||||||
|
g = (uint8_t)(g * brightness);
|
||||||
|
b = (uint8_t)(b * brightness);
|
||||||
|
spx.rgb = NP_RGB(r, g, b);
|
||||||
|
neopixel_SetPixel(neopixel, &spx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ void led_driver_init() {
|
|||||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color(uint8_t color, float brightness) {
|
void led_driver_color(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
gpio_put(PICO_DEFAULT_LED_PIN, color != LED_COLOR_OFF);
|
(void)led_brightness;
|
||||||
|
gpio_put(PICO_DEFAULT_LED_PIN, progress >= 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ void led_driver_init() {
|
|||||||
gpio_set_dir(LED_B_PIN, GPIO_OUT);
|
gpio_set_dir(LED_B_PIN, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color(uint8_t color, float brightness) {
|
void led_driver_color(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
|
if (progress < 0.5) {
|
||||||
|
color = LED_COLOR_OFF;
|
||||||
|
}
|
||||||
gpio_put(LED_R_PIN, pixel[color][0]);
|
gpio_put(LED_R_PIN, pixel[color][0]);
|
||||||
gpio_put(LED_G_PIN, pixel[color][1]);
|
gpio_put(LED_G_PIN, pixel[color][1]);
|
||||||
gpio_put(LED_B_PIN, pixel[color][2]);
|
gpio_put(LED_B_PIN, pixel[color][2]);
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ uint32_t pixel[] = {
|
|||||||
0xffffff00 // 7: white
|
0xffffff00 // 7: white
|
||||||
};
|
};
|
||||||
|
|
||||||
void led_driver_color(uint8_t color, float brightness) {
|
void led_driver_color(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
|
float brightness = ((float)led_brightness / MAX_BTNESS) * progress;
|
||||||
uint32_t pixel_color = pixel[color];
|
uint32_t pixel_color = pixel[color];
|
||||||
uint8_t r = (pixel_color >> 16) & 0xFF;
|
uint8_t r = (pixel_color >> 16) & 0xFF;
|
||||||
uint8_t g = (pixel_color >> 24) & 0xFF;
|
uint8_t g = (pixel_color >> 24) & 0xFF;
|
||||||
|
|||||||
Reference in New Issue
Block a user