From c67c9f1d98d23b35c468d7d3af10f4ced677ddc2 Mon Sep 17 00:00:00 2001
From: Felipe Curty <felipecrp@gmail.com>
Date: Thu, 12 Oct 2023 17:31:41 -0300
Subject: Add support for CSTC40 keyboard (#22154)

Co-authored-by: jack <0x6a73@protonmail.com>
Co-authored-by: lesshonor and waffle87
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: lesshonor
Co-authored-by: itsvar <120035196+itsvar8@users.noreply.github.com>
---
 keyboards/kprepublic/cstc40/config.h               |  59 ++++++++++
 .../cstc40/daughterboard/daughterboard.c           |  71 +++++++++++
 .../kprepublic/cstc40/daughterboard/info.json      |   6 +
 keyboards/kprepublic/cstc40/daughterboard/rules.mk |   1 +
 keyboards/kprepublic/cstc40/halconf.h              |  20 ++++
 keyboards/kprepublic/cstc40/info.json              | 130 +++++++++++++++++++++
 .../kprepublic/cstc40/keymaps/default/keymap.c     |  94 +++++++++++++++
 .../kprepublic/cstc40/keymaps/default/rules.mk     |   1 +
 keyboards/kprepublic/cstc40/keymaps/via/keymap.c   |  94 +++++++++++++++
 keyboards/kprepublic/cstc40/keymaps/via/rules.mk   |   1 +
 keyboards/kprepublic/cstc40/mcuconf.h              |  21 ++++
 keyboards/kprepublic/cstc40/readme.md              |  26 +++++
 keyboards/kprepublic/cstc40/single_pcb/info.json   |   6 +
 keyboards/kprepublic/cstc40/single_pcb/rules.mk    |   1 +
 .../kprepublic/cstc40/single_pcb/single_pcb.c      |  71 +++++++++++
 15 files changed, 602 insertions(+)
 create mode 100644 keyboards/kprepublic/cstc40/config.h
 create mode 100644 keyboards/kprepublic/cstc40/daughterboard/daughterboard.c
 create mode 100644 keyboards/kprepublic/cstc40/daughterboard/info.json
 create mode 100644 keyboards/kprepublic/cstc40/daughterboard/rules.mk
 create mode 100644 keyboards/kprepublic/cstc40/halconf.h
 create mode 100644 keyboards/kprepublic/cstc40/info.json
 create mode 100644 keyboards/kprepublic/cstc40/keymaps/default/keymap.c
 create mode 100644 keyboards/kprepublic/cstc40/keymaps/default/rules.mk
 create mode 100644 keyboards/kprepublic/cstc40/keymaps/via/keymap.c
 create mode 100644 keyboards/kprepublic/cstc40/keymaps/via/rules.mk
 create mode 100644 keyboards/kprepublic/cstc40/mcuconf.h
 create mode 100644 keyboards/kprepublic/cstc40/readme.md
 create mode 100644 keyboards/kprepublic/cstc40/single_pcb/info.json
 create mode 100644 keyboards/kprepublic/cstc40/single_pcb/rules.mk
 create mode 100644 keyboards/kprepublic/cstc40/single_pcb/single_pcb.c

diff --git a/keyboards/kprepublic/cstc40/config.h b/keyboards/kprepublic/cstc40/config.h
new file mode 100644
index 0000000000..c430986895
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/config.h
@@ -0,0 +1,59 @@
+// Copyright 2022 Var (@itsvar8)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#define I2C1_SDA_PIN B9
+#define I2C1_SCL_PIN B8
+#define DRIVER_ADDR_1 0b1010000
+#define DRIVER_COUNT 1
+#define RGB_MATRIX_LED_COUNT 47
+
+#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
+#define RGB_MATRIX_KEYPRESSES
+
+#define ENABLE_RGB_MATRIX_ALPHAS_MODS
+#define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+#define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT
+#define ENABLE_RGB_MATRIX_BREATHING
+#define ENABLE_RGB_MATRIX_BAND_SAT
+#define ENABLE_RGB_MATRIX_BAND_VAL
+#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
+#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
+#define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT
+#define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL
+#define ENABLE_RGB_MATRIX_CYCLE_ALL
+#define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+#define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN
+#define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN
+#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
+#define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL
+#define ENABLE_RGB_MATRIX_CYCLE_SPIRAL
+#define ENABLE_RGB_MATRIX_DUAL_BEACON
+#define ENABLE_RGB_MATRIX_RAINBOW_BEACON
+#define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+#define ENABLE_RGB_MATRIX_RAINDROPS
+#define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
+#define ENABLE_RGB_MATRIX_HUE_BREATHING
+#define ENABLE_RGB_MATRIX_HUE_PENDULUM
+#define ENABLE_RGB_MATRIX_HUE_WAVE
+#define ENABLE_RGB_MATRIX_PIXEL_FRACTAL
+#define ENABLE_RGB_MATRIX_PIXEL_FLOW
+#define ENABLE_RGB_MATRIX_PIXEL_RAIN
+#define ENABLE_RGB_MATRIX_TYPING_HEATMAP
+#define ENABLE_RGB_MATRIX_DIGITAL_RAIN
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
+#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
+#define ENABLE_RGB_MATRIX_SPLASH
+#define ENABLE_RGB_MATRIX_MULTISPLASH
+#define ENABLE_RGB_MATRIX_SOLID_SPLASH
+#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
+
+#define RGB_DISABLE_WHEN_USB_SUSPENDED
diff --git a/keyboards/kprepublic/cstc40/daughterboard/daughterboard.c b/keyboards/kprepublic/cstc40/daughterboard/daughterboard.c
new file mode 100644
index 0000000000..39d3d7ff52
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/daughterboard/daughterboard.c
@@ -0,0 +1,71 @@
+/* Copyright 2022 bdtc123
+ *
+ * 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 "quantum.h"
+
+#ifdef RGB_MATRIX_ENABLE
+const is31_led g_is31_leds[RGB_MATRIX_LED_COUNT] = {
+    { 0, L_1,  K_1,  J_1 },
+    { 0, L_2,  K_2,  J_2 },
+    { 0, L_3,  K_3,  J_3 },
+    { 0, L_4,  K_4,  J_4 },
+    { 0, L_5,  K_5,  J_5 },
+    { 0, L_6,  K_6,  J_6 },
+    { 0, L_7,  K_7,  J_7 },
+    { 0, L_8,  K_8,  J_8 },
+    { 0, L_9,  K_9,  J_9 },
+    { 0, L_10, K_10, J_10 },
+    { 0, L_11, K_11, J_11 },
+    { 0, L_12, K_12, J_12 },
+
+    { 0, I_1,  H_1,  G_1 },
+    { 0, I_2,  H_2,  G_2 },
+    { 0, I_3,  H_3,  G_3 },
+    { 0, I_4,  H_4,  G_4 },
+    { 0, I_5,  H_5,  G_5 },
+    { 0, I_6,  H_6,  G_6 },
+    { 0, I_7,  H_7,  G_7 },
+    { 0, I_8,  H_8,  G_8 },
+    { 0, I_9,  H_9,  G_9 },
+    { 0, I_10, H_10, G_10 },
+    { 0, I_11, H_11, G_11 },
+    { 0, I_12, H_12, G_12 },
+
+    { 0, F_1,  E_1,  D_1 },
+    { 0, F_2,  E_2,  D_2 },
+    { 0, F_3,  E_3,  D_3 },
+    { 0, F_4,  E_4,  D_4 },
+    { 0, F_5,  E_5,  D_5 },
+    { 0, F_6,  E_6,  D_6 },
+    { 0, F_7,  E_7,  D_7 },
+    { 0, F_8,  E_8,  D_8 },
+    { 0, F_9,  E_9,  D_9 },
+    { 0, F_10, E_10, D_10 },
+    { 0, F_11, E_11, D_11 },
+    { 0, F_12, E_12, D_12 },
+
+    { 0, C_1, B_1, A_1 },
+    { 0, C_2, B_2, A_2 },
+    { 0, C_3, B_3, A_3 },
+    { 0, C_4, B_4, A_4 },
+    { 0, C_5, B_5, A_5 },
+    { 0, C_6, B_6, A_6 },
+    { 0, C_8, B_8, A_8 },
+    { 0, C_9, B_9, A_9 },
+    { 0, C_10, B_10, A_10 },
+    { 0, C_11, B_11, A_11 },
+    { 0, C_12, B_12, A_12 }
+};
+#endif
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/daughterboard/info.json b/keyboards/kprepublic/cstc40/daughterboard/info.json
new file mode 100644
index 0000000000..cdba7942df
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/daughterboard/info.json
@@ -0,0 +1,6 @@
+{
+    "matrix_pins": {
+        "cols": ["B15", "B14", "B13", "B10", "B12", "A5", "C4", "A7", "A15", "C10", "C11", "C0"],
+        "rows": ["B1", "B0", "C5", "A6"]
+    }
+}
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/daughterboard/rules.mk b/keyboards/kprepublic/cstc40/daughterboard/rules.mk
new file mode 100644
index 0000000000..7ff128fa69
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/daughterboard/rules.mk
@@ -0,0 +1 @@
+# This file intentionally left blank
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/halconf.h b/keyboards/kprepublic/cstc40/halconf.h
new file mode 100644
index 0000000000..0f279040aa
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/halconf.h
@@ -0,0 +1,20 @@
+/* Copyright 2020 Nick Brassel (tzarc)
+ *
+ *  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 3 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 <https://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#define HAL_USE_I2C TRUE
+
+#include_next <halconf.h>
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/info.json b/keyboards/kprepublic/cstc40/info.json
new file mode 100644
index 0000000000..4ccd8389e8
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/info.json
@@ -0,0 +1,130 @@
+{
+    "manufacturer": "kprepublic",
+    "keyboard_name": "cstc40",
+    "maintainer": "itsvar8",
+    "bootloader": "stm32-dfu",
+    "diode_direction": "ROW2COL",
+        "debounce": 2,
+    "features": {
+        "bootmagic": true,
+        "command": false,
+        "console": false,
+        "extrakey": true,
+        "mousekey": true,
+        "nkro": true,
+        "rgb_matrix": true
+    },
+    "processor": "STM32F401",
+    "url": "",
+    "usb": {
+        "device_version": "1.0.0",
+        "pid": "0x0040",
+        "vid": "0x586A"
+    },
+    "layouts": {
+        "LAYOUT_planck_mit": {
+            "layout": [
+                { "matrix": [0, 0], "x": 0, "y": 0 },
+                { "matrix": [0, 1], "x": 1, "y": 0 },
+                { "matrix": [0, 2], "x": 2, "y": 0 },
+                { "matrix": [0, 3], "x": 3, "y": 0 },
+                { "matrix": [0, 4], "x": 4, "y": 0 },
+                { "matrix": [0, 5], "x": 5, "y": 0 },
+                { "matrix": [0, 6], "x": 6, "y": 0 },
+                { "matrix": [0, 7], "x": 7, "y": 0 },
+                { "matrix": [0, 8], "x": 8, "y": 0 },
+                { "matrix": [0, 9], "x": 9, "y": 0 },
+                { "matrix": [0, 10], "x": 10, "y": 0 },
+                { "matrix": [0, 11], "x": 11, "y": 0 },
+                { "matrix": [1, 0], "x": 0, "y": 1 },
+                { "matrix": [1, 1], "x": 1, "y": 1 },
+                { "matrix": [1, 2], "x": 2, "y": 1 },
+                { "matrix": [1, 3], "x": 3, "y": 1 },
+                { "matrix": [1, 4], "x": 4, "y": 1 },
+                { "matrix": [1, 5], "x": 5, "y": 1 },
+                { "matrix": [1, 6], "x": 6, "y": 1 },
+                { "matrix": [1, 7], "x": 7, "y": 1 },
+                { "matrix": [1, 8], "x": 8, "y": 1 },
+                { "matrix": [1, 9], "x": 9, "y": 1 },
+                { "matrix": [1, 10], "x": 10, "y": 1 },
+                { "matrix": [1, 11], "x": 11, "y": 1 },
+                { "matrix": [2, 0], "x": 0, "y": 2 },
+                { "matrix": [2, 1], "x": 1, "y": 2 },
+                { "matrix": [2, 2], "x": 2, "y": 2 },
+                { "matrix": [2, 3], "x": 3, "y": 2 },
+                { "matrix": [2, 4], "x": 4, "y": 2 },
+                { "matrix": [2, 5], "x": 5, "y": 2 },
+                { "matrix": [2, 6], "x": 6, "y": 2 },
+                { "matrix": [2, 7], "x": 7, "y": 2 },
+                { "matrix": [2, 8], "x": 8, "y": 2 },
+                { "matrix": [2, 9], "x": 9, "y": 2 },
+                { "matrix": [2, 10], "x": 10, "y": 2 },
+                { "matrix": [2, 11], "x": 11, "y": 2 },
+                { "matrix": [3, 0], "x": 0, "y": 3 },
+                { "matrix": [3, 1], "x": 1, "y": 3 },
+                { "matrix": [3, 2], "x": 2, "y": 3 },
+                { "matrix": [3, 3], "x": 3, "y": 3 },
+                { "matrix": [3, 4], "x": 4, "y": 3 },
+                { "matrix": [3, 5], "w": 2, "x": 5, "y": 3 },
+                { "matrix": [3, 7], "x": 7, "y": 3 },
+                { "matrix": [3, 8], "x": 8, "y": 3 },
+                { "matrix": [3, 9], "x": 9, "y": 3 },
+                { "matrix": [3, 10], "x": 10, "y": 3 },
+                { "matrix": [3, 11], "x": 11, "y": 3 }
+            ]
+        }
+    },
+    "rgb_matrix": {
+        "driver": "is31fl3733",
+        "layout": [
+            {"matrix": [0, 0], "x": 0, "y": 0, "flags": 1},
+            {"matrix": [0, 1], "x": 20, "y": 0, "flags": 4},
+            {"matrix": [0, 2], "x": 40, "y": 0, "flags": 4},
+            {"matrix": [0, 3], "x": 61, "y": 0, "flags": 4},
+            {"matrix": [0, 4], "x": 81, "y": 0, "flags": 4},
+            {"matrix": [0, 5], "x": 101, "y": 0, "flags": 4},
+            {"matrix": [0, 6], "x": 122, "y": 0, "flags": 4},
+            {"matrix": [0, 7], "x": 142, "y": 0, "flags": 4},
+            {"matrix": [0, 8], "x": 162, "y": 0, "flags": 4},
+            {"matrix": [0, 9], "x": 183, "y": 0, "flags": 4},
+            {"matrix": [0, 10], "x": 203, "y": 0, "flags": 4},
+            {"matrix": [0, 11], "x": 224, "y": 0, "flags": 1},
+            {"matrix": [1, 0], "x": 0, "y": 21, "flags": 1},
+            {"matrix": [1, 1], "x": 20, "y": 21, "flags": 4},
+            {"matrix": [1, 2], "x": 40, "y": 21, "flags": 4},
+            {"matrix": [1, 3], "x": 61, "y": 21, "flags": 4},
+            {"matrix": [1, 4], "x": 81, "y": 21, "flags": 4},
+            {"matrix": [1, 5], "x": 101, "y": 21, "flags": 4},
+            {"matrix": [1, 6], "x": 122, "y": 21, "flags": 4},
+            {"matrix": [1, 7], "x": 142, "y": 21, "flags": 4},
+            {"matrix": [1, 8], "x": 162, "y": 21, "flags": 4},
+            {"matrix": [1, 9], "x": 183, "y": 21, "flags": 4},
+            {"matrix": [1, 10], "x": 203, "y": 21, "flags": 4},
+            {"matrix": [1, 11], "x": 224, "y": 21, "flags": 1},
+            {"matrix": [2, 0], "x": 0, "y": 42, "flags": 1},
+            {"matrix": [2, 1], "x": 20, "y": 42, "flags": 4},
+            {"matrix": [2, 2], "x": 40, "y": 42, "flags": 4},
+            {"matrix": [2, 3], "x": 61, "y": 42, "flags": 4},
+            {"matrix": [2, 4], "x": 81, "y": 42, "flags": 4},
+            {"matrix": [2, 5], "x": 101, "y": 42, "flags": 4},
+            {"matrix": [2, 6], "x": 122, "y": 42, "flags": 4},
+            {"matrix": [2, 7], "x": 142, "y": 42, "flags": 4},
+            {"matrix": [2, 8], "x": 162, "y": 42, "flags": 4},
+            {"matrix": [2, 9], "x": 183, "y": 42, "flags": 4},
+            {"matrix": [2, 10], "x": 203, "y": 42, "flags": 4},
+            {"matrix": [2, 11], "x": 224, "y": 42, "flags": 1},
+            {"matrix": [3, 0], "x": 0, "y": 64, "flags": 1},
+            {"matrix": [3, 1], "x": 20, "y": 64, "flags": 1},
+            {"matrix": [3, 2], "x": 40, "y": 64, "flags": 1},
+            {"matrix": [3, 3], "x": 61, "y": 64, "flags": 1},
+            {"matrix": [3, 4], "x": 81, "y": 64, "flags": 1},
+            {"matrix": [3, 5], "x": 111, "y": 64, "flags": 1},
+            {"matrix": [3, 7], "x": 142, "y": 64, "flags": 1},
+            {"matrix": [3, 8], "x": 162, "y": 64, "flags": 1},
+            {"matrix": [3, 9], "x": 183, "y": 64, "flags": 1},
+            {"matrix": [3, 10], "x": 203, "y": 64, "flags": 1},
+            {"matrix": [3, 11], "x": 224, "y": 64, "flags": 1}
+        ],
+        "max_brightness": 200
+    }
+}
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/keymaps/default/keymap.c b/keyboards/kprepublic/cstc40/keymaps/default/keymap.c
new file mode 100644
index 0000000000..e47ff226a9
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/keymaps/default/keymap.c
@@ -0,0 +1,94 @@
+/* Copyright 2023
+ *
+ * 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] = {
+
+/* Qwerty
+ * ,-----------------------------------------------------------------------------------.
+ * | Tab  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Esc  |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |  "   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |Enter |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | BLTog| Ctrl | Alt  | GUI  |Lower |    Space    |Raise | Left | Down |  Up  |Right |
+ * `-----------------------------------------------------------------------------------'
+ */
+[0] = LAYOUT_planck_mit(
+    KC_TAB,   KC_Q,     KC_W,     KC_E,     KC_R,     KC_T,    KC_Y,     KC_U,     KC_I,     KC_O,    KC_P,     KC_BSPC,
+    KC_ESC,   KC_A,     KC_S,     KC_D,     KC_F,     KC_G,    KC_H,     KC_J,     KC_K,     KC_L,    KC_SCLN,  KC_QUOT,
+    KC_LSFT,  KC_Z,     KC_X,     KC_C,     KC_V,     KC_B,    KC_N,     KC_M,     KC_COMM,  KC_DOT,  KC_SLSH,  KC_ENT ,
+    RGB_TOG,  KC_LCTL,  KC_LALT,  KC_LGUI,  TL_LOWR,  KC_SPC,  TL_UPPR,  KC_LEFT,  KC_DOWN,  KC_UP,   KC_RGHT   
+),
+
+/* Lower
+ * ,-----------------------------------------------------------------------------------.
+ * |   ~  |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |   {  |   }  |  |   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | | Home | End  |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
+ * `-----------------------------------------------------------------------------------'
+ */
+[1] = LAYOUT_planck_mit(
+    KC_TILD,  KC_EXLM,  KC_AT,    KC_HASH,  KC_DLR,   KC_PERC,  KC_CIRC,  KC_AMPR,     KC_ASTR,     KC_LPRN,  KC_RPRN,  KC_BSPC,
+    KC_DEL,   KC_F1,    KC_F2,    KC_F3,    KC_F4,    KC_F5,    KC_F6,    KC_UNDS,     KC_PLUS,     KC_LCBR,  KC_RCBR,  KC_PIPE,
+    _______,  KC_F7,    KC_F8,    KC_F9,    KC_F10,   KC_F11,   KC_F12,   S(KC_NUHS),  S(KC_NUBS),  KC_HOME,  KC_END,   _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  KC_MNXT,     KC_VOLD,     KC_VOLU,  KC_MPLY   
+),
+
+/* Raise
+ * ,-----------------------------------------------------------------------------------.
+ * |   `  |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   -  |   =  |   [  |   ]  |  \   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO # |ISO / |Pg Up |Pg Dn |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
+ * `-----------------------------------------------------------------------------------'
+ */
+[2] = LAYOUT_planck_mit(
+    KC_GRV,   KC_1,     KC_2,     KC_3,     KC_4,     KC_5,     KC_6,     KC_7,     KC_8,     KC_9,     KC_0,     KC_BSPC,
+    KC_DEL,   KC_F1,    KC_F2,    KC_F3,    KC_F4,    KC_F5,    KC_F6,    KC_MINS,  KC_EQL,   KC_LBRC,  KC_RBRC,  KC_BSLS,
+    _______,  KC_F7,    KC_F8,    KC_F9,    KC_F10,   KC_F11,   KC_F12,   KC_NUHS,  KC_NUBS,  KC_PGUP,  KC_PGDN,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  KC_MNXT,  KC_VOLD,  KC_VOLU,  KC_MPLY   
+),
+
+/* Adjust (Lower + Raise)
+ *                      v------------------------RGB CONTROL--------------------v
+ * ,-----------------------------------------------------------------------------------.
+ * |      | Reset|Debug | RGB  |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-|  Del |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |      |      |      |      |      |      |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |      |      |      |      |      |      |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      |      |      |      |      |
+ * `-----------------------------------------------------------------------------------'
+ */
+[3] = LAYOUT_planck_mit(
+    _______,  QK_BOOT,  DB_TOGG,  RGB_TOG,  RGB_MOD,  RGB_HUI,  RGB_HUD,  RGB_SAI,  RGB_SAD,  RGB_VAI,  RGB_VAD,  KC_DEL,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______   
+)
+
+};
diff --git a/keyboards/kprepublic/cstc40/keymaps/default/rules.mk b/keyboards/kprepublic/cstc40/keymaps/default/rules.mk
new file mode 100644
index 0000000000..7c9bf212a6
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/keymaps/default/rules.mk
@@ -0,0 +1 @@
+TRI_LAYER_ENABLE = yes
diff --git a/keyboards/kprepublic/cstc40/keymaps/via/keymap.c b/keyboards/kprepublic/cstc40/keymaps/via/keymap.c
new file mode 100644
index 0000000000..e47ff226a9
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/keymaps/via/keymap.c
@@ -0,0 +1,94 @@
+/* Copyright 2023
+ *
+ * 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] = {
+
+/* Qwerty
+ * ,-----------------------------------------------------------------------------------.
+ * | Tab  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Esc  |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |  "   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |Enter |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | BLTog| Ctrl | Alt  | GUI  |Lower |    Space    |Raise | Left | Down |  Up  |Right |
+ * `-----------------------------------------------------------------------------------'
+ */
+[0] = LAYOUT_planck_mit(
+    KC_TAB,   KC_Q,     KC_W,     KC_E,     KC_R,     KC_T,    KC_Y,     KC_U,     KC_I,     KC_O,    KC_P,     KC_BSPC,
+    KC_ESC,   KC_A,     KC_S,     KC_D,     KC_F,     KC_G,    KC_H,     KC_J,     KC_K,     KC_L,    KC_SCLN,  KC_QUOT,
+    KC_LSFT,  KC_Z,     KC_X,     KC_C,     KC_V,     KC_B,    KC_N,     KC_M,     KC_COMM,  KC_DOT,  KC_SLSH,  KC_ENT ,
+    RGB_TOG,  KC_LCTL,  KC_LALT,  KC_LGUI,  TL_LOWR,  KC_SPC,  TL_UPPR,  KC_LEFT,  KC_DOWN,  KC_UP,   KC_RGHT   
+),
+
+/* Lower
+ * ,-----------------------------------------------------------------------------------.
+ * |   ~  |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |   {  |   }  |  |   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | | Home | End  |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
+ * `-----------------------------------------------------------------------------------'
+ */
+[1] = LAYOUT_planck_mit(
+    KC_TILD,  KC_EXLM,  KC_AT,    KC_HASH,  KC_DLR,   KC_PERC,  KC_CIRC,  KC_AMPR,     KC_ASTR,     KC_LPRN,  KC_RPRN,  KC_BSPC,
+    KC_DEL,   KC_F1,    KC_F2,    KC_F3,    KC_F4,    KC_F5,    KC_F6,    KC_UNDS,     KC_PLUS,     KC_LCBR,  KC_RCBR,  KC_PIPE,
+    _______,  KC_F7,    KC_F8,    KC_F9,    KC_F10,   KC_F11,   KC_F12,   S(KC_NUHS),  S(KC_NUBS),  KC_HOME,  KC_END,   _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  KC_MNXT,     KC_VOLD,     KC_VOLU,  KC_MPLY   
+),
+
+/* Raise
+ * ,-----------------------------------------------------------------------------------.
+ * |   `  |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  | Bksp |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   -  |   =  |   [  |   ]  |  \   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO # |ISO / |Pg Up |Pg Dn |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
+ * `-----------------------------------------------------------------------------------'
+ */
+[2] = LAYOUT_planck_mit(
+    KC_GRV,   KC_1,     KC_2,     KC_3,     KC_4,     KC_5,     KC_6,     KC_7,     KC_8,     KC_9,     KC_0,     KC_BSPC,
+    KC_DEL,   KC_F1,    KC_F2,    KC_F3,    KC_F4,    KC_F5,    KC_F6,    KC_MINS,  KC_EQL,   KC_LBRC,  KC_RBRC,  KC_BSLS,
+    _______,  KC_F7,    KC_F8,    KC_F9,    KC_F10,   KC_F11,   KC_F12,   KC_NUHS,  KC_NUBS,  KC_PGUP,  KC_PGDN,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  KC_MNXT,  KC_VOLD,  KC_VOLU,  KC_MPLY   
+),
+
+/* Adjust (Lower + Raise)
+ *                      v------------------------RGB CONTROL--------------------v
+ * ,-----------------------------------------------------------------------------------.
+ * |      | Reset|Debug | RGB  |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-|  Del |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |      |      |      |      |      |      |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |      |      |      |      |      |      |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      |      |      |      |      |
+ * `-----------------------------------------------------------------------------------'
+ */
+[3] = LAYOUT_planck_mit(
+    _______,  QK_BOOT,  DB_TOGG,  RGB_TOG,  RGB_MOD,  RGB_HUI,  RGB_HUD,  RGB_SAI,  RGB_SAD,  RGB_VAI,  RGB_VAD,  KC_DEL,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,
+    _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______   
+)
+
+};
diff --git a/keyboards/kprepublic/cstc40/keymaps/via/rules.mk b/keyboards/kprepublic/cstc40/keymaps/via/rules.mk
new file mode 100644
index 0000000000..1e5b99807c
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/keymaps/via/rules.mk
@@ -0,0 +1 @@
+VIA_ENABLE = yes
diff --git a/keyboards/kprepublic/cstc40/mcuconf.h b/keyboards/kprepublic/cstc40/mcuconf.h
new file mode 100644
index 0000000000..a56e52fb8d
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/mcuconf.h
@@ -0,0 +1,21 @@
+/* Copyright 2020 Nick Brassel (tzarc)
+ *
+ *  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 3 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 <https://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include_next <mcuconf.h>
+
+#undef STM32_I2C_USE_I2C1
+#define STM32_I2C_USE_I2C1 TRUE
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/readme.md b/keyboards/kprepublic/cstc40/readme.md
new file mode 100644
index 0000000000..211c078cc2
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/readme.md
@@ -0,0 +1,26 @@
+# cstc40
+
+A 40% hotswap ortholinear RGB keyboard from KP Republic.
+
+* Keyboard Maintainer: [Var](https://github.com/itsvar8)
+* Hardware Supported: CSTC40
+* Hardware Availability: kprepublic.com
+
+The differences between the two versions are just the rows and columns pins and the additional small pcb for the daughterboard version.
+
+Make example for this keyboard (after setting up your build environment):
+
+    for daughterboard version: make kprepublic/cstc40/daughterboard:default
+    for single pcb version: make kprepublic/cstc40/single_pcb: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 (usually the top left key or Escape) and plug in the keyboard
+* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead
+* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available
+
+The single_pcb uses pin A10, which apparently is a design flaw that prevent the bootloader to start every time - https://docs.qmk.fm/#/platformdev_blackpill_f4x1?id=pins-to-be-avoided. There is a simple workaround that works most of the time - press the pin key (generally the letter R) during the boot.
diff --git a/keyboards/kprepublic/cstc40/single_pcb/info.json b/keyboards/kprepublic/cstc40/single_pcb/info.json
new file mode 100644
index 0000000000..330ada7bac
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/single_pcb/info.json
@@ -0,0 +1,6 @@
+{
+    "matrix_pins": {
+        "cols": ["C7", "C8", "C9", "A8", "A10", "B10", "A15", "C13", "B6", "B5", "B4", "B3"],
+        "rows": ["C12", "C10", "C11", "B0"]
+    }
+}
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/single_pcb/rules.mk b/keyboards/kprepublic/cstc40/single_pcb/rules.mk
new file mode 100644
index 0000000000..7ff128fa69
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/single_pcb/rules.mk
@@ -0,0 +1 @@
+# This file intentionally left blank
\ No newline at end of file
diff --git a/keyboards/kprepublic/cstc40/single_pcb/single_pcb.c b/keyboards/kprepublic/cstc40/single_pcb/single_pcb.c
new file mode 100644
index 0000000000..39d3d7ff52
--- /dev/null
+++ b/keyboards/kprepublic/cstc40/single_pcb/single_pcb.c
@@ -0,0 +1,71 @@
+/* Copyright 2022 bdtc123
+ *
+ * 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 "quantum.h"
+
+#ifdef RGB_MATRIX_ENABLE
+const is31_led g_is31_leds[RGB_MATRIX_LED_COUNT] = {
+    { 0, L_1,  K_1,  J_1 },
+    { 0, L_2,  K_2,  J_2 },
+    { 0, L_3,  K_3,  J_3 },
+    { 0, L_4,  K_4,  J_4 },
+    { 0, L_5,  K_5,  J_5 },
+    { 0, L_6,  K_6,  J_6 },
+    { 0, L_7,  K_7,  J_7 },
+    { 0, L_8,  K_8,  J_8 },
+    { 0, L_9,  K_9,  J_9 },
+    { 0, L_10, K_10, J_10 },
+    { 0, L_11, K_11, J_11 },
+    { 0, L_12, K_12, J_12 },
+
+    { 0, I_1,  H_1,  G_1 },
+    { 0, I_2,  H_2,  G_2 },
+    { 0, I_3,  H_3,  G_3 },
+    { 0, I_4,  H_4,  G_4 },
+    { 0, I_5,  H_5,  G_5 },
+    { 0, I_6,  H_6,  G_6 },
+    { 0, I_7,  H_7,  G_7 },
+    { 0, I_8,  H_8,  G_8 },
+    { 0, I_9,  H_9,  G_9 },
+    { 0, I_10, H_10, G_10 },
+    { 0, I_11, H_11, G_11 },
+    { 0, I_12, H_12, G_12 },
+
+    { 0, F_1,  E_1,  D_1 },
+    { 0, F_2,  E_2,  D_2 },
+    { 0, F_3,  E_3,  D_3 },
+    { 0, F_4,  E_4,  D_4 },
+    { 0, F_5,  E_5,  D_5 },
+    { 0, F_6,  E_6,  D_6 },
+    { 0, F_7,  E_7,  D_7 },
+    { 0, F_8,  E_8,  D_8 },
+    { 0, F_9,  E_9,  D_9 },
+    { 0, F_10, E_10, D_10 },
+    { 0, F_11, E_11, D_11 },
+    { 0, F_12, E_12, D_12 },
+
+    { 0, C_1, B_1, A_1 },
+    { 0, C_2, B_2, A_2 },
+    { 0, C_3, B_3, A_3 },
+    { 0, C_4, B_4, A_4 },
+    { 0, C_5, B_5, A_5 },
+    { 0, C_6, B_6, A_6 },
+    { 0, C_8, B_8, A_8 },
+    { 0, C_9, B_9, A_9 },
+    { 0, C_10, B_10, A_10 },
+    { 0, C_11, B_11, A_11 },
+    { 0, C_12, B_12, A_12 }
+};
+#endif
\ No newline at end of file
-- 
cgit v1.2.3