/dts-v1/;

#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_wifi_pinned.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_spi.h>
#include <tactility/bindings/esp32_adc_oneshot.h>
#include <tactility/bindings/esp32_pwm_ledc.h>
#include <tactility/bindings/esp32_usbdevice.h>
#include <tactility/bindings/battery_sense.h>
#include <bindings/bmi270.h>
#include <bindings/bm8563.h>
#include <bindings/gt911.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <bindings/papers3_power.h>
#include <bindings/papers3_display.h>

/ {
	compatible = "root";
	model = "M5Stack PaperS3";

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

	ble0 {
		compatible = "espressif,esp32-ble";
		status = "disabled";
	};

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

	i2c_internal {
		compatible = "espressif,esp32-i2c";
		port = <I2C_NUM_0>;
		clock-frequency = <400000>;
		pin-sda = <&gpio0 41 GPIO_FLAG_NONE>;
		pin-scl = <&gpio0 42 GPIO_FLAG_NONE>;

		bmi270 {
			compatible = "bosch,bmi270";
			reg = <0x68>;
		};

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

		touch {
			compatible = "goodix,gt911";
			reg = <0x5D>;
			x-max = <540>;
			y-max = <960>;
			pin-interrupt = <&gpio0 48 GPIO_FLAG_NONE>;
		};
	};

	spi0 {
		compatible = "espressif,esp32-spi";
		host = <SPI2_HOST>;
		cs-gpios = <&gpio0 47 GPIO_FLAG_NONE>;
		pin-mosi = <&gpio0 38 GPIO_FLAG_NONE>;
		pin-miso = <&gpio0 40 GPIO_FLAG_NONE>;
		pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>;
		max-transfer-size = <4096>;

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

	adc0 {
		compatible = "espressif,esp32-adc-oneshot";
		unit-id = <ADC_UNIT_1>;
		channels = <ADC_CHANNEL_2 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
	};

	battery-sense {
		compatible = "battery-sense";
		io-channel = <&adc0 0>;
		reference-voltage-mv = <3300>;
		multiplier = <2000>;
	};

	buzzer_pwm {
		compatible = "espressif,esp32-pwm-ledc";
		pin = <&gpio0 21 GPIO_FLAG_NONE>;
		period-ns = <1000000>;
		ledc-timer = <0>;
		ledc-channel = <0>;
	};

	power {
		compatible = "m5stack,papers3-power";
		pin-charge-status = <&gpio0 4 GPIO_FLAG_NONE>;
		pin-usb-detect = <&gpio0 5 GPIO_FLAG_NONE>;
		pin-power-off = <&gpio0 44 GPIO_FLAG_NONE>;
		pwm = <&buzzer_pwm>;
	};

	// M5Stack PaperS3 E-Ink display (EPDiy library, ED047TC1 panel)
	display {
		compatible = "m5stack,papers3-display";
		temperature-celsius = <20>;
		// EPD_ROT_PORTRAIT rendered 180deg rotated on real hardware; INVERTED_PORTRAIT is
		// exactly 180deg from it (verified against epdiy's _rotate()) and is this panel's
		// correct orientation.
		rotation = <EPD_ROT_INVERTED_PORTRAIT>;
	};

	usbdevice0 {
		compatible = "espressif,esp32-usbdevice";

		usbdevicemsc0 {
			compatible = "espressif,esp32-usbdevice-msc";
		};
	};
};
