Skip to content

Commit c026ac1

Browse files
committed
feat: new project layout and new boards support
1 parent 3151494 commit c026ac1

37 files changed

+450
-240
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,5 @@
11
on: [push, pull_request, workflow_dispatch]
22

3-
name: Build
4-
53
jobs:
6-
matrix:
7-
runs-on: ubuntu-latest
8-
name: Fetch Build Keyboards
9-
outputs:
10-
matrix: ${{ steps.set-matrix.outputs.matrix }}
11-
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Install yaml2json
15-
run: python3 -m pip install remarshal
16-
- id: set-matrix
17-
name: Fetch Build Matrix
18-
run: |
19-
matrix=$(yaml2json build.yaml | jq -c .)
20-
yaml2json build.yaml
21-
echo "::set-output name=matrix::${matrix}"
224
build:
23-
runs-on: ubuntu-latest
24-
container:
25-
image: zmkfirmware/zmk-build-arm:stable
26-
needs: matrix
27-
name: Build
28-
strategy:
29-
fail-fast: false
30-
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
31-
steps:
32-
- name: Prepare variables
33-
id: variables
34-
run: |
35-
if [ -n "${{ matrix.shield }}" ]; then
36-
EXTRA_CMAKE_ARGS="-DSHIELD=${{ matrix.shield }}"
37-
ARTIFACT_NAME="${{ matrix.shield }}-${{ matrix.board }}-zmk"
38-
DISPLAY_NAME="${{ matrix.shield }} - ${{ matrix.board }}"
39-
else
40-
EXTRA_CMAKE_ARGS=
41-
DISPLAY_NAME="${{ matrix.board }}"
42-
ARTIFACT_NAME="${{ matrix.board }}-zmk"
43-
fi
44-
echo ::set-output name=extra-cmake-args::${EXTRA_CMAKE_ARGS}
45-
echo ::set-output name=artifact-name::${ARTIFACT_NAME}
46-
echo ::set-output name=display-name::${DISPLAY_NAME}
47-
- name: Checkout
48-
uses: actions/checkout@v2
49-
- name: Cache west modules
50-
uses: actions/cache@v2
51-
env:
52-
cache-name: cache-zephyr-modules
53-
with:
54-
path: |
55-
modules/
56-
tools/
57-
zephyr/
58-
bootloader/
59-
zmk/
60-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('manifest-dir/west.yml') }}
61-
restore-keys: |
62-
${{ runner.os }}-build-${{ env.cache-name }}-
63-
${{ runner.os }}-build-
64-
${{ runner.os }}-
65-
- name: West Init
66-
run: west init -l config
67-
- name: West Update
68-
run: west update
69-
- name: West Zephyr export
70-
run: west zephyr-export
71-
- name: West Build (${{ steps.variables.outputs.display-name }})
72-
run: |
73-
west build -s zmk/app -b ${{ matrix.board }} -- -DZEPHYR_EXTRA_MODULES="$PWD/zmk/app/drivers;${GITHUB_WORKSPACE}/config/hhkb_drivers" -DZMK_CONFIG=${GITHUB_WORKSPACE}/config ${{ steps.variables.outputs.extra-cmake-args }} ${{ matrix.cmake-args }}
74-
- name: ${{ steps.variables.outputs.display-name }} Kconfig file
75-
run: cat build/zephyr/.config | grep -v "^#" | grep -v "^$"
76-
- name: Rename artifacts
77-
run: |
78-
mkdir build/artifacts
79-
if [ -f build/zephyr/zmk.uf2 ]
80-
then
81-
cp build/zephyr/zmk.uf2 "build/artifacts/${{ steps.variables.outputs.artifact-name }}.uf2"
82-
elif [ -f build/zephyr/zmk.hex ]
83-
then
84-
cp build/zephyr/zmk.hex "build/artifacts/${{ steps.variables.outputs.artifact-name }}.hex"
85-
fi
86-
- name: Archive (${{ steps.variables.outputs.display-name }})
87-
uses: actions/upload-artifact@v2
88-
with:
89-
name: firmware
90-
path: build/artifacts
5+
uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.vscode/
2+
/.west/
3+
/build/
4+
/modules/
5+
/zephyr/
6+
/zmk/

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- WHKB Pro2 Rev A support.
13+
14+
### Changed
15+
16+
- Upgraded to Zephyr 3.2 and latest ZMK.
17+
- New project layout based on Zephyr recommendations.
18+
19+
## 1.0.0 - 2022-05-13
20+
21+
Initial release.
22+
23+
[unreleased]: https://github.com/kanru/hhkb-zmk/compare/039f708e5301819adebd99227f8592b7cd955ebe...HEAD

