From 414ee9583eb4996f4e44e3a4a7f8e5510b6a2de8 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 15 Jan 2025 10:48:23 -0700 Subject: [PATCH] feat(core): Make physical layout key rotation optional To be able to save on flash space, for layouts on space constrained devices that don't require rotation, make key rotation props optional behind a new Kconfig flag. --- app/Kconfig | 4 ++++ app/include/zmk/physical_layouts.h | 2 ++ app/src/physical_layouts.c | 8 +++++--- app/src/studio/keymap_subsystem.c | 2 ++ docs/docs/config/layout.md | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 971c4991c7c..5fc03822a02 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -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 diff --git a/app/include/zmk/physical_layouts.h b/app/include/zmk/physical_layouts.h index 4760b48dfe6..d5cf6527379 100644 --- a/app/include/zmk/physical_layouts.h +++ b/app/include/zmk/physical_layouts.h @@ -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 { diff --git a/app/src/physical_layouts.c b/app/src/physical_layouts.c index cb62ed850f2..8d384308892 100644 --- a/app/src/physical_layouts.c +++ b/app/src/physical_layouts.c @@ -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) \ diff --git a/app/src/studio/keymap_subsystem.c b/app/src/studio/keymap_subsystem.c index 1b88a4b8f85..1d51975c840 100644 --- a/app/src/studio/keymap_subsystem.c +++ b/app/src/studio/keymap_subsystem.c @@ -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 }; if (!pb_encode_submessage(stream, &zmk_keymap_KeyPhysicalAttrs_msg, &layout_kp_msg)) { diff --git a/docs/docs/config/layout.md b/docs/docs/config/layout.md index 385d60c3b4b..04fdf73bc41 100644 --- a/docs/docs/config/layout.md +++ b/docs/docs/config/layout.md @@ -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.