From 4ad3834925508b79f2ff9fd5526dfc39f07fa3bc Mon Sep 17 00:00:00 2001
From: Alin M Elena <alinm.elena@gmail.com>
Date: Mon, 3 May 2021 13:30:03 +0100
Subject: [PATCH] add support for gd32f303cct6 by we act in rev2

---
 keyboards/m65/readme.md      | 13 +++++++++++++
 keyboards/m65/rev2/board.h   |  3 +++
 keyboards/m65/rev2/chconf.h  | 29 +++++++++++++++++++++++++++++
 keyboards/m65/rev2/config.h  | 31 +++++++++++++++++++++++++++++++
 keyboards/m65/rev2/halconf.h | 24 ++++++++++++++++++++++++
 keyboards/m65/rev2/mcuconf.h | 27 +++++++++++++++++++++++++++
 keyboards/m65/rev2/readme.md |  0
 keyboards/m65/rev2/rules.mk  | 24 ++++++++++++++++++++++++
 8 files changed, 151 insertions(+)
 create mode 100644 keyboards/m65/rev2/board.h
 create mode 100644 keyboards/m65/rev2/chconf.h
 create mode 100644 keyboards/m65/rev2/config.h
 create mode 100644 keyboards/m65/rev2/halconf.h
 create mode 100644 keyboards/m65/rev2/mcuconf.h
 create mode 100644 keyboards/m65/rev2/readme.md
 create mode 100644 keyboards/m65/rev2/rules.mk

diff --git a/keyboards/m65/readme.md b/keyboards/m65/readme.md
index 91162aa91e51..884c432178b7 100644
--- a/keyboards/m65/readme.md
+++ b/keyboards/m65/readme.md
@@ -19,4 +19,17 @@ Flashing example for this keyboard:
 
 To enter flashing mode, press Lower+Raise+R.
 
+Alternative boards, one can use weact GD32F303CCT6 which is pin compatible by making the firmware
+
+   make m65/rev2:default
+
+Flashing example for this keyboard:
+
+    make m65/rev2:default:flash
+
+To enter flashing mode, press KEY button and power the keyboard.
+
+uk and dk variants are in place too if one pleases.
+
+
 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/m65/rev2/board.h b/keyboards/m65/rev2/board.h
new file mode 100644
index 000000000000..8bbf3747ce7e
--- /dev/null
+++ b/keyboards/m65/rev2/board.h
@@ -0,0 +1,3 @@
+#include_next <board.h>
+#undef STM32F103xB
+#define STM32F103xE
diff --git a/keyboards/m65/rev2/chconf.h b/keyboards/m65/rev2/chconf.h
new file mode 100644
index 000000000000..8c43fb26979b
--- /dev/null
+++ b/keyboards/m65/rev2/chconf.h
@@ -0,0 +1,29 @@
+/* Copyright 2021 QMK
+ *
+ * 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/>.
+ */
+
+/*
+ * This file was auto-generated by:
+ *    `qmk chibios-confmigrate -i keyboards/m65/rev1/chconf.h -r platforms/chibios/common/configs/chconf.h`
+ */
+
+#pragma once
+
+#define CH_CFG_ST_TIMEDELTA 0
+
+#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE
+
+#include_next <chconf.h>
+
diff --git a/keyboards/m65/rev2/config.h b/keyboards/m65/rev2/config.h
new file mode 100644
index 000000000000..28abbbe157e5
--- /dev/null
+++ b/keyboards/m65/rev2/config.h
@@ -0,0 +1,31 @@
+/*
+Copyright 2021 Alin M Elena <alinm.elena@gmail.com>
+
+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
+
+#define DEVICE_VER      0x0002
+#define PRODUCT_ID      0x6060
+
+#define LED_NUM_LOCK_PIN B12
+#define LED_CAPS_LOCK_PIN B13
+
+//                          0   1   2    3   4
+#define MATRIX_ROW_PINS { B11, B0, B1,  A2, A3 }
+//                         0    1   2   3   4   5   6   7   8    9  10  11   12
+#define MATRIX_COL_PINS {A10, A15, B3, B4, B5, B9, B8, B7, B6, C15, A0, A7, B10 }
+
+#define UNUSED_PINS
diff --git a/keyboards/m65/rev2/halconf.h b/keyboards/m65/rev2/halconf.h
new file mode 100644
index 000000000000..f9a24becca54
--- /dev/null
+++ b/keyboards/m65/rev2/halconf.h
@@ -0,0 +1,24 @@
+/* Copyright 2021 QMK
+ *
+ * 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/>.
+ */
+
+/*
+ * This file was auto-generated by:
+ *    `qmk chibios-confmigrate -i keyboards/m65/rev1/halconf.h -r platforms/chibios/common/configs/halconf.h`
+ */
+
+#pragma once
+
+#include_next <halconf.h>
diff --git a/keyboards/m65/rev2/mcuconf.h b/keyboards/m65/rev2/mcuconf.h
new file mode 100644
index 000000000000..20df276a5ac2
--- /dev/null
+++ b/keyboards/m65/rev2/mcuconf.h
@@ -0,0 +1,27 @@
+/* Copyright 2021 QMK
+ *
+ * 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/>.
+ */
+
+/*
+ * This file was auto-generated by:
+ *    `qmk chibios-confmigrate -i keyboards/m65/rev1/mcuconf.h -r platforms/chibios/STM32_F103_STM32DUINO/configs/mcuconf.h`
+ */
+
+#pragma once
+
+#include_next <mcuconf.h>
+
+#undef STM32_SPI_USE_SPI2
+#define STM32_SPI_USE_SPI2 FALSE
diff --git a/keyboards/m65/rev2/readme.md b/keyboards/m65/rev2/readme.md
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/keyboards/m65/rev2/rules.mk b/keyboards/m65/rev2/rules.mk
new file mode 100644
index 000000000000..84fe753a0171
--- /dev/null
+++ b/keyboards/m65/rev2/rules.mk
@@ -0,0 +1,24 @@
+# MCU name
+MCU = STM32F103  #GD32F303CCT6 weact
+
+# Bootloader selection
+BOOTLOADER = stm32duino
+
+# Build Options
+#   change yes to no to disable
+#
+BOOTMAGIC_ENABLE = full     # Virtual DIP switch configuration
+MOUSEKEY_ENABLE = yes       # Mouse keys
+EXTRAKEY_ENABLE = yes       # Audio control and System control
+CONSOLE_ENABLE = yes        # Console for debug
+COMMAND_ENABLE = yes        # 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 = yes           # USB Nkey Rollover
+BACKLIGHT_ENABLE = no       # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no        # Enable keyboard RGB underglow
+BLUETOOTH_ENABLE = no       # Enable Bluetooth
+AUDIO_ENABLE = no           # Audio output
+
+LAYOUTS = ortho_5x13