fix(pm): Fixes for dedicated on/off on peripherals.
* Add new flag to differentiate soft off on peripherals that is invoked by split GATT svc and dedicated additional ones tied to GPIO pin.
This commit is contained in:
parent
41d81801ed
commit
7e7110d85f
4 changed files with 19 additions and 9 deletions
|
@ -35,10 +35,9 @@ encoder: &qdec0 {
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
behaviors {
|
behaviors {
|
||||||
soft_off: soft_off {
|
hw_soft_off: hw_soft_off {
|
||||||
compatible = "zmk,behavior-soft-off";
|
compatible = "zmk,behavior-soft-off";
|
||||||
#binding-cells = <0>;
|
#binding-cells = <0>;
|
||||||
status = "okay";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ encoder: &qdec0 {
|
||||||
soft_off {
|
soft_off {
|
||||||
row = <0>;
|
row = <0>;
|
||||||
column = <0>;
|
column = <0>;
|
||||||
bindings = <&soft_off>;
|
bindings = <&hw_soft_off>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
behaviors {
|
behaviors {
|
||||||
/omit-if-no-ref/ soft_off: soft_off {
|
/omit-if-no-ref/ soft_off: keymap_soft_off {
|
||||||
compatible = "zmk,behavior-soft-off";
|
compatible = "zmk,behavior-soft-off";
|
||||||
#binding-cells = <0>;
|
#binding-cells = <0>;
|
||||||
|
split-peripheral-off-on-press;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,3 +12,6 @@ properties:
|
||||||
type: int
|
type: int
|
||||||
required: false
|
required: false
|
||||||
description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off.
|
description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off.
|
||||||
|
split-peripheral-off-on-press:
|
||||||
|
type: boolean
|
||||||
|
description: When built for a split peripheral, turn off on press, not release
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
struct behavior_soft_off_config {
|
struct behavior_soft_off_config {
|
||||||
|
bool split_peripheral_turn_off_on_press;
|
||||||
uint32_t hold_time_ms;
|
uint32_t hold_time_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,18 +24,22 @@ struct behavior_soft_off_data {
|
||||||
uint32_t press_start;
|
uint32_t press_start;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define IS_SPLIT_PERIPHERAL \
|
||||||
|
(IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL))
|
||||||
|
|
||||||
static int behavior_soft_off_init(const struct device *dev) { return 0; };
|
static int behavior_soft_off_init(const struct device *dev) { return 0; };
|
||||||
|
|
||||||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev);
|
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev);
|
||||||
struct behavior_soft_off_data *data = dev->data;
|
struct behavior_soft_off_data *data = dev->data;
|
||||||
|
const struct behavior_soft_off_config *config = dev->config;
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
|
if (IS_SPLIT_PERIPHERAL && config->split_peripheral_turn_off_on_press) {
|
||||||
zmk_pm_soft_off();
|
zmk_pm_soft_off();
|
||||||
#else
|
} else {
|
||||||
data->press_start = k_uptime_get();
|
data->press_start = k_uptime_get();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return ZMK_BEHAVIOR_OPAQUE;
|
return ZMK_BEHAVIOR_OPAQUE;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +76,8 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = {
|
||||||
#define BSO_INST(n) \
|
#define BSO_INST(n) \
|
||||||
static const struct behavior_soft_off_config bso_config_##n = { \
|
static const struct behavior_soft_off_config bso_config_##n = { \
|
||||||
.hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \
|
.hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \
|
||||||
|
.split_peripheral_turn_off_on_press = \
|
||||||
|
DT_INST_PROP_OR(n, split_peripheral_off_on_press, false), \
|
||||||
}; \
|
}; \
|
||||||
static struct behavior_soft_off_data bso_data_##n = {}; \
|
static struct behavior_soft_off_data bso_data_##n = {}; \
|
||||||
BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \
|
BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \
|
||||||
|
|
Loading…
Add table
Reference in a new issue