forked from zmkfirmware/zmk
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add keyboard physical layout system.
* Add bindings to allow creating multiple physical layouts that specify their key's physical attributes, and the matching matrix transform and dependant kscan to use. * Synthesize a basic physical layout if none specified, for backwards compatibility. * Update matrix transform API to explicitly pass in the selected transform to the API instead of using a fixed chosen transform. * Move kscan subscription and handling into the physical layout code, so that selecting a different physical layout at runtime can also use the correct kscan instance. * Add `physical_layouts.dtsi` file to include so you can use the pre-configured `&key_physical_attrs` for adding you layout keys.
- Loading branch information
1 parent
f18974e
commit 3ecee59
Showing
13 changed files
with
606 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright (c) 2024 The ZMK Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: | | ||
The physical attributes of a key, including size, location, and rotation | ||
compatible: "zmk,key-physical-attrs" | ||
|
||
properties: | ||
"#key-cells": | ||
type: int | ||
required: true | ||
const: 7 | ||
|
||
key-cells: | ||
- width | ||
- height | ||
- x | ||
- y | ||
- r | ||
- rx | ||
- ry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) 2024 The ZMK Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: | | ||
Describes how to correlate equivalent keys between layouts that don't have the exact same X,Y location. | ||
compatible: "zmk,physical-layout-position-map" | ||
|
||
properties: | ||
complete: | ||
type: boolean | ||
description: If the mapping complete describes the key mapping, and no position based mapping should be used. | ||
|
||
child-binding: | ||
properties: | ||
physical-layout: | ||
type: phandle | ||
description: The physical layout that corresponds to this mapping entry. | ||
positions: | ||
type: array | ||
description: Array of key positions that match the same array entry in the other sibling nodes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# Copyright (c) 2024 The ZMK Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: | | ||
Describe the physical layout of a keyboard, including deps like the transform and kscan | ||
that are needed for that layout to work. | ||
compatible: "zmk,physical-layout" | ||
|
||
properties: | ||
display-name: | ||
type: string | ||
required: true | ||
description: The name of this layout to display in the UI | ||
transform: | ||
type: phandle | ||
required: true | ||
description: The matrix transform to use along with this layout. | ||
kscan: | ||
type: phandle | ||
description: The kscan to use along with this layout. | ||
keys: | ||
type: phandle-array | ||
description: Array of key physical attributes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/ { | ||
key_physical_attrs: key_physical_attrs { | ||
compatible = "zmk,key-physical-attrs"; | ||
|
||
#key-cells = <7>; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zmk/matrix_transform.h> | ||
|
||
struct zmk_key_physical_attrs { | ||
int16_t width; | ||
int16_t height; | ||
int16_t x; | ||
int16_t y; | ||
int16_t rx; | ||
int16_t ry; | ||
int16_t r; | ||
}; | ||
|
||
struct zmk_physical_layout { | ||
const char *display_name; | ||
|
||
zmk_matrix_transform_t matrix_transform; | ||
const struct device *kscan; | ||
|
||
const struct zmk_key_physical_attrs *keys; | ||
size_t keys_len; | ||
}; | ||
|
||
#define ZMK_PHYS_LAYOUTS_FOREACH(_ref) STRUCT_SECTION_FOREACH(zmk_physical_layout, _ref) | ||
|
||
size_t zmk_physical_layouts_get_list(struct zmk_physical_layout const *const **phys_layouts); | ||
|
||
int zmk_physical_layouts_select(uint8_t index); | ||
int zmk_physical_layouts_get_selected(void); | ||
|
||
int zmk_physical_layouts_check_unsaved_selection(void); | ||
int zmk_physical_layouts_save_selected(void); | ||
int zmk_physical_layouts_revert_selected(void); | ||
|
||
int zmk_physical_layouts_get_position_map(uint8_t source, uint8_t dest, uint32_t *map); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.