From 6ccf774ea5f0b07ac02c31ddc196e1c921898038 Mon Sep 17 00:00:00 2001
From: MechMerlin <30334081+mechmerlin@users.noreply.github.com>
Date: Wed, 10 Nov 2021 06:24:16 -0800
Subject: [PATCH] [Keyboard] Element Hotswap PCB (#15082)

Co-authored-by: Drashna Jaelre <drashna@live.com>
---
 keyboards/neokeys/g67/element_hs/config.h     | 66 +++++++++++++++
 keyboards/neokeys/g67/element_hs/element_hs.c | 17 ++++
 keyboards/neokeys/g67/element_hs/element_hs.h | 34 ++++++++
 keyboards/neokeys/g67/element_hs/info.json    | 82 +++++++++++++++++++
 .../g67/element_hs/keymaps/default/keymap.c   | 34 ++++++++
 .../g67/element_hs/keymaps/via/keymap.c       | 49 +++++++++++
 .../g67/element_hs/keymaps/via/rules.mk       |  3 +
 keyboards/neokeys/g67/element_hs/readme.md    | 19 +++++
 keyboards/neokeys/g67/element_hs/rules.mk     | 25 ++++++
 9 files changed, 329 insertions(+)
 create mode 100644 keyboards/neokeys/g67/element_hs/config.h
 create mode 100644 keyboards/neokeys/g67/element_hs/element_hs.c
 create mode 100644 keyboards/neokeys/g67/element_hs/element_hs.h
 create mode 100644 keyboards/neokeys/g67/element_hs/info.json
 create mode 100644 keyboards/neokeys/g67/element_hs/keymaps/default/keymap.c
 create mode 100644 keyboards/neokeys/g67/element_hs/keymaps/via/keymap.c
 create mode 100644 keyboards/neokeys/g67/element_hs/keymaps/via/rules.mk
 create mode 100644 keyboards/neokeys/g67/element_hs/readme.md
 create mode 100644 keyboards/neokeys/g67/element_hs/rules.mk

diff --git a/keyboards/neokeys/g67/element_hs/config.h b/keyboards/neokeys/g67/element_hs/config.h
new file mode 100644
index 00000000000..3efc322d8d1
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/config.h
@@ -0,0 +1,66 @@
+/* Copyright 2021 MechMerlin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "config_common.h"
+
+/* USB Device descriptor parameter */
+#define VENDOR_ID       0x4E4B // "NK"
+#define PRODUCT_ID      0x5049
+#define DEVICE_VER      0x0100
+#define MANUFACTURER    NEO Keys
+#define PRODUCT         Element G67 Hotswap
+
+/* key matrix size */
+#define MATRIX_ROWS 5
+#define MATRIX_COLS 15
+
+/*
+ * Keyboard Matrix Assignments
+ *
+ * Change this to how you wired your keyboard
+ * COLS: AVR pins used for columns, left to right
+ * ROWS: AVR pins used for rows, top to bottom
+ * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
+ *                  ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
+ *
+ */
+#define MATRIX_ROW_PINS { B0, B1, B2, B3, F7 }
+#define MATRIX_COL_PINS { C7, F6, F5, F4, F1, B7, D5, D1, D2, D3, D4, D0, D6, D7, B4 }
+
+#define DIODE_DIRECTION COL2ROW
+
+#if defined(RGBLIGHT_ENABLE)
+    #define RGB_DI_PIN F0
+    #define RGBLED_NUM 77
+    #define RGBLIGHT_HUE_STEP 8
+    #define RGBLIGHT_SAT_STEP 8
+    #define RGBLIGHT_VAL_STEP 8
+    #define RGBLIGHT_LIMIT_VAL 150 /* The maximum brightness level */
+    #define RGBLIGHT_SLEEP  /* If defined, the RGB lighting will be switched off when the host goes to sleep */
+/*== all animations enable ==*/
+#define RGBLIGHT_EFFECT_BREATHING
+#define RGBLIGHT_EFFECT_RAINBOW_MOOD
+#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
+#define RGBLIGHT_EFFECT_SNAKE
+#define RGBLIGHT_EFFECT_KNIGHT
+#define RGBLIGHT_EFFECT_CHRISTMAS
+#define RGBLIGHT_EFFECT_STATIC_GRADIENT
+#define RGBLIGHT_EFFECT_RGB_TEST
+#define RGBLIGHT_EFFECT_ALTERNATING
+#define RGBLIGHT_EFFECT_TWINKLE
+#endif
diff --git a/keyboards/neokeys/g67/element_hs/element_hs.c b/keyboards/neokeys/g67/element_hs/element_hs.c
new file mode 100644
index 00000000000..c5dd40fe6a9
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/element_hs.c
@@ -0,0 +1,17 @@
+/* Copyright 2021 MechMerlin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "element_hs.h"
diff --git a/keyboards/neokeys/g67/element_hs/element_hs.h b/keyboards/neokeys/g67/element_hs/element_hs.h
new file mode 100644
index 00000000000..cfb7d67b60c
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/element_hs.h
@@ -0,0 +1,34 @@
+/* Copyright 2021 MechMerlin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "quantum.h"
+
+#define LAYOUT_65_ansi_blocker( \
+    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D,      K0E,   \
+    K10,   K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D,    K1E,   \
+    K20,    K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D,        K2E,   \
+    K30,       K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D,     K3E,   \
+    K40,  K41,  K43,              K46,                K4A,  K4B,  K4C,  K4D,   K4E    \
+) { \
+    { K00,   K01,   K02,   K03,   K04,   K05,   K06,   K07,   K08,   K09,   K0A,   K0B,   K0C,   K0D,   K0E   }, \
+    { K10,   K11,   K12,   K13,   K14,   K15,   K16,   K17,   K18,   K19,   K1A,   K1B,   K1C,   K1D,   K1E   }, \
+    { K20,   K21,   K22,   K23,   K24,   K25,   K26,   K27,   K28,   K29,   K2A,   K2B,   KC_NO, K2D,   K2E   }, \
+    { K30,   KC_NO, K32,   K33,   K34,   K35,   K36,   K37,   K38,   K39,   K3A,   K3B,   K3C,   K3D,   K3E   }, \
+    { K40,   K41,   KC_NO, K43,   KC_NO, KC_NO, K46,   KC_NO, KC_NO, KC_NO, K4A,   K4B,   K4C,   K4D,   K4E   }, \
+}
+
diff --git a/keyboards/neokeys/g67/element_hs/info.json b/keyboards/neokeys/g67/element_hs/info.json
new file mode 100644
index 00000000000..3b20d104024
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/info.json
@@ -0,0 +1,82 @@
+{
+    "keyboard_name": "NEO Keys Element Hotswap",
+    "url": "",
+    "maintainer": "qmk",
+    "layouts": {
+        "LAYOUT_65_ansi_blocker": {
+            "layout": [
+                {"x":0, "y":0},
+                {"x":1, "y":0},
+                {"x":2, "y":0},
+                {"x":3, "y":0},
+                {"x":4, "y":0},
+                {"x":5, "y":0},
+                {"x":6, "y":0},
+                {"x":7, "y":0},
+                {"x":8, "y":0},
+                {"x":9, "y":0},
+                {"x":10, "y":0},
+                {"x":11, "y":0},
+                {"x":12, "y":0},
+                {"x":13, "y":0, "w":2},
+                {"x":15, "y":0},
+
+                {"x":0, "y":1, "w":1.5},
+                {"x":1.5, "y":1},
+                {"x":2.5, "y":1},
+                {"x":3.5, "y":1},
+                {"x":4.5, "y":1},
+                {"x":5.5, "y":1},
+                {"x":6.5, "y":1},
+                {"x":7.5, "y":1},
+                {"x":8.5, "y":1},
+                {"x":9.5, "y":1},
+                {"x":10.5, "y":1},
+                {"x":11.5, "y":1},
+                {"x":12.5, "y":1},
+                {"x":13.5, "y":1, "w":1.5},
+                {"x":15, "y":1},
+
+                {"x":0, "y":2, "w":1.75},
+                {"x":1.75, "y":2},
+                {"x":2.75, "y":2},
+                {"x":3.75, "y":2},
+                {"x":4.75, "y":2},
+                {"x":5.75, "y":2},
+                {"x":6.75, "y":2},
+                {"x":7.75, "y":2},
+                {"x":8.75, "y":2},
+                {"x":9.75, "y":2},
+                {"x":10.75, "y":2},
+                {"x":11.75, "y":2},
+                {"x":12.75, "y":2, "w":2.25},
+                {"x":15, "y":2},
+
+                {"x":0, "y":3, "w":2.25},
+                {"x":2.25, "y":3},
+                {"x":3.25, "y":3},
+                {"x":4.25, "y":3},
+                {"x":5.25, "y":3},
+                {"x":6.25, "y":3},
+                {"x":7.25, "y":3},
+                {"x":8.25, "y":3},
+                {"x":9.25, "y":3},
+                {"x":10.25, "y":3},
+                {"x":11.25, "y":3},
+                {"x":12.25, "y":3, "w":1.75},
+                {"x":14, "y":3},
+                {"x":15, "y":3},
+
+                {"x":0, "y":4, "w":1.25},
+                {"x":1.25, "y":4, "w":1.25},
+                {"x":2.5, "y":4, "w":1.25},
+                {"x":3.75, "y":4, "w":6.25},
+                {"x":10, "y":4, "w":1.25},
+                {"x":11.25, "y":4, "w":1.25},
+                {"x":13, "y":4},
+                {"x":14, "y":4},
+                {"x":15, "y":4}
+            ]
+        }
+    }
+}
diff --git a/keyboards/neokeys/g67/element_hs/keymaps/default/keymap.c b/keyboards/neokeys/g67/element_hs/keymaps/default/keymap.c
new file mode 100644
index 00000000000..e617a80b523
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/keymaps/default/keymap.c
@@ -0,0 +1,34 @@
+/* Copyright 2021 MechMerlin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include QMK_KEYBOARD_H
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+    [0] = LAYOUT_65_ansi_blocker(
+        KC_ESC,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_MINS, KC_EQL,  KC_BSPC, KC_TILD,
+        KC_TAB,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL,
+        KC_CAPS, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT,          KC_ENT,  KC_PGUP,
+        KC_LSFT,          KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_RSFT, KC_UP,   KC_PGDN,
+        KC_LCTL, KC_LGUI, KC_LALT,                            KC_SPC,                    MO(1),   KC_RCTL,          KC_LEFT, KC_DOWN, KC_RGHT
+    ),
+    [1] = LAYOUT_65_ansi_blocker(
+        _______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  _______, KC_HOME,
+        _______, RGB_TOG, KC_UP,   RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_PSCR, KC_SLCK, KC_PAUS, _______, KC_END,
+        _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_INS,  KC_HOME, KC_PGUP,          _______, KC_PGUP,
+        _______,          RESET,   BL_DEC,  BL_TOGG, BL_INC,  KC_VOLD, KC_MUTE, KC_VOLU, _______, KC_DEL,  KC_END,  KC_PGDN, _______, KC_PGDN,
+        _______, _______, _______,                            _______,                   _______, _______,          _______, _______, _______
+    ),
+};
diff --git a/keyboards/neokeys/g67/element_hs/keymaps/via/keymap.c b/keyboards/neokeys/g67/element_hs/keymaps/via/keymap.c
new file mode 100644
index 00000000000..5fb2edac5e0
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/keymaps/via/keymap.c
@@ -0,0 +1,49 @@
+/* Copyright 2021 MechMerlin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include QMK_KEYBOARD_H
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+    [0] = LAYOUT_65_ansi_blocker(
+        KC_ESC,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_MINS, KC_EQL,  KC_BSPC, KC_TILD,
+        KC_TAB,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL,
+        KC_CAPS, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT,          KC_ENT,  KC_PGUP,
+        KC_LSFT,          KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_RSFT, KC_UP,   KC_PGDN,
+        KC_LCTL, KC_LGUI, KC_LALT,                            KC_SPC,                    MO(1),   KC_RCTL,          KC_LEFT, KC_DOWN, KC_RGHT
+    ),
+    [1] = LAYOUT_65_ansi_blocker(
+        _______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  _______, KC_HOME,
+        _______, RGB_TOG, KC_UP,   RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_PSCR, KC_SLCK, KC_PAUS, _______, KC_END,
+        _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_INS,  KC_HOME, KC_PGUP,          _______, KC_PGUP,
+        _______,          RESET,   BL_DEC,  BL_TOGG, BL_INC,  KC_VOLD, KC_MUTE, KC_VOLU, _______, KC_DEL,  KC_END,  KC_PGDN, _______, KC_PGDN,
+        _______, _______, _______,                            _______,                   _______, _______,          _______, _______, _______
+    ),
+    [2] = LAYOUT_65_ansi_blocker(
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,          _______, _______,
+        _______,          _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______,                            _______,                   _______, _______,          _______, _______, _______
+
+    ),
+    [3] = LAYOUT_65_ansi_blocker(
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,          _______, _______,
+        _______,          _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+        _______, _______, _______,                            _______,                   _______, _______,          _______, _______, _______
+    ),
+};
diff --git a/keyboards/neokeys/g67/element_hs/keymaps/via/rules.mk b/keyboards/neokeys/g67/element_hs/keymaps/via/rules.mk
new file mode 100644
index 00000000000..152460f3047
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/keymaps/via/rules.mk
@@ -0,0 +1,3 @@
+VIA_ENABLE = yes
+LTO_ENABLE = yes
+KEY_LOCK_ENABLE = no
diff --git a/keyboards/neokeys/g67/element_hs/readme.md b/keyboards/neokeys/g67/element_hs/readme.md
new file mode 100644
index 00000000000..02f63e9f9e4
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/readme.md
@@ -0,0 +1,19 @@
+# Element G67 Hotswap
+
+A blockered 65% with per-key RGB, underglow, and USB Type C.
+
+* Keyboard Maintainer: [MechMerlin](https://github.com/mechmerlin)
+* Hardware Supported: Element G67 Hotswap (ATmega32U4)
+* Hardware Availability: [NEO Keys](https://www.neokeys.net/)
+
+Make example for this keyboard (after setting up your build environment):
+
+    make neokeys/g67/element_hs:default
+
+Flashing example for this keyboard:
+
+    make neokeys/g67/element_hs:default:flash
+
+To reset the board into bootloader mode, hold the key at the top left of the keyboard while connecting the USB cable (also erases persistent settings).
+
+See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
diff --git a/keyboards/neokeys/g67/element_hs/rules.mk b/keyboards/neokeys/g67/element_hs/rules.mk
new file mode 100644
index 00000000000..bf105353e17
--- /dev/null
+++ b/keyboards/neokeys/g67/element_hs/rules.mk
@@ -0,0 +1,25 @@
+# MCU name
+MCU = atmega32u4
+
+# Bootloader selection
+BOOTLOADER = atmel-dfu
+
+# Build Options
+#   change yes to no to disable
+#
+BOOTMAGIC_ENABLE = yes      # Enable Bootmagic Lite
+MOUSEKEY_ENABLE = yes       # Mouse keys
+EXTRAKEY_ENABLE = yes       # Audio control and System control
+CONSOLE_ENABLE = no         # Console for debug
+COMMAND_ENABLE = no         # Commands for debug and configuration
+# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
+SLEEP_LED_ENABLE = no       # Breathing sleep LED during USB suspend
+# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
+NKRO_ENABLE = no            # USB Nkey Rollover
+BACKLIGHT_ENABLE = no       # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = yes       # Enable keyboard RGB underglow
+AUDIO_ENABLE = no           # Audio output
+
+KEY_LOCK_ENABLE = yes       # Enable KC_LOCK support
+
+LAYOUTS = 65_ansi_blocker