Skip to content

Commit

Permalink
fix: Defer auto enabling of kscan sideband.
Browse files Browse the repository at this point in the history
* Now that device init of kscan sideband is in POST_KERNEL stage,
  use a separate SYS_INIT for auto enabling the device so processing
  of early/initial presses from referenced toggle mode kscan devices
  occurs at the proper time during init.
  • Loading branch information
petejohanson committed Aug 5, 2024
1 parent cd25c12 commit 98a4408
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions app/src/kscan_sideband_behaviors.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,11 @@ static int ksbb_init(const struct device *dev) {
return -ENODEV;
}

if (config->auto_enable) {
#if !IS_ENABLED(CONFIG_PM_DEVICE)
kscan_config(config->kscan, &ksbb_inner_kscan_callback);
kscan_enable_callback(config->kscan);
#else
ksbb_pm_action(dev, PM_DEVICE_ACTION_RESUME);
} else {
#if IS_ENABLED(CONFIG_PM_DEVICE)
if (!config->auto_enable) {
pm_device_init_suspended(dev);
#endif
}
#endif

return 0;
}
Expand All @@ -183,11 +178,22 @@ static const struct kscan_driver_api ksbb_api = {

#define ENTRY(e) \
{ \
.row = DT_PROP(e, row), .column = DT_PROP(e, column), \
.row = DT_PROP(e, row), \
.column = DT_PROP(e, column), \
.binding = ZMK_KEYMAP_EXTRACT_BINDING(0, e), \
}

#define KSBB_INST(n) \
COND_CODE_1(DT_INST_PROP_OR(n, auto_enable, false), (static int ksbb_auto_enable_##n(void) { \
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(n)); \
const struct ksbb_config *config = dev->config; \
COND_CODE_1(IS_ENABLED(CONFIG_PM_DEVICE), \
(ksbb_pm_action(dev, PM_DEVICE_ACTION_RESUME);), \
(kscan_config(config->kscan, &ksbb_inner_kscan_callback); \
kscan_enable_callback(config->kscan);)) \
return 0; \
} SYS_INIT(ksbb_auto_enable_##n, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);), \
()) \
static struct ksbb_entry entries_##n[] = { \
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, ENTRY, (, ))}; \
const struct ksbb_config ksbb_config_##n = { \
Expand Down

0 comments on commit 98a4408

Please sign in to comment.