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

#include <dt-bindings/zmk/matrix_transform.h>
#include "boardsource3x4-layouts.dtsi"


&horizontal_physical_layout {
    transform = <&horizontal_transform>;
};
&vertical_physical_layout {
    transform = <&vertical_transform>;
};

/ {
    chosen {
        zmk,kscan = &kscan0;
        zmk,physical-layout = &horizontal_physical_layout;
    };

    horizontal_transform: horizontal_transform {
        compatible = "zmk,matrix-transform";
        columns = <4>;
        rows = <3>;
        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)
            RC(2,0) RC(2,1) RC(2,2) RC(2,3)
            >;
    };

    vertical_transform: vertical_transform {
        compatible = "zmk,matrix-transform";
        columns = <4>;
        rows = <3>;
        map = <
            RC(0,3) RC(1,3) RC(2,3)
            RC(0,2) RC(1,2) RC(2,2)
            RC(0,1) RC(1,1) RC(2,1)
            RC(0,0) RC(1,0) RC(2,0)
            >;
    };

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

        diode-direction = "col2row";

         row-gpios
            = <&pro_micro 18 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&pro_micro 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            , <&pro_micro 20 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
            ;

        col-gpios
            = <&pro_micro 10 GPIO_ACTIVE_HIGH>
            , <&pro_micro 16 GPIO_ACTIVE_HIGH>
            , <&pro_micro 14 GPIO_ACTIVE_HIGH>
            , <&pro_micro 15 GPIO_ACTIVE_HIGH>
            ;
    };
};