Skip to content

Commit

Permalink
Merge branch 'zmkfirmware:main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
LostQuasar authored Aug 14, 2024
2 parents efa6eda + ba0dee0 commit f9ae596
Show file tree
Hide file tree
Showing 35 changed files with 788 additions and 364 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hardware-metadata-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: pip install -r app/scripts/requirements.txt
run: pip install --break-system-packages -r app/scripts/requirements.txt
- name: West init
run: west init -l app
- name: Update modules (west update)
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ms-python.python",
"ms-vscode.cpptools",
"plorefice.devicetree",
"twxs.cmake"
"twxs.cmake",
"unifiedjs.vscode-mdx"
]
}
4 changes: 2 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse.c)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c)
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_HOLD_TAP app PRIVATE src/behaviors/behavior_hold_tap.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_STICKY_KEY app PRIVATE src/behaviors/behavior_sticky_key.c)
target_sources(app PRIVATE src/behaviors/behavior_caps_word.c)
target_sources(app PRIVATE src/behaviors/behavior_key_repeat.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_MACRO app PRIVATE src/behaviors/behavior_macro.c)
Expand Down
37 changes: 37 additions & 0 deletions app/Kconfig.behaviors
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ endchoice

endif


config ZMK_BEHAVIOR_HOLD_TAP
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_HOLD_TAP_ENABLED

if ZMK_BEHAVIOR_HOLD_TAP

config ZMK_BEHAVIOR_HOLD_TAP_MAX_HELD
int "Hold Tap Max Held"
default 10
help
Max number of simultaneously held hold-taps

config ZMK_BEHAVIOR_HOLD_TAP_MAX_CAPTURED_EVENTS
int "Hold Tap Max Captured Events"
default 40
help
Max number of captured system events while waiting to resolve hold taps

endif

config ZMK_BEHAVIOR_KEY_TOGGLE
bool
default y
Expand All @@ -51,6 +73,21 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED
imply ZMK_MOUSE

config ZMK_BEHAVIOR_STICKY_KEY
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_STICKY_KEY_ENABLED

if ZMK_BEHAVIOR_STICKY_KEY

config ZMK_BEHAVIOR_STICKY_KEY_MAX_HELD
int "Sticky Key Max Held"
default 10
help
Max number of simultaneously held sticky keys

endif

config ZMK_BEHAVIOR_SOFT_OFF
bool
default y
Expand Down
107 changes: 82 additions & 25 deletions app/module/drivers/kscan/kscan_composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DT_DRV_COMPAT zmk_kscan_composite

#include <zephyr/device.h>
#include <zephyr/pm/device.h>
#include <zephyr/drivers/kscan.h>
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
Expand All @@ -26,10 +27,10 @@ struct kscan_composite_child_config {
.row_offset = DT_PROP(inst, row_offset), \
.column_offset = DT_PROP(inst, column_offset)},

const struct kscan_composite_child_config kscan_composite_children[] = {
DT_FOREACH_CHILD(MATRIX_NODE_ID, CHILD_CONFIG)};

struct kscan_composite_config {};
struct kscan_composite_config {
const struct kscan_composite_child_config *children;
size_t children_len;
};

