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

feat(core): Make physical layout key rotation optional #2770

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/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ endif # ZMK_BLE || ZMK_SPLIT_BLE

endmenu # Initialization Priorities

config ZMK_PHYSICAL_LAYOUT_KEY_ROTATION
bool "Support rotation of keys in physical layouts"
default y

menuconfig ZMK_KSCAN
bool "ZMK KScan Integration"
default y
Expand Down
2 changes: 2 additions & 0 deletions app/include/zmk/physical_layouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ struct zmk_key_physical_attrs {
int16_t height;
int16_t x;
int16_t y;
#if IS_ENABLED(CONFIG_ZMK_PHYSICAL_LAYOUT_KEY_ROTATION)
int16_t rx;
int16_t ry;
int16_t r;
#endif
};

struct zmk_physical_layout {
Expand Down
8 changes: 5 additions & 3 deletions app/src/physical_layouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ BUILD_ASSERT(
.height = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, height), \
.x = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, x), \
.y = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, y), \
.rx = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, rx), \
.ry = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, ry), \
.r = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, r), \
COND_CODE_1(IS_ENABLED(CONFIG_ZMK_PHYSICAL_LAYOUT_KEY_ROTATION), \
(.rx = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, rx), \
.ry = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, ry), \
.r = (int16_t)(int32_t)DT_INST_PHA_BY_IDX(n, keys, i, r), ), \
()) \
}

#define ZMK_LAYOUT_INST(n) \
Expand Down
2 changes: 2 additions & 0 deletions app/src/studio/keymap_subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ static bool encode_layout_keys(pb_ostream_t *stream, const pb_field_t *field, vo
.height = layout_kp->height,
.x = layout_kp->x,
.y = layout_kp->y,
#if IS_ENABLED(CONFIG_ZMK_PHYSICAL_LAYOUT_KEY_ROTATION)
.r = layout_kp->r,
.rx = layout_kp->rx,
.ry = layout_kp->ry,
#endif
caksoylar marked this conversation as resolved.
Show resolved Hide resolved
};

if (!pb_encode_submessage(stream, &zmk_keymap_KeyPhysicalAttrs_msg, &layout_kp_msg)) {
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/config/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ Each element of the `keys` array has the shape `<&key_physical_attrs w h x y r r

The `key_physical_attrs` node is defined in [`dts/physical_layouts.dtsi`](https://github.com/zmkfirmware/zmk/blob/main/app/dts/physical_layouts.dtsi) and is mandatory.

## Kconfig

| Config | Type | Description | Default |
| ----------------------------------------- | ---- | ------------------------------------------------------------- | ------- |
| `CONFIG_ZMK_PHYSICAL_LAYOUT_KEY_ROTATION` | bool | Whether to store/support key rotation information internally. | y |

## Physical Layout Position Map

Defines a mapping between [physical layouts](#physical-layout), allowing key mappings to be preserved in the same locations as previously when using [ZMK Studio](../features/studio.md). Read through the [page on physical layouts](../development/hardware-integration/physical-layouts.md) for more information.
Expand Down
Loading