From 382c3bd0bd49fc0d53358f45477c48f5ae47f2ff Mon Sep 17 00:00:00 2001
From: adophoxia <100170946+adophoxia@users.noreply.github.com>
Date: Wed, 31 Jan 2024 23:46:08 -0800
Subject: [PATCH] Add Doio KB04 (#22754)

Co-authored-by: Joel Challis <git@zvecr.com>
---
 keyboards/doio/kb04/info.json                | 111 +++++++++++++++++++
 keyboards/doio/kb04/keymaps/default/keymap.c |  48 ++++++++
 keyboards/doio/kb04/keymaps/default/rules.mk |   1 +
 keyboards/doio/kb04/keymaps/via/keymap.c     |  48 ++++++++
 keyboards/doio/kb04/keymaps/via/rules.mk     |   2 +
 keyboards/doio/kb04/readme.md                |  27 +++++
 keyboards/doio/kb04/rules.mk                 |   1 +
 7 files changed, 238 insertions(+)
 create mode 100644 keyboards/doio/kb04/info.json
 create mode 100644 keyboards/doio/kb04/keymaps/default/keymap.c
 create mode 100644 keyboards/doio/kb04/keymaps/default/rules.mk
 create mode 100644 keyboards/doio/kb04/keymaps/via/keymap.c
 create mode 100644 keyboards/doio/kb04/keymaps/via/rules.mk
 create mode 100644 keyboards/doio/kb04/readme.md
 create mode 100644 keyboards/doio/kb04/rules.mk

diff --git a/keyboards/doio/kb04/info.json b/keyboards/doio/kb04/info.json
new file mode 100644
index 0000000000..2455f82e03
--- /dev/null
+++ b/keyboards/doio/kb04/info.json
@@ -0,0 +1,111 @@
+{
+    "manufacturer": "DOIO",
+    "keyboard_name": "KB04-01",
+    "maintainer": "filmstarr",
+    "bootloader": "stm32duino",
+    "build": {
+        "lto": true
+    },
+    "diode_direction": "COL2ROW",
+    "encoder": {
+        "rotary": [
+            {"pin_a": "B5", "pin_b": "B6"}
+        ]
+    },
+    "features": {
+        "bootmagic": true,
+        "command": false,
+        "console": false,
+        "encoder": true,
+        "extrakey": true,
+        "mousekey": true,
+        "nkro": false,
+        "rgb_matrix": true
+    },
+    "matrix_pins": {
+        "cols": ["B14", "B13", "B12", "B0", "A7"],
+        "rows": ["B3"]
+    },
+    "processor": "STM32F103",
+    "rgb_matrix": {
+        "animations": {
+            "alphas_mods": true,
+            "gradient_up_down": true,
+            "gradient_left_right": true,
+            "breathing": true,
+            "band_sat": true,
+            "band_val": true,
+            "band_pinwheel_sat": true,
+            "band_pinwheel_val": true,
+            "band_spiral_sat": true,
+            "band_spiral_val": true,
+            "cycle_all": true,
+            "cycle_left_right": true,
+            "cycle_up_down": true,
+            "cycle_out_in": true,
+            "cycle_out_in_dual": true,
+            "rainbow_moving_chevron": true,
+            "cycle_pinwheel": true,
+            "cycle_spiral": true,
+            "dual_beacon": true,
+            "rainbow_beacon": true,
+            "rainbow_pinwheels": true,
+            "raindrops": true,
+            "jellybean_raindrops": true,
+            "hue_breathing": true,
+            "hue_pendulum": true,
+            "hue_wave": true,
+            "pixel_fractal": true,
+            "pixel_flow": true,
+            "pixel_rain": true,
+            "typing_heatmap": true,
+            "digital_rain": true,
+            "solid_reactive_simple": true,
+            "solid_reactive": true,
+            "solid_reactive_wide": true,
+            "solid_reactive_multiwide": true,
+            "solid_reactive_cross": true,
+            "solid_reactive_multicross": true,
+            "solid_reactive_nexus": true,
+            "solid_reactive_multinexus": true,
+            "splash": true,
+            "multisplash": true,
+            "solid_splash": true,
+            "solid_multisplash": true
+        },
+        "driver": "ws2812",
+        "layout": [
+            {"matrix": [0, 0], "x": 0, "y": 0, "flags": 1},
+            {"matrix": [0, 1], "x": 75, "y": 0, "flags": 1},
+            {"matrix": [0, 2], "x": 149, "y": 0, "flags": 1},
+            {"matrix": [0, 3], "x": 224, "y": 0, "flags": 1},
+            
+            {"x": 112, "y": 64, "flags": 1},
+            {"x": 112, "y": 64, "flags": 1},
+            {"x": 112, "y": 64, "flags": 1},
+            {"x": 112, "y": 64, "flags": 1}
+        ],
+        "max_brightness": 200,
+        "sleep": true
+    },
+    "url": "https://www.keebmonkey.com/products/megalodon-macro-pad-with-a-knob",
+    "usb": {
+        "device_version": "0.0.1",
+        "pid": "0x0401",
+        "vid": "0xD010"
+    },
+    "ws2812": {
+        "pin": "A10"
+    },
+    "layouts": {
+        "LAYOUT": {
+            "layout": [
+                {"label": "1!", "matrix": [0, 0], "x": 0, "y": 0},
+                {"label": "2@", "matrix": [0, 1], "x": 1, "y": 0},
+                {"label": "3#", "matrix": [0, 2], "x": 2, "y": 0},
+                {"label": "4$", "matrix": [0, 3], "x": 3, "y": 0},
+                {"label": "Encoder", "matrix": [0, 4], "x": 1.5, "y": 1}
+            ]
+        }
+    }
+}
\ No newline at end of file
diff --git a/keyboards/doio/kb04/keymaps/default/keymap.c b/keyboards/doio/kb04/keymaps/default/keymap.c
new file mode 100644
index 0000000000..7df80397fd
--- /dev/null
+++ b/keyboards/doio/kb04/keymaps/default/keymap.c
@@ -0,0 +1,48 @@
+/* Copyright 2022 filmstarr <https://github.com/filmstarr>
+ *
+ * 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
+
+enum layer_names {
+    _LAY0,
+    _LAY1
+};
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+/*
+       L0:
+       ┌───┬───┬───┬───┐   ┌───┐
+       │MO1│Prv│Ply│Nxt│   │Mut│
+       └───┴───┴───┴───┘   └───┘
+       L1:
+       ┌───┬───┬───┬───┐   ┌───┐
+       │   │Hud│Tog│Mod│   │   │
+       └───┴───┴───┴───┘   └───┘
+*/
+    [_LAY0] = LAYOUT(
+        MO(_LAY1),   KC_MPRV,    KC_MPLY,    KC_MNXT,     KC_MUTE
+    ),
+    [_LAY1] = LAYOUT(
+        KC_TRNS,     RGB_HUD,    RGB_TOG,    RGB_MOD,     KC_TRNS
+    )
+};
+
+#ifdef ENCODER_MAP_ENABLE
+const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
+    [_LAY0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
+    [_LAY1] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }
+};
+#endif
diff --git a/keyboards/doio/kb04/keymaps/default/rules.mk b/keyboards/doio/kb04/keymaps/default/rules.mk
new file mode 100644
index 0000000000..a40474b4d5
--- /dev/null
+++ b/keyboards/doio/kb04/keymaps/default/rules.mk
@@ -0,0 +1 @@
+ENCODER_MAP_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/doio/kb04/keymaps/via/keymap.c b/keyboards/doio/kb04/keymaps/via/keymap.c
new file mode 100644
index 0000000000..7df80397fd
--- /dev/null
+++ b/keyboards/doio/kb04/keymaps/via/keymap.c
@@ -0,0 +1,48 @@
+/* Copyright 2022 filmstarr <https://github.com/filmstarr>
+ *
+ * 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
+
+enum layer_names {
+    _LAY0,
+    _LAY1
+};
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+/*
+       L0:
+       ┌───┬───┬───┬───┐   ┌───┐
+       │MO1│Prv│Ply│Nxt│   │Mut│
+       └───┴───┴───┴───┘   └───┘
+       L1:
+       ┌───┬───┬───┬───┐   ┌───┐
+       │   │Hud│Tog│Mod│   │   │
+       └───┴───┴───┴───┘   └───┘
+*/
+    [_LAY0] = LAYOUT(
+        MO(_LAY1),   KC_MPRV,    KC_MPLY,    KC_MNXT,     KC_MUTE
+    ),
+    [_LAY1] = LAYOUT(
+        KC_TRNS,     RGB_HUD,    RGB_TOG,    RGB_MOD,     KC_TRNS
+    )
+};
+
+#ifdef ENCODER_MAP_ENABLE
+const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
+    [_LAY0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
+    [_LAY1] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }
+};
+#endif
diff --git a/keyboards/doio/kb04/keymaps/via/rules.mk b/keyboards/doio/kb04/keymaps/via/rules.mk
new file mode 100644
index 0000000000..4253f570f0
--- /dev/null
+++ b/keyboards/doio/kb04/keymaps/via/rules.mk
@@ -0,0 +1,2 @@
+VIA_ENABLE = yes
+ENCODER_MAP_ENABLE = yes
\ No newline at end of file
diff --git a/keyboards/doio/kb04/readme.md b/keyboards/doio/kb04/readme.md
new file mode 100644
index 0000000000..8277164bf3
--- /dev/null
+++ b/keyboards/doio/kb04/readme.md
@@ -0,0 +1,27 @@
+# doio/kb04
+
+![doio/kb04](https://i.imgur.com/lqABZw4h.png)
+
+A macropad that have 4-key keyboard made by DOIO, which controlled by an APM32F103CBT6 chipset. The keyboard features per-key RGB and 1 encoder.
+
+* Keyboard Maintainer: [filmstarr](https://github.com/filmstarr)
+* Hardware Supported: DOIO Knob Board - KB04
+* Hardware Availability: [keebmonkey.com](https://www.keebmonkey.com/products/megalodon-macro-pad-with-a-knob)
+
+Make example for this keyboard (after setting up your build environment):
+
+    qmk compile -kb doio/kb04 -km default
+
+Flashing example for this keyboard:
+
+    qmk flash -kb doio/kb04 -km default
+
+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).
+
+## Bootloader
+
+Enter the bootloader in 3 ways:
+
+* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (1! key) and plug in the keyboard
+* **Physical reset button**: Briefly press the button on the back of the PCB
+* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available
diff --git a/keyboards/doio/kb04/rules.mk b/keyboards/doio/kb04/rules.mk
new file mode 100644
index 0000000000..7ff128fa69
--- /dev/null
+++ b/keyboards/doio/kb04/rules.mk
@@ -0,0 +1 @@
+# This file intentionally left blank
\ No newline at end of file