Skip to content

Commit

Permalink
fix(power): Fixes for dynamic PD in display/RGB.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Jul 5, 2024
1 parent 37acfeb commit 2adaeb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
14 changes: 9 additions & 5 deletions app/src/display/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ static void initialize_theme() {
#endif // CONFIG_LV_USE_THEME_MONO
}

#define HAS_DISPLAY_PD \
(DT_HAS_CHOSEN(zmk_display_default_power_domain) || DT_HAS_CHOSEN(zmk_default_power_domain))
#define GET_DISPLAY_PD \
DEVICE_DT_GET(COND_CODE_1(DT_HAS_CHOSEN(zmk_display_default_power_domain), \
(DT_CHOSEN(zmk_display_default_power_domain)), \
(DT_CHOSEN(zmk_default_power_domain))))

void initialize_display(struct k_work *work) {
LOG_DBG("");

Expand All @@ -119,17 +126,14 @@ void initialize_display(struct k_work *work) {
return;
}

#if IS_ENABLED(CONFIG_ZMK_DISPLAY_DEFAULT_POWER_DOMAIN) && DT_HAS_CHOSEN(zmk_default_power_domain)

#if IS_ENABLED(CONFIG_ZMK_DISPLAY_DEFAULT_POWER_DOMAIN) && HAS_DISPLAY_PD
pm_device_runtime_enable(display);
if (!pm_device_on_power_domain(display)) {
int rc =
pm_device_power_domain_add(display, DEVICE_DT_GET(DT_CHOSEN(zmk_default_power_domain)));
int rc = pm_device_power_domain_add(display, GET_DISPLAY_PD);
if (rc < 0) {
LOG_ERR("Failed to add the display to the default power domain (0x%02x)", -rc);
}
}

#endif

initialized = true;
Expand Down
24 changes: 12 additions & 12 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct rgb_underglow_state {
bool on;
};

static const struct device *led_strip;
static const struct device *led_strip = DEVICE_DT_GET(STRIP_CHOSEN);

static struct led_rgb pixels[STRIP_NUM_PIXELS];

Expand Down Expand Up @@ -245,23 +245,27 @@ static void zmk_rgb_underglow_save_state_work(struct k_work *_work) {
static struct k_work_delayable underglow_save_work;
#endif

static int zmk_rgb_underglow_init(void) {
led_strip = DEVICE_DT_GET(STRIP_CHOSEN);
#define HAS_RGB_UG_PD \
(DT_HAS_CHOSEN(zmk_rgb_underglow_default_power_domain) || \
DT_HAS_CHOSEN(zmk_default_power_domain))
#define GET_RGB_UG_PD \
DEVICE_DT_GET(COND_CODE_1(DT_HAS_CHOSEN(zmk_rgb_underglow_default_power_domain), \
(DT_CHOSEN(zmk_rgb_underglow_default_power_domain)), \
(DT_CHOSEN(zmk_default_power_domain))))

static int zmk_rgb_underglow_init(void) {
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER)
if (!device_is_ready(ext_power)) {
LOG_ERR("External power device \"%s\" is not ready", ext_power->name);
return -ENODEV;
}
#endif

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_DEFAULT_POWER_DOMAIN) && \
DT_HAS_CHOSEN(zmk_default_power_domain)
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_DEFAULT_POWER_DOMAIN) && HAS_RGB_UG_PD

pm_device_runtime_enable(led_strip);
if (!pm_device_on_power_domain(led_strip)) {
int rc = pm_device_power_domain_add(led_strip,
DEVICE_DT_GET(DT_CHOSEN(zmk_default_power_domain)));
int rc = pm_device_power_domain_add(led_strip, GET_RGB_UG_PD);
if (rc < 0) {
LOG_ERR("Failed to add the LED strip to the default power domain (0x%02x)", -rc);
}
Expand Down Expand Up @@ -315,12 +319,8 @@ int zmk_rgb_underglow_get_state(bool *on_off) {
}

int zmk_rgb_underglow_on(void) {
if (!led_strip)
return -ENODEV;
}

// Newer PM device approach to ensuring powered on when used.
const int rc = pm_device_runtime_get(led_strip);
int rc = pm_device_runtime_get(led_strip);
if (rc < 0) {
LOG_ERR("Failed to enable/get the PM device (%d)", rc);
return rc;
Expand Down

0 comments on commit 2adaeb7

Please sign in to comment.