Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext-power): Initialize as soon as settings are available #675

Merged
merged 2 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/dts/bindings/zmk,ext-power-generic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ properties:
label:
type: string
required: true
init-delay-ms:
type: int
description: Number of milliseconds to delay after initializing driver
required: false
16 changes: 12 additions & 4 deletions app/src/ext_power_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ext_power_generic_config {
const char *label;
const uint8_t pin;
const uint8_t flags;
const uint16_t init_delay_ms;
};

struct ext_power_generic_data {
Expand Down Expand Up @@ -171,6 +172,10 @@ static int ext_power_generic_init(const struct device *dev) {
ext_power_enable(dev);
#endif

if (config->init_delay_ms) {
k_msleep(config->init_delay_ms);
}

return 0;
}

Expand Down Expand Up @@ -210,7 +215,8 @@ static int ext_power_generic_pm_control(const struct device *dev, uint32_t ctrl_
static const struct ext_power_generic_config config = {
.label = DT_INST_GPIO_LABEL(0, control_gpios),
.pin = DT_INST_GPIO_PIN(0, control_gpios),
.flags = DT_INST_GPIO_FLAGS(0, control_gpios)};
.flags = DT_INST_GPIO_FLAGS(0, control_gpios),
.init_delay_ms = DT_INST_PROP_OR(0, init_delay_ms, 0)};

static struct ext_power_generic_data data = {
.status = false,
Expand All @@ -223,13 +229,15 @@ static const struct ext_power_api api = {.enable = ext_power_generic_enable,
.disable = ext_power_generic_disable,
.get = ext_power_generic_get};

#define ZMK_EXT_POWER_INIT_PRIORITY 81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but something to consider moving to Kconfig as needed.


#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
DEVICE_DEFINE(ext_power_generic, DT_INST_LABEL(0), ext_power_generic_init,
&ext_power_generic_pm_control, &data, &config, APPLICATION,
CONFIG_APPLICATION_INIT_PRIORITY, &api);
&ext_power_generic_pm_control, &data, &config, POST_KERNEL,
ZMK_EXT_POWER_INIT_PRIORITY, &api);
#else
DEVICE_AND_API_INIT(ext_power_generic, DT_INST_LABEL(0), ext_power_generic_init, &data, &config,
APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY, &api);
POST_KERNEL, ZMK_EXT_POWER_INIT_PRIORITY, &api);
#endif /* CONFIG_DEVICE_POWER_MANAGEMENT */

#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */