Skip to content

Commit

Permalink
Merge pull request #8 from kanru/whkb-pro2-rev-a
Browse files Browse the repository at this point in the history
feat: new project layout and new boards support
  • Loading branch information
kanru authored Nov 12, 2023
2 parents 3151494 + c026ac1 commit a96e956
Show file tree
Hide file tree
Showing 37 changed files with 450 additions and 240 deletions.
87 changes: 1 addition & 86 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,5 @@
on: [push, pull_request, workflow_dispatch]

name: Build

jobs:
matrix:
runs-on: ubuntu-latest
name: Fetch Build Keyboards
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install yaml2json
run: python3 -m pip install remarshal
- id: set-matrix
name: Fetch Build Matrix
run: |
matrix=$(yaml2json build.yaml | jq -c .)
yaml2json build.yaml
echo "::set-output name=matrix::${matrix}"
build:
runs-on: ubuntu-latest
container:
image: zmkfirmware/zmk-build-arm:stable
needs: matrix
name: Build
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- name: Prepare variables
id: variables
run: |
if [ -n "${{ matrix.shield }}" ]; then
EXTRA_CMAKE_ARGS="-DSHIELD=${{ matrix.shield }}"
ARTIFACT_NAME="${{ matrix.shield }}-${{ matrix.board }}-zmk"
DISPLAY_NAME="${{ matrix.shield }} - ${{ matrix.board }}"
else
EXTRA_CMAKE_ARGS=
DISPLAY_NAME="${{ matrix.board }}"
ARTIFACT_NAME="${{ matrix.board }}-zmk"
fi
echo ::set-output name=extra-cmake-args::${EXTRA_CMAKE_ARGS}
echo ::set-output name=artifact-name::${ARTIFACT_NAME}
echo ::set-output name=display-name::${DISPLAY_NAME}
- name: Checkout
uses: actions/checkout@v2
- name: Cache west modules
uses: actions/cache@v2
env:
cache-name: cache-zephyr-modules
with:
path: |
modules/
tools/
zephyr/
bootloader/
zmk/
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('manifest-dir/west.yml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: West Init
run: west init -l config
- name: West Update
run: west update
- name: West Zephyr export
run: west zephyr-export
- name: West Build (${{ steps.variables.outputs.display-name }})
run: |
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 }}
- name: ${{ steps.variables.outputs.display-name }} Kconfig file
run: cat build/zephyr/.config | grep -v "^#" | grep -v "^$"
- name: Rename artifacts
run: |
mkdir build/artifacts
if [ -f build/zephyr/zmk.uf2 ]
then
cp build/zephyr/zmk.uf2 "build/artifacts/${{ steps.variables.outputs.artifact-name }}.uf2"
elif [ -f build/zephyr/zmk.hex ]
then
cp build/zephyr/zmk.hex "build/artifacts/${{ steps.variables.outputs.artifact-name }}.hex"
fi
- name: Archive (${{ steps.variables.outputs.display-name }})
uses: actions/upload-artifact@v2
with:
name: firmware
path: build/artifacts
uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.vscode/
/.west/
/build/
/modules/
/zephyr/
/zmk/
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- WHKB Pro2 Rev A support.

### Changed

- Upgraded to Zephyr 3.2 and latest ZMK.
- New project layout based on Zephyr recommendations.

## 1.0.0 - 2022-05-13

Initial release.

[unreleased]: https://github.com/kanru/hhkb-zmk/compare/039f708e5301819adebd99227f8592b7cd955ebe...HEAD
62 changes: 52 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
# HHKB Pro 2 with nice!nano board and ZMK firmware
# HHKB Pro 2 with ZMK firmware

This project provides an out-of-tree Zephyr module and shield definition
for the HHKB Pro2 daugther board.

The `hhkb_pro2` shield defines the default HHKB keymap and `zmk,kscan`
chosen. Any board can use the `hhkb_pro2` shield by defining the
`hhkb_pro2_connector` gpio nexus node. Examples can be find in
[custom_pro2.overlay](config/boards/shields/custom_pro2/custom_pro2.overlay) and
[whkb_pro2.dts](config/boards/arm/whkb_pro2/whkb_pro2.dts).

## Customizing

Clone this repository then add your keymap overlay to the `custom_pro2` shield.
You can also create more complex customization by creating entirely new boards or
shields.

The default Github Actions will build the firmware using the [build.yml](./build.yaml)
definition.

## Build locally

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

Add the extra kscan module:
Setup Zephyr

```sh
west init -l config
west update
```

To build nice_nano_v2 based board:

```sh
west build -s zmk/app -p -b nice_nano_v2 -- \
-DSHIELD="hhkb_pro2 custom_pro2" \
-DZMK_CONFIG=$PWD/config
```

or to build WHKB Pro2:

```sh
west build -b nice_nano_v2 -- \
-DSHIELD=hhkb \
-DZEPHYR_EXTRA_MODULES=$ZMK_PATH/app/drivers/;$WORKSPACE_PATH/config/hhkb_drivers/ \
-DZMK_CONFIG=$WORKSPACE_PATH/config
west build -s zmk/app -p -b whkb_pro2 -- \
-DSHIELD=hhkb_pro2 \
-DZMK_CONFIG=$PWD/config
```

## Soldering (WIP)
The finished UF2 file is at `build/zephyr/zmk.uf2`

