chore: Various soft-off review fixes
* Code style to avoid goto. * Enable pm.c compilation via dedicated Kconfig flag. * Comment wakeup trigger PM behavior.
This commit is contained in:
parent
fceb0351a5
commit
5ebe924e94
6 changed files with 26 additions and 12 deletions
|
@ -31,7 +31,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)
|
||||
|
|
|
@ -423,8 +423,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
|
||||
|
|
|
@ -324,11 +324,9 @@ static int kscan_direct_init(const struct device *dev) {
|
|||
static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) {
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
kscan_direct_disable(dev);
|
||||
break;
|
||||
return kscan_direct_disable(dev);
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
kscan_direct_enable(dev);
|
||||
break;
|
||||
return kscan_direct_enable(dev);
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
@ -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)
|
Loading…
Add table
Reference in a new issue