Skip to content

Commit

Permalink
feat(core): Make physical layout key rotation optional (#2770)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petejohanson authored Jan 15, 2025
1 parent 6941abc commit c367d8f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
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
};

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

0 comments on commit c367d8f

Please sign in to comment.