From b7b82d509bfccd69c6507761f03910f34b4366cb Mon Sep 17 00:00:00 2001
From: Craig Gardner <40006110+LeafCutterLabs@users.noreply.github.com>
Date: Wed, 6 Jan 2021 10:00:05 -0800
Subject: [PATCH] [Keyboard] add support for bigknob (#11291)

* add support for bigknob

Add support for bigknob macropad

* corrected files

* Apply suggestions from code review

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

* corrected tap dance

* Update config.h

* correct image link

* Apply suggestions from code review

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

* added GPL headers

* Update readme.md

Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
---
 keyboards/leafcutterlabs/bigknob/bigknob.c    | 17 ++++++
 keyboards/leafcutterlabs/bigknob/bigknob.h    | 27 +++++++++
 keyboards/leafcutterlabs/bigknob/config.h     | 58 +++++++++++++++++++
 keyboards/leafcutterlabs/bigknob/info.json    | 12 ++++
 .../bigknob/keymaps/default/keymap.c          | 55 ++++++++++++++++++
 keyboards/leafcutterlabs/bigknob/readme.md    | 15 +++++
 keyboards/leafcutterlabs/bigknob/rules.mk     | 24 ++++++++
 7 files changed, 208 insertions(+)
 create mode 100644 keyboards/leafcutterlabs/bigknob/bigknob.c
 create mode 100644 keyboards/leafcutterlabs/bigknob/bigknob.h
 create mode 100644 keyboards/leafcutterlabs/bigknob/config.h
 create mode 100644 keyboards/leafcutterlabs/bigknob/info.json
 create mode 100644 keyboards/leafcutterlabs/bigknob/keymaps/default/keymap.c
 create mode 100644 keyboards/leafcutterlabs/bigknob/readme.md
 create mode 100644 keyboards/leafcutterlabs/bigknob/rules.mk

diff --git a/keyboards/leafcutterlabs/bigknob/bigknob.c b/keyboards/leafcutterlabs/bigknob/bigknob.c
new file mode 100644
index 00000000000..0a4d173e578
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/bigknob.c
@@ -0,0 +1,17 @@
+/* Copyright 2021 Craig Gardner 
+  * 
+  * 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 "bigknob.h"
diff --git a/keyboards/leafcutterlabs/bigknob/bigknob.h b/keyboards/leafcutterlabs/bigknob/bigknob.h
new file mode 100644
index 00000000000..ddd3aa4ae00
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/bigknob.h
@@ -0,0 +1,27 @@
+/* Copyright 2021 Craig Gardner 
+  * 
+  * 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 LAYOUT_ortho_1x5( \
+    k01, k02, k03, k04, k05\
+  ) { \
+    { k01, k02, k03, k04, k05 } \
+}
+
+#define LAYOUT LAYOUT_ortho_1x5 
\ No newline at end of file
diff --git a/keyboards/leafcutterlabs/bigknob/config.h b/keyboards/leafcutterlabs/bigknob/config.h
new file mode 100644
index 00000000000..5f958293cd8
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/config.h
@@ -0,0 +1,58 @@
+/*
+Copyright 2012 Jun Wako <wakojun@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 */
+#define VENDOR_ID       0xCEEB
+#define PRODUCT_ID      0x0007
+#define DEVICE_VER      0x0001
+#define MANUFACTURER    leafcutterlabs
+#define PRODUCT         bigKNOB
+/* key matrix size */
+#define MATRIX_ROWS 1
+#define MATRIX_COLS 5
+
+/*
+ * 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)
+ *                  NO_DIODE = switches are directly connected to AVR pins
+ *
+*/
+
+// Srating with closest to USB port 
+#define DIRECT_PINS {   \
+    { B7, D4, D6, F6, F7} \
+}
+#define UNUSED_PINS
+
+/* rotary encoder 1,2,3 closest to usb port is 0*/
+#define ENCODERS_PAD_A { D0}
+#define ENCODERS_PAD_B { D2}
+#define ENCODER_RESOLUTION 4 //default/suggested
+
+/* ws2812 RGB LED */
+#define RGB_DI_PIN C7 //D3 - underglow C7 - backlight
+#define RGBLIGHT_ANIMATIONS
+#define RGBLED_NUM 5    // Number of LEDs
diff --git a/keyboards/leafcutterlabs/bigknob/info.json b/keyboards/leafcutterlabs/bigknob/info.json
new file mode 100644
index 00000000000..697edebbefd
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/info.json
@@ -0,0 +1,12 @@
+{
+  "keyboard_name": "bigknob",
+  "url": "",
+  "maintainer": "qmk",
+  "width": 5,
+  "height": 1,
+  "layouts": {
+    "LAYOUT_ortho_1x5": {
+      "layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":4, "y":0}]
+    }
+  }
+}
diff --git a/keyboards/leafcutterlabs/bigknob/keymaps/default/keymap.c b/keyboards/leafcutterlabs/bigknob/keymaps/default/keymap.c
new file mode 100644
index 00000000000..999d3c43476
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/keymaps/default/keymap.c
@@ -0,0 +1,55 @@
+/* Copyright 2021 Craig Gardner 
+  * 
+  * 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
+
+#define _MAIN 0
+
+void encoder_update_user(uint8_t index, bool clockwise) {
+  if (index == 0) { 
+    if (clockwise) {
+      tap_code(KC_VOLU);
+    } else {
+      tap_code(KC_VOLD);
+    }
+  } 
+}
+
+enum {
+  TD_RGB = 0
+};
+
+void dance_rgb_finished (qk_tap_dance_state_t *state, void *user_data) {
+  if (state->count == 1) {
+    tap_code(KC_MNXT);
+  } else if (state->count == 2) {
+    rgblight_toggle();
+  } else if (state->count == 3) {
+    rgblight_step();
+  }
+}
+
+//All tap dance functions would go here. Only showing this one.
+qk_tap_dance_action_t tap_dance_actions[] = {
+ [TD_RGB] = ACTION_TAP_DANCE_FN_ADVANCED (NULL, dance_rgb_finished, NULL)
+};
+
+//
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { //buttion closest to usb is first
+  [_MAIN] = LAYOUT(
+     KC_MUTE, KC_MEDIA_PREV_TRACK, KC_MEDIA_PLAY_PAUSE, KC_MEDIA_STOP, TD(TD_RGB)
+  )
+};
diff --git a/keyboards/leafcutterlabs/bigknob/readme.md b/keyboards/leafcutterlabs/bigknob/readme.md
new file mode 100644
index 00000000000..d67a1858b5a
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/readme.md
@@ -0,0 +1,15 @@
+# bigknob
+
+A 4 key Macropad with Rotary Encoder based on Atmega32u4.
+
+![](https://i.imgur.com/Px3EpOUl.jpg)
+
+* Keyboard Maintainer: [LeafCutterLabs](https://github.com/LeafCutterLabs)
+* Hardware Supported: Atmega32u4
+* Hardware availability: Case files are available [here](https://github.com/LeafCutterLabs/bigKNOB)
+
+Make example for this keyboard (after setting up your build environment):
+
+    make leafcutterlabs/bigknob: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/leafcutterlabs/bigknob/rules.mk b/keyboards/leafcutterlabs/bigknob/rules.mk
new file mode 100644
index 00000000000..5993a2c1cf0
--- /dev/null
+++ b/keyboards/leafcutterlabs/bigknob/rules.mk
@@ -0,0 +1,24 @@
+# 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 = yes           # USB Nkey Rollover
+BACKLIGHT_ENABLE = no       # Enable keyboard backlight functionality
+RGBLIGHT_ENABLE = yes       # Enable keyboard RGB underglow
+BLUETOOTH_ENABLE = no       # Enable Bluetooth
+AUDIO_ENABLE = no           # Audio output
+ENCODER_ENABLE = yes        # Enable rotary encoders
+TAP_DANCE_ENABLE = yes
\ No newline at end of file