From b63b72ce7fb26d486d5997e9bd02eaa230de63d9 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Tue, 25 Jul 2023 13:37:48 +0100 Subject: [PATCH] Cirque Gen trackpad driver --- app/boards/arm/bt60/Kconfig | 2 +- app/boards/arm/bt60/Kconfig.board | 6 +- app/boards/arm/bt60/Kconfig.defconfig | 2 +- app/boards/arm/bt60/{bt60.dtsi => bt60.dts} | 75 ++-- app/boards/arm/bt60/bt60.keymap | 21 + .../arm/bt60/{bt60_v1.yaml => bt60.yaml} | 4 +- .../{bt60_v1_defconfig => bt60_defconfig} | 22 +- app/boards/arm/bt60/bt60_v1.dts | 113 ----- app/boards/arm/bt60/bt60_v1.keymap | 180 -------- app/boards/arm/bt60/bt60_v1.zmk.yml | 12 - app/boards/arm/bt60/bt60_v1_hs.dts | 61 --- app/boards/arm/bt60/bt60_v1_hs.keymap | 37 -- app/boards/arm/bt60/bt60_v1_hs.yaml | 15 - app/boards/arm/bt60/bt60_v1_hs.zmk.yml | 12 - app/boards/arm/bt60/bt60_v1_hs_defconfig | 25 -- app/boards/arm/bt60/pinctrl.dtsi | 44 ++ app/drivers/sensor/gen4/CMakeLists.txt | 1 + app/drivers/sensor/gen4/gen4.c | 414 +++++++++++++++++- app/drivers/sensor/gen4/gen4.h | 157 +++++++ app/include/drivers/sensor/gen4.h | 39 ++ 20 files changed, 732 insertions(+), 510 deletions(-) rename app/boards/arm/bt60/{bt60.dtsi => bt60.dts} (66%) create mode 100644 app/boards/arm/bt60/bt60.keymap rename app/boards/arm/bt60/{bt60_v1.yaml => bt60.yaml} (77%) rename app/boards/arm/bt60/{bt60_v1_defconfig => bt60_defconfig} (54%) delete mode 100644 app/boards/arm/bt60/bt60_v1.dts delete mode 100644 app/boards/arm/bt60/bt60_v1.keymap delete mode 100644 app/boards/arm/bt60/bt60_v1.zmk.yml delete mode 100644 app/boards/arm/bt60/bt60_v1_hs.dts delete mode 100644 app/boards/arm/bt60/bt60_v1_hs.keymap delete mode 100644 app/boards/arm/bt60/bt60_v1_hs.yaml delete mode 100644 app/boards/arm/bt60/bt60_v1_hs.zmk.yml delete mode 100644 app/boards/arm/bt60/bt60_v1_hs_defconfig create mode 100644 app/boards/arm/bt60/pinctrl.dtsi create mode 100644 app/include/drivers/sensor/gen4.h diff --git a/app/boards/arm/bt60/Kconfig b/app/boards/arm/bt60/Kconfig index d57a6b7efe3..d53ac8baed1 100644 --- a/app/boards/arm/bt60/Kconfig +++ b/app/boards/arm/bt60/Kconfig @@ -4,4 +4,4 @@ config BOARD_ENABLE_DCDC bool "Enable DCDC mode" select SOC_DCDC_NRF52X default y - depends on (BOARD_BT60_V1_HS || BOARD_BT60_V1) + depends on BOARD_BT60 diff --git a/app/boards/arm/bt60/Kconfig.board b/app/boards/arm/bt60/Kconfig.board index 24c0a8b5b0c..7a489e64016 100644 --- a/app/boards/arm/bt60/Kconfig.board +++ b/app/boards/arm/bt60/Kconfig.board @@ -3,10 +3,6 @@ # Copyright (c) 2021 Polarity Works # SPDX-License-Identifier: MIT -config BOARD_BT60_V1 +config BOARD_BT60 bool "bt60" depends on SOC_NRF52840_QIAA - -config BOARD_BT60_V1_HS - bool "bt60 hotswap" - depends on SOC_NRF52840_QIAA diff --git a/app/boards/arm/bt60/Kconfig.defconfig b/app/boards/arm/bt60/Kconfig.defconfig index e7cf1a48cff..0258147956f 100644 --- a/app/boards/arm/bt60/Kconfig.defconfig +++ b/app/boards/arm/bt60/Kconfig.defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2021 Polarity Works # SPDX-License-Identifier: MIT -if BOARD_BT60_V1_HS || BOARD_BT60_V1 +if BOARD_BT60 config BOARD default "bt60" diff --git a/app/boards/arm/bt60/bt60.dtsi b/app/boards/arm/bt60/bt60.dts similarity index 66% rename from app/boards/arm/bt60/bt60.dtsi rename to app/boards/arm/bt60/bt60.dts index 6e4900af53c..0e106d87def 100644 --- a/app/boards/arm/bt60/bt60.dtsi +++ b/app/boards/arm/bt60/bt60.dts @@ -6,39 +6,38 @@ /dts-v1/; #include + +#include #include +#include "pinctrl.dtsi" + / { model = "BT60"; - compatible = "polarityworks,bt60"; + compatible = "polarityworks,bt60v2"; chosen { zephyr,code-partition = &code_partition; zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &cdc_acm_uart; - zmk,battery = &vbatt; zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; - }; + zephyr,console = &cdc_acm_uart; - sensors { - compatible = "zmk,keymap-sensors"; - sensors = <&left_encoder>; }; + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + diode-direction = "col2row"; + col-gpios + = <&gpio0 24 GPIO_ACTIVE_HIGH> + ; - left_encoder: encoder_left { - compatible = "alps,ec11"; - label = "LEFT_ENCODER"; - a-gpios = <&gpio1 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - b-gpios = <&gpio1 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - resolution = <4>; - status = "okay"; + row-gpios + = <&gpio0 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; }; - leds { compatible = "gpio-leds"; blue_led: led_0 { @@ -47,19 +46,13 @@ }; }; - vbatt: vbatt { - compatible = "zmk,battery-voltage-divider"; - label = "BATTERY"; - io-channels = <&adc 2>; - output-ohms = <2000000>; - full-ohms = <(2000000 + 806000)>; - }; }; &adc { status = "okay"; }; + &gpiote { status = "okay"; }; @@ -72,24 +65,12 @@ status = "okay"; }; -&i2c0 { - compatible = "nordic,nrf-twi"; - sda-pin = <17>; - scl-pin = <20>; -}; - -&uart0 { - compatible = "nordic,nrf-uarte"; - tx-pin = <6>; - rx-pin = <8>; -}; - &usbd { status = "okay"; cdc_acm_uart: cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; - }; + compatible = "zephyr,cdc-acm-uart"; + label = "CDC_ACM_0"; + }; }; @@ -132,3 +113,21 @@ }; }; }; + +&i2c1 { + compatible = "nordic,nrf-twim"; + /* Cannot be used together with spi1. */ + status = "okay"; + pinctrl-0 = <&i2c1_default>; + pinctrl-1 = <&i2c1_sleep>; + pinctrl-names = "default", "sleep"; + clock-frequency = ; + trackpad: trackpad@2c { + compatible = "cirque,gen4"; + status = "okay"; + reg = <0x2C>; + dr-gpios = <&gpio0 17 (GPIO_ACTIVE_LOW)>; + rotate-90; + sleep; + }; + }; diff --git a/app/boards/arm/bt60/bt60.keymap b/app/boards/arm/bt60/bt60.keymap new file mode 100644 index 00000000000..791d1a345b2 --- /dev/null +++ b/app/boards/arm/bt60/bt60.keymap @@ -0,0 +1,21 @@ +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + + default_layer { +// ------------------------------------------------------------------------------------------ +// | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | +// | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | "|" | +// | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | +// | SHIFT | Z | X | C | V | B | N | M | , | . | SHIFT(/) | ^ | DEL | +// | CTL | WIN | ALT | SPACE | ALT | MO(1) | <- | v | -> | +// ------------------------------------------------------------------------------------------ + bindings = < + &kp ESC + >; + }; + }; +}; \ No newline at end of file diff --git a/app/boards/arm/bt60/bt60_v1.yaml b/app/boards/arm/bt60/bt60.yaml similarity index 77% rename from app/boards/arm/bt60/bt60_v1.yaml rename to app/boards/arm/bt60/bt60.yaml index 41fd7e40945..35e907528c5 100644 --- a/app/boards/arm/bt60/bt60_v1.yaml +++ b/app/boards/arm/bt60/bt60.yaml @@ -1,5 +1,5 @@ -identifier: bt60_v1 -name: BT60 V1 Soldered +identifier: bt60 +name: bt60 type: mcu arch: arm toolchain: diff --git a/app/boards/arm/bt60/bt60_v1_defconfig b/app/boards/arm/bt60/bt60_defconfig similarity index 54% rename from app/boards/arm/bt60/bt60_v1_defconfig rename to app/boards/arm/bt60/bt60_defconfig index 813dcecea5a..2f799d9515d 100644 --- a/app/boards/arm/bt60/bt60_v1_defconfig +++ b/app/boards/arm/bt60/bt60_defconfig @@ -2,7 +2,7 @@ CONFIG_SOC_SERIES_NRF52X=y CONFIG_SOC_NRF52840_QIAA=y -CONFIG_BOARD_BT60_V1=y +CONFIG_BOARD_BT60=y # Enable MPU CONFIG_ARM_MPU=y @@ -10,12 +10,16 @@ CONFIG_ARM_MPU=y # enable GPIO CONFIG_GPIO=y -# encoder -CONFIG_EC11=y -CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y +CONFIG_PINCTRL=y + +CONFIG_ZMK_USB_LOGGING=y + +CONFIG_I2C=y +CONFIG_GEN4=y +CONFIG_GEN4_TRIGGER_GLOBAL_THREAD=y + CONFIG_USE_DT_CODE_PARTITION=y -CONFIG_BUILD_OUTPUT_UF2=y CONFIG_MPU_ALLOW_FLASH_WRITE=y CONFIG_NVS=y @@ -23,3 +27,11 @@ CONFIG_SETTINGS_NVS=y CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y + +CONFIG_LOG_BUFFER_SIZE=38000 +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=38000 +CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS=8000 + +CONFIG_BT_CTLR_TX_PWR_PLUS_8=y + +CONFIG_BUILD_OUTPUT_UF2=y diff --git a/app/boards/arm/bt60/bt60_v1.dts b/app/boards/arm/bt60/bt60_v1.dts deleted file mode 100644 index 0cfe184a090..00000000000 --- a/app/boards/arm/bt60/bt60_v1.dts +++ /dev/null @@ -1,113 +0,0 @@ -/* -* Copyright (c) 2021 Polarity Works -* -* SPDX-License-Identifier: MIT -*/ - -/dts-v1/; -#include "bt60.dtsi" - - -/ { - chosen { - zmk,kscan = &kscan0; - zmk,matrix_transform = &ansi_transform; - }; - - ansi_transform: keymap_transform_0 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,13) - RC(3,0) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) - RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,10) RC(4,11) RC(4,12) RC(4,13) RC(4,14) - >; - }; - - hhkb_transform: keymap_transform_1 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) RC(0,14) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,13) - RC(3,0) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) RC(3,14) - RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,10) RC(4,11) RC(4,12) RC(4,13) - >; - }; - - iso_transform: keymap_transform_2 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,12) RC(2,13) - RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) - RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,10) RC(4,11) RC(4,12) RC(4,13) - >; - }; - - all_1u_transform: keymap_transform_3 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,13) - RC(3,0) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) RC(3,13) RC(3,14) - RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,10) RC(4,11) RC(4,12) RC(4,13) RC(4,14) - >; - }; - - split_transform: keymap_transform_4 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) RC(0,14) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,13) - RC(3,0) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) RC(3,12) RC(3,14) - RC(4,0) RC(4,1) RC(4,2) RC(4,6) RC(4,10) RC(4,11) RC(4,12) RC(4,13) - >; - }; - - kscan0: kscan_0 { - compatible = "zmk,kscan-gpio-matrix"; - label = "KSCAN"; - diode-direction = "col2row"; - - col-gpios - = <&gpio1 13 GPIO_ACTIVE_HIGH> - , <&gpio1 10 GPIO_ACTIVE_HIGH> - , <&gpio1 11 GPIO_ACTIVE_HIGH> - , <&gpio1 15 GPIO_ACTIVE_HIGH> - , <&gpio0 3 GPIO_ACTIVE_HIGH> - , <&gpio0 2 GPIO_ACTIVE_HIGH> - , <&gpio0 28 GPIO_ACTIVE_HIGH> - , <&gpio0 29 GPIO_ACTIVE_HIGH> - , <&gpio0 30 GPIO_ACTIVE_HIGH> - , <&gpio0 31 GPIO_ACTIVE_HIGH> - , <&gpio0 5 GPIO_ACTIVE_HIGH> - , <&gpio0 7 GPIO_ACTIVE_HIGH> - , <&gpio1 9 GPIO_ACTIVE_HIGH> - , <&gpio0 12 GPIO_ACTIVE_HIGH> - , <&gpio0 23 GPIO_ACTIVE_HIGH> - ; - - row-gpios - = <&gpio1 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 22 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio1 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - ; - }; -}; diff --git a/app/boards/arm/bt60/bt60_v1.keymap b/app/boards/arm/bt60/bt60_v1.keymap deleted file mode 100644 index 25ae269d306..00000000000 --- a/app/boards/arm/bt60/bt60_v1.keymap +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include -#include - -#define ANSI true -//#define HHKB true -//#define ISO true -//#define ALL_1U true -//#define SPLIT_BKSP_RSHFT true - - - -/ { - chosen { - #ifdef ANSI - zmk,matrix_transform = &ansi_transform; - #elif defined(HHKB) - zmk,matrix_transform = &hhkb_transform; - #elif defined(ISO) - zmk,matrix_transform = &iso_transform; - #elif defined(ALL_1U) - zmk,matrix_transform = &all_1u_transform; - #else - zmk,matrix_transform = &split_transform; - #endif - }; - - - keymap { - compatible = "zmk,keymap"; - #ifdef ANSI - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | | | - // | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | - // | SHIFT | Z | X | C | V | B | N | M | , | . | / | SHIFT | - // | CTL | WIN | ALT | SPACE | ALT | 1 | MENU | CTRL | - // ------------------------------------------------------------------------------------------ - 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 BSPC - &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 BSLH - &kp CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp RET - &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT - &kp LCTRL &kp LGUI &kp LALT &kp SPACE &kp RALT &mo 1 &kp K_CMENU &kp RCTRL &bt BT_CLR - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - // ------------------------------------------------------------------------------------------ - // |GRAVE| F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DEL | - // | TAB | Q | UP | E | R | T | Y | U | INS | O |PSCRN|SLCK |PSEBRK| RESET | - // | CAPS |LEFT |DOWN |RIGHT| F | G | H | J | K | L |HOME |PGUP | BOOTLOADER | - // | PREV |VOLUP |VOLDN|MUTE | V | B | N | M | , | END | PGDN | NEXT | - // | CTL | WIN | ALT | SPACE | ALT | 1 | MENU | BT_CLR | - // ------------------------------------------------------------------------------------------ - bindings = < - &kp GRAVE &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 DEL - &trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &sys_reset - &trans &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME &kp PG_UP &bootloader - &kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &kp END &kp PG_DN &kp C_NEXT - &bt BT_PRV &bt BT_NXT &trans &trans &trans &trans &trans &bt BT_CLR &trans - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - #elif defined(HHKB) - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` | - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | BSPC | - // | CTRL | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | - // | SHIFT | Z | X | C | V | B | N | M | , | . | / | SHIFT | 1 | - // | CAPS | ALT | WIN | SPACE | WIN | ALT | CTRL | - // ------------------------------------------------------------------------------------------ - 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 RET - &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT &mo 1 - &kp LCTRL &kp LALT &kp LGUI &kp SPACE &kp RGUI &kp RALT &kp RCTRL - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - bindings = < - &trans &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 CLCK &bt BT_PRV &bt BT_NXT &bt BT_CLR &trans &trans &trans &trans &trans &trans &trans &kp UP &trans &sys_reset - &trans &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &trans &kp LEFT &kp RIGHT &trans - &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &kp DOWN &trans &trans - &trans &trans &trans &bootloader &trans &trans &trans - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - #elif defined(ISO) - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | | - // | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | # | ENTER | - // | SHIFT | | | Z | X | C | V | B | N | M | , | . | / | SHIFT | - // | CTL | WIN | ALT | SPACE | ALT | 1 | MENU | CTRL | - // ------------------------------------------------------------------------------------------ - 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 BSPC - &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 CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp NON_US_HASH &kp RET - &kp LSHFT &kp NON_US_BSLH &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT - &kp LCTRL &kp LGUI &kp LALT &kp SPACE &kp RALT &mo 1 &kp K_CMENU &kp RCTRL - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - bindings = < - &kp GRAVE &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 DEL - &sys_reset &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK - &trans &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME &kp PG_UP &trans &bootloader - &kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &trans &kp END &kp PG_DN &kp C_NEXT - &bt BT_PRV &bt BT_NXT &trans &trans &trans &trans &trans &bt BT_CLR - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - #elif defined(ALL_1U) - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | "|" | - // | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | - // | SHIFT | Z | X | C | V | B | N | M | , | . | / | SHFT | UP | 1 | - // | CTL | WIN | ALT | SPACE | ALT | CTRL | LEFT | DOWN | RIGHT | - // ------------------------------------------------------------------------------------------ - 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 BSPC - &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 BSLH - &kp CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp RET - &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT &kp UP &mo 1 - &kp LCTRL &kp LGUI &kp LALT &kp SPACE &kp RALT &kp RCTRL &kp LEFT &kp DOWN &kp RIGHT - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - bindings = < - &kp GRAVE &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 F1 - &trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &sys_reset - &trans &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME &kp PG_UP &bootloader - &kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &trans &trans &kp END &kp PG_DN &kp C_NEXT - &bt BT_PRV &bt BT_NXT &trans &trans &trans &trans &trans &trans &bt BT_CLR - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - #else - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = |BKSP| DEL | - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ | - // | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | - // | SHIFT | Z | X | C | V | B | N | M | , | . | / | SHIFT | 1 | - // | CTL | WIN | ALT | SPACE | ALT | 1 | CTRL | - // ------------------------------------------------------------------------------------------ - 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 BSPC &kp DEL - &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 BSLH - &kp CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp RET - &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT &mo 1 - &kp LCTRL &kp LGUI &kp LALT &kp SPACE &kp RALT &kp RGUI &kp C_MENU &kp RCTRL - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - bindings = < - &kp GRAVE &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 DEL &trans - &trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &sys_reset - &trans &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME &kp PG_UP &bootloader - &kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &kp END &kp PG_DN &kp C_NEXT &trans - &bt BT_PRV &bt BT_NXT &trans &trans &trans &trans &trans &bt BT_CLR - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - #endif - }; -}; diff --git a/app/boards/arm/bt60/bt60_v1.zmk.yml b/app/boards/arm/bt60/bt60_v1.zmk.yml deleted file mode 100644 index 9909f191234..00000000000 --- a/app/boards/arm/bt60/bt60_v1.zmk.yml +++ /dev/null @@ -1,12 +0,0 @@ -file_format: "1" -id: bt60_v1 -name: BT60 V1 Soldered -type: board -arch: arm -features: - - keys - - encoder -outputs: - - usb - - ble -url: https://polarityworks.com diff --git a/app/boards/arm/bt60/bt60_v1_hs.dts b/app/boards/arm/bt60/bt60_v1_hs.dts deleted file mode 100644 index b24dee1e82b..00000000000 --- a/app/boards/arm/bt60/bt60_v1_hs.dts +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Copyright (c) 2021 Polarity Works -* -* SPDX-License-Identifier: MIT -*/ - -/dts-v1/; -#include "bt60.dtsi" - - -/ { - chosen { - zmk,kscan = &kscan0; - zmk,matrix_transform = &default_transform; - }; - - default_transform: keymap_transform_0 { - compatible = "zmk,matrix-transform"; - columns = <15>; - rows = <5>; - map = < - RC(0,0) RC(0,1) RC(0,2) RC(0,3) RC(0,4) RC(0,5) RC(0,6) RC(0,7) RC(0,8) RC(0,9) RC(0,10) RC(0,11) RC(0,12) RC(0,13) RC(2,13) - RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) RC(1,9) RC(1,10) RC(1,11) RC(1,12) RC(1,13) - RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10) RC(2,11) RC(2,12) - RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) RC(3,9) RC(3,10) RC(3,11) - RC(4,0) RC(4,1) RC(4,2) RC(4,5) RC(4,8) RC(4,9) RC(4,10) RC(4,11) - >; - }; - - - kscan0: kscan_0 { - compatible = "zmk,kscan-gpio-matrix"; - label = "KSCAN"; - diode-direction = "col2row"; - - col-gpios - = <&gpio1 11 GPIO_ACTIVE_HIGH> - , <&gpio1 10 GPIO_ACTIVE_HIGH> - , <&gpio1 13 GPIO_ACTIVE_HIGH> - , <&gpio1 15 GPIO_ACTIVE_HIGH> - , <&gpio0 3 GPIO_ACTIVE_HIGH> - , <&gpio0 2 GPIO_ACTIVE_HIGH> - , <&gpio0 28 GPIO_ACTIVE_HIGH> - , <&gpio0 29 GPIO_ACTIVE_HIGH> - , <&gpio0 30 GPIO_ACTIVE_HIGH> - , <&gpio0 31 GPIO_ACTIVE_HIGH> - , <&gpio0 5 GPIO_ACTIVE_HIGH> - , <&gpio0 7 GPIO_ACTIVE_HIGH> - , <&gpio1 9 GPIO_ACTIVE_HIGH> - , <&gpio0 12 GPIO_ACTIVE_HIGH> - ; - - row-gpios - = <&gpio1 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 22 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - , <&gpio0 23 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> - ; - }; -}; diff --git a/app/boards/arm/bt60/bt60_v1_hs.keymap b/app/boards/arm/bt60/bt60_v1_hs.keymap deleted file mode 100644 index 6c26756e35a..00000000000 --- a/app/boards/arm/bt60/bt60_v1_hs.keymap +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include - -/ { - keymap { - compatible = "zmk,keymap"; - - default_layer { - // ------------------------------------------------------------------------------------------ - // | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | DEL - // | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | | | - // | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | ENTER | - // | SHIFT | Z | X | C | V | B | N | M | , | . | / | SHIFT | - // | CTL | WIN | ALT | SPACE | ALT | 1 | MENU | CTRL | - // ------------------------------------------------------------------------------------------ - 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 BSPC &bt BT_CLR - &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 BSLH - &kp CLCK &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SEMI &kp SQT &kp RET - &kp LSHFT &kp Z &kp X &kp C &kp V &kp B &kp N &kp M &kp COMMA &kp DOT &kp FSLH &kp RSHFT - &kp LCTRL &kp LGUI &kp LALT &kp SPACE &kp RALT &mo 1 &kp K_CMENU &kp RCTRL - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - raise { - bindings = < - &kp GRAVE &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 DEL &trans - &trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &sys_reset - &trans &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME &kp PG_UP &bootloader - &kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &kp END &kp PG_DN &kp C_NEXT - &bt BT_PRV &bt BT_NXT &trans &trans &trans &trans &trans &bt BT_CLR - >; - sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; - }; - }; -}; diff --git a/app/boards/arm/bt60/bt60_v1_hs.yaml b/app/boards/arm/bt60/bt60_v1_hs.yaml deleted file mode 100644 index 5a73753b5e2..00000000000 --- a/app/boards/arm/bt60/bt60_v1_hs.yaml +++ /dev/null @@ -1,15 +0,0 @@ -identifier: bt60_v1_hs -name: BT60 V1 Hotswap -type: mcu -arch: arm -toolchain: - - zephyr - - gnuarmemb - - xtools -supported: - - adc - - usb_device - - ble - - ieee802154 - - pwm - - watchdog diff --git a/app/boards/arm/bt60/bt60_v1_hs.zmk.yml b/app/boards/arm/bt60/bt60_v1_hs.zmk.yml deleted file mode 100644 index bc9acea46a7..00000000000 --- a/app/boards/arm/bt60/bt60_v1_hs.zmk.yml +++ /dev/null @@ -1,12 +0,0 @@ -file_format: "1" -id: bt60_v1_hs -name: BT60 V1 Hotswap -type: board -arch: arm -features: - - keys - - encoder -outputs: - - usb - - ble -url: https://polarityworks.com diff --git a/app/boards/arm/bt60/bt60_v1_hs_defconfig b/app/boards/arm/bt60/bt60_v1_hs_defconfig deleted file mode 100644 index f2327fd3f42..00000000000 --- a/app/boards/arm/bt60/bt60_v1_hs_defconfig +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: MIT - -CONFIG_SOC_SERIES_NRF52X=y -CONFIG_SOC_NRF52840_QIAA=y -CONFIG_BOARD_BT60_V1_HS=y - -# Enable MPU -CONFIG_ARM_MPU=y - -# enable GPIO -CONFIG_GPIO=y - -# encoder -CONFIG_EC11=y -CONFIG_EC11_TRIGGER_GLOBAL_THREAD=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/app/boards/arm/bt60/pinctrl.dtsi b/app/boards/arm/bt60/pinctrl.dtsi new file mode 100644 index 00000000000..f019ab374d8 --- /dev/null +++ b/app/boards/arm/bt60/pinctrl.dtsi @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 The ZMK Contributors + * SPDX-License-Identifier: MIT + */ + +&pinctrl { + spi3_default: spi3_default { + group1 { + psels = ; + }; + }; + + spi3_sleep: spi3_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; + pwm0_default: pwm0_default { + group1 { + psels = ; + }; + }; + pwm0_sleep: pwm0_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; + i2c1_default: i2c1_default { + group1 { + psels = , + ; + }; + }; + + i2c1_sleep: i2c1_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; diff --git a/app/drivers/sensor/gen4/CMakeLists.txt b/app/drivers/sensor/gen4/CMakeLists.txt index e48e31b7cbc..1aea0d1aa0d 100644 --- a/app/drivers/sensor/gen4/CMakeLists.txt +++ b/app/drivers/sensor/gen4/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT zephyr_include_directories(.) +include_directories(${CMAKE_SOURCE_DIR}/include) zephyr_library() diff --git a/app/drivers/sensor/gen4/gen4.c b/app/drivers/sensor/gen4/gen4.c index ee8be181aa0..5847ed2522f 100644 --- a/app/drivers/sensor/gen4/gen4.c +++ b/app/drivers/sensor/gen4/gen4.c @@ -1,8 +1,416 @@ +#define DT_DRV_COMPAT cirque_gen4 +#include +#include +#include -uint8_t gen4_checksum(uint8_t *buffer, uint8_t length) { +#include +#include "gen4.h" + +LOG_MODULE_REGISTER(gen4, CONFIG_SENSOR_LOG_LEVEL); + +static int gen4_normal_read(const struct device *dev, uint8_t *buf, const uint8_t len) { + const struct gen4_config *config = dev->config; + return i2c_read_dt(&config->bus, buf, len); +} + +static uint8_t gen4_checksum(uint8_t *buffer, uint8_t length) { uint16_t temp; uint8_t checksum = 0; for (temp = 0; temp < length; temp++) - checksum += *(buffer + temp); -} \ No newline at end of file + checksum += (*(buffer + temp) & 0xFF); + return checksum; +} + +static int gen4_ext_read(const struct device *dev, const uint16_t addr, const uint8_t len, + uint8_t *buffer) { + const struct gen4_config *cfg = dev->config; + uint8_t request[8] = {(uint8_t)(GEN4_EXT_ACCESS_READ & 0xFF), + (uint8_t)((GEN4_EXT_ACCESS_READ >> 8) & 0xFF), + (uint8_t)(addr & 0xFF), + (uint8_t)((addr >> 8) & 0xFF), + 0, + 0, + (uint8_t)(len & 0xFF), + (uint8_t)((len >> 8) & 0xFF)}; + int ret = i2c_write_read_dt(&cfg->bus, request, 8, buffer, (len + 3)); + if (ret < 0) { + LOG_ERR("ext read status: %d", ret); + return ret; + } + LOG_DBG("received value %x", buffer[2]); + uint8_t checksum = gen4_checksum(buffer, len + 2); + if (checksum != *(buffer + len + 2)) { + LOG_ERR("checksum failed: %d", (int)checksum); + // return 1; + } + return 0; +} + +static int gen4_ext_write_1byte(const struct device *dev, const uint16_t addr, const uint8_t val) { + const struct gen4_config *cfg = dev->config; + + uint8_t sendbuf[10]; + + sendbuf[0] = (uint8_t)(GEN4_EXT_ACCESS_WRITE & 0xFF); + sendbuf[1] = (uint8_t)((GEN4_EXT_ACCESS_WRITE >> 8) & 0xFF); + sendbuf[2] = (uint8_t)(addr & 0xFF); + sendbuf[3] = (uint8_t)((addr >> 8) & 0xFF); + sendbuf[4] = 0; + sendbuf[5] = 0; + sendbuf[6] = (uint8_t)(1 & 0xFF); + sendbuf[7] = 0; + sendbuf[8] = val; + sendbuf[9] = gen4_checksum(sendbuf, 9); + + int ret = i2c_write_dt(&cfg->bus, sendbuf, 10); + if (ret < 0) { + LOG_ERR("ext read status: %d", ret); + return ret; + } + return ret; +} + +static int gen4_channel_get(const struct device *dev, enum sensor_channel chan, + struct sensor_value *val) { + const struct gen4_data *data = dev->data; + switch ((enum sensor_channel_gen4)chan) { + case SENSOR_CHAN_FINGERS: + val->val1 = data->contacts; + break; + case SENSOR_CHAN_X_0: + val->val1 = data->fingers[0].x; + break; + case SENSOR_CHAN_X_1: + val->val1 = data->fingers[1].x; + break; + case SENSOR_CHAN_X_2: + val->val1 = data->fingers[2].x; + break; + case SENSOR_CHAN_X_3: + val->val1 = data->fingers[3].x; + break; + case SENSOR_CHAN_X_4: + val->val1 = data->fingers[4].x; + break; + case SENSOR_CHAN_Y_0: + val->val1 = data->fingers[0].y; + break; + case SENSOR_CHAN_Y_1: + val->val1 = data->fingers[1].y; + break; + case SENSOR_CHAN_Y_2: + val->val1 = data->fingers[2].y; + break; + case SENSOR_CHAN_Y_3: + val->val1 = data->fingers[3].y; + break; + case SENSOR_CHAN_Y_4: + val->val1 = data->fingers[4].y; + break; + case SENSOR_CHAN_PRESENT_0: + val->val1 = data->fingers[0].present; + break; + case SENSOR_CHAN_PRESENT_1: + val->val1 = data->fingers[1].present; + break; + case SENSOR_CHAN_PRESENT_2: + val->val1 = data->fingers[2].present; + break; + case SENSOR_CHAN_PRESENT_3: + val->val1 = data->fingers[3].present; + break; + case SENSOR_CHAN_PRESENT_4: + val->val1 = data->fingers[4].present; + break; + case SENSOR_CHAN_PALM_0: + val->val1 = data->fingers[0].palm; + break; + case SENSOR_CHAN_PALM_1: + val->val1 = data->fingers[1].palm; + break; + case SENSOR_CHAN_PALM_2: + val->val1 = data->fingers[2].palm; + break; + case SENSOR_CHAN_PALM_3: + val->val1 = data->fingers[3].palm; + break; + case SENSOR_CHAN_PALM_4: + val->val1 = data->fingers[4].palm; + break; + case SENSOR_CHAN_BUTTONS: + val->val1 = data->btns; + break; + default: + return -ENOTSUP; + } + return 0; +} + +static int gen4_sample_fetch(const struct device *dev, enum sensor_channel) { + uint8_t packet[52]; + int ret; + ret = gen4_normal_read(dev, packet, 52); + if (ret < 0) { + LOG_ERR("read status: %d", ret); + return ret; + } + if (!(packet[GEN4_REPORT_ID_SHIFT] == 9)) { + return -EAGAIN; + } + struct gen4_data *data = dev->data; + data->btns = packet[GEN4_BTNS_SHIFT]; + data->contacts = packet[GEN4_NUM_CONTACT_SHIFT]; + // Finger 0 + if (data->contacts & BIT(0)) { + data->fingers[0].present = packet[GEN4_F0_PALM_SHIFT] & BIT(1); + data->fingers[0].palm = packet[GEN4_F0_PALM_SHIFT] & BIT(7); + data->fingers[0].x = + (uint16_t)(packet[GEN4_F0_X_HI_SHIFT] << 8) + packet[GEN4_F0_X_LO_SHIFT]; + data->fingers[0].y = + (uint16_t)(packet[GEN4_F0_Y_HI_SHIFT] << 8) + packet[GEN4_F0_Y_LO_SHIFT]; + LOG_DBG("Finger 0 detected: %d", data->fingers[0].present); + LOG_DBG("Finger 0 palm: %d", data->fingers[0].palm); + LOG_DBG("Finger 0 x: %d", data->fingers[0].x); + LOG_DBG("Finger 0 y: %d", data->fingers[0].y); + + } else { + data->fingers[0].present = false; + LOG_DBG("Finger 0 not detected: %d", data->fingers[0].present); + } + // Finger 1 + if (data->contacts & BIT(1)) { + data->fingers[1].present = packet[GEN4_F1_PALM_SHIFT] & BIT(1); + data->fingers[1].palm = packet[GEN4_F1_PALM_SHIFT] & BIT(7); + data->fingers[1].x = + (uint16_t)(packet[GEN4_F1_X_HI_SHIFT] << 8) + packet[GEN4_F1_X_LO_SHIFT]; + data->fingers[1].y = + (uint16_t)(packet[GEN4_F1_Y_HI_SHIFT] << 8) + packet[GEN4_F1_Y_LO_SHIFT]; + } else { + data->fingers[1].present = false; + } + // Finger 2 + if (data->contacts & BIT(2)) { + data->fingers[2].present = packet[GEN4_F2_PALM_SHIFT] & BIT(1); + data->fingers[2].palm = packet[GEN4_F2_PALM_SHIFT] & BIT(7); + data->fingers[2].x = + (uint16_t)(packet[GEN4_F2_X_HI_SHIFT] << 8) + packet[GEN4_F2_X_LO_SHIFT]; + data->fingers[2].y = + (uint16_t)(packet[GEN4_F2_Y_HI_SHIFT] << 8) + packet[GEN4_F2_Y_LO_SHIFT]; + } else { + data->fingers[2].present = false; + } + // Finger 3 + if (data->contacts & BIT(3)) { + data->fingers[3].present = packet[GEN4_F3_PALM_SHIFT] & BIT(1); + data->fingers[3].palm = packet[GEN4_F3_PALM_SHIFT] & BIT(7); + data->fingers[3].x = + (uint16_t)(packet[GEN4_F3_X_HI_SHIFT] << 8) + packet[GEN4_F3_X_LO_SHIFT]; + data->fingers[3].y = + (uint16_t)(packet[GEN4_F3_Y_HI_SHIFT] << 8) + packet[GEN4_F3_Y_LO_SHIFT]; + } else { + data->fingers[3].present = false; + } + // Finger 4 + if (data->contacts & BIT(4)) { + data->fingers[4].present = packet[GEN4_F4_PALM_SHIFT] & BIT(1); + data->fingers[4].palm = packet[GEN4_F4_PALM_SHIFT] & BIT(7); + data->fingers[4].x = + (uint16_t)(packet[GEN4_F4_X_HI_SHIFT] << 8) + packet[GEN4_F4_X_LO_SHIFT]; + data->fingers[4].y = + (uint16_t)(packet[GEN4_F4_Y_HI_SHIFT] << 8) + packet[GEN4_F4_Y_LO_SHIFT]; + } else { + data->fingers[4].present = false; + } + return 0; +} + +#ifdef CONFIG_GEN4_TRIGGER +static void set_int(const struct device *dev, const bool en) { + const struct gen4_config *config = dev->config; + int ret = gpio_pin_interrupt_configure_dt(&config->dr, + en ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE); + if (ret < 0) { + LOG_ERR("can't set interrupt"); + } +} + +static int gen4_trigger_set(const struct device *dev, const struct sensor_trigger *trig, + sensor_trigger_handler_t handler) { + struct gen4_data *data = dev->data; + + set_int(dev, false); + if (trig->type != SENSOR_TRIG_DATA_READY) { + return -ENOTSUP; + } + data->data_ready_trigger = trig; + data->data_ready_handler = handler; + set_int(dev, true); + return 0; +} + +static void gen4_int_cb(const struct device *dev) { + struct gen4_data *data = dev->data; + LOG_DBG("Gen4 interrupt trigd: %d", 0); + gen4_sample_fetch(dev, 0); + data->data_ready_handler(dev, data->data_ready_trigger); + set_int(dev, true); + data->in_int = false; +} + +#ifdef CONFIG_GEN4_TRIGGER_OWN_THREAD +static void gen4_thread(void *arg) { + const struct device *dev = arg; + struct gen4_data *data = dev->data; + + while (1) { + k_sem_take(&data->gpio_sem, K_FOREVER); + gen4_int_cb(dev); + } +} +#elif defined(CONFIG_GEN4_TRIGGER_GLOBAL_THREAD) +static void gen4_work_cb(struct k_work *work) { + struct gen4_data *data = CONTAINER_OF(work, struct gen4_data, work); + gen4_int_cb(data->dev); +} +#endif + +static void gen4_gpio_cb(const struct device *port, struct gpio_callback *cb, uint32_t pins) { + struct gen4_data *data = CONTAINER_OF(cb, struct gen4_data, gpio_cb); + data->in_int = true; +#if defined(CONFIG_GEN4_TRIGGER_OWN_THREAD) + k_sem_give(&data->gpio_sem); +#elif defined(CONFIG_GEN4_TRIGGER_GLOBAL_THREAD) + k_work_submit(&data->work); +#endif +} +#endif + +static int gen4_init(const struct device *dev) { + struct gen4_data *data = dev->data; + const struct gen4_config *config = dev->config; + + LOG_WRN("gen4 start"); + data->in_int = false; + int ret; + ret = gen4_ext_write_1byte(dev, GEN4_REG_RESETCONTROL, GEN4_RESET_CONTROL); + if (ret < 0) { + LOG_ERR("can't reset %d", ret); + return ret; + } + k_msleep(60); + uint8_t extcache[4] = {0}; + + ret = gen4_ext_read(dev, GEN4_REG_SECURITYSTATUS, 1, extcache); // Read and pritn chip ID + if (ret < 0) { + LOG_ERR("can't read chip id %d", ret); + return ret; + } else + LOG_DBG("Chip ID: %x", extcache[2]); + + ret = gen4_ext_read(dev, GEN4_REG_FEEDCONFIG_1, 1, extcache); // Read feedconfig 1 + if (ret < 0) { + LOG_ERR("can't reaf feedconfig 1 %d", ret); + return ret; + } + // Configure abs reporting + extcache[2] |= GEN4_PRI_FEED_EN; + extcache[2] |= GEN4_PRI_FEED_TYPE; + k_usleep(50); + + ret = gen4_ext_write_1byte(dev, GEN4_REG_FEEDCONFIG_1, extcache[2]); // Write feedconfig 1 + if (ret < 0) { + LOG_ERR("can't Write feedconfig 1 %d", ret); + return ret; + } + k_usleep(50); + ret = gen4_ext_read(dev, GEN4_REG_FEEDCONFIG_1, 1, extcache); // Read feedconfig 1 + if (ret < 0) { + LOG_ERR("can't reaf feedconfig 1 %d", ret); + return ret; + } + + /*if (config->no_taps || config->rotate_90) { + ret = gen4_ext_read(dev, GEN4_REG_FEEDCONFIG_2, 1, extcache); // Read feedconfig 2 + if (ret < 0) { + LOG_ERR("can't reaf feedconfig 2 %d", ret); + return ret; + } + // Configure abs reporting + extcache[2] |= config->rotate_90 ? GEN4_SWAP_XY : 0; + extcache[2] |= config->no_taps ? GEN4_DISABLE_BUTTONS : 0; + k_usleep(50); + + ret = gen4_ext_write_1byte(dev, GEN4_REG_FEEDCONFIG_2, extcache[2]); // Write feedconfig + 2 if (ret < 0) { LOG_ERR("can't Write feedconfig 2 %d", ret); return ret; + } + k_usleep(50); + } + ret = gen4_ext_write_1byte(dev, GEN4_REG_ZIDLE, 1); // one Z-Idle packet + if (ret < 0) { + LOG_ERR("can't write %d", ret); + return ret; + } + + ret = gen4_ext_read(dev, GEN4_REG_POWERCONTROL, 1, extcache); // Read Powercontrol + if (ret < 0) { + LOG_ERR("can't read Powercontrol %d", ret); + return ret; + } + // Configure deep sleep + extcache[2] |= config->sleep_en ? GEN4_DEEP_SLEEP_EN : 0; + k_usleep(50); + + ret = gen4_ext_write_1byte(dev, GEN4_REG_POWERCONTROL, extcache[2]); // Write Powercontrol + if (ret < 0) { + LOG_ERR("can't Write Powercontrol %d", ret); + return ret; + } + k_usleep(50); + */ + gen4_sample_fetch(dev, 0); +#ifdef CONFIG_GEN4_TRIGGER + data->dev = dev; + gpio_pin_configure_dt(&config->dr, GPIO_INPUT); + gpio_init_callback(&data->gpio_cb, gen4_gpio_cb, BIT(config->dr.pin)); + ret = gpio_add_callback(config->dr.port, &data->gpio_cb); + if (ret < 0) { + LOG_ERR("Failed to set DR callback: %d", ret); + return -EIO; + } + +#if defined(CONFIG_GEN4_TRIGGER_OWN_THREAD) + k_sem_init(&data->gpio_sem, 0, UINT_MAX); + + k_thread_create(&data->thread, data->thread_stack, CONFIG_GEN4_THREAD_STACK_SIZE, + (k_thread_entry_t)gen4_thread, (void *)dev, 0, NULL, + K_PRIO_COOP(CONFIG_GEN4_THREAD_PRIORITY), 0, K_NO_WAIT); +#elif defined(CONFIG_GEN4_TRIGGER_GLOBAL_THREAD) + k_work_init(&data->work, gen4_work_cb); +#endif +#endif + LOG_WRN("inited"); + return 0; +} + +static const struct sensor_driver_api gen4_driver_api = { +#if CONFIG_GEN4_TRIGGER + .trigger_set = gen4_trigger_set, +#endif + .sample_fetch = gen4_sample_fetch, + .channel_get = gen4_channel_get, +}; + +#define GEN4_INST(n) \ + static struct gen4_data gen4_data_##n; \ + static const struct gen4_config gen4_config_##n = { \ + .bus = I2C_DT_SPEC_INST_GET(n), \ + .rotate_90 = DT_INST_PROP(0, rotate_90), \ + .sleep_en = DT_INST_PROP(0, sleep), \ + .no_taps = DT_INST_PROP(0, no_taps), \ + COND_CODE_1(CONFIG_GEN4_TRIGGER, (.dr = GPIO_DT_SPEC_GET(DT_DRV_INST(0), dr_gpios), ), \ + ())}; \ + DEVICE_DT_INST_DEFINE(n, gen4_init, NULL, &gen4_data_##n, &gen4_config_##n, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, &gen4_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(GEN4_INST) \ No newline at end of file diff --git a/app/drivers/sensor/gen4/gen4.h b/app/drivers/sensor/gen4/gen4.h index 4036d12cdcd..219b1dde197 100644 --- a/app/drivers/sensor/gen4/gen4.h +++ b/app/drivers/sensor/gen4/gen4.h @@ -1,3 +1,10 @@ +#pragma once + +#include +#include +#include +#include + #define GEN4_REG_CHIP_ID 0xC2C0 #define GEN4_REG_FW_VER 0xC2C1 #define GEN4_REG_SYSCONFIG_1 0xC2C2 @@ -11,6 +18,156 @@ #define GEN4_REG_ZIDLE 0xC2CA #define GEN4_REG_FILTERCONTROL 0xC2CB #define GEN4_REG_POWERCONTROL 0xC2CE +#define GEN4_REG_RESETCONTROL 0xC2CF +#define GEN4_REG_SECURITYSTATUS 0xC418 + +// Normal read packet +#define GEN4_LEN_LO_SHIFT 0 +#define GEN4_LEN_HI_SHIFT 1 +#define GEN4_REPORT_ID_SHIFT 2 +#define GEN4_NUM_CONTACT_SHIFT 3 +#define GEN4_F0_PALM_SHIFT 4 +#define GEN4_F0_X_LO_SHIFT 5 +#define GEN4_F0_X_HI_SHIFT 6 +#define GEN4_F0_Y_LO_SHIFT 7 +#define GEN4_F0_Y_HI_SHIFT 8 +#define GEN4_F1_PALM_SHIFT 9 +#define GEN4_F1_X_LO_SHIFT 10 +#define GEN4_F1_X_HI_SHIFT 11 +#define GEN4_F1_Y_LO_SHIFT 12 +#define GEN4_F1_Y_HI_SHIFT 13 +#define GEN4_F2_PALM_SHIFT 14 +#define GEN4_F2_X_LO_SHIFT 15 +#define GEN4_F2_X_HI_SHIFT 16 +#define GEN4_F2_Y_LO_SHIFT 17 +#define GEN4_F2_Y_HI_SHIFT 18 +#define GEN4_F3_PALM_SHIFT 19 +#define GEN4_F3_X_LO_SHIFT 20 +#define GEN4_F3_X_HI_SHIFT 21 +#define GEN4_F3_Y_LO_SHIFT 22 +#define GEN4_F3_Y_HI_SHIFT 23 +#define GEN4_F4_PALM_SHIFT 24 +#define GEN4_F4_X_LO_SHIFT 25 +#define GEN4_F4_X_HI_SHIFT 26 +#define GEN4_F4_Y_LO_SHIFT 27 +#define GEN4_F4_Y_HI_SHIFT 28 +#define GEN4_BTNS_SHIFT 29 + +// Sysconfig 1 +#define GEN4_PS2_MODE BIT(0) +#define GEN4_TRACKING_EN BIT(1) +#define GEN4_ANY_MEAS_EN BIT(2) +#define GEN4_ASSERT_DR_POR BIT(3) +#define GEN4_INTERFACE_PRIORITY_PRI BIT(4) +#define GEN4_INTERFACE_PRIORITY_SEC BIT(5) +#define GEN4_RANDOMISE_DRIVE BIT(7) + +// Sysconfig 2 +#define GEN4_NO_INTELLIMOUSE BIT(0) +#define GEN4_UPSET_REC_EN BIT(1) +#define GEN4_DOUBLE_MEAS_RES BIT(2) +#define GEN4_RES_SCALER_EN BIT(3) +#define GEN4_GEN_PEAK_DATA BIT(4) +#define GEN4_DISABLE_WATCHDOG BIT(5) +#define GEN4_TRISTATE_UNMUXED_SENSE BIT(6) +#define GEN4_EXECUTE_EF_AUTOTUNE BIT(7) + +// Feedconfig 1 +#define GEN4_PRI_FEED_EN BIT(0) +#define GEN4_PRI_FEED_TYPE BIT(1) +#define GEN4_ABS_XYZZ_EN BIT(2) +#define GEN4_SEC_FEED_TYPE BIT(4) +#define GEN4_LOCK_DATA_PORT BIT(5) +#define GEN4_LOCK_DATA_PORT_SEL BIT(6) +#define GEN4_CAL BIT(7) + +// Feedconfig 2 +#define GEN4_INV_X BIT(0) +#define GEN4_INV_Y BIT(1) +#define GEN4_SWAP_XY BIT(2) +#define GEN4_Y_PAN_INV BIT(3) +#define GEN4_DISABLE_COORD BIT(4) +#define GEN4_DISABLE_BUTTONS BIT(5) +#define GEN4_KEYPAD_AVAILABLE BIT(6) +#define GEN4_KEYPAD_EN BIT(7) + +// Feedconfig 3 +#define GEN4_LINEAR_CORR_EN BIT(0) +#define GEN4_EDGE_STAB_DISABLE BIT(1) +#define GEN4_DELTA_ACCELERATION_EN BIT(2) +#define GEN4_NOISE_AVOIDANCE_EN BIT(3) +#define GEN4_MULTI_FINGER_FRAME BIT(4) +#define GEN4_CLIP_SCALAR_BOUNDARIES BIT(5) +#define GEN4_DISCARD_NOISY_DATA BIT(6) +#define GEN4_EN_INTELLIMOUSE BIT(7) + +// Compconfig 1 +#define GEN4_BIST_RUN BIT(0) +#define GEN4_OFFSET_COMP_EN BIT(1) +#define GEN4_BACKGROUND_COMP_EN BIT(2) +#define GEN4_SIG_SIGN_COMP_EN BIT(3) +#define GEN4_CONGRUENCE_COMP_EN BIT(4) +#define GEN4_POS_COMP_EN BIT(5) +#define GEN4_BIST_PASS BIT(6) +#define GEN4_NFC_ACTIVE BIT(7) + +// Filtercontrol +#define GEN4_FILTER_JITTER_EN BIT(0) +#define GEN4_FILTER_LEAST_CHANGE_EN BIT(1) +#define GEN4_FILTER_SMOOTHING_EN BIT(2) +#define GEN4_FILTER_ADAPTIVE_EXP_EN BIT(3) +#define GEN4_FILTER_ONLY_MULTI_FINGER_EN BIT(4) +#define GEN4_FILTER_HOVER_EN BIT(5) +#define GEN4_FILTER_SWARM_EN BIT(6) + +// Powercontrol +#define GEN4_DEEP_SLEEP_EN BIT(0) +#define GEN4_BUTTON_WAKE_EN BIT(1) +#define GEN4_SLEEP_WHEN_DISABLED BIT(2) +#define GEN4_COMP_ON_WAKE BIT(3) +#define GEN4_DISABLE_ST2_SLEEP BIT(4) +#define GEN4_DISABLE_PS2_IN_SLEEP BIT(5) + +// Resetcontrol +#define GEN4_RESET_CONTROL BIT(7) #define GEN4_EXT_ACCESS_WRITE 0x0900 #define GEN4_EXT_ACCESS_READ 0x0901 + +#define GEN4_ADDRESS 0x2A + +struct gen4_finger_data { + bool present; + bool palm; + uint16_t x, y; +}; + +struct gen4_data { + uint8_t contacts; + uint8_t btns; + struct gen4_finger_data fingers[5]; + bool in_int; +#ifdef CONFIG_GEN4_TRIGGER + const struct device *dev; + const struct sensor_trigger *data_ready_trigger; + struct gpio_callback gpio_cb; + sensor_trigger_handler_t data_ready_handler; +#if defined(CONFIG_GEN4_TRIGGER_OWN_THREAD) + K_THREAD_STACK_MEMBER(thread_stack, CONFIG_GEN4_THREAD_STACK_SIZE); + struct k_sem gpio_sem; + struct k_thread thread; +#elif defined(CONFIG_GEN4_TRIGGER_GLOBAL_THREAD) + struct k_work work; +#endif +#endif +}; + +struct gen4_config { +#if DT_INST_ON_BUS(0, i2c) + const struct i2c_dt_spec bus; +#endif + bool rotate_90, sleep_en, no_taps; +#ifdef CONFIG_GEN4_TRIGGER + const struct gpio_dt_spec dr; +#endif +}; diff --git a/app/include/drivers/sensor/gen4.h b/app/include/drivers/sensor/gen4.h new file mode 100644 index 00000000000..19e9d814f1a --- /dev/null +++ b/app/include/drivers/sensor/gen4.h @@ -0,0 +1,39 @@ +#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_GEN4_H_ +#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_GEN4_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +enum sensor_channel_gen4 { + SENSOR_CHAN_FINGERS = SENSOR_CHAN_PRIV_START, + SENSOR_CHAN_X_0, + SENSOR_CHAN_X_1, + SENSOR_CHAN_X_2, + SENSOR_CHAN_X_3, + SENSOR_CHAN_X_4, + SENSOR_CHAN_Y_0, + SENSOR_CHAN_Y_1, + SENSOR_CHAN_Y_2, + SENSOR_CHAN_Y_3, + SENSOR_CHAN_Y_4, + SENSOR_CHAN_PRESENT_0, + SENSOR_CHAN_PRESENT_1, + SENSOR_CHAN_PRESENT_2, + SENSOR_CHAN_PRESENT_3, + SENSOR_CHAN_PRESENT_4, + SENSOR_CHAN_PALM_0, + SENSOR_CHAN_PALM_1, + SENSOR_CHAN_PALM_2, + SENSOR_CHAN_PALM_3, + SENSOR_CHAN_PALM_4, + SENSOR_CHAN_BUTTONS, +}; + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file