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

 #include "zmk_uno.dtsi"

 #include <physical_layouts.dtsi>

 left_encoder: &encoder {
    status = "disabled";
 };

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

    split_matrix_transform: split_matrix_transform {
        compatible = "zmk,matrix-transform";
        rows = <4>;
        columns = <2>;

        map = <
        RC(0,0) RC(0,1)
        RC(1,0) RC(1,1)

        RC(3,0) RC(3,1)
        RC(4,0) RC(4,1)
        >;
    };

    split_direct_matrix_transform: split_direct_matrix_transform {
        compatible = "zmk,matrix-transform";
        rows = <2>;
        columns = <4>;

        map = <
        RC(0,0) RC(0,1)
        RC(0,2) RC(0,3)

        RC(1,0) RC(1,1)
        RC(1,2) RC(1,3)
        >;
    };

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

        kscan = <&kscan_matrix>;
        transform = <&split_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>
            , <&key_physical_attrs 100 100   0 200 0 0 0>
            , <&key_physical_attrs 100 100 100 200 0 0 0>
            , <&key_physical_attrs 100 100   0 300 0 0 0>
            , <&key_physical_attrs 100 100 100 300 0 0 0>
            ;
    };

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

        display-name = "Direct Wire Layout";

        kscan = <&kscan_direct>;
        transform = <&split_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>
            , <&key_physical_attrs 100 100   0 200 0 0 0>
            , <&key_physical_attrs 100 100 100 200 0 0 0>
            , <&key_physical_attrs 100 100   0 300 0 0 0>
            , <&key_physical_attrs 100 100 100 300 0 0 0>
            ;
    };

    right_encoder: right_encoder {
        steps = <80>;
        status = "disabled";
        compatible = "alps,ec11";
        a-gpios = <&arduino_header 15 GPIO_PULL_UP>;
        b-gpios = <&arduino_header 14 GPIO_PULL_UP>;
    };

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