/dts-v1/;

#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_spi.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/esp32_wifi.h>

#include <bindings/tca8418.h>
#include <bindings/bm8563.h>
#include <bindings/esp_epaper.h>

/ {
	compatible = "root";
	model = "CL-32";

	gpio0 {
		compatible = "espressif,esp32-gpio";
		gpio-count = <49>;
	};

	wifi0 {
		compatible = "espressif,esp32-wifi";
		status = "disabled";
	};

	// Top Stemma/Qwiic port 1 shares this bus with the keyboard and RTC (SDA: pin 1 <-> SCL: pin 2).
	// External I2C devices on that port are reachable via i2c0.
	i2c0 {
		compatible = "espressif,esp32-i2c";
		port = <I2C_NUM_0>;
		clock-frequency = <100000>;
		pin-sda = <&gpio0 1 GPIO_FLAG_PULL_UP>;
		pin-scl = <&gpio0 2 GPIO_FLAG_PULL_UP>;

		keyboard {
			compatible = "ti,tca8418";
			reg = <0x34>;
			rows = <8>;
			columns = <10>;
			keymap-lc = [
				37 49 50 51 52 53 54 55 56 0 // % 1 2 3 4 5 6 7 8
				57 48 8 91 93 43 34 39 27 0 // 9 0 BKSP [ ] + " ' EXIT
				9 113 119 101 114 116 121 117 105 0 // TAB q w e r t y u i
				111 112 10 40 41 45 59 58 3 0 // o p ENTER ( ) - ; : STOP
				0 97 115 100 102 103 104 106 107 0 //   a s d f g h j k
				108 17 35 123 125 42 44 46 2 0 // l UP # { } * , . MENU
				122 120 99 118 98 32 32 110 109 0 // z x c v b   n m
				20 18 19 60 62 47 92 61 10 0 // LEFT DOWN RIGHT < > / \ = RUN
			];
			keymap-uc = [
				37 49 50 51 52 53 54 55 56 0 // % 1 2 3 4 5 6 7 8
				57 48 8 91 93 43 34 39 27 0 // 9 0 BKSP [ ] + " ' EXIT
				9 81 87 69 82 84 89 85 73 0 // TAB Q W E R T Y U I
				79 80 10 40 41 45 59 58 3 0 // O P ENTER ( ) - ; : STOP
				0 65 83 68 70 71 72 74 75 0 //   A S D F G H J K
				76 17 35 123 125 42 44 46 2 0 // L UP # { } * , . MENU
				90 88 67 86 66 32 32 78 77 0 // Z X C V B   N M
				20 18 19 60 62 47 92 61 10 0 // LEFT DOWN RIGHT < > / \ = RUN
			];
			keymap-sy = [
				37 49 50 51 52 53 54 55 56 0 // % 1 2 3 4 5 6 7 8
				57 48 8 91 93 43 34 39 27 0 // 9 0 BKSP [ ] + " ' EXIT
				9 113 119 101 114 116 121 117 105 0 // TAB q w e r t y u i
				111 112 10 40 41 45 59 58 3 0 // o p ENTER ( ) - ; : STOP
				0 97 115 100 102 103 104 106 107 0 //   a s d f g h j k
				108 17 35 123 125 42 44 46 2 0 // l UP # { } * , . MENU
				122 120 99 118 98 32 32 110 109 0 // z x c v b   n m
				20 18 19 60 62 47 92 61 10 0 // LEFT DOWN RIGHT < > / \ = RUN
			];
			shift-row = <4>;
			shift-col = <0>;
			sym-row = <5>;
			sym-col = <8>;
		};

		rtc: bm8563 {
			compatible = "belling,bm8563";
			reg = <0x51>;
		};
	};

	port_b: grove1 {
		compatible = "espressif,esp32-grove";
		defaultMode = <GROVE_MODE_I2C>;
		pinSdaTx = <&gpio0 47 GPIO_FLAG_NONE>;
		pinSclRx = <&gpio0 48 GPIO_FLAG_NONE>;
		uartPort = <UART_NUM_1>;
		i2cPort = <I2C_NUM_1>;
		i2cClockFrequency = <100000>;
	};

	spi1 {
		compatible = "espressif,esp32-spi";
		host = <SPI2_HOST>;
		cs-gpios = <&gpio0 7 GPIO_FLAG_NONE>;
		pin-mosi = <&gpio0 10 GPIO_FLAG_NONE>;
		pin-miso = <&gpio0 11 GPIO_FLAG_NONE>;
		pin-sclk = <&gpio0 9 GPIO_FLAG_NONE>;
		max-transfer-size = <4096>;

		sdcard@0 {
			compatible = "espressif,esp32-sdspi";
			frequency-khz = <20000>;
		};

		epd@1 {
			compatible = "tuanpmt,esp-epaper";
			pin-dc = <&gpio0 13 GPIO_FLAG_NONE>;
			pin-reset = <&gpio0 12 GPIO_FLAG_NONE>;
			pin-busy = <&gpio0 14 GPIO_FLAG_NONE>;
			pin-cs = <&gpio0 6 GPIO_FLAG_NONE>;
			clock-speed-hz = <4000000>;
			panel-type = "gdey029t71h";
			update-mode = <2>;
			rotation = <1>;
		};
	};
};
