Skip to content

Commit e4db9e5

Browse files
committed
Update templates for hardware model v2
Updated the board templates for "zmk keyboard new" to support Zephyr's hardware model v2. Also updated links to Zephyr's documentation to point to Zephyr 4.1 to match the ZMK update that brings in hardware model v2.
1 parent af636fb commit e4db9e5

32 files changed

+132
-67
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ Run `zmk keyboard list` to print a list of supported keyboard hardware.
157157

158158
If ZMK doesn't support your keyboard yet, you can run `zmk keyboard new` to create a new keyboard from a template.
159159

160-
This won't walk you through all of the details of adding support for a new keyboard, but it will generate most of the boilerplate for you. See the [New Keyboard Shield](https://zmk.dev/docs/development/hardware-integration/new-shield) guide for how to finish writing the keyboard files.
160+
Note that this will generate most of the boilerplate for you, but you will still need to manually edit the files to match your keyboard. See the [New Keyboard Shield](https://zmk.dev/docs/development/hardware-integration/new-shield) guide for how to finish writing the keyboard files.
161161

162162
## Module Management
163163

164-
[Zephyr modules](https://docs.zephyrproject.org/3.5.0/develop/modules.html) can add support for new keyboards, behaviors, and other features to ZMK. Use the `zmk module` command to install modules into your repo:
164+
[Zephyr modules](https://docs.zephyrproject.org/4.1.0/develop/modules.html) can add support for new keyboards, behaviors, and other features to ZMK. Use the `zmk module` command to install modules into your repo:
165165

166166
```sh
167167
zmk module add # Add a module

zmk/commands/keyboard/new.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def keyboard_new(
117117
callback=_short_name_callback,
118118
),
119119
] = None,
120+
vendor: Annotated[
121+
str | None, typer.Option("--vendor", "-v", help="Keyboard vendor ID")
122+
] = None,
120123
keyboard_type: Annotated[
121124
KeyboardType | None,
122125
typer.Option(
@@ -129,6 +132,7 @@ def keyboard_new(
129132
KeyboardPlatform | None,
130133
typer.Option(
131134
"--platform",
135+
"--soc",
132136
"-p",
133137
help="If creating a board, the platform/SoC on which it is based.",
134138
),
@@ -171,6 +175,11 @@ def keyboard_new(
171175
if not keyboard_type:
172176
keyboard_type = _prompt_keyboard_type()
173177

178+
if not vendor and keyboard_type == KeyboardType.BOARD:
179+
print("Boards are typically organized into folders by vendor name.")
180+
print("(You may leave this blank to not create a vendor folder.)")
181+
vendor = VendorPrompt.ask()
182+
174183
if not interconnect_id and keyboard_type == KeyboardType.SHIELD:
175184
interconnect = _prompt_interconnect(repo)
176185
else:
@@ -357,6 +366,22 @@ def ask( # pyright: ignore[reportIncompatibleMethodOverride]
357366
return result
358367

359368

369+
class VendorPrompt(NamePromptBase):
370+
"""Prompt for a vendor identifier."""
371+
372+
@classmethod
373+
def validate(cls, value: str) -> None:
374+
if not value:
375+
# Vendor is allowed to be blank
376+
return
377+
378+
_validate_id(value)
379+
380+
@classmethod
381+
def ask(cls) -> str: # pyright: ignore[reportIncompatibleMethodOverride]
382+
return super().ask("Enter an ID for the vendor")
383+
384+
360385
_DEFAULT_ARCH = "arm"
361386
_PLATFORM_ARCH: dict[KeyboardPlatform, str] = {
362387
KeyboardPlatform.NRF52840: "arm",
@@ -376,15 +401,20 @@ def _get_template(
376401
short_name: str,
377402
keyboard_id: str,
378403
interconnect: Interconnect | None = None,
404+
vendor: str | None = None,
379405
):
380406
template = TemplateData()
381407
template.data["id"] = keyboard_id
382408
template.data["name"] = keyboard_name
383409
template.data["shortname"] = short_name
410+
template.data["vendor"] = vendor or ""
384411
template.data["keyboard_type"] = str(keyboard_type)
385412
template.data["interconnect"] = ""
386413
template.data["arch"] = ""
387414
template.data["gpio"] = _DEFAULT_GPIO
415+
template.data["soc"] = (
416+
"" if keyboard_platform == KeyboardPlatform.OTHER else str(keyboard_platform)
417+
)
388418

389419
match keyboard_type:
390420
case KeyboardType.SHIELD:
@@ -404,7 +434,7 @@ def _get_template(
404434
template.data["gpio"] = _PLATFORM_GPIO.get(keyboard_platform, _DEFAULT_GPIO)
405435

406436
template.folder = f"board/{keyboard_platform}/"
407-
template.dest = f"{arch}/{keyboard_id}"
437+
template.dest = f"{vendor}/{keyboard_id}" if vendor else keyboard_id
408438

409439
match keyboard_layout:
410440
case KeyboardLayout.UNIBODY:
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
# This file was generated from a template. Edit it to match your keyboard.
2-
# See https://docs.zephyrproject.org/3.5.0/hardware/porting/board_porting.html#write-kconfig-files
2+
# See https://docs.zephyrproject.org/4.1.0/hardware/porting/board_porting.html#write-kconfig-files
33
# for more information.
44

55
if ${self.guard() | trim}
66

7-
config BOARD_ENABLE_DCDC
8-
bool "DCDC mode"
9-
select SOC_DCDC_NRF52X
10-
default y
11-
12-
# Uncomment this block if you are powering the SoC from the VDDH pin and have
13-
# an inductor between VDD and DCCH. Otherwise, delete this block.
14-
# WARNING: uncommenting this without the correct inductor will brick the device
15-
# and require reprogramming it with a J-Link or similar debug probe!
16-
17-
# config BOARD_ENABLE_DCDC_HV
18-
# bool "High Voltage DCDC converter"
19-
# select SOC_DCDC_NRF52X_HV
20-
# default y
7+
# Define any board-specific Kconfig options here.
8+
# If there are none, you may delete this file.
219

2210
endif # ${self.guard() | trim}

zmk/templates/board/nrf52840/Kconfig.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was generated from a template. Edit it to match your keyboard.
2-
# See https://docs.zephyrproject.org/3.5.0/hardware/porting/board_porting.html#write-kconfig-files
2+
# See https://docs.zephyrproject.org/4.1.0/hardware/porting/board_porting.html#write-kconfig-files
33
# for more information.
44

55
<%block name="before" />

zmk/templates/board/nrf52840/board.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was generated from a template. Edit it to match your keyboard.
2-
# See https://docs.zephyrproject.org/3.5.0/develop/test/twister.html#board-configuration
2+
# See https://docs.zephyrproject.org/4.1.0/develop/test/twister.html#board-configuration
33
# for more information.
44

55
identifier: ${id}

zmk/templates/board/nrf52840/board_defconfig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# This file was generated from a template. Edit it to match your keyboard.
2-
# See https://docs.zephyrproject.org/3.5.0/hardware/porting/board_porting.html#write-kconfig-files
2+
# See https://docs.zephyrproject.org/4.1.0/hardware/porting/board_porting.html#write-kconfig-files
33
# for more information.
44

5-
CONFIG_SOC_SERIES_NRF52X=y
6-
CONFIG_SOC_NRF52840_QIAA=y
7-
CONFIG_BOARD_${id.upper()}=y
8-
95
# Enable MPU
106
CONFIG_ARM_MPU=y
117

zmk/templates/board/nrf52840/common_outer.dtsi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Uncomment this to switch from the LDO to the DC/DC regulator on REG0.
2+
// Do not enable the DC/DC regulator without an LC filter connected to the DCCH
3+
// pin, or the keyboard will not boot until an LC filter is connected.
4+
// &reg0 {
5+
// status = "okay";
6+
// };
7+
8+
// Uncomment this to switch from the LDO to the DC/DC regulator on REG1.
9+
// Do not enable the DC/DC regulator without an LC filter connected to the DCC
10+
// pin, or the keyboard will not boot until an LC filter is connected.
11+
// &reg1 {
12+
// regulator-initial-mode = <NRF5X_REG_MODE_DCDC>;
13+
// };
14+
115
&adc {
216
status = "okay";
317
};
@@ -22,13 +36,18 @@
2236
pinctrl-names = "default", "sleep";
2337
};
2438

39+
// If you use the NFC pins as GPIOs, uncomment this. Otherwise, remove it.
40+
// &uicr {
41+
// nfct-pins-as-gpios;
42+
// };
43+
2544
zephyr_udc0: &usbd {
2645
status = "okay";
2746
};
2847

2948
&flash0 {
3049
// Adjust this flash map as is necessary for your board. For more information, see
31-
// https://docs.zephyrproject.org/3.5.0/services/storage/flash_map/flash_map.html#relationship-with-devicetree
50+
// https://docs.zephyrproject.org/4.1.0/services/storage/flash_map/flash_map.html#relationship-with-devicetree
3251
partitions {
3352
compatible = "fixed-partitions";
3453
#address-cells = <1>;

zmk/templates/board/nrf52840/pinctrl.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file was generated from a template. Edit it to match your keyboard.
2-
// See https://docs.zephyrproject.org/3.5.0/hardware/porting/board_porting.html
3-
// and https://docs.zephyrproject.org/3.5.0/hardware/pinctrl/index.html for
2+
// See https://docs.zephyrproject.org/4.1.0/hardware/porting/board_porting.html
3+
// and https://docs.zephyrproject.org/4.1.0/hardware/pinctrl/index.html for
44
// more instructions.
55

66
#include <dt-bindings/pinctrl/nrf-pinctrl.h>

zmk/templates/board/nrf52840/split/${id}.dtsi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<%block name="chosen">
66
chosen {
77
zephyr,code-partition = &code_partition;
8-
zephyr,console = &cdc_acm_uart;
98
zephyr,sram = &sram0;
109
zephyr,flash = &flash0;
1110
// Uncomment this if you enabled one of the "vddh" nodes below.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config BOARD_${id.upper()}_LEFT
2+
select SOC_NRF52840_QIAA
3+
imply RETAINED_MEM
4+
imply RETENTION
5+
imply RETENTION_BOOT_MODE

0 commit comments

Comments
 (0)