struct kscan_composite_data {
kscan_callback_t callback;
Expand All @@ -38,51 +39,80 @@ struct kscan_composite_data {
};

static int kscan_composite_enable_callback(const struct device *dev) {
for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
const struct kscan_composite_config *cfg = dev->config;

for (int i = 0; i < cfg->children_len; i++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[i];

#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
if (!pm_device_runtime_is_enabled(dev) && pm_device_runtime_is_enabled(child_cfg->child)) {
pm_device_runtime_get(child_cfg->child);
}
#elif IS_ENABLED(CONFIG_PM_DEVICE)
pm_device_action_run(child_cfg->child, PM_DEVICE_ACTION_RESUME);
#endif // IS_ENABLED(CONFIG_PM_DEVICE)

kscan_enable_callback(cfg->child);
kscan_enable_callback(child_cfg->child);
}
return 0;
}

static int kscan_composite_disable_callback(const struct device *dev) {
for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
const struct kscan_composite_config *cfg = dev->config;
for (int i = 0; i < cfg->children_len; i++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[i];

kscan_disable_callback(child_cfg->child);

kscan_disable_callback(cfg->child);
#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
if (!pm_device_runtime_is_enabled(dev) && pm_device_runtime_is_enabled(child_cfg->child)) {
pm_device_runtime_put(child_cfg->child);
}
#elif IS_ENABLED(CONFIG_PM_DEVICE)
pm_device_action_run(child_cfg->child, PM_DEVICE_ACTION_SUSPEND);
#endif // IS_ENABLED(CONFIG_PM_DEVICE)
}
return 0;
}

#define KSCAN_COMP_INST_DEV(n) DEVICE_DT_GET(DT_DRV_INST(n)),

static const struct device *all_instances[] = {DT_INST_FOREACH_STATUS_OKAY(KSCAN_COMP_INST_DEV)};

static void kscan_composite_child_callback(const struct device *child_dev, uint32_t row,
uint32_t column, bool pressed) {
// TODO: Ideally we can get this passed into our callback!
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
struct kscan_composite_data *data = dev->data;
for (int i = 0; i < ARRAY_SIZE(all_instances); i++) {

for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
const struct device *dev = all_instances[i];
const struct kscan_composite_config *cfg = dev->config;
struct kscan_composite_data *data = dev->data;

if (cfg->child != child_dev) {
continue;
}
for (int c = 0; c < cfg->children_len; c++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[c];

if (child_cfg->child != child_dev) {
continue;
}

data->callback(dev, row + cfg->row_offset, column + cfg->column_offset, pressed);
data->callback(dev, row + child_cfg->row_offset, column + child_cfg->column_offset,
pressed);
}
}
}

static int kscan_composite_configure(const struct device *dev, kscan_callback_t callback) {
const struct kscan_composite_config *cfg = dev->config;
struct kscan_composite_data *data = dev->data;

if (!callback) {
return -EINVAL;
}

for (int i = 0; i < ARRAY_SIZE(kscan_composite_children); i++) {
const struct kscan_composite_child_config *cfg = &kscan_composite_children[i];
for (int i = 0; i < cfg->children_len; i++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[i];

kscan_config(cfg->child, &kscan_composite_child_callback);
kscan_config(child_cfg->child, &kscan_composite_child_callback);
}

data->callback = callback;
Expand All @@ -95,6 +125,10 @@ static int kscan_composite_init(const struct device *dev) {

data->dev = dev;

#if IS_ENABLED(CONFIG_PM_DEVICE)
pm_device_init_suspended(dev);
#endif

return 0;
}

Expand All @@ -104,9 +138,32 @@ static const struct kscan_driver_api mock_driver_api = {
.disable_callback = kscan_composite_disable_callback,
};

static const struct kscan_composite_config kscan_composite_config = {};
#if IS_ENABLED(CONFIG_PM_DEVICE)

static struct kscan_composite_data kscan_composite_data;
static int kscan_composite_pm_action(const struct device *dev, enum pm_device_action action) {
switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
return kscan_composite_disable_callback(dev);
case PM_DEVICE_ACTION_RESUME:
return kscan_composite_enable_callback(dev);
default:
return -ENOTSUP;
}
}

DEVICE_DT_INST_DEFINE(0, kscan_composite_init, NULL, &kscan_composite_data, &kscan_composite_config,
POST_KERNEL, CONFIG_ZMK_KSCAN_COMPOSITE_INIT_PRIORITY, &mock_driver_api);
#endif // IS_ENABLED(CONFIG_PM_DEVICE)

#define KSCAN_COMP_DEV(n) \
static const struct kscan_composite_child_config kscan_composite_children_##n[] = { \
DT_INST_FOREACH_CHILD(n, CHILD_CONFIG)}; \
static const struct kscan_composite_config kscan_composite_config_##n = { \
.children = kscan_composite_children_##n, \
.children_len = ARRAY_SIZE(kscan_composite_children_##n), \
}; \
static struct kscan_composite_data kscan_composite_data_##n; \
PM_DEVICE_DT_INST_DEFINE(n, kscan_composite_pm_action); \
DEVICE_DT_INST_DEFINE(n, kscan_composite_init, PM_DEVICE_DT_INST_GET(n), \
&kscan_composite_data_##n, &kscan_composite_config_##n, POST_KERNEL, \
CONFIG_ZMK_KSCAN_COMPOSITE_INIT_PRIORITY, &mock_driver_api);

DT_INST_FOREACH_STATUS_OKAY(KSCAN_COMP_DEV)
4 changes: 2 additions & 2 deletions app/src/behaviors/behavior_hold_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

#define ZMK_BHV_HOLD_TAP_MAX_HELD 10
#define ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS 40
#define ZMK_BHV_HOLD_TAP_MAX_HELD CONFIG_ZMK_BEHAVIOR_HOLD_TAP_MAX_HELD
#define ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS CONFIG_ZMK_BEHAVIOR_HOLD_TAP_MAX_CAPTURED_EVENTS

// increase if you have keyboard with more keys.
#define ZMK_BHV_HOLD_TAP_POSITION_NOT_USED 9999
Expand Down
2 changes: 1 addition & 1 deletion app/src/behaviors/behavior_sticky_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#define KEY_PRESS DEVICE_DT_NAME(DT_INST(0, zmk_behavior_key_press))

#define ZMK_BHV_STICKY_KEY_MAX_HELD 10
#define ZMK_BHV_STICKY_KEY_MAX_HELD CONFIG_ZMK_BEHAVIOR_STICKY_KEY_MAX_HELD

#define ZMK_BHV_STICKY_KEY_POSITION_FREE UINT32_MAX

Expand Down
7 changes: 6 additions & 1 deletion app/src/gpio_key_wakeup_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ static int zmk_gpio_key_wakeup_trigger_init(const struct device *dev) {
static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) {
const struct gpio_key_wakeup_trigger_config *config = dev->config;

int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE);
int ret = gpio_pin_configure_dt(&config->trigger, GPIO_INPUT);
if (ret < 0) {
LOG_ERR("Failed to configure wakeup trigger key GPIO pin as input (%d)", ret);
return ret;
}
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);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/behaviors/backlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ However the settings will only be saved after [`CONFIG_ZMK_SETTINGS_SAVE_DEBOUNC

## Split Keyboards

Backlight behaviors are global: This means that when triggered, they affect both the central and peripheral side of split keyboards.
Backlight behaviors are [global](../features/split-keyboards.md#global-locality-behaviors): This means that when triggered, they affect both the central and peripheral side of split keyboards.
47 changes: 7 additions & 40 deletions docs/docs/behaviors/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ sidebar_label: Layers
Often, you may want a certain key position to alter which layers are enabled, change the default layer, etc.
Some of those behaviors are still in the works; the ones that are working now are documented here.

:::note
Multiple layers can be active at the same time and activating a layer will not deactivate layers higher up in the "layer stack". See [Layers](../features/keymaps.mdx#layers) for more information.
:::

## Defines to Refer to Layers

When working with layers, you may have several different key positions with bindings that enable/disable those layers.
Expand All @@ -33,7 +37,7 @@ again.
### Behavior Binding

- Reference: `&mo`
- Parameter: The layer number to enable/disable, e.g. `1`
- Parameter: The layer number to enable while held, e.g. `1`

Example:

Expand All @@ -48,7 +52,7 @@ The "layer-tap" behavior enables a layer when a key is held, and outputs a [keyp
### Behavior Binding

- Reference: `&lt`
- Parameter: The layer number to enable when held, e.g. `1`
- Parameter: The layer number to enable while held, e.g. `1`
- Parameter: The keycode to send when tapped, e.g. `A`

Example:
Expand Down Expand Up @@ -99,7 +103,7 @@ Example:

## Toggle Layer

The "toggle layer" behavior enables a layer until the layer is manually disabled.
The "toggle layer" behavior enables a layer if it is currently disabled, or disables it if enabled.

### Behavior Binding

Expand All @@ -112,43 +116,6 @@ Example:
&tog LOWER
```

"Toggle layer" for a :

```dts
#define DEFAULT 0
#define NAVI 1
#define NONE 0
/ {
keymap {
compatible = "zmk,keymap";
default_layer {
bindings = <
&tog NAVI &kp KP_DIVIDE &kp KP_MULTIPLY &kp KP_MINUS
&kp NUMBER_7 &kp NUMBER_8 &kp NUMBER_9 &kp KP_PLUS
&kp NUMBER_4 &kp NUMBER_5 &kp NUMBER_6 &kp KP_PLUS
&kp NUMBER_1 &kp NUMBER_2 &kp NUMBER_3 &kp RETURN
&kp NUMBER_0 &kp NUMBER_0 &kp DOT &kp RETURN
>;
};
nav_layer {
bindings = <
&tog NAVI &kp KP_DIVIDE &kp KP_MULTIPLY &kp KP_MINUS
&kp HOME &kp UP &kp PAGE_UP &kp KP_PLUS
&kp LEFT &none &kp RIGHT &kp KP_PLUS
&kp END &kp DOWN &kp PAGE_DOWN &kp RETURN
&kp INSERT &kp INSERT &kp DEL &kp RETURN
>;
};
};
};
```

It is possible to use "toggle layer" to have keys that raise and lower the layers as well.

## Conditional Layers

The "conditional layers" feature enables a particular layer when all layers in a specified set are active.
Expand Down
Loading

0 comments on commit f9ae596

Please sign in to comment.