Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose --dts-layout to CLI
Browse files Browse the repository at this point in the history
Fixes #124
caksoylar committed Oct 26, 2024
1 parent 6cf6c22 commit ae315bc
Showing 3 changed files with 39 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -395,6 +395,7 @@ _Default:_ `{}`
#### `zmk_preamble`

A string to prepend to ZMK keymaps before parsing that can be used to influence the parsed content.
Also used for parsing DTS format physical layouts specified with `--dts-layout`.
The default defines a `KEYMAP_DRAWER` symbol which can be used for checks with preprocessor directives.

_Type:_ `string`
@@ -403,7 +404,9 @@ _Default:_ `"#define KEYMAP_DRAWER"`

#### `zmk_additional_includes`

A list of paths to add as search paths to the preprocessor for `#include` directives. This can be needed if you use Zephyr modules such as [`zmk-helpers`](https://github.com/urob/zmk-helpers/tree/v2) since they require augmenting the search path.
A list of paths to add as search paths to the preprocessor for `#include` directives.
This can be needed if you use Zephyr modules such as [`zmk-helpers`](https://github.com/urob/zmk-helpers/tree/v2) since they require augmenting the search path.
Also used for parsing DTS format physical layouts specified with `--dts-layout`.

_Type:_ `list[str]`

26 changes: 24 additions & 2 deletions KEYMAP_SPEC.md
Original file line number Diff line number Diff line change
@@ -47,8 +47,9 @@ Following physical layout parameters can be specified either in the command line
_Example:_ `layout: {qmk_info_json: my_special_layout.json}`

- **`layout_name`** (equivalent to `-l`/`--layout-name` on the command line):
Specifies the layout macro to be used for the QMK keyboard, defaults to first one specified if not used --
should be used alongside one of the above two options.
This argument is shared with the ZMK `dts_layout` below and when used with either of above two options,
it specifies the layout macro to be used among the ones defined in the QMK info file.
Defaults to first one specified if not used, should be used alongside one of the above three options.

_Example:_ `layout: {qmk_keyboard: crkbd/rev1, layout_name: LAYOUT_split_3x5_3}`

@@ -66,6 +67,27 @@ PCBs using the "Import" tool.[^1]
For this reason it is recommended to explicitly specify `rx`, `ry` fields if `r` is specified. You might also want to omit the fields
besides `x`, `y`, `r`, `rx` and `ry` in your final JSON since they won't be used by `keymap-drawer`.

### ZMK physical layout specification

This is the [official ZMK format](https://zmk.dev/docs/development/hardware-integration/physical-layouts) for specifying physical layouts,
which are written in devicetree format and included in keyboard definitions.
It lets you specify multiple "layouts" per keyboard corresponding to different devicetree nodes to support physical variations, similar to QMK format.
The fields to specify each layout are described in the docs linked.

ZMK physical layouts in devicetree files can be specified via either in the command line or under this field definition as key-value pairs:

- **`dts_layout`** (equivalent to `-d`/`--dts-layout` on the command line):
Specifies the path to a local devicetree file containing ZMK physical layouts.

_Example:_ `layout: {dts_layout: my_keyboard-layouts.dtsi}`

- **`layout_name`** (equivalent to `-l`/`--layout-name` on the command line):
This argument is shared with the QMK options and when used with `dts_layout`, specifies the node label for
in the devicetree ZMK physical layouts file to be used for display.
Defaults to first one specified if not used.

_Example:_ `layout: {dts_layout: path/to/kyria-layouts.dtsi, layout_name: splitkb_kyria_5col_layout}`

### Parametrized ortholinear layout specification

This option lets you specify a set of parameters to automatically generate a split or non-split ortholinear layout.
14 changes: 11 additions & 3 deletions keymap_drawer/__main__.py
Original file line number Diff line number Diff line change
@@ -22,17 +22,19 @@ def draw(args: Namespace, config: Config) -> None:
yaml_data = yaml.safe_load(args.keymap_yaml)
assert "layers" in yaml_data, 'Keymap needs to be specified via the "layers" field in keymap_yaml'

if args.qmk_keyboard or args.qmk_info_json or args.ortho_layout or args.cols_thumbs_notation:
if args.qmk_keyboard or args.qmk_info_json or args.dts_layout or args.ortho_layout or args.cols_thumbs_notation:
layout = {
"qmk_keyboard": args.qmk_keyboard,
"qmk_info_json": args.qmk_info_json,
"dts_layout": args.dts_layout,
"layout_name": args.layout_name,
"ortho_layout": args.ortho_layout,
"cols_thumbs_notation": args.cols_thumbs_notation,
}
else:
assert "layout" in yaml_data, (
"A physical layout needs to be specified either via --qmk-keyboard/--layout-name/--ortho-layout, "
"A physical layout needs to be specified either via "
"--qmk-keyboard/--qmk-info-json/--dts-layout/--ortho-layout/--cols-thumbs-notation, "
'or in a "layout" field in the keymap_yaml'
)
layout = yaml_data["layout"]
@@ -114,12 +116,18 @@ def main() -> None:
help="Name of the keyboard in QMK to fetch info.json containing the physical layout info, "
"including revision if any",
)
info_srcs.add_argument(
"-d",
"--dts-layout",
help="Path to file containing ZMK physical layout definition in devicetree format",
type=Path,
)
draw_p.add_argument(
"-l",
"--layout-name",
"--qmk-layout",
help='Name of the layout to use in the QMK keyboard info file (starting with "LAYOUT_"), '
"use the first defined one by default",
"or ZMK DTS physical layout (node name). Use the first defined one if not specified",
)
draw_p.add_argument(
"--ortho-layout",

0 comments on commit ae315bc

Please sign in to comment.