Skip to content

Commit

Permalink
indicator: Update indicator in low priority workqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Oct 17, 2023
1 parent 572afb0 commit 9099224
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config/app/indicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#include <zephyr/drivers/led_strip_remap.h>

#include <zmk/workqueue.h>
#include <zmk/event_manager.h>
#include <zmk/events/activity_state_changed.h>

Expand Down Expand Up @@ -57,7 +58,9 @@ static inline void apply_brightness(struct led_rgb *c_out, const struct led_rgb
static void indicator_update(struct k_work *work)
{
if (!settings.enable) {
unsigned int key = irq_lock();
led_strip_remap_clear(led_strip, STRIP_INDICATOR_LABEL);
irq_unlock(key);
return;
}

Expand All @@ -72,14 +75,16 @@ static void indicator_update(struct k_work *work)
LOG_DBG("Update indicator, color: %02X%02X%02X, brightness: %d -> %02X%02X%02X", current.r,
current.g, current.b, bri, color.r, color.g, color.b);

unsigned int key = irq_lock();
led_strip_remap_set(led_strip, STRIP_INDICATOR_LABEL, &color);
irq_unlock(key);
}

K_WORK_DEFINE(indicator_update_work, indicator_update);

static inline void post_indicator_update(void)
{
k_work_submit_to_queue(&k_sys_work_q, &indicator_update_work);
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &indicator_update_work);
}

uint32_t indicator_set_bits(uint32_t bits)
Expand Down Expand Up @@ -167,7 +172,9 @@ static void indicator_preview_brightness(uint8_t brightness)
LOG_DBG("Preview indicator, color: %02X%02X%02X, brightness: %d -> %02X%02X%02X", current.r,
current.g, current.b, brightness, color.r, color.g, color.b);

unsigned int key = irq_lock();
led_strip_remap_set(led_strip, "STATUS", &color);
irq_unlock(key);

k_work_reschedule(&indicator_clear_preview_work, K_MSEC(2000));
}
Expand Down Expand Up @@ -235,7 +242,7 @@ static int indicator_init(const struct device *dev)
#endif

k_mutex_init(&lock);
k_work_submit_to_queue(&k_sys_work_q, &indicator_update_work);
k_work_submit_to_queue(zmk_workqueue_lowprio_work_q(), &indicator_update_work);

return 0;
}
Expand Down

0 comments on commit 9099224

Please sign in to comment.