From 687f85c38c94626a080bbc6b1c4f6119613fc0d1 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 12 Nov 2023 00:09:10 +0900 Subject: [PATCH] wip: whkb_pro2 board --- .gitignore | 6 + README.md | 29 +++- config/boards/arm/whkb_pro2/Kconfig | 7 + config/boards/arm/whkb_pro2/Kconfig.board | 6 + config/boards/arm/whkb_pro2/Kconfig.defconfig | 28 ++++ config/boards/arm/whkb_pro2/whkb_pro2.dts | 152 ++++++++++++++++++ config/boards/arm/whkb_pro2/whkb_pro2.keymap | 43 +++++ .../boards/arm/whkb_pro2/whkb_pro2_defconfig | 24 +++ config/hhkb_drivers/zephyr/module.yml | 4 - .../{hhkb_drivers => module}/CMakeLists.txt | 0 config/{hhkb_drivers => module}/Kconfig | 0 .../kscan/CMakeLists.txt | 0 config/{hhkb_drivers => module}/kscan/Kconfig | 0 .../kscan/kscan_gpio_topre.c | 7 +- .../pm/CMakeLists.txt | 0 config/{hhkb_drivers => module}/pm/Kconfig | 0 .../pm/pm_wake_sensor.c | 0 config/module/zephyr/module.yml | 6 + {images => docs/images}/board.jpg | Bin {images => docs/images}/connector.jpg | Bin {images => docs/images}/parts.jpg | Bin 21 files changed, 297 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 config/boards/arm/whkb_pro2/Kconfig create mode 100644 config/boards/arm/whkb_pro2/Kconfig.board create mode 100644 config/boards/arm/whkb_pro2/Kconfig.defconfig create mode 100644 config/boards/arm/whkb_pro2/whkb_pro2.dts create mode 100644 config/boards/arm/whkb_pro2/whkb_pro2.keymap create mode 100644 config/boards/arm/whkb_pro2/whkb_pro2_defconfig delete mode 100644 config/hhkb_drivers/zephyr/module.yml rename config/{hhkb_drivers => module}/CMakeLists.txt (100%) rename config/{hhkb_drivers => module}/Kconfig (100%) rename config/{hhkb_drivers => module}/kscan/CMakeLists.txt (100%) rename config/{hhkb_drivers => module}/kscan/Kconfig (100%) rename config/{hhkb_drivers => module}/kscan/kscan_gpio_topre.c (97%) rename config/{hhkb_drivers => module}/pm/CMakeLists.txt (100%) rename config/{hhkb_drivers => module}/pm/Kconfig (100%) rename config/{hhkb_drivers => module}/pm/pm_wake_sensor.c (100%) create mode 100644 config/module/zephyr/module.yml rename {images => docs/images}/board.jpg (100%) rename {images => docs/images}/connector.jpg (100%) rename {images => docs/images}/parts.jpg (100%) 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/README.md b/README.md index 7780edf..9818aaa 100644 --- a/README.md +++ b/README.md @@ -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) 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..2668c95 --- /dev/null +++ b/config/boards/arm/whkb_pro2/whkb_pro2.dts @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/dts-v1/; +#include +#include +#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; + 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>; + }; + }; +}; diff --git a/config/boards/arm/whkb_pro2/whkb_pro2.keymap b/config/boards/arm/whkb_pro2/whkb_pro2.keymap new file mode 100644 index 0000000..e785814 --- /dev/null +++ b/config/boards/arm/whkb_pro2/whkb_pro2.keymap @@ -0,0 +1,43 @@ +#include +#include +#include + +#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 + >; + }; + }; +}; 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/hhkb_drivers/zephyr/module.yml b/config/hhkb_drivers/zephyr/module.yml deleted file mode 100644 index 02a1f8f..0000000 --- a/config/hhkb_drivers/zephyr/module.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: hhkb_drivers -build: - cmake: . - kconfig: Kconfig diff --git a/config/hhkb_drivers/CMakeLists.txt b/config/module/CMakeLists.txt similarity index 100% rename from config/hhkb_drivers/CMakeLists.txt rename to config/module/CMakeLists.txt diff --git a/config/hhkb_drivers/Kconfig b/config/module/Kconfig similarity index 100% rename from config/hhkb_drivers/Kconfig rename to config/module/Kconfig diff --git a/config/hhkb_drivers/kscan/CMakeLists.txt b/config/module/kscan/CMakeLists.txt similarity index 100% rename from config/hhkb_drivers/kscan/CMakeLists.txt rename to config/module/kscan/CMakeLists.txt diff --git a/config/hhkb_drivers/kscan/Kconfig b/config/module/kscan/Kconfig similarity index 100% rename from config/hhkb_drivers/kscan/Kconfig rename to config/module/kscan/Kconfig diff --git a/config/hhkb_drivers/kscan/kscan_gpio_topre.c b/config/module/kscan/kscan_gpio_topre.c similarity index 97% rename from config/hhkb_drivers/kscan/kscan_gpio_topre.c rename to config/module/kscan/kscan_gpio_topre.c index 876c093..51909bd 100644 --- a/config/hhkb_drivers/kscan/kscan_gpio_topre.c +++ b/config/module/kscan/kscan_gpio_topre.c @@ -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) @@ -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) @@ -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); diff --git a/config/hhkb_drivers/pm/CMakeLists.txt b/config/module/pm/CMakeLists.txt similarity index 100% rename from config/hhkb_drivers/pm/CMakeLists.txt rename to config/module/pm/CMakeLists.txt diff --git a/config/hhkb_drivers/pm/Kconfig b/config/module/pm/Kconfig similarity index 100% rename from config/hhkb_drivers/pm/Kconfig rename to config/module/pm/Kconfig diff --git a/config/hhkb_drivers/pm/pm_wake_sensor.c b/config/module/pm/pm_wake_sensor.c similarity index 100% rename from config/hhkb_drivers/pm/pm_wake_sensor.c rename to config/module/pm/pm_wake_sensor.c diff --git a/config/module/zephyr/module.yml b/config/module/zephyr/module.yml new file mode 100644 index 0000000..d9644b5 --- /dev/null +++ b/config/module/zephyr/module.yml @@ -0,0 +1,6 @@ +name: hhkb-drivers +build: + cmake: . + kconfig: Kconfig + depends: + - module 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