From a94044c15c8217d8a6ad016cc0233abe3de374b0 Mon Sep 17 00:00:00 2001
From: Suschman <Suschman@users.noreply.github.com>
Date: Wed, 30 Dec 2020 02:46:16 +0100
Subject: [PATCH] 40percentclub sixpack support (#11007)

* QMK support for 40percentclub SixPack

* Update readme.md

* QMK support for 40percentclub SixPack

* fix info.json

* Apply suggestions from code review

Co-authored-by: Joel Challis <git@zvecr.com>

* update PRODUCT name and change BL levels to 6

* Add Fkeys keymap

* correct readme

* add via keymap

* correct readme

* change indentation

* Apply suggestions from code review

Co-authored-by: Ryan <fauxpark@gmail.com>

* requested change and more cleanup

* Update keyboards/40percentclub/sixpack/sixpack.h

Co-authored-by: Erovia <Erovia@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Suschman <suschman@gmail.com>
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
---
 keyboards/40percentclub/sixpack/config.h      | 122 ++++++++++++++++++
 keyboards/40percentclub/sixpack/info.json     |  15 +++
 .../sixpack/keymaps/default/keymap.c          |  31 +++++
 .../sixpack/keymaps/default/readme.md         |   1 +
 .../sixpack/keymaps/fkeys/keymap.c            |  50 +++++++
 .../sixpack/keymaps/fkeys/readme.md           |   1 +
 .../sixpack/keymaps/fkeys/rules.mk            |   1 +
 .../sixpack/keymaps/via/keymap.c              |  41 ++++++
 .../sixpack/keymaps/via/rules.mk              |   1 +
 keyboards/40percentclub/sixpack/readme.md     |  21 +++
 keyboards/40percentclub/sixpack/rules.mk      |  22 ++++
 keyboards/40percentclub/sixpack/sixpack.c     |  24 ++++
 keyboards/40percentclub/sixpack/sixpack.h     |  34 +++++
 13 files changed, 364 insertions(+)
 create mode 100644 keyboards/40percentclub/sixpack/config.h
 create mode 100644 keyboards/40percentclub/sixpack/info.json
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/default/keymap.c
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/default/readme.md
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/fkeys/keymap.c
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/fkeys/readme.md
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/fkeys/rules.mk
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/via/keymap.c
 create mode 100644 keyboards/40percentclub/sixpack/keymaps/via/rules.mk
 create mode 100644 keyboards/40percentclub/sixpack/readme.md
 create mode 100644 keyboards/40percentclub/sixpack/rules.mk
 create mode 100644 keyboards/40percentclub/sixpack/sixpack.c
 create mode 100644 keyboards/40percentclub/sixpack/sixpack.h

diff --git a/keyboards/40percentclub/sixpack/config.h b/keyboards/40percentclub/sixpack/config.h
new file mode 100644
index 0000000000..db91ca7b80
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/config.h
@@ -0,0 +1,122 @@
+/*
+Copyright 2020
+
+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       0x3430 // "40"
+#define PRODUCT_ID      0x5350 // "SP"
+#define DEVICE_VER      0x1001
+#define MANUFACTURER    di0ib
+#define PRODUCT         Six Pack
+
+/* key matrix size */
+#define MATRIX_ROWS 2
+#define MATRIX_COLS 3
+
+/*
+ * 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 { B0 } // B0 equivalents the ground pin
+// #define MATRIX_COL_PINS { E6, D7, C6, D4 }
+#define DIRECT_PINS { \
+    { D4, C6, D7 }, \
+    { E6, B4, B5 }  \
+}
+#define UNUSED_PINS { D1, D0, C4, C5, B1, B2, B3 } // TX, RX, SDA, SCL, PB1, PB2, PB3 on expansion connector
+
+/* COL2ROW, ROW2COL*/
+#define DIODE_DIRECTION COL2ROW
+
+/* Backlight */
+#define BACKLIGHT_BREATHING
+#define BACKLIGHT_LEVELS 6
+#define BACKLIGHT_PINS { F4, F5 } // Top Row, Bottom Row
+
+// #define RGB_DI_PIN B1 // PB1 on expansion connector
+// #ifdef RGB_DI_PIN
+//   #define RGBLED_NUM 16
+//   #define RGBLIGHT_HUE_STEP 8
+//   #define RGBLIGHT_SAT_STEP 8
+//   #define RGBLIGHT_VAL_STEP 8
+//   #define RGBLIGHT_LIMIT_VAL 255 /* The maximum brightness level */
+//   #define RGBLIGHT_SLEEP  /* If defined, the RGB lighting will be switched off when the host goes to sleep */
+// /*== all animations enable ==*/
+//   #define RGBLIGHT_ANIMATIONS
+// /*== or choose animations ==*/
+//   #define RGBLIGHT_EFFECT_BREATHING
+//   #define RGBLIGHT_EFFECT_RAINBOW_MOOD
+//   #define RGBLIGHT_EFFECT_RAINBOW_SWIRL
+//   #define RGBLIGHT_EFFECT_SNAKE
+//   #define RGBLIGHT_EFFECT_KNIGHT
+//   #define RGBLIGHT_EFFECT_CHRISTMAS
+//   #define RGBLIGHT_EFFECT_STATIC_GRADIENT
+//   #define RGBLIGHT_EFFECT_RGB_TEST
+//   #define RGBLIGHT_EFFECT_ALTERNATING
+// /*== customize breathing effect ==*/
+//   /*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/
+//   #define RGBLIGHT_BREATHE_TABLE_SIZE 256      // 256(default) or 128 or 64
+//   /*==== use exp() and sin() ====*/
+//   #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85  // 1 to 2.7
+//   #define RGBLIGHT_EFFECT_BREATHE_MAX    255   // 0 to 255
+// #endif
+
+/* 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
+
+/* 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
+
+
+/* Bootmagic Lite key configuration */
+// #define BOOTMAGIC_LITE_ROW 0
+// #define BOOTMAGIC_LITE_COLUMN 0
diff --git a/keyboards/40percentclub/sixpack/info.json b/keyboards/40percentclub/sixpack/info.json
new file mode 100644
index 0000000000..3c78e26fbc
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/info.json
@@ -0,0 +1,15 @@
+{
+    "keyboard_name": "sixpack",
+    "url": "https://www.40percent.club/2017/05/six-pack-11.html",
+    "maintainer": "qmk",
+    "width": 3,
+    "height": 2,
+    "layouts": {
+        "LAYOUT_ortho_2x3": {
+          "layout": [
+                {"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0},
+                {"x":0, "y":1}, {"x":1, "y":1}, {"x":2, "y":1}
+          ]
+        }
+    }
+}
diff --git a/keyboards/40percentclub/sixpack/keymaps/default/keymap.c b/keyboards/40percentclub/sixpack/keymaps/default/keymap.c
new file mode 100644
index 0000000000..48885fc50a
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/default/keymap.c
@@ -0,0 +1,31 @@
+/* Copyright 2020
+ *
+ * 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] = {
+
+    /* Default 2x3 layout
+     * .--------------------------.
+     * |  MUTE  |   UP   |  PLAY  |
+     * |--------+--------+--------+
+     * |  LEFT  |  DOWN  |  RIGHT |
+     * '--------------------------'
+     */
+
+    [0] = LAYOUT_ortho_2x3(/* Default */
+                 KC_MUTE, KC_UP,   KC_MPLY,
+                 KC_LEFT, KC_DOWN, KC_RGHT),
+};
diff --git a/keyboards/40percentclub/sixpack/keymaps/default/readme.md b/keyboards/40percentclub/sixpack/keymaps/default/readme.md
new file mode 100644
index 0000000000..178cae1010
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/default/readme.md
@@ -0,0 +1 @@
+# The default keymap for Six Pack
diff --git a/keyboards/40percentclub/sixpack/keymaps/fkeys/keymap.c b/keyboards/40percentclub/sixpack/keymaps/fkeys/keymap.c
new file mode 100644
index 0000000000..8ca5a5a27b
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/fkeys/keymap.c
@@ -0,0 +1,50 @@
+/* Copyright 2020
+ *
+ * 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
+
+// Tap Dance declarations
+enum {
+    F13F19,
+    F14F20,
+    F15F21,
+    F16F22,
+    F17F23,
+    F18F24,
+};
+
+// Tap Dance definitions
+qk_tap_dance_action_t tap_dance_actions[] = {
+    // Tap once for F13 to F18, twice for F19 to F24
+    [F13F19] = ACTION_TAP_DANCE_DOUBLE(KC_F13, KC_F19), [F14F20] = ACTION_TAP_DANCE_DOUBLE(KC_F14, KC_F20), [F15F21] = ACTION_TAP_DANCE_DOUBLE(KC_F15, KC_F21),
+    [F16F22] = ACTION_TAP_DANCE_DOUBLE(KC_F16, KC_F22), [F17F23] = ACTION_TAP_DANCE_DOUBLE(KC_F17, KC_F23), [F18F24] = ACTION_TAP_DANCE_DOUBLE(KC_F18, KC_F24)
+};
+
+// Add tap dance item in place of a key code
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+
+    /* 2x3 layout
+     * .-----------------------------.
+     * | F13/F19 | D14/F20 | F15/F21 |
+     * |---------+---------+---------+
+     * | F16/F22 | D17/F23 | F18/F24 |
+     * '-----------------------------'
+     */
+
+    [0] = LAYOUT_ortho_2x3(/* F13 to F24 */
+                 TD(F13F19), TD(F14F20), TD(F15F21),
+		 TD(F16F22), TD(F17F23), TD(F18F24)
+		),
+};
diff --git a/keyboards/40percentclub/sixpack/keymaps/fkeys/readme.md b/keyboards/40percentclub/sixpack/keymaps/fkeys/readme.md
new file mode 100644
index 0000000000..9974588e5f
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/fkeys/readme.md
@@ -0,0 +1 @@
+# F13 to F24 keymap with Tap Dance for Six Pack
diff --git a/keyboards/40percentclub/sixpack/keymaps/fkeys/rules.mk b/keyboards/40percentclub/sixpack/keymaps/fkeys/rules.mk
new file mode 100644
index 0000000000..e5ddcae8d9
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/fkeys/rules.mk
@@ -0,0 +1 @@
+TAP_DANCE_ENABLE = yes
diff --git a/keyboards/40percentclub/sixpack/keymaps/via/keymap.c b/keyboards/40percentclub/sixpack/keymaps/via/keymap.c
new file mode 100644
index 0000000000..f3268a22ab
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/via/keymap.c
@@ -0,0 +1,41 @@
+/* Copyright 2020
+ *
+ * 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] = {
+
+    /* Default 2x3 layout with 6 Layers
+     * .--------------------------.
+     * |  MUTE  |   UP   |  PLAY  |
+     * |--------+--------+--------+
+     * |  LEFT  |  DOWN  |  RIGHT |
+     * '--------------------------'
+     */
+
+    [0] = LAYOUT_ortho_2x3(KC_MUTE, KC_UP  , KC_MPLY,
+		 KC_LEFT, KC_DOWN, KC_RGHT),
+    [1] = LAYOUT_ortho_2x3(KC_TRNS, KC_TRNS, KC_TRNS,
+		 KC_TRNS, KC_TRNS, KC_TRNS),
+    [2] = LAYOUT_ortho_2x3(KC_TRNS, KC_TRNS, KC_TRNS,
+		 KC_TRNS, KC_TRNS, KC_TRNS),
+    [3] = LAYOUT_ortho_2x3(KC_TRNS, KC_TRNS, KC_TRNS,
+		 KC_TRNS, KC_TRNS, KC_TRNS),
+    [4] = LAYOUT_ortho_2x3(KC_TRNS, KC_TRNS, KC_TRNS,
+		 KC_TRNS, KC_TRNS, KC_TRNS),
+    [5] = LAYOUT_ortho_2x3(KC_TRNS, KC_TRNS, KC_TRNS,
+		 KC_TRNS, KC_TRNS, KC_TRNS),
+
+};
diff --git a/keyboards/40percentclub/sixpack/keymaps/via/rules.mk b/keyboards/40percentclub/sixpack/keymaps/via/rules.mk
new file mode 100644
index 0000000000..1e5b99807c
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/keymaps/via/rules.mk
@@ -0,0 +1 @@
+VIA_ENABLE = yes
diff --git a/keyboards/40percentclub/sixpack/readme.md b/keyboards/40percentclub/sixpack/readme.md
new file mode 100644
index 0000000000..571f927087
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/readme.md
@@ -0,0 +1,21 @@
+# Six Pack
+
+![sixpack](https://4.bp.blogspot.com/-sCUGxPAmcu4/WQj4cd9ZlAI/AAAAAAACBhs/174XLIHIfzISucFFEgo53H73HdVJfn3ZwCLcB/s640/IMG_0265.JPG)
+
+A 6-key macropad PCB with its switch and LED pins wired directly to microcontroller IO pins.
+
+You can find the main blog post about this macropad [here](http://www.40percent.club/2017/05/six-pack-11.html), also the Gerber files and other documentation is located [here](https://git.40percent.club/di0ib/Misc/src/branch/master/Six%20Pack).
+
+* Keyboard Maintainer: [The QMK Community](https://github.com/qmk)
+* Hardware Supported: Six Pack PCB, Pro Micro
+* Hardware Availability: [40percent.club](https://git.40percent.club/di0ib/Misc/src/branch/master/Six%20Pack)
+
+Make example for this macropad (after setting up your build environment):
+
+    make 40percentclub/sixpack:default
+
+Flashing example for this keyboard:
+
+    make 40percentclub/sixpack: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/40percentclub/sixpack/rules.mk b/keyboards/40percentclub/sixpack/rules.mk
new file mode 100644
index 0000000000..9d7d9a2cf0
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/rules.mk
@@ -0,0 +1,22 @@
+# MCU name
+MCU = atmega32u4
+
+# Bootloader selection
+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 = 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
+# 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 = yes      # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = no        # Enable keyboard RGB underglow
+BLUETOOTH_ENABLE = no       # Enable Bluetooth
+AUDIO_ENABLE = no           # Audio output
diff --git a/keyboards/40percentclub/sixpack/sixpack.c b/keyboards/40percentclub/sixpack/sixpack.c
new file mode 100644
index 0000000000..cc0e9e3add
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/sixpack.c
@@ -0,0 +1,24 @@
+/* Copyright 2020
+ *
+ * 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 "sixpack.h"
+
+void matrix_init_kb(void) {
+    setPinOutput(B6);  // Backlight cathodes Col.3
+    setPinOutput(F6);  // Backlight cathodes Col.2
+    setPinOutput(F7);  // Backlight cathodes Col.1
+
+    matrix_init_user();
+}
diff --git a/keyboards/40percentclub/sixpack/sixpack.h b/keyboards/40percentclub/sixpack/sixpack.h
new file mode 100644
index 0000000000..94db5ee9e8
--- /dev/null
+++ b/keyboards/40percentclub/sixpack/sixpack.h
@@ -0,0 +1,34 @@
+/* Copyright 2020
+ *
+ * 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"
+
+/* This a shortcut to help you visually see your layout.
+ *
+ * The first section contains all of the arguments representing the physical
+ * layout of the board and position of the keys.
+ *
+ * The second converts the arguments into a two-dimensional array which
+ * represents the switch matrix.
+ */
+#define LAYOUT_ortho_2x3( \
+    k00, k01, k02, \
+    k10, k11, k12  \
+) { \
+    { k00, k01, k02 }, \
+    { k10, k11, k12 }  \
+}