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

#include "corneish_zen.dtsi"

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

    kscan0: kscan {
        compatible = "zmk,kscan-gpio-matrix";
        wakeup-source;

        diode-direction = "col2row";
        row-gpios
            = <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&gpio0  4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&gpio0 31 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&gpio0 30 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            ;

        col-gpios
            = <&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>
            , <&gpio0  5 GPIO_ACTIVE_HIGH>
            ;
    };

    leds {
        compatible = "gpio-leds";
        blue_led: led_0 {
            gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
        };
    };
};

&pinctrl {
    spi2_default: spi2_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                <NRF_PSEL(SPIM_MOSI, 0, 8)>,
                <NRF_PSEL(SPIM_MISO, 0, 22)>;
        };
    };

    spi2_sleep: spi2_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                <NRF_PSEL(SPIM_MOSI, 0, 8)>,
                <NRF_PSEL(SPIM_MISO, 0, 22)>;
            low-power-enable;
        };
    };

    i2c0_default: i2c0_default {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 6)>,
                <NRF_PSEL(TWIM_SCL, 0, 26)>;
        };
    };

    i2c0_sleep: i2c0_sleep {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 6)>,
                <NRF_PSEL(TWIM_SCL, 0, 26)>;
            low-power-enable;
        };
    };
};

&i2c0 {
    status = "okay";
    compatible = "nordic,nrf-twim";
    pinctrl-0 = <&i2c0_default>;
    pinctrl-1 = <&i2c0_sleep>;
    pinctrl-names = "default", "sleep";
    clock-frequency = <100000>;

    fuelgauge: bq274xx@55 {
        compatible = "ti,bq274xx";
        reg = <0x55>;
        design-voltage = <3700>; //Battery Design Voltage in mV
        design-capacity = <180>; //Battery Design Capacity in mAh
        taper-current = <2>; //Battery Taper current in mAh
        terminate-voltage = <2750>; //Battery Terminate Voltage in mV
        int-gpios = <&gpio1 14 GPIO_ACTIVE_LOW>;
    };
};

&spi2 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = <&spi2_default>;
    pinctrl-1 = <&spi2_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;

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