diff options
| author | Josh Johnson <josh@joshajohnson.com> | 2020-02-11 00:16:27 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-10 14:16:27 +0100 |
| commit | 89c528e443561731eb3cf4ed3d49002545421afe (patch) | |
| tree | 9beae0152d07b742d7a3ee6323816312d03fb805 | |
| parent | 8f333138f5cc76ecc7538100ce93af5e228f0eb0 (diff) | |
| download | qmk_firmware-89c528e443561731eb3cf4ed3d49002545421afe.tar.gz qmk_firmware-89c528e443561731eb3cf4ed3d49002545421afe.zip | |
[Keyboard] Add support for Hub16 (#7794)
Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com>
Co-Authored-By: fauxpark <fauxpark@gmail.com>
| -rwxr-xr-x | keyboards/hub16/config.h | 97 | ||||
| -rwxr-xr-x | keyboards/hub16/hub16.c | 16 | ||||
| -rwxr-xr-x | keyboards/hub16/hub16.h | 42 | ||||
| -rwxr-xr-x | keyboards/hub16/keymaps/default/keymap.c | 96 | ||||
| -rwxr-xr-x | keyboards/hub16/keymaps/no_mod/keymap.c | 63 | ||||
| -rw-r--r-- | keyboards/hub16/matrix.c | 270 | ||||
| -rwxr-xr-x | keyboards/hub16/readme.md | 15 | ||||
| -rwxr-xr-x | keyboards/hub16/rules.mk | 38 |
8 files changed, 637 insertions, 0 deletions
diff --git a/keyboards/hub16/config.h b/keyboards/hub16/config.h new file mode 100755 index 000000000..c7dec995e --- /dev/null +++ b/keyboards/hub16/config.h | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2019 Josh Johnson | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include "config_common.h" | ||
| 21 | |||
| 22 | /* USB Device descriptor parameter */ | ||
| 23 | #define VENDOR_ID 0xFEED | ||
| 24 | #define PRODUCT_ID 0x8F73 | ||
| 25 | #define DEVICE_VER 0x0001 | ||
| 26 | #define MANUFACTURER Josh Johnson | ||
| 27 | #define PRODUCT Hub16 | ||
| 28 | #define DESCRIPTION Macro Pad with USB Hub and Encoders | ||
| 29 | |||
| 30 | /* key matrix size */ | ||
| 31 | #define MATRIX_ROWS 5 | ||
| 32 | #define MATRIX_COLS 4 | ||
| 33 | |||
| 34 | /* | ||
| 35 | * Keyboard Matrix Assignments | ||
| 36 | * | ||
| 37 | * Change this to how you wired your keyboard | ||
| 38 | * COLS: AVR pins used for columns, left to right | ||
| 39 | * ROWS: AVR pins used for rows, top to bottom | ||
| 40 | * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) | ||
| 41 | * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) | ||
| 42 | * | ||
| 43 | */ | ||
| 44 | #define MATRIX_ROW_PINS \ | ||
| 45 | { F0, C7, C6, B6, E6} | ||
| 46 | #define MATRIX_COL_PINS \ | ||
| 47 | { F4, F1, D5, D3 } | ||
| 48 | |||
| 49 | /* COL2ROW, ROW2COL*/ | ||
| 50 | #define DIODE_DIRECTION COL2ROW | ||
| 51 | |||
| 52 | #define RGB_DI_PIN D1 | ||
| 53 | // #ifdef RGB_DI_PIN | ||
| 54 | #define RGBLED_NUM 11 | ||
| 55 | #define RGBLIGHT_HUE_STEP 8 | ||
| 56 | #define RGBLIGHT_SAT_STEP 8 | ||
| 57 | #define RGBLIGHT_VAL_STEP 8 | ||
| 58 | #define RGBLIGHT_LIMIT_VAL 255 /* The maximum brightness level */ | ||
| 59 | #define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */ | ||
| 60 | // /*== all animations enable ==*/ | ||
| 61 | // #define RGBLIGHT_ANIMATIONS | ||
| 62 | // /*== or choose animations ==*/ | ||
| 63 | #define RGBLIGHT_EFFECT_BREATHING | ||
| 64 | #define RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 65 | #define RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 66 | #define RGBLIGHT_EFFECT_SNAKE | ||
| 67 | #define RGBLIGHT_EFFECT_KNIGHT | ||
| 68 | // #define RGBLIGHT_EFFECT_CHRISTMAS | ||
| 69 | // #define RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 70 | // #define RGBLIGHT_EFFECT_RGB_TEST | ||
| 71 | // #define RGBLIGHT_EFFECT_ALTERNATING | ||
| 72 | // /*== customize breathing effect ==*/ | ||
| 73 | // /*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/ | ||
| 74 | // #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256(default) or 128 or 64 | ||
| 75 | // /*==== use exp() and sin() ====*/ | ||
| 76 | // #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7 | ||
| 77 | // #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255 | ||
| 78 | // #endif | ||
| 79 | |||
| 80 | /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ | ||
| 81 | #define DEBOUNCE 20 | ||
| 82 | |||
| 83 | /* ENCODER THINGS */ | ||
| 84 | |||
| 85 | // #define NUMBER_OF_ENCODERS 2 | ||
| 86 | #define ENCODERS_PAD_A \ | ||
| 87 | { F6, B4 } | ||
| 88 | #define ENCODERS_PAD_B \ | ||
| 89 | { F5, B5 } | ||
| 90 | |||
| 91 | /* Tap Dance timing */ | ||
| 92 | #define TAPPING_TERM 200 | ||
| 93 | |||
| 94 | /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ | ||
| 95 | #define LOCKING_SUPPORT_ENABLE | ||
| 96 | /* Locking resynchronize hack */ | ||
| 97 | #define LOCKING_RESYNC_ENABLE | ||
diff --git a/keyboards/hub16/hub16.c b/keyboards/hub16/hub16.c new file mode 100755 index 000000000..e18ba5526 --- /dev/null +++ b/keyboards/hub16/hub16.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* Copyright 2019 Josh Johnson | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include "hub16.h" \ No newline at end of file | ||
diff --git a/keyboards/hub16/hub16.h b/keyboards/hub16/hub16.h new file mode 100755 index 000000000..36830bf5c --- /dev/null +++ b/keyboards/hub16/hub16.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* Copyright 2019 Josh Johnson | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include "quantum.h" | ||
| 19 | #define ___ KC_NO | ||
| 20 | |||
| 21 | /* This a shortcut to help you visually see your layout. | ||
| 22 | * | ||
| 23 | * The first section contains all of the arguments representing the physical | ||
| 24 | * layout of the board and position of the keys. | ||
| 25 | * | ||
| 26 | * The second converts the arguments into a two-dimensional array which | ||
| 27 | * represents the switch matrix. | ||
| 28 | */ | ||
| 29 | #define LAYOUT( \ | ||
| 30 | k40, k41, \ | ||
| 31 | k00, k01, k02, k03, \ | ||
| 32 | k10, k11, k12, k13, \ | ||
| 33 | k20, k21, k22, k23, \ | ||
| 34 | k30, k31, k32, k33 \ | ||
| 35 | ) { \ | ||
| 36 | { k00, k01, k02, k03, }, \ | ||
| 37 | { k10, k11, k12, k13, }, \ | ||
| 38 | { k20, k21, k22, k23, }, \ | ||
| 39 | { k30, k31, k32, k33, }, \ | ||
| 40 | { k40, k41, ___, ___, } \ | ||
| 41 | } | ||
| 42 | |||
diff --git a/keyboards/hub16/keymaps/default/keymap.c b/keyboards/hub16/keymaps/default/keymap.c new file mode 100755 index 000000000..a77c8bc78 --- /dev/null +++ b/keyboards/hub16/keymaps/default/keymap.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* Copyright 2019 Josh Johnson | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include QMK_KEYBOARD_H | ||
| 17 | |||
| 18 | // Function key we are 'wrapping' usual key presses in | ||
| 19 | #define KC_WRAP KC_F24 | ||
| 20 | |||
| 21 | // Tap Dance Declarations | ||
| 22 | enum { TD_TO_LED = 0, TD_TO_DEFAULT = 1 }; | ||
| 23 | |||
| 24 | qk_tap_dance_action_t tap_dance_actions[] = { | ||
| 25 | // Tap once for HID, twice to toggle layer 1 | ||
| 26 | [TD_TO_LED] = ACTION_TAP_DANCE_DUAL_ROLE(_______, 1), | ||
| 27 | [TD_TO_DEFAULT] = ACTION_TAP_DANCE_DUAL_ROLE(_______, 0)}; | ||
| 28 | |||
| 29 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 30 | [0] = LAYOUT( /* Base */ | ||
| 31 | KC_S, KC_V, | ||
| 32 | KC_A, KC_B, KC_C, KC_D, | ||
| 33 | KC_E, KC_F, KC_G, KC_H, | ||
| 34 | KC_I, KC_J, KC_K, KC_L, | ||
| 35 | KC_M, KC_N, KC_O, TD(TD_TO_LED) | ||
| 36 | ), | ||
| 37 | |||
| 38 | [1] = LAYOUT( /* LED Control */ | ||
| 39 | KC_NO, KC_NO, | ||
| 40 | _______, RGB_MOD, RGB_RMOD, RGB_TOG, | ||
| 41 | RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI, | ||
| 42 | RGB_SAD, RGB_SAI, _______, _______, | ||
| 43 | _______, _______, RESET, TD(TD_TO_DEFAULT) | ||
| 44 | ), | ||
| 45 | }; | ||
| 46 | |||
| 47 | // Keyboard is setup to 'warp' the pressed key with F24, | ||
| 48 | // allowing for easy differentiation from a real keyboard. | ||
| 49 | void encoder_update_user(uint8_t index, bool clockwise) { | ||
| 50 | if (index == 0) { /* Left Encoder */ | ||
| 51 | if (clockwise) { | ||
| 52 | register_code(KC_WRAP); | ||
| 53 | tap_code(KC_R); | ||
| 54 | unregister_code(KC_WRAP); | ||
| 55 | } else { | ||
| 56 | register_code(KC_WRAP); | ||
| 57 | tap_code(KC_Q); | ||
| 58 | unregister_code(KC_WRAP); | ||
| 59 | } | ||
| 60 | } else if (index == 1) { /* Right Encoder */ | ||
| 61 | if (clockwise) { | ||
| 62 | register_code(KC_WRAP); | ||
| 63 | tap_code(KC_U); | ||
| 64 | unregister_code(KC_WRAP); | ||
| 65 | } else { | ||
| 66 | register_code(KC_WRAP); | ||
| 67 | tap_code(KC_T); | ||
| 68 | unregister_code(KC_WRAP); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | // Below stolen from TaranVH (https://github.com/TaranVH/2nd-keyboard/blob/master/HASU_USB/F24/keymap.c) | ||
| 74 | // Shoutout to drashna on the QMK discord for basically writing this for me.... :P | ||
| 75 | |||
| 76 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 77 | static uint8_t f24_tracker; | ||
| 78 | switch (keycode) { | ||
| 79 | case KC_A ... KC_F23: | ||
| 80 | case KC_EXECUTE ... KC_EXSEL: | ||
| 81 | if (record->event.pressed) { | ||
| 82 | register_code(KC_WRAP); | ||
| 83 | f24_tracker++; | ||
| 84 | register_code(keycode); | ||
| 85 | } else { | ||
| 86 | unregister_code(keycode); | ||
| 87 | f24_tracker--; | ||
| 88 | if (!f24_tracker) { | ||
| 89 | unregister_code(KC_WRAP); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | return false; | ||
| 93 | break; | ||
| 94 | } | ||
| 95 | return true; | ||
| 96 | } | ||
diff --git a/keyboards/hub16/keymaps/no_mod/keymap.c b/keyboards/hub16/keymaps/no_mod/keymap.c new file mode 100755 index 000000000..c86ffcc16 --- /dev/null +++ b/keyboards/hub16/keymaps/no_mod/keymap.c | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /* Copyright 2019 Josh Johnson | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include QMK_KEYBOARD_H | ||
| 17 | |||
| 18 | // Function key we are 'wrapping' usual key presses in | ||
| 19 | #define KC_WRAP KC_F24 | ||
| 20 | |||
| 21 | // Tap Dance Declarations | ||
| 22 | enum { TD_TO_LED = 0, TD_TO_DEFAULT = 1 }; | ||
| 23 | |||
| 24 | qk_tap_dance_action_t tap_dance_actions[] = { | ||
| 25 | // Tap once for HID, twice to toggle layer 1 | ||
| 26 | [TD_TO_LED] = ACTION_TAP_DANCE_DUAL_ROLE(_______, 1), | ||
| 27 | [TD_TO_DEFAULT] = ACTION_TAP_DANCE_DUAL_ROLE(_______, 0)}; | ||
| 28 | |||
| 29 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 30 | [0] = LAYOUT( /* Base */ | ||
| 31 | KC_S, KC_V, | ||
| 32 | KC_A, KC_B, KC_C, KC_D, | ||
| 33 | KC_E, KC_F, KC_G, KC_H, | ||
| 34 | KC_I, KC_J, KC_K, KC_L, | ||
| 35 | KC_M, KC_N, KC_O, TD(TD_TO_LED) | ||
| 36 | ), | ||
| 37 | |||
| 38 | [1] = LAYOUT( /* LED Control */ | ||
| 39 | KC_NO, KC_NO, | ||
| 40 | _______, RGB_MOD, RGB_RMOD, RGB_TOG, | ||
| 41 | RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI, | ||
| 42 | RGB_SAD, RGB_SAI, _______, _______, | ||
| 43 | _______, _______, RESET, TD(TD_TO_DEFAULT) | ||
| 44 | ), | ||
| 45 | }; | ||
| 46 | |||
| 47 | // Keyboard is setup to 'warp' the pressed key with F24, | ||
| 48 | // allowing for easy differentiation from a real keyboard. | ||
| 49 | void encoder_update_user(uint8_t index, bool clockwise) { | ||
| 50 | if (index == 0) { /* Left Encoder */ | ||
| 51 | if (clockwise) { | ||
| 52 | tap_code(KC_R); | ||
| 53 | } else { | ||
| 54 | tap_code(KC_Q); | ||
| 55 | } | ||
| 56 | } else if (index == 1) { /* Right Encoder */ | ||
| 57 | if (clockwise) { | ||
| 58 | tap_code(KC_U); | ||
| 59 | } else { | ||
| 60 | tap_code(KC_T); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } \ No newline at end of file | ||
diff --git a/keyboards/hub16/matrix.c b/keyboards/hub16/matrix.c new file mode 100644 index 000000000..ad77c923b --- /dev/null +++ b/keyboards/hub16/matrix.c | |||
| @@ -0,0 +1,270 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <stdint.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "wait.h" | ||
| 20 | #include "util.h" | ||
| 21 | #include "matrix.h" | ||
| 22 | #include "debounce.h" | ||
| 23 | #include "quantum.h" | ||
| 24 | |||
| 25 | // Encoder things | ||
| 26 | #define SWITCH_1 F7 | ||
| 27 | #define SWITCH_2 D7 | ||
| 28 | static bool read_encoder_values(matrix_row_t current_matrix[], uint8_t current_row); | ||
| 29 | |||
| 30 | #ifdef MATRIX_MASKED | ||
| 31 | extern const matrix_row_t matrix_mask[]; | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #ifdef DIRECT_PINS | ||
| 35 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; | ||
| 36 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | ||
| 37 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 38 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 39 | #endif | ||
| 40 | |||
| 41 | /* matrix state(1:on, 0:off) */ | ||
| 42 | static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | ||
| 43 | static matrix_row_t matrix[MATRIX_ROWS]; // debounced values | ||
| 44 | |||
| 45 | // helper functions | ||
| 46 | |||
| 47 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } | ||
| 48 | |||
| 49 | inline matrix_row_t matrix_get_row(uint8_t row) { | ||
| 50 | // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a | ||
| 51 | // switch blocker installed and the switch is always pressed. | ||
| 52 | #ifdef MATRIX_MASKED | ||
| 53 | return matrix[row] & matrix_mask[row]; | ||
| 54 | #else | ||
| 55 | return matrix[row]; | ||
| 56 | #endif | ||
| 57 | } | ||
| 58 | |||
| 59 | // matrix code | ||
| 60 | |||
| 61 | #ifdef DIRECT_PINS | ||
| 62 | |||
| 63 | static void init_pins(void) { | ||
| 64 | for (int row = 0; row < MATRIX_ROWS; row++) { | ||
| 65 | for (int col = 0; col < MATRIX_COLS; col++) { | ||
| 66 | pin_t pin = direct_pins[row][col]; | ||
| 67 | if (pin != NO_PIN) { | ||
| 68 | setPinInputHigh(pin); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | ||
| 75 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 76 | current_matrix[current_row] = 0; | ||
| 77 | |||
| 78 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | ||
| 79 | pin_t pin = direct_pins[current_row][col_index]; | ||
| 80 | if (pin != NO_PIN) { | ||
| 81 | current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | return (last_row_value != current_matrix[current_row]); | ||
| 86 | } | ||
| 87 | |||
| 88 | #elif (DIODE_DIRECTION == COL2ROW) | ||
| 89 | |||
| 90 | static void select_row(uint8_t row) { | ||
| 91 | setPinOutput(row_pins[row]); | ||
| 92 | writePinLow(row_pins[row]); | ||
| 93 | } | ||
| 94 | |||
| 95 | static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } | ||
| 96 | |||
| 97 | static void unselect_rows(void) { | ||
| 98 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | ||
| 99 | setPinInputHigh(row_pins[x]); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | static void init_pins(void) { | ||
| 104 | unselect_rows(); | ||
| 105 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 106 | setPinInputHigh(col_pins[x]); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | ||
| 111 | // Store last value of row prior to reading | ||
| 112 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 113 | |||
| 114 | // Clear data in matrix row | ||
| 115 | current_matrix[current_row] = 0; | ||
| 116 | |||
| 117 | // Select row and wait for row selecton to stabilize | ||
| 118 | select_row(current_row); | ||
| 119 | wait_us(30); | ||
| 120 | |||
| 121 | // For each col... | ||
| 122 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | ||
| 123 | // Select the col pin to read (active low) | ||
| 124 | uint8_t pin_state = readPin(col_pins[col_index]); | ||
| 125 | |||
| 126 | // Populate the matrix row with the state of the col pin | ||
| 127 | current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | ||
| 128 | } | ||
| 129 | |||
| 130 | // Unselect row | ||
| 131 | unselect_row(current_row); | ||
| 132 | |||
| 133 | return (last_row_value != current_matrix[current_row]); | ||
| 134 | } | ||
| 135 | |||
| 136 | #elif (DIODE_DIRECTION == ROW2COL) | ||
| 137 | |||
| 138 | static void select_col(uint8_t col) { | ||
| 139 | setPinOutput(col_pins[col]); | ||
| 140 | writePinLow(col_pins[col]); | ||
| 141 | } | ||
| 142 | |||
| 143 | static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } | ||
| 144 | |||
| 145 | static void unselect_cols(void) { | ||
| 146 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 147 | setPinInputHigh(col_pins[x]); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | static void init_pins(void) { | ||
| 152 | unselect_cols(); | ||
| 153 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | ||
| 154 | setPinInputHigh(row_pins[x]); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | ||
| 159 | bool matrix_changed = false; | ||
| 160 | |||
| 161 | // Select col and wait for col selecton to stabilize | ||
| 162 | select_col(current_col); | ||
| 163 | wait_us(30); | ||
| 164 | |||
| 165 | // For each row... | ||
| 166 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | ||
| 167 | // Store last value of row prior to reading | ||
| 168 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
| 169 | |||
| 170 | // Check row pin state | ||
| 171 | if (readPin(row_pins[row_index]) == 0) { | ||
| 172 | // Pin LO, set col bit | ||
| 173 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | ||
| 174 | } else { | ||
| 175 | // Pin HI, clear col bit | ||
| 176 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); | ||
| 177 | } | ||
| 178 | |||
| 179 | // Determine if the matrix changed state | ||
| 180 | if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) { | ||
| 181 | matrix_changed = true; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | // Unselect col | ||
| 186 | unselect_col(current_col); | ||
| 187 | |||
| 188 | return matrix_changed; | ||
| 189 | } | ||
| 190 | |||
| 191 | #endif | ||
| 192 | |||
| 193 | void matrix_init(void) { | ||
| 194 | // initialize key pins | ||
| 195 | init_pins(); | ||
| 196 | |||
| 197 | // initialize matrix state: all keys off | ||
| 198 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 199 | raw_matrix[i] = 0; | ||
| 200 | matrix[i] = 0; | ||
| 201 | } | ||
| 202 | |||
| 203 | debounce_init(MATRIX_ROWS); | ||
| 204 | |||
| 205 | matrix_init_quantum(); | ||
| 206 | } | ||
| 207 | |||
| 208 | uint8_t matrix_scan(void) { | ||
| 209 | bool changed = false; | ||
| 210 | |||
| 211 | #if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) | ||
| 212 | // Set row, read cols | ||
| 213 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | ||
| 214 | changed |= read_cols_on_row(raw_matrix, current_row); | ||
| 215 | } | ||
| 216 | #elif (DIODE_DIRECTION == ROW2COL) | ||
| 217 | // Set col, read rows | ||
| 218 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | ||
| 219 | changed |= read_rows_on_col(raw_matrix, current_col); | ||
| 220 | } | ||
| 221 | #endif | ||
| 222 | |||
| 223 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | ||
| 224 | |||
| 225 | // Read encoder switches, already debounced | ||
| 226 | changed |= read_encoder_values(matrix, 4); | ||
| 227 | |||
| 228 | matrix_scan_quantum(); | ||
| 229 | return (uint8_t)changed; | ||
| 230 | } | ||
| 231 | |||
| 232 | // Customisations for the encoders | ||
| 233 | void matrix_init_kb(void){ | ||
| 234 | setPinInput(SWITCH_1); | ||
| 235 | setPinInput(SWITCH_2); | ||
| 236 | } | ||
| 237 | |||
| 238 | void matrix_scan_kb(void){ | ||
| 239 | |||
| 240 | } | ||
| 241 | |||
| 242 | void matrix_print(void){ | ||
| 243 | |||
| 244 | } | ||
| 245 | |||
| 246 | static bool read_encoder_values(matrix_row_t current_matrix[], uint8_t current_row) { | ||
| 247 | // Store last value of row prior to reading | ||
| 248 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 249 | |||
| 250 | // Clear data in matrix row | ||
| 251 | current_matrix[current_row] = 0; | ||
| 252 | |||
| 253 | // Debounce the encoder buttons using a shift register | ||
| 254 | static uint8_t btn_1_array; | ||
| 255 | static uint8_t btn_2_array; | ||
| 256 | bool btn_1_rising = 0; | ||
| 257 | bool btn_2_rising = 0; | ||
| 258 | btn_1_array <<= 1; | ||
| 259 | btn_2_array <<= 1; | ||
| 260 | btn_1_array |= readPin(SWITCH_1); | ||
| 261 | btn_2_array |= readPin(SWITCH_2); | ||
| 262 | (btn_1_array == 0b01111111) ? (btn_1_rising = 1) : (btn_1_rising = 0); | ||
| 263 | (btn_2_array == 0b01111111) ? (btn_2_rising = 1) : (btn_2_rising = 0); | ||
| 264 | |||
| 265 | // Populate the matrix row with the state of the encoder | ||
| 266 | current_matrix[current_row] |= btn_1_rising ? (1 << 0) : 0; | ||
| 267 | current_matrix[current_row] |= btn_2_rising ? (1 << 1) : 0; | ||
| 268 | |||
| 269 | return (last_row_value != current_matrix[current_row]); | ||
| 270 | } \ No newline at end of file | ||
diff --git a/keyboards/hub16/readme.md b/keyboards/hub16/readme.md new file mode 100755 index 000000000..996fa4463 --- /dev/null +++ b/keyboards/hub16/readme.md | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | # Hub16 | ||
| 2 | |||
| 3 | Hub16 is a 16 Key Macro Pad with inbuilt USB 2.0 hub and dual rotary encoders. | ||
| 4 | |||
| 5 | For more information regarding the keyboard, please visit the [Hub16 Webpage](https://www.joshajohnson.com/hub16-keyboard/) or [GitHub Repo](https://github.com/joshajohnson/Hub16). | ||
| 6 | |||
| 7 | * Keyboard Maintainer: [Josh Johnson](https://github.com/joshajohnson) | ||
| 8 | * Hardware Supported: Hub16 PCB (atmega32u4) | ||
| 9 | * Hardware Availability: [Josh Johnson](https://www.joshajohnson.com/hub16-keyboard/) | ||
| 10 | |||
| 11 | Make example for this keyboard (after setting up your build environment): | ||
| 12 | |||
| 13 | make hub16:default | ||
| 14 | |||
| 15 | 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/hub16/rules.mk b/keyboards/hub16/rules.mk new file mode 100755 index 000000000..ad1e23860 --- /dev/null +++ b/keyboards/hub16/rules.mk | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | # MCU name | ||
| 2 | MCU = atmega32u4 | ||
| 3 | |||
| 4 | # Bootloader selection | ||
| 5 | # Teensy halfkay | ||
| 6 | # Pro Micro caterina | ||
| 7 | # Atmel DFU atmel-dfu | ||
| 8 | # LUFA DFU lufa-dfu | ||
| 9 | # QMK DFU qmk-dfu | ||
| 10 | # ATmega32A bootloadHID | ||
| 11 | # ATmega328P USBasp | ||
| 12 | BOOTLOADER = caterina | ||
| 13 | |||
| 14 | # Build Options | ||
| 15 | # change yes to no to disable | ||
| 16 | # | ||
| 17 | CUSTOM_MATRIX = yes # Custom scanning of matrix | ||
| 18 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration | ||
| 19 | MOUSEKEY_ENABLE = no # Mouse keys | ||
| 20 | EXTRAKEY_ENABLE = yes # Audio control and System control | ||
| 21 | CONSOLE_ENABLE = yes # Console for debug | ||
| 22 | COMMAND_ENABLE = yes # Commands for debug and configuration | ||
| 23 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | ||
| 24 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | ||
| 25 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 26 | NKRO_ENABLE = no # USB Nkey Rollover | ||
| 27 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 28 | RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow | ||
| 29 | MIDI_ENABLE = no # MIDI support | ||
| 30 | UNICODE_ENABLE = no # Unicode | ||
| 31 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | ||
| 32 | AUDIO_ENABLE = no # Audio output on port C6 | ||
| 33 | FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches | ||
| 34 | HD44780_ENABLE = no # Enable support for HD44780 based LCDs | ||
| 35 | ENCODER_ENABLE = yes # Rotary Encoder support | ||
| 36 | TAP_DANCE_ENABLE = yes # Support for tap dancing | ||
| 37 | |||
| 38 | SRC = matrix.c | ||
