From f437c99b9d2f4028f0b1391aa9ad4846af9655e0 Mon Sep 17 00:00:00 2001 From: suriaribeiro <134444434+suriaribeiro@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:44:46 +0200 Subject: [PATCH] Update acari_right.overlay --- .../boards/shields/acari/acari_right.overlay | 519 ++++++++++++++++++ 1 file changed, 519 insertions(+) diff --git a/config/boards/shields/acari/acari_right.overlay b/config/boards/shields/acari/acari_right.overlay index 5b3c49f..71cd8ad 100644 --- a/config/boards/shields/acari/acari_right.overlay +++ b/config/boards/shields/acari/acari_right.overlay @@ -19,3 +19,522 @@ , <&xiao_d 0 GPIO_ACTIVE_HIGH> ; }; + +/* + * PS/2 Mouse / Trackpoint - User Configuration + * + * Enable PS/2 drivers on this side of the keyboard. + * It MUST be the central half. If you connected your TP or mouse to the + * left side, then move the following content to `your_keyboard_left.overlay` + * + * You also need to adjust `Kconfig.defconfig` and configure that this side + * is the central side. + * + */ + + +// Pick the PS/2 driver +// +// Comment out the following define to use the PS/2 GPIO driver instead of the +// UART driver. +// +// Both, the UART and GPIO drivers, implement the PS/2 protocol and work with +// trackpoints and other mouse devices that use PS/2. +// +// The only difference is which hardware they use on your controller to +// transmit the data. The UART driver has MUCH better performance and should +// be used by most people. +// +// The GPIO driver should only be used if your PS/2 pointing device uses a +// clock frequency rate that is not compatible with the UART baud rates. Or +// if you are NOT using a nrf52-based controller, such as the nice!nano, +// nice!nano clone or a seeduino xiao. +// +// In all other cases you should try using the UART driver first. +#define MOUSE_PS2_DRIVER_UART + + +// Configure the SCL and SDA pins using the`&pro_micro` notation. +// +// If possible, try to choose the blue high frequency pins to avoid +// bluetooth interference. +// +// It will still work even if you pick low frequency pins, but there is a risk +// that the trackpoint could cause bluetooth interference. +// +// On the nice!nano documentation these are green DX pins: +// https://nicekeyboards.com/docs/nice-nano/pinout-schematic +// +// The ideal pins are... +// - D1 and D0 for clock and data, because they are high frequency. +// - D8, D9, D16 or D10 for the trackpoint reset pin, because it doesn't +// need to be high frequency (only needed if you are not using a reset +// circuit) +// +// But on the corne keyboard, these pins are used for the backlight. So, this +// example config uses the pins D16 and D10 for clock and data and +// D9 for the reset circuit. +#define MOUSE_PS2_PIN_SCL_PRO_MICRO <&xiao_d 10 GPIO_ACTIVE_HIGH> +#define MOUSE_PS2_PIN_SDA_PRO_MICRO <&xiao_d 9 GPIO_ACTIVE_HIGH> + +// Configure the Power-On-Reset pin +// +// 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. +// +// You don't need this if you are not using a trackpoint or if you have a +// trackpoint reset circuit. +// +// It's ok to use a low-frequency pin for this. +#define MOUSE_PS2_PIN_RST_PRO_MICRO <&xiao_d 7 GPIO_ACTIVE_HIGH> + + +// Configure SDA pin using the pinctrl notation +// +// Now configure SDA pin using the pinctrl notation. Make sure to use the same +// pin as in the pro micro notation, but convert it to the pinctrl notation. +// +// For the nice!nano you can find it on their pinout schematic, next to the +// pins, in the blue or violet boxes, with a format like `PX.YY` (P0.09). +// +// Enter it like `X, Y` without leading zeroes. +// +// Examples: +// D1 - P0.06: 0, 6 +// D0 - P0.08: 0, 8 +// D15 - P1.13: 1, 13 +// D16 - P0.10: 0, 10 +// D10 - P0.09: 0, 9 +// +// We don't define the SCL pin, because UART uses a baud rate instead of +// a clock pin. +#define MOUSE_PS2_PIN_SDA_PINCTRL + +// Configure UART BAUD Rate +// +// TLDR WARNING: +// Most likely you won't need to adjust this. So leave it at the default value +// of 14,400 and test if your mouse or trackpoint works. +// +// If it doesn't work, try using the GPIO version of the driver. If it works +// with the GPIO driver, then try using the UART driver with the BAUD rates +// 19,200 and 9,600. +// +// So far, all the trackpoints, which the community tested, worked with the +// 14,400 rate. +// +// Explanation what this is: +// +// 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 +// +// You can also measure the frequency of your mouse/TP using a $5 logic +// analyzer from AliExpress. +// +// Actual frequency of PS/2 trackpoint: 67us +// Corresponding baud rate: 14,925 +// +// Closest available baud rate in zephyr: 14,400 +// Corresponding 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 +// +// Most likely values +// +// The PS/2 protocol specifies that devices must use a clock line +// frequency in the range of 10 - 16.7 kHz. +// +// Most trackpoints seem to operate at around 14-15kHz. +// +// Therefore, the most likely values to try are: +// - 14400 ( 69 us cycle length / 14.5kHz) +// - 9600 (100 us cycle length / 10.0kHz) +// - 19200 ( 52 us cycle length / 19kHz) +#define MOUSE_PS2_UART_BAUD_RATE <14400> + + +/* + * PS/2 Mouse / Trackpoint - User Configuration if NOT using nice!nano + * + * WARNING: Do NOT change this if you are using a nice!nano v2 or clone. + */ + +// Unexposed UART pins +// 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. +// +// Do NOT change these if you are using a nice!nano (or a clone of it) +#define MOUSE_PS2_PIN_UNEXPOSED_TX +#define MOUSE_PS2_PIN_UNEXPOSED_RX + + +// Adjust GPIO interrupt priority to the highest level. +// +// IMPORTANT TLDR: +// If you are using the nice_nano_v2 board, you don't need to make changes to +// the config below and can leave it as it is. +// +// Explanation of these settings: +// +// PS/2 events must be processed within 30-50us, but frequently bluetooth and +// other interrupts take longer to finish. +// +// Therefore we change the default GPIO priority to the highest level (0) and +// demote all BT interrupt priorities by one level using the kconfig settings: +// - CONFIG_BT_CTLR_LLL_PRIO 1 +// - CONFIG_BT_CTLR_ULL_HIGH_PRIO 2 +// - CONFIG_BT_CTLR_ULL_LOW_PRIOCONFIG 2 +// +// These config options are enabled automatically by the PS2 UART and GPIO +// drivers... so you don't have to enable them manually. +// +// Then we lower the interrupt priority of all other devices by 2 levels using +// the devicetree config below. +// +// This allows the PS/2 interrupts to be triggered faster and reduces +// transmission errors. +// +// If you are using the nice_nano_v2 board, you can reuse my config below. +// +// Otherwise, you can generate the interrupt overrides using this script: +// https://github.com/infused-kim/kb_zmk_ps2_mouse_trackpoint_driver/blob/main/scripts/gen_interrupt_priority_overrides.py +// +// Make sure to do it on a zephyr.dts where the interrupts have not been +// adjusted yet (i.e. a config that doesn't have the the following options +// enabled). +// +// If you are building using a toolchain you can find the zephyr.dts in the +// build directory, which by default is: `app/build/zephyr/zephyr.dts` +// +// If you are building using the github actions, copy the output of the build +// step `xxxx_right - nice_nano_v2 Devicetree file` into a file and run the +// script on it. + +// gpiote should have the highest interrupt priority (0) +&gpiote { + interrupts = < 6 0 >; +}; + +// All other priorities should be two levels lower than their defaults +// (which is usually 1 and should be demoted to 3) +&clock { + interrupts = < 0 3 >; +}; + +&power { + interrupts = < 0 3 >; +}; + +&radio { + interrupts = < 1 3 >; +}; + +&uart0 { + interrupts = < 2 3 >; +}; + +&i2c0 { + interrupts = < 3 3 >; +}; + +&spi0 { + interrupts = < 3 3 >; +}; + +&i2c1 { + interrupts = < 4 3 >; +}; + +&spi1 { + interrupts = < 4 3 >; +}; + +&nfct { + interrupts = < 5 3 >; +}; + +&adc { + interrupts = < 7 3 >; +}; + +&timer0 { + interrupts = < 8 3 >; +}; + +&timer1 { + interrupts = < 9 3 >; +}; + +&timer2 { + interrupts = < 10 3 >; +}; + +&rtc0 { + interrupts = < 11 3 >; +}; + +&temp { + interrupts = < 12 3 >; +}; + +&rng { + interrupts = < 13 3 >; +}; + +&ecb { + interrupts = < 14 3 >; +}; + +&ccm { + interrupts = < 15 3 >; +}; + +&wdt { + interrupts = < 16 3 >; +}; + +&rtc1 { + interrupts = < 17 3 >; +}; + +&qdec { + interrupts = < 18 3 >; +}; + +&comp { + interrupts = < 19 3 >; +}; + +&egu0 { + interrupts = < 20 3 >; +}; + +&egu1 { + interrupts = < 21 3 >; +}; + +&egu2 { + interrupts = < 22 3 >; +}; + +&egu3 { + interrupts = < 23 3 >; +}; + +&egu4 { + interrupts = < 24 3 >; +}; + +&egu5 { + interrupts = < 25 3 >; +}; + +&timer3 { + interrupts = < 26 3 >; +}; + +&timer4 { + interrupts = < 27 3 >; +}; + +&pwm0 { + interrupts = < 28 3 >; +}; + +&pdm0 { + interrupts = < 29 3 >; +}; + +&pwm1 { + interrupts = < 33 3 >; +}; + +&pwm2 { + interrupts = < 34 3 >; +}; + +&spi2 { + interrupts = < 35 3 >; +}; + +&rtc2 { + interrupts = < 36 3 >; +}; + +&i2s0 { + interrupts = < 37 3 >; +}; + +&usbd { + interrupts = < 39 3 >; +}; + +&uart1 { + interrupts = < 40 3 >; +}; + +&qspi { + interrupts = < 41 3 >; +}; + +&pwm3 { + interrupts = < 45 3 >; +}; + +&spi3 { + interrupts = < 47 3 >; +}; + +&cryptocell { + interrupts = < 42 3 >; +}; + + +/* + * PS/2 Mouse / Trackpoint - Device Definitions + * + * WARNING: Do not change anything beyond here unless you know what you are + * doing. + */ + + +// Firmware with alternative pins +// +// This can safely be removed. It's only used in the example zmk-config repo +// to create an additional firmware with alternative PIN assignments. +// +// You can leave it or remove in your own zmk config. If you remove it, you +// should also remove the entry in `zmk-config-example/build.yaml` that uses +// it. +#ifdef MOUSE_PS2_ALT_PINS + #undef MOUSE_PS2_PIN_SCL_PRO_MICRO + #undef MOUSE_PS2_PIN_SDA_PRO_MICRO + #undef MOUSE_PS2_PIN_SDA_PINCTRL + + #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> + #define MOUSE_PS2_PIN_SDA_PINCTRL +#endif + +// This define can be used in the keymap file to check whether the device tree +// configs in this file are present to void build errors on the side that does +// not have the mouse or TP +#define MOUSE_PS2_DT_PRESENT + +&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 the PS/2 UART driver doesn't use UART for + // transmissions and instead use GPIO bit-banging. + // + // When the driver switches to transmit mode, it frees up the SDA pin by + // switching the UART controller to unexposed/unused pins. + // + // Then it configures the GPIO controller to use the SCL and SDA pins + uart0_ps2_off: uart0_ps2_off { + group1 { + psels = MOUSE_PS2_PIN_UNEXPOSED_TX, + MOUSE_PS2_PIN_UNEXPOSED_RX; + }; + }; +}; + + +#ifdef MOUSE_PS2_DRIVER_UART + + &uart0 { + status = "disabled"; + compatible = "nordic,nrf-uarte"; + + current-speed = MOUSE_PS2_UART_BAUD_RATE; + 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; + }; + }; + +#else + + / { + 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; + }; + }; + +#endif + + +/ { + mouse_ps2: mouse_ps2 { + status = "disabled"; + compatible = "zmk,input-mouse-ps2"; + +#ifdef MOUSE_PS2_DRIVER_UART + ps2-device = <&uart_ps2>; +#else + ps2-device = <&gpio_ps2>; +#endif + +#ifdef MOUSE_PS2_PIN_RST_PRO_MICRO + rst-gpios = MOUSE_PS2_PIN_RST_PRO_MICRO; +#endif + }; + + mouse_ps2_input_listener: mouse_ps2_input_listener { + compatible = "zmk,input-listener-ps2"; + status = "disabled"; + + device = <&mouse_ps2>; + + // Some of the available settings depend on the keymap. So they + // are adjusted in... + // zmk-config/config/includes/mouse_tp.dtsi + }; +};