/*
*
* 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";
        wakeup-source;

        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>;
        };
    };

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

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

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

&pinctrl {
    spi0_default: spi0_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,
                <NRF_PSEL(SPIM_MOSI, 0, 24)>,
                <NRF_PSEL(SPIM_MISO, 0, 27)>;
        };
    };

    spi0_sleep: spi0_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,
                <NRF_PSEL(SPIM_MOSI, 0, 24)>,
                <NRF_PSEL(SPIM_MISO, 0, 27)>;
            low-power-enable;
        };
    };
};

&spi0 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi0_default>;
    pinctrl-1 = <&spi0_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;

    epd: il0323@0 {
        compatible = "gooddisplay,il0323";
        reg =  <0>;
        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];
        cdi = <0xd2>;
        tcon = <0x22>;
    };
};
