Skip to content

Commit

Permalink
chore: Various soft-off review fixes
Browse files Browse the repository at this point in the history
* Code style to avoid goto.
* Enable pm.c compilation via dedicated Kconfig flag.
* Comment wakeup trigger PM behavior.
  • Loading branch information
petejohanson committed Dec 29, 2023
1 parent b2a9990 commit bf87543
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c)
target_sources(app PRIVATE src/event_manager.c)
target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c)
target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c)
target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c)
target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c)
target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c)
target_sources(app PRIVATE src/events/activity_state_changed.c)
Expand Down
4 changes: 4 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,12 @@ config ZMK_EXT_POWER
bool "Enable support to control external power output"
default y

config ZMK_PM
bool

config ZMK_PM_SOFT_OFF
bool "Soft-off support"
select ZMK_PM
select PM_DEVICE

config ZMK_GPIO_KEY_WAKEUP_TRIGGER
Expand Down
6 changes: 2 additions & 4 deletions app/module/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,9 @@ static int kscan_matrix_init(const struct device *dev) {
static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) {
switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
kscan_matrix_disable(dev);
break;
return kscan_matrix_disable(dev);
case PM_DEVICE_ACTION_RESUME:
kscan_matrix_enable(dev);
break;
return kscan_matrix_enable(dev);
default:
return -ENOTSUP;
}
Expand Down
16 changes: 13 additions & 3 deletions app/src/gpio_key_wakeup_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) {
int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE);
if (ret < 0) {
LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret);
goto exit;
return ret;
}

for (int i = 0; i < config->extra_gpios_count; i++) {
ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret);
goto exit;
return ret;
}
}

exit:
return ret;
}

Expand All @@ -62,9 +61,20 @@ static int gpio_key_wakeup_trigger_pm_suspend(const struct device *dev) {
LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret);
}

for (int i = 0; i < config->extra_gpios_count; i++) {
ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_DISCONNECTED);
if (ret < 0) {
LOG_WRN("Failed to set extra GPIO pin disconnected for waker (%d)", ret);
return ret;
}
}

return ret;
}

// The waker is "backwards", in as much as it is designed to be resumed/enabled immediately
// before a soft-off state is entered, so it can wake the device from that state later.
// So this waker correctly resumes and is ready to wake the device later.
static int gpio_key_wakeup_trigger_pm_action(const struct device *dev,
enum pm_device_action action) {
switch (action) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#include <zmk/endpoints.h>

#if IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF)

#define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources)

#if HAS_WAKERS
Expand Down Expand Up @@ -63,3 +65,5 @@ int zmk_pm_soft_off(void) {
LOG_DBG("soft-off: go to sleep");
return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
}

#endif // IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF)

0 comments on commit bf87543

Please sign in to comment.