From 3f63bbc7d829d7269e9caa89f128adf86ae5b196 Mon Sep 17 00:00:00 2001
From: nodatk <nodatk@gmail.com>
Date: Wed, 5 Oct 2022 10:40:18 +0900
Subject: [PATCH] [Keyboard] Twig50 (#18085)

Co-authored-by: Ryan <fauxpark@gmail.com>
---
 keyboards/handwired/twig/twig50/config.h      | 28 +++++++
 keyboards/handwired/twig/twig50/info.json     | 20 +++++
 .../twig/twig50/keymaps/default/keymap.c      | 79 +++++++++++++++++++
 keyboards/handwired/twig/twig50/readme.md     | 29 +++++++
 keyboards/handwired/twig/twig50/rules.mk      | 19 +++++
 keyboards/handwired/twig/twig50/twig50.c      |  4 +
 keyboards/handwired/twig/twig50/twig50.h      | 20 +++++
 7 files changed, 199 insertions(+)
 create mode 100644 keyboards/handwired/twig/twig50/config.h
 create mode 100644 keyboards/handwired/twig/twig50/info.json
 create mode 100644 keyboards/handwired/twig/twig50/keymaps/default/keymap.c
 create mode 100644 keyboards/handwired/twig/twig50/readme.md
 create mode 100644 keyboards/handwired/twig/twig50/rules.mk
 create mode 100644 keyboards/handwired/twig/twig50/twig50.c
 create mode 100644 keyboards/handwired/twig/twig50/twig50.h

diff --git a/keyboards/handwired/twig/twig50/config.h b/keyboards/handwired/twig/twig50/config.h
new file mode 100644
index 0000000000..ecdf7bf9fb
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/config.h
@@ -0,0 +1,28 @@
+// Copyright 2022 Takeshi Noda (nodatk@gmail.com)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "config_common.h"
+
+/* key matrix size */
+#define MATRIX_ROWS 4
+#define MATRIX_COLS 14
+
+#define MATRIX_ROW_PINS { B7, B6, B5, B4 }
+#define MATRIX_COL_PINS { A2, A1, A0, B8 , B13, B14, B15, B9, B10, B11, B3, B2, B1, B0}
+
+#define DIODE_DIRECTION COL2ROW
+
+#define DEBOUNCE 8
+#define TAPPING_TERM 150
+
+#define FORCE_NKRO
+
+#ifdef AUDIO_ENABLE
+  #define AUDIO_PIN A5
+  #define AUDIO_PIN_ALT A4
+  #define AUDIO_PIN_ALT_AS_NEGATIVE
+  #define STARTUP_SONG SONG(STARTUP_SOUND)
+  #define AUDIO_INIT_DELAY
+#endif
diff --git a/keyboards/handwired/twig/twig50/info.json b/keyboards/handwired/twig/twig50/info.json
new file mode 100644
index 0000000000..12b2e397b1
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/info.json
@@ -0,0 +1,20 @@
+{
+    "keyboard_name": "twig50",
+    "manufacturer": "Twig",
+    "url": "",
+    "maintainer": "nodatk",
+    "usb": {
+      "vid": "0xFEED",
+      "pid": "0x6060",
+      "device_version": "0.2.1"
+    },
+    "layouts": {
+      "LAYOUT_diag_4x14": {
+        "layout": [
+{"x":0, "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},
+{"x":0, "y":1}, {"x":2, "y":1}, {"x":3, "y":1}, {"x":4, "y":1}, {"x":5, "y":1}, {"x":6, "y":1}, {"x":7, "y":1}, {"x":8, "y":1}, {"x":9, "y":1}, {"x":10, "y":1}, {"x":11, "y":1}, {"x":12, "y":1}, {"x":13, "y":1},
+{"x":0, "y":2}, {"x":1, "y":2}, {"x":2, "y":2}, {"x":3, "y":2}, {"x":4, "y":2}, {"x":5, "y":2}, {"x":6, "y":2}, {"x":7, "y":2}, {"x":8, "y":2}, {"x":9, "y":2}, {"x":10, "y":2}, {"x":11, "y":2}, {"x":13, "y":2},
+{"x":0, "y":3}, {"x":1, "y":3}, {"x":2, "y":3}, {"x":4, "y":3}, {"x":5, "y":3}, {"x":7, "y":3}, {"x":8, "y":3}, {"x":9, "y":3}, {"x":10, "y":3}, {"x":11, "y":3}, {"x":13, "y":3}]
+      }
+    }
+  }
diff --git a/keyboards/handwired/twig/twig50/keymaps/default/keymap.c b/keyboards/handwired/twig/twig50/keymaps/default/keymap.c
new file mode 100644
index 0000000000..7270773a93
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/keymaps/default/keymap.c
@@ -0,0 +1,79 @@
+// Copyright 2022 Takeshi Noda (nodatk@gmail.com)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "twig50.h"
+
+#define LAL_NCV  LALT_T(KC_LANG2)
+#define RAL_CNV  RALT_T(KC_LANG1)
+#define LGU_NCV  LGUI_T(KC_LANG2)
+#define RGU_ENT  RGUI_T(KC_ENT)
+#define RGU_IN8  RGUI_T(KC_INT8)
+
+#define RSF_SCL  RSFT_T(KC_SCLN)
+#define RCT_ESC  RCTL_T(KC_ESC)
+#define RCT_IN7  RCTL_T(KC_INT7)
+
+#define LT1_SPC  LT(1, KC_SPC)
+#define LT2_F    LT(2, KC_F)
+#define LT2_N    LT(2, KC_N)
+#define LT3_BS   LT(3, KC_BSPC)
+#define LT3_V    LT(3, KC_V)
+#define LT3_QOT  LT(3, KC_QUOT)
+#define TG4      TG(4)
+
+#define SFT_1    RSFT(KC_1)
+#define SFT_2    RSFT(KC_2)
+#define SFT_3    RSFT(KC_3)
+#define SFT_4    RSFT(KC_4)
+#define SFT_5    RSFT(KC_5)
+#define SFT_6    LSFT(KC_6)
+#define SFT_7    LSFT(KC_7)
+#define SFT_8    LSFT(KC_8)
+#define SFT_9    LSFT(KC_9)
+#define SFT_0    LSFT(KC_0)
+#define SFT_LBR  LSFT(KC_LBRC)
+
+#define OSM_LSF  OSM(MOD_LSFT)
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+
+  // Layer 0, Base layer
+  LAYOUT_diag_4x14(
+    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_BSPC,
+    KC_LCTL,          KC_A,    KC_S,    KC_D,    LT2_F,   KC_G,         KC_H,    KC_J,    KC_K,    KC_L,    RSF_SCL, LT3_QOT, KC_ENT,
+    KC_LSFT, TG4,     KC_Z,    KC_X,    KC_C,    LT3_V,   KC_B,         LT2_N,   KC_M,    KC_COMM, KC_DOT,  KC_SLSH,          KC_RSFT,
+    KC_BTN1, KC_BTN2, KC_LALT,          LGU_NCV, LT1_SPC,               RCT_ESC, RGU_ENT, RAL_CNV, KC_INT1, KC_DEL,           MU_TOG
+  ),
+
+  // Layer 1, Space-modifiers: Basic keys
+  LAYOUT_diag_4x14(
+    RESET,            KC_EXEC, KC_HELP, KC_MENU, KC_SLCT, KC_STOP,      KC_BTN2, KC_INT1, KC_MINS, KC_EQL,  KC_INT3, SFT_LBR, KC_TRNS,
+    KC_TRNS,          KC_AGIN, KC_FIND, KC_PGUP, KC_PGDN, KC_F19,       KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT, KC_ENT,  SFT_7,   SFT_2,
+    KC_TRNS, KC_TRNS, KC_UNDO, KC_CUT,  KC_COPY, KC_PSTE, KC_APP,       KC_BSPC, KC_DEL,  KC_RBRC, KC_BSLS, KC_HOME,          KC_END,
+    KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS, KC_TRNS,               RCT_IN7, RGU_IN8, KC_TRNS, KC_INT2, KC_INT4,          MU_MOD
+  ),
+
+  // Layer 2, F,N-modifiers: Number keys and symbols
+  LAYOUT_diag_4x14(
+    KC_TRNS,          SFT_1,   SFT_2,   SFT_3,   SFT_4,   SFT_5,        SFT_6,   SFT_7,   SFT_8,   SFT_9,   KC_COMM, KC_DOT,  KC_QUOT,
+    KC_TRNS,          KC_1,    KC_2,    KC_3,    KC_4,    KC_5,         KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    SFT_1,   SFT_2,
+    KC_TRNS, KC_TRNS, KC_6,    KC_7,    KC_8,    KC_9,    KC_0,         KC_BSPC, KC_MINS, SFT_4,   SFT_5,   KC_TRNS,          KC_TRNS,
+    KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS, KC_4,                  KC_5,    KC_TRNS, KC_TRNS, KC_INT5, KC_INT6,          KC_TRNS
+  ),
+
+  // Layer 3, V,:-modifiers: Functions and mouse keys
+  LAYOUT_diag_4x14(
+    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_TRNS,
+    KC_MPLY,          KC_MRWD, KC_MFFD, KC_MUTE, KC_VOLD, KC_VOLU,      KC_MS_L, KC_MS_D, KC_MS_U, KC_MS_R, KC_BTN3, KC_TRNS, KC_TRNS,
+    KC_TRNS, KC_TRNS, KC_F20,  KC_F21,  KC_F22,  KC_F23,  KC_F24,       KC_F13,  KC_F14,  KC_F15,  KC_F16,  KC_F17,           KC_F18,
+    KC_TRNS, KC_TRNS, KC_TRNS,          KC_BTN2, KC_BTN1,               KC_WH_D, KC_WH_U, KC_TRNS, KC_TRNS, KC_TRNS,          KC_TRNS
+  ),
+
+  // Layer 4, Toggles: One handed mode
+  LAYOUT_diag_4x14(
+    KC_TRNS,          KC_TRNS, KC_UP,   KC_TRNS, KC_TRNS, KC_TRNS,      KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
+    KC_TRNS,          KC_LEFT, KC_DOWN, KC_RGHT, KC_LSFT, KC_TRNS,      KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT, KC_RSFT, KC_TRNS, KC_TRNS,
+    KC_TRNS, TG4,     KC_TRNS, KC_TRNS, KC_PGUP, KC_PGDN, KC_TRNS,      KC_PGDN, KC_PGUP, KC_TRNS, KC_TRNS, KC_UP,            KC_TRNS,
+    KC_TRNS, KC_TRNS, KC_LALT,          KC_LGUI, KC_LCTL,               KC_RCTL, KC_RGUI, KC_RALT, KC_LEFT, KC_DOWN,          KC_RGHT
+  )
+};
diff --git a/keyboards/handwired/twig/twig50/readme.md b/keyboards/handwired/twig/twig50/readme.md
new file mode 100644
index 0000000000..ae3692c1a0
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/readme.md
@@ -0,0 +1,29 @@
+# Twig50
+
+![Twig50](https://user-images.githubusercontent.com/12627081/185365257-03a4904b-8432-445b-9eca-67f2aff57cd9.jpg "Sample build")
+
+Handwired 50 key with Proton C.
+
+* Keyboard Maintainer: [Takeshi Noda](https://github.com/nodatk)
+* Hardware Supported: Proton C
+* Hardware Availability: Sorry, not available for now
+
+Layout data is available [here](http://www.keyboard-layout-editor.com/#/gists/8df4caf51c8d57e4069e2ae19965f02c).
+
+Make example for this keyboard (after setting up your build environment):
+
+    make handwired/twig/twig50:default
+
+Flashing example for this keyboard:
+
+    make handwired/twig/twig50:default:flash
+
+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 `RESET` if it is available
diff --git a/keyboards/handwired/twig/twig50/rules.mk b/keyboards/handwired/twig/twig50/rules.mk
new file mode 100644
index 0000000000..137022d672
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/rules.mk
@@ -0,0 +1,19 @@
+# MCU name
+MCU = STM32F303
+BOARD = QMK_PROTON_C
+
+# Bootloader selection
+BOOTLOADER = stm32-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
+NKRO_ENABLE = yes           # Enable N-Key Rollover
+BACKLIGHT_ENABLE = no       # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no        # Enable keyboard RGB underglow
+AUDIO_ENABLE = yes          # Audio output
diff --git a/keyboards/handwired/twig/twig50/twig50.c b/keyboards/handwired/twig/twig50/twig50.c
new file mode 100644
index 0000000000..7c4c8572f8
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/twig50.c
@@ -0,0 +1,4 @@
+// Copyright 2022 Takeshi Noda (nodatk@gmail.com)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "twig50.h"
diff --git a/keyboards/handwired/twig/twig50/twig50.h b/keyboards/handwired/twig/twig50/twig50.h
new file mode 100644
index 0000000000..771f13e051
--- /dev/null
+++ b/keyboards/handwired/twig/twig50/twig50.h
@@ -0,0 +1,20 @@
+// Copyright 2022 Takeshi Noda (nodatk@gmail.com)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "quantum.h"
+
+#define ___ KC_NO
+
+#define LAYOUT_diag_4x14( \
+	K00,      K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
+	K10,      K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
+	K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, \
+	K30, K31, K32,      K34, K35,      K37, K38, K39, K3A, K3B,      K3D  \
+) { \
+	{ K00, ___, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D }, \
+	{ K10, ___, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D }, \
+	{ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, ___, K2D }, \
+	{ K30, K31, K32, ___, K34, K35, ___, K37, K38, K39, K3A, K3B, ___, K3D }  \
+}