diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30e216e..d74fb89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..805a7b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.vscode/ +/.west/ +/build/ +/modules/ +/zephyr/ +/zmk/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3e5de87 --- /dev/null +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 7780edf..6f9cfd6 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build.yaml b/build.yaml index 8d6b4f3..53b1c10 100644 --- a/build.yaml +++ b/build.yaml @@ -13,5 +13,7 @@ # --- include: + - board: whkb_pro2 + shield: hhkb_pro2 - board: nice_nano_v2 - shield: hhkb + shield: hhkb_pro2 custom_pro2 diff --git a/config/boards/arm/whkb_pro2/Kconfig b/config/boards/arm/whkb_pro2/Kconfig new file mode 100644 index 0000000..5532569 --- /dev/null +++ b/config/boards/arm/whkb_pro2/Kconfig @@ -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 diff --git a/config/boards/arm/whkb_pro2/Kconfig.board b/config/boards/arm/whkb_pro2/Kconfig.board new file mode 100644 index 0000000..3a027ee --- /dev/null +++ b/config/boards/arm/whkb_pro2/Kconfig.board @@ -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 \ No newline at end of file diff --git a/config/boards/arm/whkb_pro2/Kconfig.defconfig b/config/boards/arm/whkb_pro2/Kconfig.defconfig new file mode 100644 index 0000000..ceb9557 --- /dev/null +++ b/config/boards/arm/whkb_pro2/Kconfig.defconfig @@ -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 \ No newline at end of file diff --git a/config/boards/arm/whkb_pro2/whkb_pro2.dts b/config/boards/arm/whkb_pro2/whkb_pro2.dts new file mode 100644 index 0000000..f406008 --- /dev/null +++ b/config/boards/arm/whkb_pro2/whkb_pro2.dts @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/dts-v1/; +#include +#include + +/ { + 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>; + }; + }; +}; diff --git a/config/boards/arm/whkb_pro2/whkb_pro2_defconfig b/config/boards/arm/whkb_pro2/whkb_pro2_defconfig new file mode 100644 index 0000000..da6258f --- /dev/null +++ b/config/boards/arm/whkb_pro2/whkb_pro2_defconfig @@ -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 diff --git a/config/boards/shields/custom_pro2/Kconfig.defconfig b/config/boards/shields/custom_pro2/Kconfig.defconfig new file mode 100644 index 0000000..d875812 --- /dev/null +++ b/config/boards/shields/custom_pro2/Kconfig.defconfig @@ -0,0 +1,6 @@ +if SHIELD_CUSTOM_PRO2 + +config ZMK_KEYBOARD_NAME + default "Custom HHKB Pro2" + +endif \ No newline at end of file diff --git a/config/boards/shields/custom_pro2/Kconfig.shield b/config/boards/shields/custom_pro2/Kconfig.shield new file mode 100644 index 0000000..cb39f97 --- /dev/null +++ b/config/boards/shields/custom_pro2/Kconfig.shield @@ -0,0 +1,3 @@ +config SHIELD_CUSTOM_PRO2 + def_bool $(shields_list_contains,custom_pro2) + depends on KSCAN_HHKB_PRO2 \ No newline at end of file diff --git a/config/boards/shields/custom_pro2/custom_pro2.overlay b/config/boards/shields/custom_pro2/custom_pro2.overlay new file mode 100644 index 0000000..eaa24e0 --- /dev/null +++ b/config/boards/shields/custom_pro2/custom_pro2.overlay @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022, 2023 Kan-Ru Chen + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + model = "custom_pro2"; + compatible = "kanru,hhkb_pro2"; + + 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 &gpio1 6 NRF_GPIO_DRIVE_S0H1>, + <1 0 &gpio1 4 0>, + <2 0 &gpio0 11 0>, + <3 0 &gpio1 0 0>, + <4 0 &gpio0 24 0>, + <5 0 &gpio0 22 0>, + <6 0 &gpio0 20 0>, + <7 0 &gpio0 17 0>, + <8 0 &gpio0 8 0>, + <9 0 &gpio0 6 0>; + }; +}; \ No newline at end of file diff --git a/config/boards/shields/hhkb/Kconfig.defconfig b/config/boards/shields/hhkb/Kconfig.defconfig deleted file mode 100644 index a31e43a..0000000 --- a/config/boards/shields/hhkb/Kconfig.defconfig +++ /dev/null @@ -1,6 +0,0 @@ -if SHIELD_HHKB - -config ZMK_KEYBOARD_NAME - default "HHKB" - -endif diff --git a/config/boards/shields/hhkb/Kconfig.shield b/config/boards/shields/hhkb/Kconfig.shield deleted file mode 100644 index 5cf15e0..0000000 --- a/config/boards/shields/hhkb/Kconfig.shield +++ /dev/null @@ -1,2 +0,0 @@ -config SHIELD_HHKB - def_bool $(shields_list_contains,hhkb) \ No newline at end of file diff --git a/config/boards/shields/hhkb/hhkb.conf b/config/boards/shields/hhkb/hhkb.conf deleted file mode 100644 index c72923b..0000000 --- a/config/boards/shields/hhkb/hhkb.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_BT_MAX_PAIRED=3 - -CONFIG_ZMK_IDLE_TIMEOUT=5000 -CONFIG_ZMK_SLEEP=y -CONFIG_ZMK_IDLE_SLEEP_TIMEOUT=900000 -CONFIG_ZMK_BLE=y -CONFIG_ZMK_EXT_POWER=n - -CONFIG_ZMK_BATTERY_REPORT_INTERVAL=3600 \ No newline at end of file diff --git a/config/boards/shields/hhkb/hhkb.overlay b/config/boards/shields/hhkb/hhkb.overlay deleted file mode 100644 index 734005e..0000000 --- a/config/boards/shields/hhkb/hhkb.overlay +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -/ { - chosen { - zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; - }; - - kscan0: kscan_0 { - compatible = "zmk,kscan-gpio-topre"; - label = "KSCAN"; - gpios = <&pro_micro_d 9 GPIO_ACTIVE_HIGH>, /* 0: POWER */ - <&pro_micro_d 8 (GPIO_ACTIVE_LOW|GPIO_PULL_UP)>, /* 1: KEY */ - <&pro_micro_d 7 GPIO_ACTIVE_HIGH>, /* 2: HYS */ - <&pro_micro_d 6 GPIO_ACTIVE_HIGH>, /* 3: BIT0 */ - <&pro_micro_d 5 GPIO_ACTIVE_HIGH>, /* 4: BIT1 */ - <&pro_micro_d 4 GPIO_ACTIVE_HIGH>, /* 5: BIT2 */ - <&pro_micro_d 3 GPIO_ACTIVE_HIGH>, /* 6: BIT3 */ - <&pro_micro_d 2 GPIO_ACTIVE_HIGH>, /* 7: BIT4 */ - <&pro_micro_d 0 GPIO_ACTIVE_HIGH>, /* 8: BIT5 */ - <&pro_micro_d 1 GPIO_ACTIVE_HIGH>; /* 9: STROBE */ - }; - - pm_wake_sensor { - compatible = "zmk,pm-wake-sensor"; - status = "okay"; - power-gpios = <&pro_micro_d 19 GPIO_ACTIVE_HIGH>; - sensor-gpios = <&pro_micro_d 10 (GPIO_ACTIVE_LOW|GPIO_PULL_DOWN)>; - }; - - default_transform: keymap_transform_0 { - compatible = "zmk,matrix-transform"; - columns = <8>; - rows = <8>; - map = < - RC(3,1) RC(3,0) RC(0,0) RC(1,0) RC(1,1) RC(2,0) RC(2,1) RC(4,0) RC(4,1) RC(6,0) RC(6,1) RC(7,0) RC(7,1) RC(5,0) RC(5,1) - RC(3,2) RC(0,1) RC(0,2) RC(1,3) RC(1,2) RC(2,3) RC(2,2) RC(4,2) RC(4,3) RC(6,2) RC(6,3) RC(7,3) RC(7,2) RC(5,2) - RC(3,3) RC(0,4) RC(0,3) RC(1,4) RC(1,5) RC(2,4) RC(2,5) RC(4,5) RC(4,4) RC(6,5) RC(6,4) RC(7,4) RC(5,3) - RC(3,4) RC(0,5) RC(0,6) RC(0,7) RC(1,6) RC(1,7) RC(2,6) RC(4,6) RC(6,6) RC(7,6) RC(7,5) RC(5,5) RC(5,4) - RC(3,5) RC(3,6) RC(3,7) RC(5,7) RC(5,6) - >; - }; -}; \ No newline at end of file diff --git a/config/hhkb_drivers/Kconfig b/config/boards/shields/hhkb_pro2/Kconfig.defconfig similarity index 100% rename from config/hhkb_drivers/Kconfig rename to config/boards/shields/hhkb_pro2/Kconfig.defconfig diff --git a/config/boards/shields/hhkb_pro2/Kconfig.shield b/config/boards/shields/hhkb_pro2/Kconfig.shield new file mode 100644 index 0000000..b4534c6 --- /dev/null +++ b/config/boards/shields/hhkb_pro2/Kconfig.shield @@ -0,0 +1,3 @@ +config SHIELD_HHKB_PRO2 + def_bool $(shields_list_contains,hhkb_pro2) + depends on KSCAN_HHKB_PRO2 \ No newline at end of file diff --git a/config/boards/shields/hhkb/hhkb.keymap b/config/boards/shields/hhkb_pro2/hhkb_pro2.keymap similarity index 100% rename from config/boards/shields/hhkb/hhkb.keymap rename to config/boards/shields/hhkb_pro2/hhkb_pro2.keymap diff --git a/config/boards/shields/hhkb_pro2/hhkb_pro2.overlay b/config/boards/shields/hhkb_pro2/hhkb_pro2.overlay new file mode 100644 index 0000000..fdb0188 --- /dev/null +++ b/config/boards/shields/hhkb_pro2/hhkb_pro2.overlay @@ -0,0 +1,36 @@ +#include +#include + +/ { + chosen { + zmk,kscan = &kscan0; + zmk,matrix_transform = &default_transform; + }; + + kscan0: kscan0 { + compatible = "zmk,kscan-hhkb-pro2"; + gpios = <&hhkb_pro2_connector 0 GPIO_ACTIVE_HIGH>, /* 0: POWER */ + <&hhkb_pro2_connector 1 (GPIO_ACTIVE_LOW|GPIO_PULL_UP)>, /* 1: KEY */ + <&hhkb_pro2_connector 2 GPIO_ACTIVE_HIGH>, /* 2: HYS */ + <&hhkb_pro2_connector 3 GPIO_ACTIVE_HIGH>, /* 3: BIT0 */ + <&hhkb_pro2_connector 4 GPIO_ACTIVE_HIGH>, /* 4: BIT1 */ + <&hhkb_pro2_connector 5 GPIO_ACTIVE_HIGH>, /* 5: BIT2 */ + <&hhkb_pro2_connector 6 GPIO_ACTIVE_HIGH>, /* 6: BIT3 */ + <&hhkb_pro2_connector 7 GPIO_ACTIVE_HIGH>, /* 7: BIT4 */ + <&hhkb_pro2_connector 8 GPIO_ACTIVE_HIGH>, /* 8: BIT5 */ + <&hhkb_pro2_connector 9 GPIO_ACTIVE_HIGH>; /* 9: STROBE */ + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <8>; + rows = <8>; + map = < + RC(3,1) RC(3,0) RC(0,0) RC(1,0) RC(1,1) RC(2,0) RC(2,1) RC(4,0) RC(4,1) RC(6,0) RC(6,1) RC(7,0) RC(7,1) RC(5,0) RC(5,1) + RC(3,2) RC(0,1) RC(0,2) RC(1,3) RC(1,2) RC(2,3) RC(2,2) RC(4,2) RC(4,3) RC(6,2) RC(6,3) RC(7,3) RC(7,2) RC(5,2) + RC(3,3) RC(0,4) RC(0,3) RC(1,4) RC(1,5) RC(2,4) RC(2,5) RC(4,5) RC(4,4) RC(6,5) RC(6,4) RC(7,4) RC(5,3) + RC(3,4) RC(0,5) RC(0,6) RC(0,7) RC(1,6) RC(1,7) RC(2,6) RC(4,6) RC(6,6) RC(7,6) RC(7,5) RC(5,5) RC(5,4) + RC(3,5) RC(3,6) RC(3,7) RC(5,7) RC(5,6) + >; + }; +}; \ No newline at end of file diff --git a/config/dts/bindings/hhkb_pro2/zmk,hhkb-pro2-header.yaml b/config/dts/bindings/hhkb_pro2/zmk,hhkb-pro2-header.yaml new file mode 100644 index 0000000..f6b4e29 --- /dev/null +++ b/config/dts/bindings/hhkb_pro2/zmk,hhkb-pro2-header.yaml @@ -0,0 +1,28 @@ +# Copyright (c) 2022 Kan-Ru Chen +# SPDX-License-Identifier: MIT + +description: | + Pins exposed on HHKB Pro2 daughter board header. + + This binding provides a nexus mapping for the 13 pin header found + on the HHKB Pro2 daugther board. + + Header | Pin | name + -------+-----+----- + 1 P0 VCC + 2 P0 VCC + 3 P1 KEY + 4 P2 HYS + 5 P3 BIT0 + 6 P4 BIT1 + 7 P5 BIT2 + 8 P6 BIT3 + 9 P7 BIT4 + 10 P8 BIT5 + 11 P9 STROBE + 12 P10 GND + 13 P10 GND + +compatible: "zmk,hhkb-pro2-header" + +include: [base.yaml, gpio-nexus.yaml] diff --git a/config/dts/bindings/kscan/zmk,kscan-gpio-topre.yaml b/config/dts/bindings/kscan/zmk,kscan-hhkb-pro2.yaml similarity index 84% rename from config/dts/bindings/kscan/zmk,kscan-gpio-topre.yaml rename to config/dts/bindings/kscan/zmk,kscan-hhkb-pro2.yaml index bf14ac2..6d430e7 100644 --- a/config/dts/bindings/kscan/zmk,kscan-gpio-topre.yaml +++ b/config/dts/bindings/kscan/zmk,kscan-hhkb-pro2.yaml @@ -1,9 +1,9 @@ # Copyright (c) 2022 Kan-Ru Chen # SPDX-License-Identifier: MIT -description: GPIO topre keyboard controller +description: HHKB Pro2 keyboard controller -compatible: "zmk,kscan-gpio-topre" +compatible: "zmk,kscan-hhkb-pro2" include: kscan.yaml diff --git a/config/hhkb_drivers/CMakeLists.txt b/config/hhkb_drivers/CMakeLists.txt deleted file mode 100644 index fb2887d..0000000 --- a/config/hhkb_drivers/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(kscan) -add_subdirectory(pm) \ No newline at end of file diff --git a/config/hhkb_drivers/zephyr/module.yml b/config/hhkb_drivers/zephyr/module.yml deleted file mode 100644 index 63729da..0000000 --- a/config/hhkb_drivers/zephyr/module.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: hhkb_drivers -build: - depends: - - drivers - cmake: . - kconfig: Kconfig diff --git a/config/zephyr/CMakeLists.txt b/config/zephyr/CMakeLists.txt new file mode 100644 index 0000000..ef96116 --- /dev/null +++ b/config/zephyr/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory_ifdef(CONFIG_KSCAN_HHKB_PRO2 kscan) +add_subdirectory_ifdef(CONFIG_PM_WAKE_SENSOR pm) \ No newline at end of file diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig new file mode 100644 index 0000000..88dcd0e --- /dev/null +++ b/config/zephyr/Kconfig @@ -0,0 +1,7 @@ +config KSCAN_HHKB_PRO2 + bool "HHKB Pro2 daugther board driver" + default y + +config PM_WAKE_SENSOR + bool + default n \ No newline at end of file diff --git a/config/hhkb_drivers/kscan/CMakeLists.txt b/config/zephyr/kscan/CMakeLists.txt similarity index 80% rename from config/hhkb_drivers/kscan/CMakeLists.txt rename to config/zephyr/kscan/CMakeLists.txt index 8d7f154..eb87cba 100644 --- a/config/hhkb_drivers/kscan/CMakeLists.txt +++ b/config/zephyr/kscan/CMakeLists.txt @@ -4,4 +4,4 @@ zephyr_library_named(zmk__hhkb_drivers__kscan_topre) zephyr_library_include_directories(${CMAKE_SOURCE_DIR}/include) -zephyr_library_sources(kscan_gpio_topre.c) +zephyr_library_sources(kscan_hhkb_pro2.c) diff --git a/config/hhkb_drivers/kscan/Kconfig b/config/zephyr/kscan/Kconfig similarity index 100% rename from config/hhkb_drivers/kscan/Kconfig rename to config/zephyr/kscan/Kconfig diff --git a/config/hhkb_drivers/kscan/kscan_gpio_topre.c b/config/zephyr/kscan/kscan_hhkb_pro2.c similarity index 64% rename from config/hhkb_drivers/kscan/kscan_gpio_topre.c rename to config/zephyr/kscan/kscan_hhkb_pro2.c index 876c093..ab312b0 100644 --- a/config/hhkb_drivers/kscan/kscan_gpio_topre.c +++ b/config/zephyr/kscan/kscan_hhkb_pro2.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_kscan_gpio_topre +#define DT_DRV_COMPAT zmk_kscan_hhkb_pro2 #include #include @@ -20,7 +20,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define MATRIX_CELLS (MATRIX_ROWS * MATRIX_COLS) #define SEL_PINS 6 -struct kscan_gpio_topre_config +struct kscan_hhkb_pro2_config { struct gpio_dt_spec bits[SEL_PINS]; struct gpio_dt_spec power; @@ -34,7 +34,7 @@ struct kscan_gpio_topre_config const uint16_t sleep_polling_interval_ms; }; -struct kscan_gpio_topre_data +struct kscan_hhkb_pro2_data { kscan_callback_t callback; struct k_timer poll_timer; @@ -43,10 +43,10 @@ struct kscan_gpio_topre_data const struct device *dev; }; -static int kscan_gpio_topre_configure(const struct device *dev, kscan_callback_t callback) +static int kscan_hhkb_pro2_configure(const struct device *dev, kscan_callback_t callback) { LOG_DBG("KSCAN API configure"); - struct kscan_gpio_topre_data *data = dev->data; + struct kscan_hhkb_pro2_data *data = dev->data; if (!callback) { return -EINVAL; @@ -56,43 +56,43 @@ static int kscan_gpio_topre_configure(const struct device *dev, kscan_callback_t return 0; } -static int kscan_gpio_topre_enable(const struct device *dev) +static int kscan_hhkb_pro2_enable(const struct device *dev) { LOG_DBG("KSCAN API enable"); - struct kscan_gpio_topre_data *data = dev->data; - const struct kscan_gpio_topre_config *cfg = dev->config; + struct kscan_hhkb_pro2_data *data = dev->data; + const struct kscan_hhkb_pro2_config *cfg = dev->config; k_timer_start(&data->poll_timer, K_MSEC(cfg->active_polling_interval_ms), K_MSEC(cfg->active_polling_interval_ms)); return 0; } -static int kscan_gpio_topre_disable(const struct device *dev) +static int kscan_hhkb_pro2_disable(const struct device *dev) { LOG_DBG("KSCAN API disable"); - struct kscan_gpio_topre_data *data = dev->data; + struct kscan_hhkb_pro2_data *data = dev->data; k_timer_stop(&data->poll_timer); return 0; } -static void kscan_gpio_topre_timer_handler(struct k_timer *timer) +static void kscan_hhkb_pro2_timer_handler(struct k_timer *timer) { - struct kscan_gpio_topre_data *data = - CONTAINER_OF(timer, struct kscan_gpio_topre_data, poll_timer); + struct kscan_hhkb_pro2_data *data = + CONTAINER_OF(timer, struct kscan_hhkb_pro2_data, poll_timer); k_work_submit(&data->poll); } -static void kscan_gpio_topre_work_handler(struct k_work *work) +static void kscan_hhkb_pro2_work_handler(struct k_work *work) { - struct kscan_gpio_topre_data *data = CONTAINER_OF(work, struct kscan_gpio_topre_data, poll); + struct kscan_hhkb_pro2_data *data = CONTAINER_OF(work, struct kscan_hhkb_pro2_data, poll); const struct device *dev = data->dev; - const struct kscan_gpio_topre_config *cfg = dev->config; + const struct kscan_hhkb_pro2_config *cfg = dev->config; bool matrix_read[MATRIX_CELLS]; // Power on everything gpio_pin_configure(cfg->key.port, cfg->key.pin, GPIO_INPUT | cfg->key.dt_flags); gpio_pin_set(cfg->strobe.port, cfg->strobe.pin, 1); - gpio_pin_set(cfg->power.port, cfg->power.pin, 1); + // gpio_pin_set(cfg->power.port, cfg->power.pin, 1); // Topre controller board needs 5 ms to be operational k_sleep(K_MSEC(5)); for (int r = 0; r < MATRIX_ROWS; ++r) @@ -131,7 +131,7 @@ static void kscan_gpio_topre_work_handler(struct k_work *work) gpio_pin_set(cfg->bits[i].port, cfg->bits[i].pin, 0); } gpio_pin_configure(cfg->key.port, cfg->key.pin, GPIO_DISCONNECTED); - gpio_pin_set(cfg->power.port, cfg->power.pin, 0); + // gpio_pin_set(cfg->power.port, cfg->power.pin, 0); gpio_pin_set(cfg->strobe.port, cfg->strobe.pin, 0); for (int r = 0; r < MATRIX_ROWS; ++r) @@ -148,15 +148,15 @@ static void kscan_gpio_topre_work_handler(struct k_work *work) } } -static int kscan_gpio_topre_activity_event_handler(const struct device *dev, const zmk_event_t *eh) +static int kscan_hhkb_pro2_activity_event_handler(const struct device *dev, const zmk_event_t *eh) { struct zmk_activity_state_changed *ev = as_zmk_activity_state_changed(eh); if (ev == NULL) { return -ENOTSUP; } - struct kscan_gpio_topre_data *data = dev->data; - const struct kscan_gpio_topre_config *cfg = dev->config; + struct kscan_hhkb_pro2_data *data = dev->data; + const struct kscan_hhkb_pro2_config *cfg = dev->config; uint16_t poll_interval; switch (ev->state) { @@ -178,11 +178,11 @@ static int kscan_gpio_topre_activity_event_handler(const struct device *dev, con return 0; } -static int kscan_gpio_topre_init(const struct device *dev) +static int kscan_hhkb_pro2_init(const struct device *dev) { LOG_DBG("KSCAN init"); - struct kscan_gpio_topre_data *data = dev->data; - const struct kscan_gpio_topre_config *cfg = dev->config; + struct kscan_hhkb_pro2_data *data = dev->data; + const struct kscan_hhkb_pro2_config *cfg = dev->config; data->dev = dev; for (int i = 0; i < SEL_PINS; ++i) { @@ -192,61 +192,60 @@ static int kscan_gpio_topre_init(const struct device *dev) } // The power line needs to source more than 0.5 mA current. Set the GPIO // drive mode to high drive. - gpio_pin_configure(cfg->power.port, cfg->power.pin, - GPIO_OUTPUT_INACTIVE | GPIO_DS_ALT_HIGH | cfg->power.dt_flags); + gpio_pin_configure(cfg->power.port, cfg->power.pin, GPIO_OUTPUT_ACTIVE | cfg->power.dt_flags); // Disconnect input pin to save power. gpio_pin_configure(cfg->key.port, cfg->key.pin, GPIO_DISCONNECTED); gpio_pin_configure(cfg->hys.port, cfg->hys.pin, GPIO_OUTPUT_INACTIVE | cfg->hys.dt_flags); gpio_pin_configure(cfg->strobe.port, cfg->strobe.pin, GPIO_OUTPUT_INACTIVE | cfg->strobe.dt_flags); - k_timer_init(&data->poll_timer, kscan_gpio_topre_timer_handler, NULL); - k_work_init(&data->poll, kscan_gpio_topre_work_handler); + k_timer_init(&data->poll_timer, kscan_hhkb_pro2_timer_handler, NULL); + k_work_init(&data->poll, kscan_hhkb_pro2_work_handler); return 0; } -static const struct kscan_driver_api kscan_gpio_topre_api = { - .config = kscan_gpio_topre_configure, - .enable_callback = kscan_gpio_topre_enable, - .disable_callback = kscan_gpio_topre_disable, +static const struct kscan_driver_api kscan_hhkb_pro2_api = { + .config = kscan_hhkb_pro2_configure, + .enable_callback = kscan_hhkb_pro2_enable, + .disable_callback = kscan_hhkb_pro2_disable, }; -#define CREATE_KSCAN_GPIO_TOPRE(inst) \ - static struct kscan_gpio_topre_data kscan_gpio_topre_data##inst; \ - static const struct kscan_gpio_topre_config kscan_gpio_topre_config##inst = { \ - .bits = \ - { \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 3), \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 4), \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 5), \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 6), \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 7), \ - GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 8), \ - }, \ - .power = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 0), \ - .key = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 1), \ - .hys = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 2), \ - .strobe = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 9), \ - .matrix_relax_us = DT_INST_PROP(inst, matrix_relax_us), \ - .adc_read_settle_us = DT_INST_PROP(inst, adc_read_settle_us), \ - .active_polling_interval_ms = DT_INST_PROP(inst, active_polling_interval_ms), \ - .idle_polling_interval_ms = DT_INST_PROP(inst, idle_polling_interval_ms), \ - .sleep_polling_interval_ms = DT_INST_PROP(inst, sleep_polling_interval_ms), \ - }; \ - static int kscan_gpio_topre_activity_event_handler_wrapper##inst(const zmk_event_t *eh) \ - { \ - const struct device *dev = DEVICE_DT_INST_GET(inst); \ - return kscan_gpio_topre_activity_event_handler(dev, eh); \ - } \ - ZMK_LISTENER(kscan_gpio_topre##inst, \ - kscan_gpio_topre_activity_event_handler_wrapper##inst); \ - ZMK_SUBSCRIPTION(kscan_gpio_topre##inst, zmk_activity_state_changed); \ - DEVICE_DT_INST_DEFINE(inst, \ - kscan_gpio_topre_init, \ - NULL, \ - &kscan_gpio_topre_data##inst, \ - &kscan_gpio_topre_config##inst, \ - APPLICATION, \ - CONFIG_APPLICATION_INIT_PRIORITY, \ - &kscan_gpio_topre_api); - -DT_INST_FOREACH_STATUS_OKAY(CREATE_KSCAN_GPIO_TOPRE) +#define CREATE_kscan_hhkb_pro2(inst) \ + static struct kscan_hhkb_pro2_data kscan_hhkb_pro2_data##inst; \ + static const struct kscan_hhkb_pro2_config kscan_hhkb_pro2_config##inst = { \ + .bits = \ + { \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 3), \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 4), \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 5), \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 6), \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 7), \ + GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 8), \ + }, \ + .power = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 0), \ + .key = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 1), \ + .hys = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 2), \ + .strobe = GPIO_DT_SPEC_INST_GET_BY_IDX(inst, gpios, 9), \ + .matrix_relax_us = DT_INST_PROP(inst, matrix_relax_us), \ + .adc_read_settle_us = DT_INST_PROP(inst, adc_read_settle_us), \ + .active_polling_interval_ms = DT_INST_PROP(inst, active_polling_interval_ms), \ + .idle_polling_interval_ms = DT_INST_PROP(inst, idle_polling_interval_ms), \ + .sleep_polling_interval_ms = DT_INST_PROP(inst, sleep_polling_interval_ms), \ + }; \ + static int kscan_hhkb_pro2_activity_event_handler_wrapper##inst(const zmk_event_t *eh) \ + { \ + const struct device *dev = DEVICE_DT_INST_GET(inst); \ + return kscan_hhkb_pro2_activity_event_handler(dev, eh); \ + } \ + ZMK_LISTENER(kscan_hhkb_pro2##inst, \ + kscan_hhkb_pro2_activity_event_handler_wrapper##inst); \ + ZMK_SUBSCRIPTION(kscan_hhkb_pro2##inst, zmk_activity_state_changed); \ + DEVICE_DT_INST_DEFINE(inst, \ + kscan_hhkb_pro2_init, \ + NULL, \ + &kscan_hhkb_pro2_data##inst, \ + &kscan_hhkb_pro2_config##inst, \ + APPLICATION, \ + CONFIG_APPLICATION_INIT_PRIORITY, \ + &kscan_hhkb_pro2_api); + +DT_INST_FOREACH_STATUS_OKAY(CREATE_kscan_hhkb_pro2) diff --git a/config/zephyr/module.yml b/config/zephyr/module.yml new file mode 100644 index 0000000..7591486 --- /dev/null +++ b/config/zephyr/module.yml @@ -0,0 +1,6 @@ +name: hhkb-zmk +build: + settings: + dts_root: . + depends: + - module # zmk module diff --git a/config/hhkb_drivers/pm/CMakeLists.txt b/config/zephyr/pm/CMakeLists.txt similarity index 100% rename from config/hhkb_drivers/pm/CMakeLists.txt rename to config/zephyr/pm/CMakeLists.txt diff --git a/config/hhkb_drivers/pm/Kconfig b/config/zephyr/pm/Kconfig similarity index 100% rename from config/hhkb_drivers/pm/Kconfig rename to config/zephyr/pm/Kconfig diff --git a/config/hhkb_drivers/pm/pm_wake_sensor.c b/config/zephyr/pm/pm_wake_sensor.c similarity index 100% rename from config/hhkb_drivers/pm/pm_wake_sensor.c rename to config/zephyr/pm/pm_wake_sensor.c diff --git a/images/board.jpg b/docs/images/board.jpg similarity index 100% rename from images/board.jpg rename to docs/images/board.jpg diff --git a/images/connector.jpg b/docs/images/connector.jpg similarity index 100% rename from images/connector.jpg rename to docs/images/connector.jpg diff --git a/images/parts.jpg b/docs/images/parts.jpg similarity index 100% rename from images/parts.jpg rename to docs/images/parts.jpg