/*
 * Copyright (c) 2020 The ZMK Contributors
 * Copyright (c) 2025 Innaworks Development Limited, trading as MoErgo
 *
 * SPDX-License-Identifier: MIT
 */


/* THIS FILE WAS GENERATED BY GO60 LAYOUT EDITOR
 *
 * This file was generated automatically. You may or may not want to
 * edit it directly.
 */

#include <behaviors.dtsi>

/* Include all behavior includes needed */

#include <dt-bindings/zmk/outputs.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/rgb.h>

#include <input/processors.dtsi>
#include <dt-bindings/zmk/input_transform.h>
#include <zephyr/dt-bindings/input/input-event-codes.h>

/* On demand includes */
#include <dt-bindings/zmk/input_transform.h>
#include <dt-bindings/zmk/pointing.h>
#include <input/processors.dtsi>

/* Helper Macros, based on https://github.com/urob/zmk-helpers/ */

#pragma once

#define ZMK_HELPER_STRINGIFY(x) #x

// Preprocessor mechanism to overload macros, cf. https://stackoverflow.com/a/27051616/6114651
#define VARGS_(_10, _9, _8, _7, _6, _5, _4, _3, _2, _1, N, ...) N
#define VARGS(...) VARGS_(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define CONCAT_(a, b) a##b
#define CONCAT(a, b) CONCAT_(a, b)

#define ZMK_BEHAVIOR_CORE_tap_dance  \
    compatible = "zmk,behavior-tap-dance"; \
    #binding-cells = <0>

#define ZMK_BEHAVIOR(name, type, ...) \
    name: name { \
        ZMK_BEHAVIOR_CORE_ ## type; \
        __VA_ARGS__ \
    };

#define ZMK_TAP_DANCE(name, ...) \
    ZMK_BEHAVIOR(name, tap_dance, __VA_ARGS__)

#define ZMK_TD_LAYER(name, layer) \
    ZMK_TAP_DANCE(name, \
        tapping-term-ms = <200>; \
        bindings = <&mo layer>, <&to layer>; \
)





/* Key positions */

#define POS_LH_C6R1 0
#define POS_LH_C5R1 1
#define POS_LH_C4R1 2
#define POS_LH_C3R1 3
#define POS_LH_C2R1 4
#define POS_LH_C1R1 5
#define POS_RH_C1R1 6
#define POS_RH_C2R1 7
#define POS_RH_C3R1 8
#define POS_RH_C4R1 9
#define POS_RH_C5R1 10
#define POS_RH_C6R1 11
#define POS_LH_C6R2 12
#define POS_LH_C5R2 13
#define POS_LH_C4R2 14
#define POS_LH_C3R2 15
#define POS_LH_C2R2 16
#define POS_LH_C1R2 17
#define POS_RH_C1R2 18
#define POS_RH_C2R2 19
#define POS_RH_C3R2 20
#define POS_RH_C4R2 21
#define POS_RH_C5R2 22
#define POS_RH_C6R2 23
#define POS_LH_C6R3 24
#define POS_LH_C5R3 25
#define POS_LH_C4R3 26
#define POS_LH_C3R3 27
#define POS_LH_C2R3 28
#define POS_LH_C1R3 29
#define POS_RH_C1R3 30
#define POS_RH_C2R3 31
#define POS_RH_C3R3 32
#define POS_RH_C4R3 33
#define POS_RH_C5R3 34
#define POS_RH_C6R3 35
#define POS_LH_C6R4 36
#define POS_LH_C5R4 37
#define POS_LH_C4R4 38
#define POS_LH_C3R4 39
#define POS_LH_C2R4 40
#define POS_LH_C1R4 41
#define POS_RH_C1R4 42
#define POS_RH_C2R4 43
#define POS_RH_C3R4 44
#define POS_RH_C4R4 45
#define POS_RH_C5R4 46
#define POS_RH_C6R4 47
#define POS_LH_C4R5 48
#define POS_LH_C3R5 49
#define POS_LH_C2R5 50
#define POS_RH_C2R5 51
#define POS_RH_C3R5 52
#define POS_RH_C4R5 53
#define POS_LH_T1 54
#define POS_LH_T2 55
#define POS_LH_T3 56
#define POS_RH_T3 57
#define POS_RH_T2 58
#define POS_RH_T1 59


