summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Titmuss <richard.titmuss@gmail.com>2020-09-20 02:48:43 +0200
committerGitHub <noreply@github.com>2020-09-19 17:48:43 -0700
commite1437c1859b088c4da7ffb517f8034723172cd82 (patch)
tree9150a41bc34fea8937b2684138e826ead3f04fd2
parent741856dd57735dcd143987eb954ecc4a5ca2fc96 (diff)
[Keyboard] Add Torn keyboard (#10207)
* Add Torn keyboard * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * Remove via json file * Add mcp23081_pin_t * Apply suggestions from code review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Drashna Jaelre <drashna@live.com> * Apply suggestions from code review Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: Richard Titmuss <richardt@spotify.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Ryan <fauxpark@gmail.com>
-rw-r--r--keyboards/torn/config.h68
-rw-r--r--keyboards/torn/info.json57
-rw-r--r--keyboards/torn/keymaps/default/keymap.c119
-rw-r--r--keyboards/torn/keymaps/via/keymap.c119
-rw-r--r--keyboards/torn/keymaps/via/rules.mk2
-rw-r--r--keyboards/torn/matrix.c113
-rw-r--r--keyboards/torn/mcp23018.c63
-rw-r--r--keyboards/torn/mcp23018.h32
-rw-r--r--keyboards/torn/readme.md21
-rw-r--r--keyboards/torn/rules.mk27
-rw-r--r--keyboards/torn/torn.c50
-rw-r--r--keyboards/torn/torn.h41
-rw-r--r--keyboards/torn/torn_encoder.c86
-rw-r--r--keyboards/torn/torn_oled.c63
14 files changed, 861 insertions, 0 deletions
diff --git a/keyboards/torn/config.h b/keyboards/torn/config.h
new file mode 100644
index 0000000000..6cd6c2808e
--- /dev/null
+++ b/keyboards/torn/config.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2020 Richard Titmuss <richard.titmuss@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
+
+#include "config_common.h"
+
+/* USB Device descriptor parameter */
+/* VID & PID from vusb project, see tmk_core/protocol/vusb/USB-IDs-for-free.txt"*/
+#define VENDOR_ID 0x7274
+#define PRODUCT_ID 0x0001
+#define DEVICE_VER 0x0000
+#define MANUFACTURER richard.titmuss
+#define PRODUCT Torn
+
+/* key matrix size */
+#define MATRIX_ROWS 4
+#define MATRIX_COLS 12
+
+/*
+ * Keyboard Matrix Assignments
+ *
+ * Change this to how you wired your keyboard
+ * COLS: AVR pins used for columns, left to right
+ * ROWS: AVR pins used for rows, top to bottom
+ * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
+ * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
+ *
+ */
+#define MATRIX_ROW_PINS \
+ { D4, D1, D0, D5 }
+#define MATRIX_COL_PINS \
+ { B3, B4, B5, B0, D7, D6 }
+#define UNUSED_PINS
+
+#define SECONDARY_ROW_PINS \
+ { (1 << 5), (1 << 6), (1 << 7), (1 << 4) }
+#define SECONDARY_COL_PINS \
+ { (1 << 3), (1 << 2), (1 << 1), (1 << 0), (1 << 15), (1 << 14) }
+
+/* COL2ROW, ROW2COL*/
+#define DIODE_DIRECTION COL2ROW
+
+#define ENCODERS_PAD_A \
+ { B2 }
+#define ENCODERS_PAD_B \
+ { B1 }
+
+#define USB_MAX_POWER_CONSUMPTION 100
+
+/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
+#define DEBOUNCE 5
+
+#define OLED_TIMEOUT 60000
diff --git a/keyboards/torn/info.json b/keyboards/torn/info.json
new file mode 100644
index 0000000000..340eb73597
--- /dev/null
+++ b/keyboards/torn/info.json
@@ -0,0 +1,57 @@
+{
+ "keyboard_name": "Torn / Split Through Hole",
+ "url": "https://github.com/rtitmuss/torn",
+ "maintainer": "rtitmuss",
+ "width": 15,
+ "height": 4.55,
+ "layouts": {
+ "LAYOUT_split_3x6_4": {
+ "layout": [
+ {"label":"SW1", "x":0, "y":0.375},
+ {"label":"SW2", "x":1, "y":0.375},
+ {"label":"SW3", "x":2, "y":0.125},
+ {"label":"SW4", "x":3, "y":0},
+ {"label":"SW5", "x":4, "y":0.125},
+ {"label":"SW6", "x":5, "y":0.25},
+ {"label":"SW23", "x":9, "y":0.25},
+ {"label":"SW24", "x":10, "y":0.125},
+ {"label":"SW25", "x":11, "y":0},
+ {"label":"SW26", "x":12, "y":0.125},
+ {"label":"SW27", "x":13, "y":0.375},
+ {"label":"SW28", "x":14, "y":0.375},
+ {"label":"SW7", "x":0, "y":1.375},
+ {"label":"SW8", "x":1, "y":1.375},
+ {"label":"SW9", "x":2, "y":1.125},
+ {"label":"SW10", "x":3, "y":1},
+ {"label":"SW11", "x":4, "y":1.125},
+ {"label":"SW12", "x":5, "y":1.25},
+ {"label":"SW29", "x":9, "y":1.25},
+ {"label":"SW30", "x":10, "y":1.125},
+ {"label":"SW31", "x":11, "y":1},
+ {"label":"SW32", "x":12, "y":1.125},
+ {"label":"SW33", "x":13, "y":1.375},
+ {"label":"SW34", "x":14, "y":1.375},
+ {"label":"SW13", "x":0, "y":2.375},
+ {"label":"SW14", "x":1, "y":2.375},
+ {"label":"SW15", "x":2, "y":2.125},
+ {"label":"SW16", "x":3, "y":2},
+ {"label":"SW17", "x":4, "y":2.125},
+ {"label":"SW18", "x":5, "y":2.25},
+ {"label":"SW35", "x":9, "y":2.25},
+ {"label":"SW36", "x":10, "y":2.125},
+ {"label":"SW37", "x":11, "y":2},
+ {"label":"SW38", "x":12, "y":2.125},
+ {"label":"SW39", "x":13, "y":2.375},
+ {"label":"SW40", "x":14, "y":2.375},
+ {"label":"SW19", "x":3, "y":3.1},
+ {"label":"SW20", "x":4, "y":3.25},
+ {"label":"SW21", "x":5, "y":3.40},
+ {"label":"SW22", "x":6, "y":3.55},
+ {"label":"SW41", "x":8, "y":3.55},
+ {"label":"SW42", "x":9, "y":3.40},
+ {"label":"SW43", "x":10, "y":3.25},
+ {"label":"SW44", "x":11, "y":3.1}
+ ]
+ }
+ }
+}
diff --git a/keyboards/torn/keymaps/default/keymap.c b/keyboards/torn/keymaps/default/keymap.c
new file mode 100644
index 0000000000..7c91325bdc
--- /dev/null
+++ b/keyboards/torn/keymaps/default/keymap.c
@@ -0,0 +1,119 @@
+/* Copyright 2020 Richard Titmuss (richard.titmuss@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/>.
+ */
+
+#include QMK_KEYBOARD_H
+
+enum torn_layers { _QWERTY, _LOWER, _RAISE, _ADJUST };
+
+#define S_BSPC LSFT_T(KC_BSPC)
+#define R_DEL LT(_RAISE, KC_DEL)
+#define G_ENT LGUI_T(KC_ENT)
+#define L_SPC LT(_LOWER, KC_SPC)
+
+// clang-format off
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+
+/* Qwerty
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | Tab | Q | W | E | R | T | | Y | U | I | O | P | ' |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ` | A | S | D | F | G | | H | J | K | L | ; | [ |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | \ | Z | X | C | V | B | | N | M | , | . | / | ] |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_QWERTY] = LAYOUT_split_3x6_4(
+ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_QUOT,
+ KC_GRV, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_LBRC,
+ KC_BSLS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RBRC ,
+ _______, KC_LCTL, S_BSPC, R_DEL, G_ENT, L_SPC, KC_RALT, _______
+),
+
+/* Lower
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | Esc | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | = | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | - |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | _ | | | | | | | | | , | . | / | + |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_LOWER] = LAYOUT_split_3x6_4(
+ KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
+ KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PMNS,
+ KC_UNDS, _______, _______, _______, _______, _______, _______, _______, KC_COMM, KC_DOT, KC_SLSH, KC_PPLS,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+),
+
+/* Raise
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | | F1 | F2 | F3 | F4 | F5 | | | & | * | ( | ) | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | F6 | F7 | F8 | F9 | F10 | | Home | Left | Down | Right| End | PgUp |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | F11 | F12 | | | | | | | | | | PgDn |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_RAISE] = LAYOUT_split_3x6_4(
+ _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, S(A(KC_LEFT)), KC_UP, S(A(KC_RGHT)), _______, _______,
+ _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, KC_PGUP,
+ _______, KC_F11, KC_F12, _______, _______, _______, A(KC_BSPC), A(KC_LEFT), S(KC_DOWN), A(KC_RGHT), _______, KC_PGDN ,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+),
+
+/* Adjust (Lower + Raise)
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_ADJUST] = LAYOUT_split_3x6_4(
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+)
+
+};
+
+const uint16_t PROGMEM encoder_keymaps[][2][2] = {
+ [_QWERTY] = { { C(S(KC_TAB)), C(KC_TAB) }, { KC_PGDN, KC_PGUP } },
+ [_LOWER] = { { C(KC_LEFT), C(KC_RGHT) }, { KC__VOLDOWN, KC__VOLUP } },
+ [_RAISE] = { { KC_TRNS, KC_TRNS }, { G(KC_TAB), G(S(KC_TAB)) } },
+ [_ADJUST] = { { KC_TRNS, KC_TRNS }, { KC_TRNS, KC_TRNS } },
+};
+// clang-format on
+
+layer_state_t layer_state_set_user(layer_state_t state) {
+ torn_set_led(0, IS_LAYER_ON_STATE(state, _RAISE));
+ torn_set_led(1, IS_LAYER_ON_STATE(state, _LOWER));
+ return state;
+}
diff --git a/keyboards/torn/keymaps/via/keymap.c b/keyboards/torn/keymaps/via/keymap.c
new file mode 100644
index 0000000000..7c91325bdc
--- /dev/null
+++ b/keyboards/torn/keymaps/via/keymap.c
@@ -0,0 +1,119 @@
+/* Copyright 2020 Richard Titmuss (richard.titmuss@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/>.
+ */
+
+#include QMK_KEYBOARD_H
+
+enum torn_layers { _QWERTY, _LOWER, _RAISE, _ADJUST };
+
+#define S_BSPC LSFT_T(KC_BSPC)
+#define R_DEL LT(_RAISE, KC_DEL)
+#define G_ENT LGUI_T(KC_ENT)
+#define L_SPC LT(_LOWER, KC_SPC)
+
+// clang-format off
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+
+/* Qwerty
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | Tab | Q | W | E | R | T | | Y | U | I | O | P | ' |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ` | A | S | D | F | G | | H | J | K | L | ; | [ |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | \ | Z | X | C | V | B | | N | M | , | . | / | ] |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_QWERTY] = LAYOUT_split_3x6_4(
+ KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_QUOT,
+ KC_GRV, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_LBRC,
+ KC_BSLS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RBRC ,
+ _______, KC_LCTL, S_BSPC, R_DEL, G_ENT, L_SPC, KC_RALT, _______
+),
+
+/* Lower
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | Esc | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | = | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | - |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | _ | | | | | | | | | , | . | / | + |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_LOWER] = LAYOUT_split_3x6_4(
+ KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
+ KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PMNS,
+ KC_UNDS, _______, _______, _______, _______, _______, _______, _______, KC_COMM, KC_DOT, KC_SLSH, KC_PPLS,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+),
+
+/* Raise
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | | F1 | F2 | F3 | F4 | F5 | | | & | * | ( | ) | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | F6 | F7 | F8 | F9 | F10 | | Home | Left | Down | Right| End | PgUp |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | F11 | F12 | | | | | | | | | | PgDn |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_RAISE] = LAYOUT_split_3x6_4(
+ _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, S(A(KC_LEFT)), KC_UP, S(A(KC_RGHT)), _______, _______,
+ _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, KC_PGUP,
+ _______, KC_F11, KC_F12, _______, _______, _______, A(KC_BSPC), A(KC_LEFT), S(KC_DOWN), A(KC_RGHT), _______, KC_PGDN ,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+),
+
+/* Adjust (Lower + Raise)
+ * ,-----------------------------------------. ,-----------------------------------------.
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | | | | | | | | | | | | | |
+ * |------+------+------+------+------+------| |------+------+------+------+------+------|
+ * | ____ | Ctrl | Bksp | Del | |Enter |Space | Alt | ____ |
+ * | | |Shift |Raise | | Gui |Lower | | |
+ * `---------------------------' `---------------------------'
+ */
+[_ADJUST] = LAYOUT_split_3x6_4(
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
+ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
+)
+
+};
+
+const uint16_t PROGMEM encoder_keymaps[][2][2] = {
+ [_QWERTY] = { { C(S(KC_TAB)), C(KC_TAB) }, { KC_PGDN, KC_PGUP } },
+ [_LOWER] = { { C(KC_LEFT), C(KC_RGHT) }, { KC__VOLDOWN, KC__VOLUP } },
+ [_RAISE] = { { KC_TRNS, KC_TRNS }, { G(KC_TAB), G(S(KC_TAB)) } },
+ [_ADJUST] = { { KC_TRNS, KC_TRNS }, { KC_TRNS, KC_TRNS } },
+};
+// clang-format on
+
+layer_state_t layer_state_set_user(layer_state_t state) {
+ torn_set_led(0, IS_LAYER_ON_STATE(state, _RAISE));
+ torn_set_led(1, IS_LAYER_ON_STATE(state, _LOWER));
+ return state;
+}
diff --git a/keyboards/torn/keymaps/via/rules.mk b/keyboards/torn/keymaps/via/rules.mk
new file mode 100644
index 0000000000..36b7ba9cbc
--- /dev/null
+++ b/keyboards/torn/keymaps/via/rules.mk
@@ -0,0 +1,2 @@
+VIA_ENABLE = yes
+LTO_ENABLE = yes
diff --git a/keyboards/torn/matrix.c b/keyboards/torn/matrix.c
new file mode 100644
index 0000000000..dd7fa1e2e1
--- /dev/null
+++ b/keyboards/torn/matrix.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2020 Richard Titmuss (richard.titmuss@gmail.com)
+ * Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar
+ *
+ * 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 "mcp23018.h"
+
+#define SPLIT_MATRIX_COLS (MATRIX_COLS / 2)
+#define SECONDARY_ROW_OFFSET (MATRIX_ROWS / 2)
+
+typedef uint16_t mcp23018_pin_t;
+
+static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
+static const pin_t col_pins[SPLIT_MATRIX_COLS] = MATRIX_COL_PINS;
+static const mcp23018_pin_t secondary_row_pins[MATRIX_ROWS] = SECONDARY_ROW_PINS;
+static const mcp23018_pin_t secondary_col_pins[SPLIT_MATRIX_COLS] = SECONDARY_COL_PINS;
+
+static void select_row(uint8_t row) {
+ setPinOutput(row_pins[row]);
+ writePinLow(row_pins[row]);
+}
+
+static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
+
+static void unselect_rows(void) {
+ for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
+ setPinInputHigh(row_pins[x]);
+ }
+}
+
+static void select_secondary_row(uint8_t row) {
+ uint8_t gpioa = 0xFF & ~secondary_row_pins[row];
+ mcp23018_writeReg(GPIOA, &gpioa, 1);
+}
+
+static void init_pins(void) {
+ unselect_rows();
+ for (uint8_t x = 0; x < SPLIT_MATRIX_COLS; x++) {
+ setPinInputHigh(col_pins[x]);
+ }
+}
+
+static matrix_row_t read_cols(void) {
+ matrix_row_t state = 0;
+
+ // For each col...
+ for (uint8_t col_index = 0; col_index < SPLIT_MATRIX_COLS; col_index++) {
+ // Select the col pin to read (active low)
+ uint8_t pin_state = readPin(col_pins[col_index]);
+
+ // Populate the matrix row with the state of the col pin
+ state |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
+ }
+
+ return state;
+}
+
+static matrix_row_t read_secondary_cols(void) {
+ matrix_row_t state = 0;
+
+ uint8_t mcp23018_pin_state[2];
+ if (mcp23018_readReg(GPIOA, mcp23018_pin_state, 2)) {
+ return 0;
+ }
+
+ uint16_t pins = mcp23018_pin_state[0] | (mcp23018_pin_state[1] << 8);
+
+ for (uint8_t col_index = 0; col_index < SPLIT_MATRIX_COLS; col_index++) {
+ uint16_t pin_state = pins & (secondary_col_pins[col_index]);
+ state |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
+ }
+
+ return state;
+}
+
+static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
+ matrix_row_t last_row_value = current_matrix[current_row];
+
+ select_row(current_row);
+ select_secondary_row(current_row);
+
+ current_matrix[current_row] = read_cols() | (read_secondary_cols() << 6);
+
+ unselect_row(current_row);
+
+ return (last_row_value != current_matrix[current_row]);
+}
+
+void matrix_init_custom(void) { init_pins(); }
+
+bool matrix_scan_custom(matrix_row_t current_matrix[]) {
+ bool changed = false;
+
+ for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
+ changed |= read_cols_on_row(current_matrix, current_row);
+ }
+
+ return changed;
+}
diff --git a/keyboards/torn/mcp23018.c b/keyboards/torn/mcp23018.c
new file mode 100644
index 0000000000..c180f1dae5
--- /dev/null
+++ b/keyboards/torn/mcp23018.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2020 Richard Titmuss (richard.titmuss@gmail.com)
+ * Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar
+ *
+ * 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 "i2c_master.h"
+#include "mcp23018.h"
+
+#define MCP23018_ADDR 0b0100000
+
+#define MCP23018_TIMEOUT 100
+
+static i2c_status_t mcp23018_status = I2C_STATUS_ERROR;
+
+void msp23018_init(void) {
+ mcp23018_status = I2C_STATUS_SUCCESS;
+
+ // Set pin direction
+ uint8_t iodir[] = {0b00001111, 0b11111111};
+ mcp23018_writeReg(IODIRA, iodir, 2);
+
+ // Set pull-up
+ uint8_t gppu[] = {0b00001111, 0b11111000};
+ mcp23018_writeReg(GPPUA, gppu, 2);
+
+ // LEDs output high
+ uint8_t gpio[] = {0b00000000, 0b00000111};
+ mcp23018_writeReg(GPIOA, gpio, 2);
+}
+
+bool mcp23018_reset_required(void) { return mcp23018_status != I2C_STATUS_SUCCESS; }
+
+i2c_status_t mcp23018_writeReg(uint8_t regaddr, const uint8_t* data, uint16_t length) {
+ if (mcp23018_status) {
+ return mcp23018_status;
+ }
+
+ mcp23018_status = i2c_writeReg((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
+ return mcp23018_status;
+}
+
+i2c_status_t mcp23018_readReg(uint8_t regaddr, uint8_t* data, uint16_t length) {
+ if (mcp23018_status) {
+ return mcp23018_status;
+ }
+
+ mcp23018_status = i2c_readReg((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
+ return mcp23018_status;
+}
diff --git a/keyboards/torn/mcp23018.h b/keyboards/torn/mcp23018.h
new file mode 100644
index 0000000000..17ecaa5a7c
--- /dev/null
+++ b/keyboards/torn/mcp23018.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 Richard Titmuss (richard.titmuss@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 IODIRA 0x00
+#define IODIRB 0x01
+#define GPPUA 0x0C
+#define GPPUB 0x0D
+#define GPIOA 0x12
+#define GPIOB 0x13
+
+typedef int16_t mcp23018_status_t;
+
+void msp23018_init(void);
+bool mcp23018_reset_required(void);
+mcp23018_status_t mcp23018_writeReg(uint8_t regaddr, const uint8_t* data, uint16_t length);
+mcp23018_status_t mcp23018_readReg(uint8_t regaddr, uint8_t* data, uint16_t length);
diff --git a/keyboards/torn/readme.md b/keyboards/torn/readme.md
new file mode 100644
index 0000000000..ffe9a2d9c2
--- /dev/null
+++ b/keyboards/torn/readme.md
@@ -0,0 +1,21 @@
+# TORN// Split Through Hole
+
+![torn](https://raw.githubusercontent.com/rtitmuss/torn/master/doc/img/torn.jpg)
+
+The split keyboard kit made by through hole components only.
+
+The design has been inspired by the Corne, Plaid and Discipline keyboards.
+
+* Keyboard Maintainer: [rtitmuss](https://github.com/rtitmuss)
+* Hardware Supported: TORN, atmega328p
+* Hardware Availability: [GitHub](https://github.com/rtitmuss/torn)
+
+Make example for this keyboard (after setting up your build environment):
+
+ make torn:default
+
+Flashing example for this keyboard:
+
+ make torn: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).
diff --git a/keyboards/torn/rules.mk b/keyboards/torn/rules.mk
new file mode 100644
index 0000000000..caf544d137
--- /dev/null
+++ b/keyboards/torn/rules.mk
@@ -0,0 +1,27 @@
+# MCU name
+MCU = atmega328p
+
+# Bootloader selection
+BOOTLOADER = USBasp
+
+# Build Options
+# change yes to no to disable
+#
+BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
+MOUSEKEY_ENABLE = no # Mouse keys
+EXTRAKEY_ENABLE = no # Audio control and System control
+CONSOLE_ENABLE = no # Console for debug
+COMMAND_ENABLE = no # 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
+BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
+ENCODER_ENABLE = yes # Enable rotary encoder
+OLED_DRIVER_ENABLE = yes
+CUSTOM_MATRIX = lite
+
+SRC += matrix.c \
+ mcp23018.c \
+ torn_encoder.c \
+ torn_oled.c
+QUANTUM_LIB_SRC += i2c_master.c
diff --git a/keyboards/torn/torn.c b/keyboards/torn/torn.c
new file mode 100644
index 0000000000..ef5060e602
--- /dev/null
+++ b/keyboards/torn/torn.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2020 Richard Titmuss <richard.titmuss@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/>.
+ */
+#include "torn.h"
+#include "i2c_master.h"
+#include "mcp23018.h"
+
+static uint8_t led_state[3] = {1, 1, 1};
+
+void matrix_init_kb(void) {
+ // put your keyboard start-up code here
+ // runs once when the firmware starts up
+ i2c_init();
+
+ matrix_init_user();
+}
+
+void matrix_scan_kb(void) {
+ // put your looping keyboard code here
+ // runs every cycle (a lot)
+ if (mcp23018_reset_required()) {
+ msp23018_init();
+ secondary_encoder_init();
+ // torn_set_led(2, 1);
+ }
+
+ matrix_scan_user();
+ secondary_encoder_read();
+}
+
+void torn_set_led(uint8_t led, bool state) {
+ led_state[led] = !state;
+
+ // toggle leds by setting the pin direction
+ uint8_t iodir = 0b11111000 | led_state[0] << 2 | led_state[1] << 1 | led_state[2];
+ mcp23018_writeReg(IODIRB, &iodir, 1);
+}
diff --git a/keyboards/torn/torn.h b/keyboards/torn/torn.h
new file mode 100644
index 0000000000..c25b5c2a0c
--- /dev/null
+++ b/keyboards/torn/torn.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 Richard Titmuss <richard.titmuss@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
+
+#include "quantum.h"
+
+#define ___ KC_NO
+
+// clang-format off
+#define LAYOUT_split_3x6_4( \
+ k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \
+ k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \
+ k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \
+ k32, k33, k34, k35, k36, k37, k38, k39 \
+) { \
+ { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b }, \
+ { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b }, \
+ { k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b }, \
+ { ___, ___, k32, k33, k34, k35, k36, k37, k38, k39, ___, ___ } \
+}
+// clang-format on
+
+void torn_set_led(uint8_t led, bool on);
+
+void secondary_encoder_read(void);
+void secondary_encoder_init(void);
diff --git a/keyboards/torn/torn_encoder.c b/keyboards/torn/torn_encoder.c
new file mode 100644
index 0000000000..ef9b0873fb
--- /dev/null
+++ b/keyboards/torn/torn_encoder.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2020 Richard Titmuss <richard.titmuss@gmail.com>
+ * Copyright 2018 Jack Humbert <jack.humb@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/>.
+ */
+
+#include "torn.h"
+#include "mcp23018.h"
+
+#ifndef ENCODER_RESOLUTION
+# define ENCODER_RESOLUTION 4
+#endif
+
+#define ENCODER_CLOCKWISE true
+#define ENCODER_COUNTER_CLOCKWISE false
+
+static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
+
+static uint8_t encoder_state = 0;
+static int8_t encoder_pulses = 0;
+
+extern const uint16_