From 5655d6e5f5d2e35d896dc08e8a040b72a1e868ce Mon Sep 17 00:00:00 2001
From: Viktor Eikman <viktor.eikman@gmail.com>
Date: Sat, 20 Feb 2021 20:32:04 +0100
Subject: [PATCH] [Keyboard] Concertina (#11922)

* [Keyboard] Concertina

* Added a novel handwired keyboard.

* Concertina lint

* Perfunctory changes to pass CI.

* Concertina line width

* Changes from code review: GPL headers, modernization, full-width
  representation of matrix to match info.json.
---
 keyboards/handwired/concertina/64key/64key.c  | 17 ++++
 keyboards/handwired/concertina/64key/64key.h  | 56 +++++++++++
 keyboards/handwired/concertina/64key/config.h | 34 +++++++
 .../concertina/64key/keymaps/default/config.h | 23 +++++
 .../concertina/64key/keymaps/default/keymap.c | 93 +++++++++++++++++++
 .../handwired/concertina/64key/readme.md      | 15 +++
 keyboards/handwired/concertina/concertina.h   | 23 +++++
 keyboards/handwired/concertina/config.h       | 26 ++++++
 keyboards/handwired/concertina/info.json      | 37 ++++++++
 keyboards/handwired/concertina/readme.md      |  6 ++
 keyboards/handwired/concertina/rules.mk       |  9 ++
 11 files changed, 339 insertions(+)
 create mode 100644 keyboards/handwired/concertina/64key/64key.c
 create mode 100644 keyboards/handwired/concertina/64key/64key.h
 create mode 100644 keyboards/handwired/concertina/64key/config.h
 create mode 100644 keyboards/handwired/concertina/64key/keymaps/default/config.h
 create mode 100644 keyboards/handwired/concertina/64key/keymaps/default/keymap.c
 create mode 100644 keyboards/handwired/concertina/64key/readme.md
 create mode 100644 keyboards/handwired/concertina/concertina.h
 create mode 100644 keyboards/handwired/concertina/config.h
 create mode 100644 keyboards/handwired/concertina/info.json
 create mode 100644 keyboards/handwired/concertina/readme.md
 create mode 100644 keyboards/handwired/concertina/rules.mk

diff --git a/keyboards/handwired/concertina/64key/64key.c b/keyboards/handwired/concertina/64key/64key.c
new file mode 100644
index 0000000000..31211b0a9a
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/64key.c
@@ -0,0 +1,17 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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 "64key.h"
diff --git a/keyboards/handwired/concertina/64key/64key.h b/keyboards/handwired/concertina/64key/64key.h
new file mode 100644
index 0000000000..a9e557fc78
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/64key.h
@@ -0,0 +1,56 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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"
+
+/*
+ * The matrix is constructed for ease of soldering and for density.
+ * The nomenclature is <side><cluster>_<column><row>.
+ *
+ * L: Left hand.
+ * R: Right hand.
+ * T: Thumb cluster.
+ * M: Main cluster.
+ *
+ * Numbers increase going to the right and away from the user on the
+ * right-hand side of the keyboard, looking directly at each of the two
+ * key clusters (main and thumb), one by one.
+ * This coordinate system is mirrored for the left-hand side.
+ */
+
+#define LAYOUT_64key( \
+                  LT_32, LT_22, LT_12,                 RT_12, RT_22, RT_32,               \
+                  LT_31, LT_21, LT_11, LT_01,   RT_01, RT_11, RT_21, RT_31,               \
+                         LT_20, LT_10, LT_00,   RT_00, RT_10, RT_20,                      \
+                                                                                          \
+                  LM_34, LM_24, LM_14, LM_04,   RM_04, RM_14, RM_24, RM_34,               \
+    LM_53, LM_43, LM_33, LM_23, LM_13, LM_03,   RM_03, RM_13, RM_23, RM_33, RM_43, RM_53, \
+    LM_52, LM_42, LM_32, LM_22, LM_12, LM_02,   RM_02, RM_12, RM_22, RM_32, RM_42, RM_52, \
+    LM_51, LM_41, LM_31, LM_21, LM_11,                 RM_11, RM_21, RM_31, RM_41, RM_51, \
+                         LM_20,                               RM_20                       \
+  ) \
+  { \
+    { LT_00, LT_10, LT_20, LT_31, LM_20, LM_31, LM_41, LM_51 }, \
+    { LT_01, LT_11, LT_21, LM_11, LM_21, LM_32, LM_42, LM_52 }, \
+    { LT_12, LT_22, LT_32, LM_12, LM_22, LM_33, LM_43, LM_53 }, \
+    { LM_02, LM_03, LM_04, LM_13, LM_23, LM_14, LM_24, LM_34 }, \
+    { RT_00, RT_10, RT_20, RT_31, RM_20, RM_31, RM_41, RM_51 }, \
+    { RT_01, RT_11, RT_21, RM_11, RM_21, RM_32, RM_42, RM_52 }, \
+    { RT_12, RT_22, RT_32, RM_12, RM_22, RM_33, RM_43, RM_53 }, \
+    { RM_02, RM_03, RM_04, RM_13, RM_23, RM_14, RM_24, RM_34 }, \
+  }
diff --git a/keyboards/handwired/concertina/64key/config.h b/keyboards/handwired/concertina/64key/config.h
new file mode 100644
index 0000000000..1b09c403f6
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/config.h
@@ -0,0 +1,34 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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"
+
+#define MATRIX_ROWS 8
+#define MATRIX_COLS 8
+
+#define MATRIX_ROW_PINS { D1, D0, D4, C6, D7, E6, B4, B5 }
+#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3, B2, B6 }
+#define UNUSED_PINS { D3, D2 }
+
+/* LEDs are not used in the standard 64key configuration. */
+#define RGB_DI_PIN D3
+#define RGBLED_NUM 0
+
+#define DIODE_DIRECTION COL2ROW
+
+#define PERMISSIVE_HOLD
diff --git a/keyboards/handwired/concertina/64key/keymaps/default/config.h b/keyboards/handwired/concertina/64key/keymaps/default/config.h
new file mode 100644
index 0000000000..4af423c3a7
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/keymaps/default/config.h
@@ -0,0 +1,23 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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
+
+/* Custom space-cadet modifier and tap combinations: Brackets on Ctrl and braces on Alt. */
+#define LCPO_KEYS KC_LCTL, KC_TRNS, KC_LBRACKET
+#define RCPC_KEYS KC_RCTL, KC_TRNS, KC_RBRACKET
+#define LAPO_KEYS KC_LALT, KC_LSFT, KC_LBRACKET
+#define RAPC_KEYS KC_RALT, KC_RSFT, KC_RBRACKET
diff --git a/keyboards/handwired/concertina/64key/keymaps/default/keymap.c b/keyboards/handwired/concertina/64key/keymaps/default/keymap.c
new file mode 100644
index 0000000000..e8425824fb
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/keymaps/default/keymap.c
@@ -0,0 +1,93 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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
+#include <keymap_colemak.h>
+#include <sendstring_colemak.h>
+
+enum layer_names {
+    _QWERTY,   // OS-side Colemak. Default.
+    _COLEMAK,  // Keyboard-side Colemak. Portability, emergency.
+    _GAMING,   // Navigation clusters (only) change hands.
+    _NUMERIC   // Numbers, function keys, special characters, mouse.
+};
+
+enum taps {
+    PNX,  // Play/pause; next track.
+};
+
+qk_tap_dance_action_t tap_dance_actions[] = {
+    [PNX] = ACTION_TAP_DANCE_DOUBLE(KC_MEDIA_PLAY_PAUSE, KC_MEDIA_NEXT_TRACK),
+};
+
+// Shorthand:
+#define LAYER_N MO(_NUMERIC)
+#define LAYER_C TG(_COLEMAK)
+#define LAYER_G TG(_GAMING)
+#define PASTE LSFT(KC_INS)  // Terminal-compatible paste.
+#define SLQ RALT(KC_9)  // Single left-side quotation mark (in Colemak).
+#define SRQ RALT(KC_0)
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+
+[_QWERTY] = LAYOUT_64key(
+                      KC_LSPO, KC_MINS, KC_EQL,                           KC_VOLD, KC_VOLU, KC_RSPC,
+                      KC_LCPO, KC_LGUI, KC_HAEN, KC_ENT,         KC_MUTE, TD(PNX), LAYER_N, KC_RCPC,
+                               KC_LAPO, KC_SPC,  SLQ,            SRQ,     KC_ESC,  KC_RAPC,
+
+                      CM_W,    CM_F,    CM_P,    CM_G,           CM_J,    CM_L,    CM_U,    CM_Y,
+    KC_TAB,  CM_Q,    CM_R,    CM_S,    CM_T,    CM_D,           CM_H,    CM_N,    CM_E,    CM_I,    CM_SCLN, KC_BSLS,
+    KC_BSPC, CM_A,    CM_X,    CM_C,    CM_V,    CM_B,           CM_K,    CM_M,    KC_COMM, KC_DOT,  CM_O,    KC_QUOT,
+    KC_DEL,  CM_Z,    KC_HOME, KC_PGUP, KC_END,                           KC_LEFT, KC_UP,   KC_RGHT, KC_SLSH, KC_GRV,
+                               KC_PGDN,                                            KC_DOWN
+),
+
+[_COLEMAK] = LAYOUT_64key(
+                      _______, _______, _______,                          _______, _______, _______,
+                      _______, _______, _______, _______,        _______, _______, _______, _______,
+                               _______, _______, _______,        _______, _______, _______,
+
+                      KC_W,    KC_F,    KC_P,    KC_G,           KC_J,    KC_L,    KC_U,    KC_Y,
+    _______, KC_Q,    KC_R,    KC_S,    KC_T,    KC_D,           KC_H,    KC_N,    KC_E,    KC_I,    KC_SCLN, _______,
+    _______, KC_A,    KC_X,    KC_C,    KC_V,    KC_B,           KC_K,    KC_M,    _______, _______, KC_O,    _______,
+    _______, KC_Z,    _______, _______, _______,                          _______, _______, _______, _______, _______,
+                               _______,                                            _______
+),
+
+[_GAMING] = LAYOUT_64key(
+                      _______, _______, _______,                          _______, _______, _______,
+                      _______, _______, _______, _______,        _______, _______, _______, _______,
+                               _______, _______, _______,        _______, _______, _______,
+
+                      _______, _______, _______, _______,        _______, _______, _______, _______,
+    _______, _______, _______, _______, _______, _______,        _______, _______, _______, _______, _______, _______,
+    _______, _______, _______, _______, _______, _______,        _______, _______, _______, _______, _______, _______,
+    _______, _______, KC_LEFT, KC_UP,   KC_RGHT,                          KC_HOME, KC_PGUP, KC_END,  _______, _______,
+                               KC_DOWN,                                            KC_PGDN
+),
+
+[_NUMERIC] = LAYOUT_64key(
+                      _______, _______, _______,                          KC_ACL1, KC_ACL2, _______,
+                      _______, _______, LAYER_C, _______,        KC_ACL0, _______, _______, _______,
+                               _______, _______, _______,        KC_SLEP, _______, _______,
+
+                      KC_F2,   KC_F3,   KC_F4,   KC_F5,          KC_F6,   KC_F7,   KC_F8,   KC_F9,
+    KC_F12,  KC_F1,   KC_2,    KC_3,    KC_4,    KC_5,           KC_6,    KC_7,    KC_8,    KC_9,    KC_F10,  KC_F11,
+    _______, KC_1,    KC_AT,   KC_HASH, KC_DLR,  KC_PERC,        KC_CIRC, KC_AMPR, KC_ASTR, KC_APP,  KC_0,    PASTE,
+    KC_INS,  KC_EXLM, KC_BTN1, KC_BTN3, KC_BTN2,                          KC_MS_L, KC_MS_U, KC_MS_R, KC_PSCR, RESET,
+                               LAYER_G,                                            KC_MS_D
+)
+};
diff --git a/keyboards/handwired/concertina/64key/readme.md b/keyboards/handwired/concertina/64key/readme.md
new file mode 100644
index 0000000000..78d384f68d
--- /dev/null
+++ b/keyboards/handwired/concertina/64key/readme.md
@@ -0,0 +1,15 @@
+The `64key` layout
+==================
+
+This folder represents the keyboard configuration identified as
+`concertina_64key` in the DMOTE application’s list of GNU make targets, as of
+version 0.7.0 of that application. The QMK code is fully compatible back to
+version 0.6.0, which introduced the Concertina.
+
+The default keymap for this layout has a QWERTY base layer but is intended for
+running Colemak on the OS side. It has a separate key layer that forces Colemak
+from the QMK side in case the keyboard has to be used with a computer that does
+not run Colemak.
+
+A full set of printable caps to match the keymap is available in the
+`dmote-keycap` application, [here](https://github.com/veikman/dmote-keycap).
diff --git a/keyboards/handwired/concertina/concertina.h b/keyboards/handwired/concertina/concertina.h
new file mode 100644
index 0000000000..b8a0c4cff6
--- /dev/null
+++ b/keyboards/handwired/concertina/concertina.h
@@ -0,0 +1,23 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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
+
+#ifdef KEYBOARD_handwired_concertina_64key
+    #include "64key.h"
+#endif
+
+#include "quantum.h"
diff --git a/keyboards/handwired/concertina/config.h b/keyboards/handwired/concertina/config.h
new file mode 100644
index 0000000000..4f6cbadc1c
--- /dev/null
+++ b/keyboards/handwired/concertina/config.h
@@ -0,0 +1,26 @@
+/* Copyright 2020-2021 Viktor Eikman
+ *
+ * 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 descriptors */
+#define VENDOR_ID       0x444D
+#define PRODUCT_ID      0x3632
+#define DEVICE_VER      0x0001
+#define PRODUCT         Concertina
+#define MANUFACTURER    Viktor Eikman
diff --git a/keyboards/handwired/concertina/info.json b/keyboards/handwired/concertina/info.json
new file mode 100644
index 0000000000..a7dd42b112
--- /dev/null
+++ b/keyboards/handwired/concertina/info.json
@@ -0,0 +1,37 @@
+{
+    "keyboard_name": "Concertina",
+    "url": "https://viktor.eikman.se/article/the-concertina/",
+    "maintainer": "veikman",
+    "width": 12,
+    "height": 8,
+    "layouts": {
+        "LAYOUT_64key": {
+            "key_count": 64,
+            "layout": [
+                {"x":2, "y":0.5}, {"x":3, "y":0}, {"x":4, "y":0.3},
+                {"x":8, "y":0.7}, {"x":9, "y":0.3}, {"x":10, "y":0},
+
+                {"x":2, "y":1.5}, {"x":3, "y":1}, {"x":4, "y":1.3}, {"x":5, "y":0.7},
+                {"x":8, "y":0.7}, {"x":9, "y":1.3}, {"x":10, "y":1}, {"x":11, "y":1.5},
+
+                {"x":3, "y":2}, {"x":4, "y":2.3}, {"x":5, "y":1.7},
+                {"x":8, "y":1.7}, {"x":9, "y":2.3}, {"x":10, "y":2},
+
+                {"x":2, "y":4}, {"x":3, "y":4}, {"x":4, "y":4}, {"x":5, "y":4},
+                {"x":8, "y":4}, {"x":9, "y":4}, {"x":10, "y":4}, {"x":11, "y":4},
+
+                {"x":0, "y":5}, {"x":1, "y":5}, {"x":2, "y":5}, {"x":3, "y":5}, {"x":4, "y":5}, {"x":5, "y":5},
+                {"x":8, "y":5}, {"x":9, "y":5}, {"x":10, "y":5}, {"x":11, "y":5}, {"x":12, "y":5}, {"x":13, "y":5},
+
+                {"x":0, "y":6}, {"x":1, "y":6}, {"x":2, "y":6}, {"x":3, "y":6}, {"x":4, "y":6}, {"x":5, "y":6},
+                {"x":8, "y":6}, {"x":9, "y":6}, {"x":10, "y":6}, {"x":11, "y":6}, {"x":12, "y":6}, {"x":13, "y":6},
+
+                {"x":0, "y":7}, {"x":1, "y":7}, {"x":2, "y":7}, {"x":3, "y":7}, {"x":4, "y":7},
+                {"x":9, "y":7}, {"x":10, "y":7}, {"x":11, "y":7}, {"x":12, "y":7}, {"x":13, "y":7},
+
+                {"x":3, "y":8},
+                {"x":10, "y":8}
+            ]
+        }
+    }
+}
diff --git a/keyboards/handwired/concertina/readme.md b/keyboards/handwired/concertina/readme.md
new file mode 100644
index 0000000000..36c0f53b63
--- /dev/null
+++ b/keyboards/handwired/concertina/readme.md
@@ -0,0 +1,6 @@
+Concertina
+==========
+
+The Concertina is one of the designs bundled with the DMOTE application, a CAD
+program specifically for novel keyboard cases, maintained
+[here](https://github.com/veikman/dactyl-keyboard).
diff --git a/keyboards/handwired/concertina/rules.mk b/keyboards/handwired/concertina/rules.mk
new file mode 100644
index 0000000000..94d6eadd00
--- /dev/null
+++ b/keyboards/handwired/concertina/rules.mk
@@ -0,0 +1,9 @@
+# Written for a Pro Micro. The keyboard case is compatible with much else.
+MCU = atmega32u4
+BOOTLOADER = caterina
+
+# Build options:
+MOUSEKEY_ENABLE = yes
+EXTRAKEY_ENABLE = yes
+TAP_DANCE_ENABLE = yes
+RGBLIGHT_ENABLE = no