#define LEFT_HAND_KEYS \
  POS_LH_C1R1 POS_LH_C2R1 POS_LH_C3R1 POS_LH_C4R1 POS_LH_C5R1 POS_LH_C6R1 \
  POS_LH_C1R2 POS_LH_C2R2 POS_LH_C3R2 POS_LH_C4R2 POS_LH_C5R2 POS_LH_C6R2 \
  POS_LH_C1R3 POS_LH_C2R3 POS_LH_C3R3 POS_LH_C4R3 POS_LH_C5R3 POS_LH_C6R3 \
  POS_LH_C1R4 POS_LH_C2R4 POS_LH_C3R4 POS_LH_C4R4 POS_LH_C5R4 POS_LH_C6R4 \
              POS_LH_C2R5 POS_LH_C3R5 POS_LH_C4R5

#define RIGHT_HAND_KEYS \
  POS_RH_C1R1 POS_RH_C2R1 POS_RH_C3R1 POS_RH_C4R1 POS_RH_C5R1 POS_RH_C6R1 \
  POS_RH_C1R2 POS_RH_C2R2 POS_RH_C3R2 POS_RH_C4R2 POS_RH_C5R2 POS_RH_C6R2 \
  POS_RH_C1R3 POS_RH_C2R3 POS_RH_C3R3 POS_RH_C4R3 POS_RH_C5R3 POS_RH_C6R3 \
  POS_RH_C1R4 POS_RH_C2R4 POS_RH_C3R4 POS_RH_C4R4 POS_RH_C5R4 POS_RH_C6R4 \
              POS_RH_C2R5 POS_RH_C3R5 POS_RH_C4R5

#define THUMB_KEYS \
  POS_LH_T1 POS_LH_T2 POS_LH_T3 \
  POS_RH_T1 POS_RH_T2 POS_RH_T3

/* Environment and metadata defines */
#define KB_TYPE_GLOVE_80 1
#define KB_TYPE_GO_60    2

#define KB_TYPE          KB_TYPE_GO_60
#define EDITOR_HOST_OS   'L'

/* Automatically generated layer name defines */
#define LAYER_Base 0
#define LAYER_Keypad 1
#define LAYER_SymbolNav 2
#define LAYER_Magic 3
#define LAYER_Factory 4

/* To deal with the situation where there is no Lower layer, to keep &lower happy */
#ifndef LAYER_Lower
#define LAYER_Lower 0
#endif

/* Generated input processors */
/ {
    input_processors {
        zip_click_to_right_click_mapper: zip_click_to_right_click_mapper {
            compatible = "zmk,input-processor-code-mapper";
            #input-processor-cells = <0>;
            type = <INPUT_EV_KEY>;
            map = <INPUT_BTN_0 INPUT_BTN_1>;
        };
    };
};

/* Custom Device-tree */


/* Input Listeners */
&cirque_rh_listener {
    input-processors = <&zip_xy_scaler 3 1>;
    layer_SymbolNav {
        layers = <LAYER_SymbolNav>;
        input-processors = <&zip_xy_scaler 9 1>;
    };
};

&cirque_lh_listener {
    input-processors = <&zip_xy_scaler 11 12>, <&zip_xy_transform INPUT_TRANSFORM_Y_INVERT>, <&zip_xy_to_scroll_mapper>, <&zip_click_to_right_click_mapper>;
    layer_Factory {
        layers = <LAYER_Factory>;
        input-processors = <&zip_xy_scaler 3 1>;
    };
};

/* System behavior and macros */
/ {
    behaviors {
        ZMK_TD_LAYER(lower, LAYER_Lower)
    };
};

/ {
    macros {
        rgb_ug_status_macro: rgb_ug_status_macro {
            label = "RGB_UG_STATUS";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&rgb_ug RGB_STATUS>;
        };
    };
};