README.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,64 @@
1-
# HHKB Pro 2 with nice!nano board and ZMK firmware
1+
# HHKB Pro 2 with ZMK firmware
2+
3+
This project provides an out-of-tree Zephyr module and shield definition
4+
for the HHKB Pro2 daugther board.
5+
6+
The `hhkb_pro2` shield defines the default HHKB keymap and `zmk,kscan`
7+
chosen. Any board can use the `hhkb_pro2` shield by defining the
8+
`hhkb_pro2_connector` gpio nexus node. Examples can be find in
9+
[custom_pro2.overlay](config/boards/shields/custom_pro2/custom_pro2.overlay) and
10+
[whkb_pro2.dts](config/boards/arm/whkb_pro2/whkb_pro2.dts).
11+
12+
## Customizing
13+
14+
Clone this repository then add your keymap overlay to the `custom_pro2` shield.
15+
You can also create more complex customization by creating entirely new boards or
16+
shields.
17+
18+
The default Github Actions will build the firmware using the [build.yml](./build.yaml)
19+
definition.
220

321
## Build locally
422

523
Follow the steps in the [official ZMK document](https://zmk.dev/docs/user-setup) to setup build environment.
624

7-
Add the extra kscan module:
25+
Setup Zephyr
26+
27+
```sh
28+
west init -l config
29+
west update
30+
```
31+
32+
To build nice_nano_v2 based board:
33+
34+
```sh
35+
west build -s zmk/app -p -b nice_nano_v2 -- \
36+
-DSHIELD="hhkb_pro2 custom_pro2" \
37+
-DZMK_CONFIG=$PWD/config
38+
```
39+
40+
or to build WHKB Pro2:
841

942
```sh
10-
west build -b nice_nano_v2 -- \
11-
-DSHIELD=hhkb \
12-
-DZEPHYR_EXTRA_MODULES=$ZMK_PATH/app/drivers/;$WORKSPACE_PATH/config/hhkb_drivers/ \
13-
-DZMK_CONFIG=$WORKSPACE_PATH/config
43+
west build -s zmk/app -p -b whkb_pro2 -- \
44+
-DSHIELD=hhkb_pro2 \
45+
-DZMK_CONFIG=$PWD/config
1446
```
1547

16-
## Soldering (WIP)
48+
The finished UF2 file is at `build/zephyr/zmk.uf2`
49+
50+
## Soldering a custom board
51+
52+
The default configuration in `custom_pro2` is based on
53+
the `nice_nano_v2` board. It only uses the pins on the
54+
left side. The pins' order is upside down so the wires
55+
can be bend easily under the case.
56+
57+
It take advantages of the high drive capability of nRF52
58+
GPIO to power the HHKB Pro2 daughter board.
1759

18-
![parts](./images/parts.jpg)
60+
![parts](./docs/images/parts.jpg)
1961

20-
![connector](./images/connector.jpg)
62+
![connector](./docs/images/connector.jpg)
2163

22-
![board](./images/board.jpg)
64+
![board](./docs/images/board.jpg)

build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
#
1414
---
1515
include:
16+
- board: whkb_pro2
17+
shield: hhkb_pro2
1618
- board: nice_nano_v2
17-
shield: hhkb
19+
shield: hhkb_pro2 custom_pro2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
config BOARD_ENABLE_DCDC
4+
bool "Enable DCDC mode"
5+
select SOC_DCDC_NRF52X
6+
default y
7+
depends on BOARD_WHKB_PRO2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2023 Kan-Ru Chen
2+
# SPDX-License-Identifier: MIT
3+
4+
config BOARD_WHKB_PRO2
5+
bool "WHKB Pro2"
6+
depends on SOC_NRF52840_QIAA
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2023 Kan-Ru Chen
2+
# SPDX-License-Identifier: MIT
3+
4+
if BOARD_WHKB_PRO2
5+
6+
config ZMK_KEYBOARD_NAME
7+
default "WHKB Pro2 Rev A"
8+
9+
config BOARD
10+
default "whkb_pro2"
11+
12+
if USB_DEVICE_STACK
13+
14+
config USB_NRFX
15+
default y
16+
17+
endif # USB_DEVICE_STACK
18+
19+
config BT_CTLR
20+
default BT
21+
22+
config ZMK_BLE
23+
default y
24+
25+
config ZMK_USB
26+
default y
27+
28+
endif # BOARD_WHKB_PRO2
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2021 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
/dts-v1/;
8+
#include <nordic/nrf52840_qiaa.dtsi>
9+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
10+
11+
/ {
12+
model = "whkb_pro2";
13+
compatible = "applet,whkb_pro2";
14+
15+
chosen {
16+
zephyr,code-partition = &code_partition;
17+
zephyr,sram = &sram0;
18+
zephyr,flash = &flash0;
19+
zephyr,console = &cdc_acm_uart;
20+
zmk,battery = &vbatt0;
21+
};
22+
23+
vbatt0: vbatt0 {
24+
compatible = "zmk,battery-voltage-divider";
25+
io-channels = <&adc 1>; // P0.03
26+
output-ohms = <2000000>;
27+
full-ohms = <(1000000 + 2000000)>;
28+
power-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>; // P0.02
29+
};
30+
31+
hhkb_pro2_connector: hhkb_pro2_connector {
32+
compatible = "zmk,hhkb-pro2-header";
33+
#gpio-cells = <2>;
34+
gpio-map-mask = <0xffffffff 0xffffffc0>;
35+
gpio-map-pass-thru = <0 0x3f>;
36+
gpio-map = <0 0 &gpio0 31 NRF_GPIO_DRIVE_S0H1>,
37+
<1 0 &gpio0 4 0>,
38+
<2 0 &gpio0 5 0>,
39+
<3 0 &gpio0 22 0>,
40+
<4 0 &gpio0 7 0>,
41+
<5 0 &gpio1 9 0>,
42+
<6 0 &gpio0 12 0>,
43+
<7 0 &gpio0 23 0>,
44+
<8 0 &gpio0 21 0>,
45+
<9 0 &gpio0 19 0>;
46+
};
47+
};
48+
49+
&adc {
50+
status = "okay";
51+
};
52+
53+
&gpio0 {
54+
status = "okay";
55+
};
56+
57+
&gpio1 {
58+
status = "okay";
59+
};
60+
61+
&usbd {
62+
status = "okay";
63+
cdc_acm_uart: cdc_acm_uart {
64+
compatible = "zephyr,cdc-acm-uart";
65+
};
66+
};
67+
68+
&flash0 {
69+
/*
70+
* For more information, see:
71+
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
72+
*/
73+
partitions {
74+
compatible = "fixed-partitions";
75+
#address-cells = <1>;
76+
#size-cells = <1>;
77+
78+
sd_partition: partition@0 {
79+
label = "softdevice";
80+
reg = <0x00000000 0x00026000>;
81+
};
82+
code_partition: partition@26000 {
83+
label = "code_partition";
84+
reg = <0x00026000 0x000c6000>;
85+
};
86+
87+
/*
88+
* The flash starting at 0x000ec000 and ending at
89+
* 0x000f3fff is reserved for use by the application.
90+
*/
91+
92+
/*
93+
* Storage partition will be used by FCB/LittleFS/NVS
94+
* if enabled.
95+
*/
96+
storage_partition: partition@ec000 {
97+
label = "storage";
98+
reg = <0x000ec000 0x00008000>;
99+
};
100+
101+
boot_partition: partition@f4000 {
102+
label = "adafruit_boot";
103+
reg = <0x000f4000 0x0000c000>;
104+
};
105+
};
106+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
CONFIG_SOC_SERIES_NRF52X=y
4+
CONFIG_SOC_NRF52840_QIAA=y
5+
CONFIG_BOARD_WHKB_PRO2=y
6+
7+
# Enable MPU
8+
CONFIG_ARM_MPU=y
9+
10+
# enable GPIO
11+
CONFIG_GPIO=y
12+
13+
# Use pinctrl
14+
CONFIG_PINCTRL=y
15+
16+
CONFIG_USE_DT_CODE_PARTITION=y
17+
CONFIG_BUILD_OUTPUT_UF2=y
18+
19+
CONFIG_MPU_ALLOW_FLASH_WRITE=y
20+
CONFIG_NVS=y
21+
CONFIG_SETTINGS_NVS=y
22+
CONFIG_FLASH=y
23+
CONFIG_FLASH_PAGE_LAYOUT=y
24+
CONFIG_FLASH_MAP=y

0 commit comments

Comments
 (0)