## Soldering a custom board

The default configuration in `custom_pro2` is based on
the `nice_nano_v2` board. It only uses the pins on the
left side. The pins' order is upside down so the wires
can be bend easily under the case.

It take advantages of the high drive capability of nRF52
GPIO to power the HHKB Pro2 daughter board.

![parts](./images/parts.jpg)
![parts](./docs/images/parts.jpg)

![connector](./images/connector.jpg)
![connector](./docs/images/connector.jpg)

![board](./images/board.jpg)
![board](./docs/images/board.jpg)
4 changes: 3 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
#
---
include:
- board: whkb_pro2
shield: hhkb_pro2
- board: nice_nano_v2
shield: hhkb
shield: hhkb_pro2 custom_pro2
7 changes: 7 additions & 0 deletions config/boards/arm/whkb_pro2/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT

config BOARD_ENABLE_DCDC
bool "Enable DCDC mode"
select SOC_DCDC_NRF52X
default y
depends on BOARD_WHKB_PRO2
6 changes: 6 additions & 0 deletions config/boards/arm/whkb_pro2/Kconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2023 Kan-Ru Chen
# SPDX-License-Identifier: MIT

config BOARD_WHKB_PRO2
bool "WHKB Pro2"
depends on SOC_NRF52840_QIAA
28 changes: 28 additions & 0 deletions config/boards/arm/whkb_pro2/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2023 Kan-Ru Chen
# SPDX-License-Identifier: MIT

if BOARD_WHKB_PRO2

config ZMK_KEYBOARD_NAME
default "WHKB Pro2 Rev A"

config BOARD
default "whkb_pro2"

if USB_DEVICE_STACK

config USB_NRFX
default y

endif # USB_DEVICE_STACK

config BT_CTLR
default BT

config ZMK_BLE
default y

config ZMK_USB
default y

endif # BOARD_WHKB_PRO2
106 changes: 106 additions & 0 deletions config/boards/arm/whkb_pro2/whkb_pro2.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>

/ {
model = "whkb_pro2";
compatible = "applet,whkb_pro2";

chosen {
zephyr,code-partition = &code_partition;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt0;
};

vbatt0: vbatt0 {
compatible = "zmk,battery-voltage-divider";
io-channels = <&adc 1>; // P0.03
output-ohms = <2000000>;
full-ohms = <(1000000 + 2000000)>;
power-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>; // P0.02
};

hhkb_pro2_connector: hhkb_pro2_connector {
compatible = "zmk,hhkb-pro2-header";
#gpio-cells = <2>;
gpio-map-mask = <0xffffffff 0xffffffc0>;
gpio-map-pass-thru = <0 0x3f>;
gpio-map = <0 0 &gpio0 31 NRF_GPIO_DRIVE_S0H1>,
<1 0 &gpio0 4 0>,
<2 0 &gpio0 5 0>,
<3 0 &gpio0 22 0>,
<4 0 &gpio0 7 0>,
<5 0 &gpio1 9 0>,
<6 0 &gpio0 12 0>,
<7 0 &gpio0 23 0>,
<8 0 &gpio0 21 0>,
<9 0 &gpio0 19 0>;
};
};

&adc {
status = "okay";
};

&gpio0 {
status = "okay";
};

&gpio1 {
status = "okay";
};

&usbd {
status = "okay";
cdc_acm_uart: cdc_acm_uart {
compatible = "zephyr,cdc-acm-uart";
};
};

&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

sd_partition: partition@0 {
label = "softdevice";
reg = <0x00000000 0x00026000>;
};
code_partition: partition@26000 {
label = "code_partition";
reg = <0x00026000 0x000c6000>;
};

/*
* The flash starting at 0x000ec000 and ending at
* 0x000f3fff is reserved for use by the application.
*/

/*
* Storage partition will be used by FCB/LittleFS/NVS
* if enabled.
*/
storage_partition: partition@ec000 {
label = "storage";
reg = <0x000ec000 0x00008000>;
};

boot_partition: partition@f4000 {
label = "adafruit_boot";
reg = <0x000f4000 0x0000c000>;
};
};
};
24 changes: 24 additions & 0 deletions config/boards/arm/whkb_pro2/whkb_pro2_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT

CONFIG_SOC_SERIES_NRF52X=y
CONFIG_SOC_NRF52840_QIAA=y
CONFIG_BOARD_WHKB_PRO2=y

# Enable MPU
CONFIG_ARM_MPU=y

# enable GPIO
CONFIG_GPIO=y

# Use pinctrl
CONFIG_PINCTRL=y

CONFIG_USE_DT_CODE_PARTITION=y
CONFIG_BUILD_OUTPUT_UF2=y

CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_NVS=y
CONFIG_SETTINGS_NVS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
6 changes: 6 additions & 0 deletions config/boards/shields/custom_pro2/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if SHIELD_CUSTOM_PRO2

config ZMK_KEYBOARD_NAME
default "Custom HHKB Pro2"

endif
3 changes: 3 additions & 0 deletions config/boards/shields/custom_pro2/Kconfig.shield
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config SHIELD_CUSTOM_PRO2
def_bool $(shields_list_contains,custom_pro2)
depends on KSCAN_HHKB_PRO2
Loading

0 comments on commit a96e956

Please sign in to comment.