/ {
#ifdef BT_DISC_CMD
    behaviors {
        bt_0: bt_0 {
            compatible = "zmk,behavior-tap-dance";
            label = "BT_0";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&bt_select_0>, <&bt BT_DISC 0>;
        };
        bt_1: bt_1 {
            compatible = "zmk,behavior-tap-dance";
            label = "BT_1";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&bt_select_1>, <&bt BT_DISC 1>;
        };
        bt_2: bt_2 {
            compatible = "zmk,behavior-tap-dance";
            label = "BT_2";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&bt_select_2>, <&bt BT_DISC 2>;
        };
        bt_3: bt_3 {
            compatible = "zmk,behavior-tap-dance";
            label = "BT_3";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&bt_select_3>, <&bt BT_DISC 3>;
        };
    };
    macros {
        bt_select_0: bt_select_0 {
            label = "BT_SELECT_0";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 0>;
        };
        bt_select_1: bt_select_1 {
            label = "BT_SELECT_1";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 1>;
        };
        bt_select_2: bt_select_2 {
            label = "BT_SELECT_2";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 2>;
        };
        bt_select_3: bt_select_3 {
            label = "BT_SELECT_3";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 3>;
        };
    };
#else
    macros {
        bt_0: bt_0 {
            label = "BT_0";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 0>;
        };
        bt_1: bt_1 {
            label = "BT_1";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 1>;
        };
        bt_2: bt_2 {
            label = "BT_2";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 2>;
        };
        bt_3: bt_3 {
            label = "BT_3";
            compatible = "zmk,behavior-macro";
            #binding-cells = <0>;
            bindings
                = <&out OUT_BLE>,
                  <&bt BT_SEL 3>;
        };
    };
#endif
};

/ {
    behaviors {
        magic: magic {
            compatible = "zmk,behavior-hold-tap";
            label = "MAGIC_HOLD_TAP";
            #binding-cells = <2>;
            flavor = "tap-preferred";
            tapping-term-ms = <200>;
            bindings = <&mo>, <&rgb_ug_status_macro>;
        };
    };
};


/* Custom Defined Behaviors */
/ {

};

/* Automatically generated macro definitions */
/ {
    macros {

    };
};

/* Automatically generated behavior definitions */
/ {
    behaviors {

        // Layer tap dance behaviors

        ZMK_TD_LAYER(td_LAYER_Keypad, 1)
        ZMK_TD_LAYER(td_LAYER_SymbolNav, 2)

    };
};

/* Automatically generated combos definitions */


