From fa935f17408d7373b9419bf19b9cecc48f363765 Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Sat, 27 Jan 2024 00:17:50 +0100 Subject: ps2 --- config/boards/shields/corne/corne.dtsi | 258 +++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 config/boards/shields/corne/corne.dtsi (limited to 'config/boards/shields/corne/corne.dtsi') diff --git a/config/boards/shields/corne/corne.dtsi b/config/boards/shields/corne/corne.dtsi new file mode 100644 index 0000000..acee29c --- /dev/null +++ b/config/boards/shields/corne/corne.dtsi @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2020 Pete Johanson + * + * SPDX-License-Identifier: MIT + */ + +#include + +/ { + chosen { + zephyr,display = &oled; + zmk,kscan = &kscan0; + zmk,matrix-transform = &default_transform; + }; + + default_transform: keymap_transform_0 { + compatible = "zmk,matrix-transform"; + columns = <12>; + rows = <4>; +// | SW1 | SW2 | SW3 | SW4 | SW5 | SW6 | | SW6 | SW5 | SW4 | SW3 | SW2 | SW1 | +// | SW7 | SW8 | SW9 | SW10 | SW11 | SW12 | | SW12 | SW11 | SW10 | SW9 | SW8 | SW7 | +// | SW13 | SW14 | SW15 | SW16 | SW17 | SW18 | | SW18 | SW17 | SW16 | SW15 | SW14 | SW13 | +// | SW19 | SW20 | SW21 | | SW21 | SW20 | SW19 | + 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(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(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(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) + >; + }; + + five_column_transform: keymap_transform_1 { + compatible = "zmk,matrix-transform"; + columns = <10>; + rows = <4>; +// | SW2 | SW3 | SW4 | SW5 | SW6 | | SW6 | SW5 | SW4 | SW3 | SW2 | +// | SW8 | SW9 | SW10 | SW11 | SW12 | | SW12 | SW11 | SW10 | SW9 | SW8 | +// | SW14 | SW15 | SW16 | SW17 | SW18 | | SW18 | SW17 | SW16 | SW15 | SW14 | +// | SW19 | SW20 | SW21 | | SW21 | SW20 | SW19 | + map = < +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(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(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(3,3) RC(3,4) RC(3,5) RC(3,6) RC(3,7) RC(3,8) + >; + }; + + kscan0: kscan { + compatible = "zmk,kscan-gpio-matrix"; + + diode-direction = "col2row"; + row-gpios + = <&pro_micro 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro 6 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&pro_micro 7 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + + }; + + // TODO: per-key RGB node(s)? +}; + +&pro_micro_i2c { + status = "okay"; + + oled: ssd1306@3c { + compatible = "solomon,ssd1306fb"; + reg = <0x3c>; + width = <128>; + height = <32>; + segment-offset = <0>; + page-offset = <0>; + display-offset = <0>; + multiplex-ratio = <31>; + segment-remap; + com-invdir; + com-sequential; + prechargep = <0x22>; + }; +}; + + +/* + * PS/2 Mouse / Trackpoint + */ + +// Configure the SCL and SDA pins of the PS/2 mouse/tp using the `&pro_micro` +// notation. +// +// If possible, try to choose the blue high frequency pins to avoid +// bluetooth interference. +// +// On the nice!nano documentation these are green DX pins: +// https://nicekeyboards.com/docs/nice-nano/pinout-schematic +// +#define MOUSE_PS2_PIN_SCL_PRO_MICRO <&pro_micro 1 GPIO_ACTIVE_HIGH> +#define MOUSE_PS2_PIN_SDA_PRO_MICRO <&pro_micro 0 GPIO_ACTIVE_HIGH> + + +// Uncomment and configure this pin if you have an extra free pin and want the +// controller to perform the Power-On-Reset sequence, which many trackpoints +// require, instead of using a trackpoint reset circuit. +// +// It's ok to use a low-frequency pin for this. +#define MOUSE_PS2_PIN_RST_PRO_MICRO <&pro_micro 9 GPIO_ACTIVE_HIGH> + + +// Now configure the same SDA pin using the pinctrl notation. +// +// For that you have to use the PX.XX notation of the nrf52 chip. +// +// On the nice!nano pinout they are shown in blue and purple next to the green +// DX pin. +// +// Enter it like `X, Y` without leading zeroes. +// Examples: +// D0 - P0.08: 0, 8 +// D15 - P1.13: 1, 13 +// +// We don't define the SCL pin, because UART uses a baud rate instead of +// a clock pin. +#define MOUSE_PS2_PIN_SDA_PINCTRL + + +// In UART two different pins are used for receiving and transmitting, but PS/2 +// uses the same pin for both. +// +// The UART config still requires both pins to be configured. So we use one of +// the nrf52 pins that are not exposed on the nice!nano board. +#define MOUSE_PS2_PIN_UNEXPOSED_TX +#define MOUSE_PS2_PIN_UNEXPOSED_RX + + +// The PS/2 GPIO driver +/ { + gpio_ps2: gpio_ps2 { + status = "disabled"; + compatible = "gpio-ps2"; + scl-gpios = MOUSE_PS2_PIN_SCL_PRO_MICRO; + sda-gpios = MOUSE_PS2_PIN_SDA_PRO_MICRO; + }; +}; + + +&pinctrl { + // This pinctrl state is used for receiving + // For `UART_TX`, set an unused and unexposed pin + // For `UART_RX`, set the PS/2 SDA pin number + uart0_ps2_default: uart0_ps2_default { + group1 { + psels = MOUSE_PS2_PIN_UNEXPOSED_TX, + MOUSE_PS2_PIN_SDA_PINCTRL; + }; + }; + + // Set this to the same pins as uart0_ps2_default + uart0_ps2_sleep: uart0_ps2_sleep { + group1 { + psels = MOUSE_PS2_PIN_UNEXPOSED_TX, + MOUSE_PS2_PIN_SDA_PINCTRL; + low-power-enable; + }; + }; + + // The nrf52 UART controller is not compatible with the PS/2 + // transmission frame. So we don't use UART for transmissions + // and instead use GPIO bitbanging. + // + // When we switch to transmit mode, we free up the SDA pin by switching + // UART to unexposed/unused pins. + // + // Then we can configure the pins to be used with the GPIO controller. + uart0_ps2_off: uart0_ps2_off { + group1 { + psels = MOUSE_PS2_PIN_UNEXPOSED_TX, + MOUSE_PS2_PIN_UNEXPOSED_RX; + }; + }; +}; + + +&uart0 { + status = "disabled"; + compatible = "nordic,nrf-uarte"; + + // PS/2 uses a clock pin to syncronize data transmissions. UART on the + // other hand uses a pre-defined frequency (baud rate). + // + // Fortunately, one of the available baud rates is very close to the + // frequency used in IBM/Lenovo trackpoints. + // + // You can find other configurable baud rates here: + // https://docs.zephyrproject.org/latest/build/dts/api/bindings/serial/nordic,nrf-uarte.html + // + // But most likely you won't need to adjust this. + // + // You can measure the frequency of your mouse/TP using a $5 logic + // analyzer from AliExpress. + // + // Actual frequency of PS/2 trackpoint: 67us + // Correspondent baud rate: 14,925 + // + // Closest available baud rate in zephyr: 14,400 + // Correspondent cycle length: 69.44 microseconds + // + // Calculations: + // + // Convert cycle length in microseconds into baud: + // 1 / PS2_CYCLE_LENGTH * 1000000 = BAUD + // 1 / 67 * 1000000 = 14,925 BAUD + // + // Convert baud into cycle length: + // 1 / BAUD * 1000000 = CYCLE_LEN (in microseconds) + // 1 / 14400 * 1000000 = 69.44 + // + current-speed = <14400>; + pinctrl-0 = <&uart0_ps2_default>; + pinctrl-1 = <&uart0_ps2_off>; + + pinctrl-names = "default", "sleep"; + + uart_ps2: uart_ps2 { + status="disabled"; + compatible = "uart-ps2"; + scl-gpios = MOUSE_PS2_PIN_SCL_PRO_MICRO; + sda-gpios = MOUSE_PS2_PIN_SDA_PRO_MICRO; + }; +}; + + +/ { + mouse_ps2: mouse_ps2 { + status = "disabled"; + compatible = "zmk,input-mouse-ps2"; + + // This will be overriden in your `xxx_right.overlay file`. + // ps2-device = <&gpio_ps2>; + ps2-device = <&uart_ps2>; + +#ifdef MOUSE_PS2_PIN_RST_PRO_MICRO + rst-gpios = MOUSE_PS2_PIN_RST_PRO_MICRO; +#endif + }; + + input_config: input_config { + compatible = "zmk,input-configs"; + status = "disabled"; + + mouse_ps2_config: mouse_ps2_config { + device = <&mouse_ps2>; + + // Some of the available settings depend on the keymap. So they + // are adjusted in... + // ../../../includes/trackpoint.dtsi + }; + }; +}; -- cgit v1.2.3