/*
*
* Copyright (c) 2021 Darryl deHaan
* SPDX-License-Identifier: MIT
*
*/

#include "corneish_zen.dtsi"

/{
	chosen {
		zephyr,display = &epd;
		zmk,battery = &vbatt;
	};

	kscan0: kscan {
		compatible = "zmk,kscan-gpio-matrix";
		label = "KSCAN";

		diode-direction = "col2row";
		row-gpios
			= <&gpio0 22 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
			, <&gpio1  0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
			, <&gpio1  3 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
			, <&gpio1  1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
			;

		col-gpios
			= <&gpio0 19 GPIO_ACTIVE_HIGH>
			, <&gpio0 21 GPIO_ACTIVE_HIGH>
			, <&gpio0 23 GPIO_ACTIVE_HIGH>
			, <&gpio0 12 GPIO_ACTIVE_HIGH>
			, <&gpio1  9 GPIO_ACTIVE_HIGH>
			, <&gpio0  7 GPIO_ACTIVE_HIGH>
			;
		
	};

	leds {
			compatible = "gpio-leds";
			blue_led: led_0 {
				gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>;
				label = "Blue LED";
			};
		};

	vbatt: vbatt {
		compatible = "zmk,battery-voltage-divider";
		label = "BATTERY";
		io-channels = <&adc 0>;
		output-ohms = <1960000>;
		full-ohms = <(1960000 + 810000)>;
	};
};

&default_transform {
	col-offset = <6>;
};
&five_column_transform {
	col-offset = <6>;
};

&spi0 {
	status = "okay";
	compatible = "nordic,nrf-spim";
	sck-pin = <20>;
	mosi-pin = <24>;
	miso-pin = <27>;
	cs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;

	epd: il0323@0 {
		compatible = "gooddisplay,il0323";
		reg =  <0>;
		label = "DISPLAY";
		width = <80>;
		height = <128>;
		spi-max-frequency = <4000000>;
		dc-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
		busy-gpios = <&gpio0 14 GPIO_ACTIVE_LOW>;
		reset-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
		pwr = [03 00 26 26];
		//softstart = [17 17 17 17];
		cdi = <0xd2>;
		tcon = <0x22>;
	};
};