/* Automatically generated keymap */
/ {
    keymap {
        compatible = "zmk,keymap";


        layer_Base {
            bindings = <
            &kp EQUAL  &kp N1     &kp N2   &kp N3               &kp N4  &kp N5                                                                     &kp N6    &kp N7     &kp N8    &kp N9    &kp N0         &kp MINUS
              &kp TAB   &kp Q      &kp W    &kp E                &kp R   &kp T                                                                      &kp Y     &kp U      &kp I     &kp O     &kp P          &kp BSLH
              &kp ESC   &kp A      &kp S    &kp D                &kp F   &kp G                                                                      &kp H     &kp J      &kp K     &kp L  &kp SEMI           &kp SQT
 &magic LAYER_Magic 0   &kp Z      &kp X    &kp C                &kp V   &kp B                                                                      &kp N     &kp M  &kp COMMA   &kp DOT  &kp FSLH  &td_LAYER_Keypad
                               &kp GRAVE  &kp DEL  &td_LAYER_SymbolNav                                                                                     &kp LGUI   &kp LBKT  &kp RBKT
                                                                                &kp BSPC  &kp LSHFT  &kp LCTRL  &kp LALT  &mt RALT RET  &kp SPACE
            >;
        };

        layer_Keypad {
            bindings = <
                &none     &kp F1     &kp F2     &kp F3     &kp F4         &kp F5                                                                     &kp F6     &kp F7      &kp F8        &kp F9          &kp F10         &kp F11
               &trans      &none   &kp HOME     &kp UP    &kp END      &kp PG_UP                                                                  &kp KP_N7  &kp KP_N8   &kp KP_N9  &kp KP_MINUS     &kp KP_SLASH         &kp F12
               &trans  &kp LC(Y)   &kp LEFT   &kp DOWN  &kp RIGHT      &kp PG_DN                                                                  &kp KP_N4  &kp KP_N5   &kp KP_N6   &kp KP_PLUS  &kp KP_MULTIPLY      &kp KP_NUM
 &magic LAYER_Magic 0  &kp LC(Z)  &kp LC(X)  &kp LC(C)  &kp LC(V)  &kp LS(LC(V))                                                                  &kp KP_N1  &kp KP_N2   &kp KP_N3  &kp KP_ENTER        &kp EQUAL  &to LAYER_Base
                                      &none     &trans     &trans                                                                                            &kp KP_N0  &kp KP_DOT      &kp BSPC
                                                                                  &mo LAYER_SymbolNav  &trans  &trans  &trans  &trans  &kp KP_N0
            >;
        };

        layer_SymbolNav {
            bindings = <
              &kp INS      &kp F1      &kp F2    &kp F3        &kp F4        &kp F5                                                      &kp F6      &kp F7           &kp F8         &kp F9          &kp F10    &kp F11
             &kp SLCK  &kp LS(N1)    &kp HOME    &kp UP       &kp END     &kp PG_UP                                                  &kp LS(N9)  &kp LS(N0)           &kp UP     &kp LS(N5)        &kp K_APP    &kp F12
             &kp CAPS  &kp LS(N2)    &kp LEFT  &kp DOWN     &kp RIGHT     &kp PG_DN                                                  &kp LS(N4)    &kp LEFT         &kp DOWN      &kp RIGHT  &kp PAUSE_BREAK  &kp PSCRN
 &magic LAYER_Magic 0  &kp LS(N3)    &kp LBKT  &kp RBKT  &kp LS(LBKT)  &kp LS(RBKT)                                                  &kp LS(N7)  &kp LS(N8)    &kp LS(MINUS)  &kp LS(EQUAL)        &kp LSHFT  &kp LCTRL
                                   &kp LS(N6)    &trans        &trans                                                                                &trans  &kp LC(LS(TAB))    &kp LC(TAB)
                                                                                      &to 0  &trans  &trans  &trans  &trans  &trans
            >;
        };

        layer_Magic {
            bindings = <
  &bt BT_CLR     &kp C_BRI_DN     &kp C_BRI_UP       &kp C_PREV       &kp C_NEXT         &kp C_PP                                                  &kp C_MUTE  &kp C_VOL_DN  &kp C_VOL_UP   &none   &none     &bt BT_CLR_ALL
 &bootloader  &rgb_ug RGB_SPI  &rgb_ug RGB_SAI  &rgb_ug RGB_HUI  &rgb_ug RGB_BRI  &rgb_ug RGB_TOG                                                       &none         &none         &none   &none   &none        &bootloader
  &sys_reset  &rgb_ug RGB_SPD  &rgb_ug RGB_SAD  &rgb_ug RGB_HUD  &rgb_ug RGB_BRD  &rgb_ug RGB_EFF                                                       &none         &none         &none   &none   &none         &sys_reset
       &none            &none            &bt_0            &bt_1            &bt_2            &bt_3                                                       &none         &none         &none   &none   &none  &to LAYER_Factory
                                  &out OUT_USB            &none            &none                                                                                      &none         &none   &none
                                                                                                    &none   &none   &none   &none   &none   &none
            >;
        };

        layer_Factory {
            bindings = <
 &kp N0  &kp N4  &kp N8  &kp N3  &kp N8  &kp N3                                                  &kp N3  &kp N8  &kp N3  &kp N8  &kp N4  &kp N0
 &kp N1  &kp N5  &kp N9  &kp N4  &kp N9  &kp N4                                                  &kp N4  &kp N9  &kp N4  &kp N9  &kp N5  &kp N1
 &kp N2  &kp N6  &kp N0  &kp N5  &kp N0  &kp N5                                                  &kp N5  &kp N0  &kp N5  &kp N0  &kp N6  &kp N2
 &kp N3  &kp N7  &kp N1  &kp N6  &kp N1  &kp N6                                                  &kp N6  &kp N1  &kp N6  &kp N1  &kp N7  &kp N3
                 &kp N2  &kp N7  &kp N2                                                                  &kp N2  &kp N7  &kp N2
                                                 &kp N7  &kp N8  &kp N9  &kp N9  &kp N8  &kp N7
            >;
        };

    };
};
