/*
 * Copyright (c) 2022 The ZMK Contributors
 *
 * SPDX-License-Identifier: MIT
 */

 #include "zmk_uno.dtsi"

#include <behaviors.dtsi>
#include <physical_layouts.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/outputs.h>

/ {
    chosen {
        zmk,physical-layout = &matrix_physical_layout;
    };

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

    macros {
        ZMK_MACRO(ble_zero,
            wait-ms = <1>;
            tap-ms = <1>;
            bindings = <&out OUT_BLE &bt BT_SEL 0>;
        )
        ZMK_MACRO(ble_one,
            wait-ms = <1>;
            tap-ms = <1>;
            bindings = <&out OUT_BLE &bt BT_SEL 1>;
        )
    };

    endpoint_sideband_behaviors {
        compatible = "zmk,kscan-sideband-behaviors";

        auto-enable;
        kscan = <&kscan_sp3t_toggle>;

        first_toggle_sideband: first_toggle_sideband {
            column = <0>;
            bindings = <&out OUT_USB>;
        };

        second_toggle_sideband: second_toggle_sideband {
            column = <1>;
            bindings = <&ble_zero>;
        };

        third_toggle_sideband: third_toggle_sideband {
            column = <2>;
            bindings = <&ble_one>;
        };
    };

    matrix_physical_layout: matrix_physical_layout {
        compatible = "zmk,physical-layout";
        display-name = "Matrix Layout";

        kscan = <&kscan_matrix>;
        transform = <&matrix_transform>;

        keys
            = <&key_physical_attrs 100 100 0   0 0 0 0>
            , <&key_physical_attrs 100 100 100 0 0 0 0>
            , <&key_physical_attrs 100 100 0   100 0 0 0>
            , <&key_physical_attrs 100 100 100 100 0 0 0>
            ;
    };

    direct_physical_layout: direct_physical_layout {
        compatible = "zmk,physical-layout";

        display-name = "Direct Wire Layout";

        kscan = <&kscan_direct>;
        transform = <&direct_matrix_transform>;

        keys
            = <&key_physical_attrs 100 100 0   0 0 0 0>
            , <&key_physical_attrs 100 100 100 0 0 0 0>
            , <&key_physical_attrs 100 100 0   100 0 0 0>
            , <&key_physical_attrs 100 100 100 100 0 0 0>
            ;
    };

};