/*
* Copyright (c) 2021 Polarity Works
*
* SPDX-License-Identifier: MIT
*/

/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
#include <dt-bindings/zmk/matrix_transform.h>

/ {
    model = "BT60";
    compatible = "polarityworks,bt60";

    chosen {
        zephyr,code-partition = &code_partition;
        zephyr,sram = &sram0;
        zephyr,flash = &flash0;
        zephyr,console = &cdc_acm_uart;
        zmk,battery = &vbatt;
        zmk,kscan = &kscan0;
        zmk,matrix_transform = &default_transform;
    };

    sensors: sensors {
        compatible = "zmk,keymap-sensors";
        sensors = <&left_encoder>;
        triggers-per-rotation = <20>;
    };



    left_encoder: encoder_left {
        compatible = "alps,ec11";
        a-gpios = <&gpio1 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
        b-gpios = <&gpio1 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
        steps = <80>;
        status = "okay";
    };


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

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

&adc {
    status = "okay";
};

&gpiote {
    status = "okay";
};

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&i2c0 {
    compatible = "nordic,nrf-twi";
    sda-pin = <17>;
    scl-pin = <20>;
};

&uart0 {
    compatible = "nordic,nrf-uarte";
    tx-pin = <6>;
    rx-pin = <8>;
};

&usbd {
    status = "okay";
    cdc_acm_uart: cdc_acm_uart {
        compatible = "zephyr,cdc-acm-uart";
    };
};


&flash0 {
    /*
     * For more information, see:
     * http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
     */
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        sd_partition: partition@0 {
            reg = <0x00000000 0x00026000>;
        };
        code_partition: partition@26000 {
            reg = <0x00026000 0x000c6000>;
        };

        /*
         * The flash starting at 0x000ec000 and ending at
         * 0x000f3fff is reserved for use by the application.
         */

        /*
         * Storage partition will be used by FCB/LittleFS/NVS
         * if enabled.
         */
        storage_partition: partition@ec000 {
            reg = <0x000ec000 0x00008000>;
        };

        boot_partition: partition@f4000 {
            reg = <0x000f4000 0x0000c000>;
        };
    };
};
