Skip to content

Commit

Permalink
wip: whkb_pro2 board
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Nov 11, 2023
1 parent c54889b commit 687f85c
Show file tree
Hide file tree
Showing 21 changed files with 297 additions and 15 deletions.
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/
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,34 @@

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 build -b nice_nano_v2 -- \
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 \
-DZEPHYR_EXTRA_MODULES=$ZMK_PATH/app/drivers/;$WORKSPACE_PATH/config/hhkb_drivers/ \
-DZMK_CONFIG=$WORKSPACE_PATH/config
-DZEPHYR_EXTRA_MODULES="$PWD/zmk/app/module/;$PWD/config/module/" \
-DZMK_CONFIG=$PWD/config
```

or to build WHKB Pro2:

```sh
west build -s zmk/app -p -b whkb_pro2 -- \
-DZEPHYR_EXTRA_MODULES="$PWD/zmk/app/module/;$PWD/config/module/" \
-DZMK_CONFIG=$PWD/config
```

## Soldering (WIP)

![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)
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
152 changes: 152 additions & 0 deletions config/boards/arm/whkb_pro2/whkb_pro2.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* 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>
#include <dt-bindings/zmk/matrix_transform.h>
#include <dt-bindings/zmk/kscan_mock.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;
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
};

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
};

vbatt1: vbatt1 {
compatible = "zmk,battery-nrf-vddh";
label = "BATTERY";
};

kscan0: kscan_0 {
compatible = "zmk,kscan-gpio-topre";
label = "KSCAN";
gpios = <&gpio0 31 (GPIO_OPEN_SOURCE|NRF_GPIO_DRIVE_H1)>, /* 0: POWER */
<&gpio0 4 (GPIO_ACTIVE_LOW|GPIO_PULL_UP)>, /* 1: KEY */
<&gpio0 5 GPIO_ACTIVE_HIGH>, /* 2: HYS */
<&gpio0 22 GPIO_ACTIVE_HIGH>, /* 3: BIT0 */
<&gpio0 7 GPIO_ACTIVE_HIGH>, /* 4: BIT1 */
<&gpio1 9 GPIO_ACTIVE_HIGH>, /* 5: BIT2 */
<&gpio0 12 GPIO_ACTIVE_HIGH>, /* 6: BIT3 */
<&gpio0 23 GPIO_ACTIVE_HIGH>, /* 7: BIT4 */
<&gpio0 21 GPIO_ACTIVE_HIGH>, /* 8: BIT5 */
<&gpio0 19 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)
>;
};
};

&adc {
status = "okay";
};

/*
&gpiote {
status = "okay";
};
*/

&gpio0 {
status = "okay";
};

&gpio1 {
status = "okay";
};


/*
&i2c0 {
compatible = "nordic,nrf-twi";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
};

&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
pinctrl-1 = <&uart0_sleep>;
pinctrl-names = "default", "sleep";
};
*/

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


&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>;
};
};
};
43 changes: 43 additions & 0 deletions config/boards/arm/whkb_pro2/whkb_pro2.keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/bt.h>

#define DEFAULT 0
#define FN 1
#define BT 2

/ {
keymap {
compatible = "zmk,keymap";

default_layer {
bindings = <
&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp MINUS &kp EQUAL &kp BSLH &kp GRAVE
&kp TAB &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp LBKT &kp RBKT &kp BSPC
&kp LCTRL &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp ENTER
&kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp SLASH &kp RSHFT &mo FN
&kp LALT &kp LGUI &kp SPACE &kp RGUI &kp RALT
>;
};

fn_layer {
bindings = <
&kp K_POWER &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp F8 &kp F9 &kp F10 &kp F11 &kp F12 &kp INS &kp DEL
&kp CAPS &trans &trans &trans &sys_reset &trans &trans &bootloader &kp PSCRN &kp SLCK &kp PAUSE_BREAK &kp UP &trans &kp BSPC
&trans &kp K_VOL_DN &kp K_VOL_UP &kp K_MUTE &kp K_EJECT &trans &kp KP_MULTIPLY &kp KP_DIVIDE &kp HOME &kp PG_UP &kp LEFT &kp RIGHT &trans
&trans &trans &trans &trans &trans &to BT &kp KP_PLUS &kp KP_MINUS &kp END &kp PG_DN &kp DOWN &trans &trans
&trans &trans &trans &trans &trans
>;
};

bt_layer {
bindings =<
&to DEFAULT &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &none &none &none &none &none &none &none &none &none
&none &none &none &none &none &none &none &none &none &none &none &none &none &none
&none &none &none &none &none &none &none &none &none &none &none &none &none
&none &none &none &bt BT_CLR &none &none &none &none &none &none &none &none &none
&none &none &none &none &none
>;
};
};
};
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
4 changes: 0 additions & 4 deletions config/hhkb_drivers/zephyr/module.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void kscan_gpio_topre_work_handler(struct k_work *work)
// 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -192,8 +192,7 @@ 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);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions config/module/zephyr/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: hhkb-drivers
build:
cmake: .
kconfig: Kconfig
depends:
- module
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 687f85c

Please sign in to comment.