From b9d0b1f06478a1b3f596882b33cb9bd84e477bea Mon Sep 17 00:00:00 2001
From: MechMerlin <30334081+mechmerlin@users.noreply.github.com>
Date: Thu, 26 Mar 2020 17:54:06 -0700
Subject: [PATCH] [Keyboard] MountainBlocks MB17 (#8554)

* initial commit

* preliminary support for mb17 using the qmk default keymap

* add the VIA keymap

* add qmk configurator support

* code cleanups before submission

* Update keyboards/mountainblocks/mb17/rules.mk

* Update keyboards/mountainblocks/mb17/info.json

* remove file
---
 keyboards/mountainblocks/mb17/config.h        | 158 ++++++++++++++++++
 keyboards/mountainblocks/mb17/info.json       |  12 ++
 .../mb17/keymaps/default/keymap.c             |  60 +++++++
 .../mb17/keymaps/default/readme.md            |   1 +
 .../mountainblocks/mb17/keymaps/via/keymap.c  |  76 +++++++++
 .../mountainblocks/mb17/keymaps/via/rules.mk  |   2 +
 keyboards/mountainblocks/mb17/mb17.c          |  17 ++
 keyboards/mountainblocks/mb17/mb17.h          |  35 ++++
 keyboards/mountainblocks/mb17/readme.md       |  13 ++
 keyboards/mountainblocks/mb17/rules.mk        |  32 ++++
 10 files changed, 406 insertions(+)
 create mode 100644 keyboards/mountainblocks/mb17/config.h
 create mode 100644 keyboards/mountainblocks/mb17/info.json
 create mode 100644 keyboards/mountainblocks/mb17/keymaps/default/keymap.c
 create mode 100644 keyboards/mountainblocks/mb17/keymaps/default/readme.md
 create mode 100644 keyboards/mountainblocks/mb17/keymaps/via/keymap.c
 create mode 100644 keyboards/mountainblocks/mb17/keymaps/via/rules.mk
 create mode 100644 keyboards/mountainblocks/mb17/mb17.c
 create mode 100644 keyboards/mountainblocks/mb17/mb17.h
 create mode 100644 keyboards/mountainblocks/mb17/readme.md
 create mode 100644 keyboards/mountainblocks/mb17/rules.mk

diff --git a/keyboards/mountainblocks/mb17/config.h b/keyboards/mountainblocks/mb17/config.h
new file mode 100644
index 0000000000..7db47ff940
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/config.h
@@ -0,0 +1,158 @@
+/*
+Copyright 2020 mechmerlin
+
+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 */
+#define VENDOR_ID 0x4D42
+#define PRODUCT_ID 0x0017
+#define DEVICE_VER 0x0001
+#define MANUFACTURER Mountainblocks
+#define PRODUCT MB17
+#define DESCRIPTION A custom numpad
+
+/* key matrix size */
+#define MATRIX_ROWS 5
+#define MATRIX_COLS 4
+
+/*
+ * 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 { F4, B1, B3, B2, B6 }
+#define MATRIX_COL_PINS { F7, E6, D7, C6 }
+#define UNUSED_PINS
+
+/* COL2ROW, ROW2COL*/
+#define DIODE_DIRECTION COL2ROW
+
+/*
+ * Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN.
+ */
+#define SOFT_SERIAL_PIN D0  // or D1, D2, D3, E6
+
+
+
+/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
+#define DEBOUNCE 5
+
+/* define if matrix has ghost (lacks anti-ghosting diodes) */
+//#define MATRIX_HAS_GHOST
+
+/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
+#define LOCKING_SUPPORT_ENABLE
+/* Locking resynchronize hack */
+#define LOCKING_RESYNC_ENABLE
+
+/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
+ * This is userful for the Windows task manager shortcut (ctrl+shift+esc).
+ */
+// #define GRAVE_ESC_CTRL_OVERRIDE
+
+/*
+ * Force NKRO
+ *
+ * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
+ * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
+ * makefile for this to work.)
+ *
+ * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
+ * until the next keyboard reset.
+ *
+ * NKRO may prevent your keystrokes from being detected in the BIOS, but it is
+ * fully operational during normal computer usage.
+ *
+ * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
+ * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
+ * bootmagic, NKRO mode will always be enabled until it is toggled again during a
+ * power-up.
+ *
+ */
+//#define FORCE_NKRO
+
+/*
+ * Magic Key Options
+ *
+ * Magic keys are hotkey commands that allow control over firmware functions of
+ * the keyboard. They are best used in combination with the HID Listen program,
+ * found here: https://www.pjrc.com/teensy/hid_listen.html
+ *
+ * The options below allow the magic key functionality to be changed. This is
+ * useful if your keyboard/keypad is missing keys and you want magic key support.
+ *
+ */
+
+/* key combination for magic key command */
+/* defined by default; to change, uncomment and set to the combination you want */
+// #define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT)
+
+/* control how magic key switches layers */
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS  true
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS  true
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
+
+/* override magic key keymap */
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
+//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
+//#define MAGIC_KEY_HELP           H
+//#define MAGIC_KEY_HELP_ALT       SLASH
+//#define MAGIC_KEY_DEBUG          D
+//#define MAGIC_KEY_DEBUG_MATRIX   X
+//#define MAGIC_KEY_DEBUG_KBD      K
+//#define MAGIC_KEY_DEBUG_MOUSE    M
+//#define MAGIC_KEY_VERSION        V
+//#define MAGIC_KEY_STATUS         S
+//#define MAGIC_KEY_CONSOLE        C
+//#define MAGIC_KEY_LAYER0         0
+//#define MAGIC_KEY_LAYER0_ALT     GRAVE
+//#define MAGIC_KEY_LAYER1         1
+//#define MAGIC_KEY_LAYER2         2
+//#define MAGIC_KEY_LAYER3         3
+//#define MAGIC_KEY_LAYER4         4
+//#define MAGIC_KEY_LAYER5         5
+//#define MAGIC_KEY_LAYER6         6
+//#define MAGIC_KEY_LAYER7         7
+//#define MAGIC_KEY_LAYER8         8
+//#define MAGIC_KEY_LAYER9         9
+//#define MAGIC_KEY_BOOTLOADER     B
+//#define MAGIC_KEY_BOOTLOADER_ALT ESC
+//#define MAGIC_KEY_LOCK           CAPS
+//#define MAGIC_KEY_EEPROM         E
+//#define MAGIC_KEY_EEPROM_CLEAR   BSPACE
+//#define MAGIC_KEY_NKRO           N
+//#define MAGIC_KEY_SLEEP_LED      Z
+
+
+/* disable these deprecated features by default */
+#ifndef LINK_TIME_OPTIMIZATION_ENABLE
+  #define NO_ACTION_MACRO
+  #define NO_ACTION_FUNCTION
+#endif
+
+
+
+
+
diff --git a/keyboards/mountainblocks/mb17/info.json b/keyboards/mountainblocks/mb17/info.json
new file mode 100644
index 0000000000..02f4021849
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/info.json
@@ -0,0 +1,12 @@
+{
+    "keyboard_name": "MB17", 
+    "url": "", 
+    "maintainer": "qmk", 
+    "width": 4, 
+    "height": 5, 
+    "layouts": {
+        "LAYOUT_numpad_5x4": {
+            "layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":0, "y":1}, {"x":1, "y":1}, {"x":2, "y":1}, {"x":0, "y":2}, {"x":1, "y":2}, {"x":2, "y":2}, {"x":3, "y":1, "h":2}, {"x":0, "y":3}, {"x":1, "y":3}, {"x":2, "y":3}, {"x":0, "y":4, "w":2}, {"x":2, "y":4}, {"x":3, "y":3, "h":2}]
+        }
+    }
+}
diff --git a/keyboards/mountainblocks/mb17/keymaps/default/keymap.c b/keyboards/mountainblocks/mb17/keymaps/default/keymap.c
new file mode 100644
index 0000000000..13c8cf8128
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/keymaps/default/keymap.c
@@ -0,0 +1,60 @@
+/* Copyright 2020 mechmerlin
+ *
+ * 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] = {
+    /*
+     * ┌───┬───┬───┬───┐
+     * │TG1│ / │ * │ - │
+     * ├───┼───┼───┼───┤
+     * │ 7 │ 8 │ 9 │   │
+     * ├───┼───┼───┤ + │
+     * │ 4 │ 5 │ 6 │   │
+     * ├───┼───┼───┼───┤
+     * │ 1 │ 2 │ 3 │   │
+     * ├───┴───┼───┤Ent│
+     * │   0   │ . │   │
+     * └───────┴───┴───┘
+     */
+    [0] = LAYOUT_numpad_5x4(
+        TG(1),   KC_PSLS, KC_PAST, KC_PMNS,
+        KC_P7,   KC_P8,   KC_P9,
+        KC_P4,   KC_P5,   KC_P6,   KC_PPLS,
+        KC_P1,   KC_P2,   KC_P3,
+        KC_P0,   KC_PDOT,          KC_PENT
+    ),
+
+    /*
+     * ┌───┬───┬───┬───┐
+     * │TG1│ / │ * │ - │
+     * ┌───┬───┬───┐───┤
+     * │Hom│ ↑ │PgU│   │
+     * ├───┼───┼───┤ + │
+     * │ ← │   │ → │   │
+     * ├───┼───┼───┤───┤
+     * │End│ ↓ │PgD│   │
+     * ├───┴───┼───┤Ent│
+     * │Insert │Del│   │
+     * └───────┴───┘───┘
+     */
+    [1] = LAYOUT_numpad_5x4(
+        _______, _______, _______, _______,
+        KC_HOME, KC_UP,   KC_PGUP,
+        KC_LEFT, XXXXXXX, KC_RGHT, _______,
+        KC_END,  KC_DOWN, KC_PGDN,
+        KC_INS,           KC_DEL,  _______
+    )
+};
\ No newline at end of file
diff --git a/keyboards/mountainblocks/mb17/keymaps/default/readme.md b/keyboards/mountainblocks/mb17/keymaps/default/readme.md
new file mode 100644
index 0000000000..fb963c6399
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/keymaps/default/readme.md
@@ -0,0 +1 @@
+# The default keymap for mb17
diff --git a/keyboards/mountainblocks/mb17/keymaps/via/keymap.c b/keyboards/mountainblocks/mb17/keymaps/via/keymap.c
new file mode 100644
index 0000000000..5cee19cb23
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/keymaps/via/keymap.c
@@ -0,0 +1,76 @@
+/* Copyright 2020 mechmerlin
+ *
+ * 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] = {
+    /*
+     * ┌───┬───┬───┬───┐
+     * │TG1│ / │ * │ - │
+     * ├───┼───┼───┼───┤
+     * │ 7 │ 8 │ 9 │   │
+     * ├───┼───┼───┤ + │
+     * │ 4 │ 5 │ 6 │   │
+     * ├───┼───┼───┼───┤
+     * │ 1 │ 2 │ 3 │   │
+     * ├───┴───┼───┤Ent│
+     * │   0   │ . │   │
+     * └───────┴───┴───┘
+     */
+    [0] = LAYOUT_numpad_5x4(
+        TG(1),   KC_PSLS, KC_PAST, KC_PMNS,
+        KC_P7,   KC_P8,   KC_P9,
+        KC_P4,   KC_P5,   KC_P6,   KC_PPLS,
+        KC_P1,   KC_P2,   KC_P3,
+        KC_P0,   KC_PDOT,          KC_PENT
+    ),
+
+    /*
+     * ┌───┬───┬───┬───┐
+     * │TG1│ / │ * │ - │
+     * ┌───┬───┬───┐───┤
+     * │Hom│ ↑ │PgU│   │
+     * ├───┼───┼───┤ + │
+     * │ ← │   │ → │   │
+     * ├───┼───┼───┤───┤
+     * │End│ ↓ │PgD│   │
+     * ├───┴───┼───┤Ent│
+     * │Insert │Del│   │
+     * └───────┴───┘───┘
+     */
+    [1] = LAYOUT_numpad_5x4(
+        _______, _______, _______, _______,
+        KC_HOME, KC_UP,   KC_PGUP,
+        KC_LEFT, XXXXXXX, KC_RGHT, _______,
+        KC_END,  KC_DOWN, KC_PGDN,
+        KC_INS,           KC_DEL,  _______
+    ),
+
+    [2] = LAYOUT_numpad_5x4(
+        _______, _______, _______, _______,
+        _______, _______, _______,
+        _______, _______, _______, _______,
+        _______, _______, _______,
+        _______,           _______,  _______
+    ),
+
+    [3] = LAYOUT_numpad_5x4(
+        _______, _______, _______, _______,
+        _______, _______, _______,
+        _______, _______, _______, _______,
+        _______, _______, _______,
+        _______,           _______,  _______
+    )
+};
\ No newline at end of file
diff --git a/keyboards/mountainblocks/mb17/keymaps/via/rules.mk b/keyboards/mountainblocks/mb17/keymaps/via/rules.mk
new file mode 100644
index 0000000000..36b7ba9cbc
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/keymaps/via/rules.mk
@@ -0,0 +1,2 @@
+VIA_ENABLE = yes
+LTO_ENABLE = yes
diff --git a/keyboards/mountainblocks/mb17/mb17.c b/keyboards/mountainblocks/mb17/mb17.c
new file mode 100644
index 0000000000..abc6183cbf
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/mb17.c
@@ -0,0 +1,17 @@
+/* Copyright 2020 mechmerlin
+ *
+ * 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 "mb17.h"
diff --git a/keyboards/mountainblocks/mb17/mb17.h b/keyboards/mountainblocks/mb17/mb17.h
new file mode 100644
index 0000000000..dbfb68a932
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/mb17.h
@@ -0,0 +1,35 @@
+/* Copyright 2020 mechmerlin
+ *
+ * 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
+
+#define LAYOUT_numpad_5x4( \
+    k00, k01, k02, k03,    \
+    k10, k11, k12,         \
+    k20, k21, k22, k23,    \
+    k30, k31, k32,         \
+    k41, k42,      k43     \
+){ \
+    { k00, k01, k02, k03 },  \
+    { k10, k11, k12, ___ },  \
+    { k20, k21, k22, k23 },  \
+    { k30, k31, k32, ___ },  \
+    { ___, k41, k42, k43 }   \
+}
diff --git a/keyboards/mountainblocks/mb17/readme.md b/keyboards/mountainblocks/mb17/readme.md
new file mode 100644
index 0000000000..c1dfd2b88a
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/readme.md
@@ -0,0 +1,13 @@
+# MB17
+
+A single layout sandwich numpad. 
+
+* Keyboard Maintainer: [MechMerlin](https://github.com/mechmerlin)
+* Hardware Supported: MB17
+* Hardware Availability: TBD
+
+Make example for this keyboard (after setting up your build environment):
+
+    make mountainblocks/mb17: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).
diff --git a/keyboards/mountainblocks/mb17/rules.mk b/keyboards/mountainblocks/mb17/rules.mk
new file mode 100644
index 0000000000..0bdce95654
--- /dev/null
+++ b/keyboards/mountainblocks/mb17/rules.mk
@@ -0,0 +1,32 @@
+# MCU name
+MCU = atmega32u4
+
+# Bootloader selection
+#   Teensy       halfkay
+#   Pro Micro    caterina
+#   Atmel DFU    atmel-dfu
+#   LUFA DFU     lufa-dfu
+#   QMK DFU      qmk-dfu
+#   ATmega32A    bootloadHID
+#   ATmega328P   USBasp
+BOOTLOADER = caterina
+
+# Build Options
+#   change yes to no to disable
+#
+BOOTMAGIC_ENABLE = lite     # 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 = no            # USB Nkey Rollover
+BACKLIGHT_ENABLE = no       # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no        # Enable keyboard RGB underglow
+MIDI_ENABLE = no            # MIDI support
+BLUETOOTH_ENABLE = no       # Enable Bluetooth with the Adafruit EZ-Key HID
+AUDIO_ENABLE = no           # Audio output on port C6
+FAUXCLICKY_ENABLE = no      # Use buzzer to emulate clicky switches
+HD44780_ENABLE = no         # Enable support for HD44780 based LCDs