From 594d03f4aaa01ea016f368aa74f5ed275635fc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:28:06 +0800 Subject: Refactor: group hub keyboards (#22762) --- keyboards/joshajohnson/hub16/config.h | 32 ++++ keyboards/joshajohnson/hub16/info.json | 69 +++++++ .../joshajohnson/hub16/keymaps/default/keymap.c | 51 +++++ .../joshajohnson/hub16/keymaps/peepeetee/config.h | 45 +++++ .../joshajohnson/hub16/keymaps/peepeetee/keymap.c | 209 +++++++++++++++++++++ .../joshajohnson/hub16/keymaps/peepeetee/rules.mk | 1 + keyboards/joshajohnson/hub16/keymaps/via/keymap.c | 67 +++++++ keyboards/joshajohnson/hub16/keymaps/via/rules.mk | 1 + keyboards/joshajohnson/hub16/matrix.c | 128 +++++++++++++ keyboards/joshajohnson/hub16/readme.md | 24 +++ keyboards/joshajohnson/hub16/rules.mk | 16 ++ 11 files changed, 643 insertions(+) create mode 100755 keyboards/joshajohnson/hub16/config.h create mode 100644 keyboards/joshajohnson/hub16/info.json create mode 100755 keyboards/joshajohnson/hub16/keymaps/default/keymap.c create mode 100644 keyboards/joshajohnson/hub16/keymaps/peepeetee/config.h create mode 100644 keyboards/joshajohnson/hub16/keymaps/peepeetee/keymap.c create mode 100644 keyboards/joshajohnson/hub16/keymaps/peepeetee/rules.mk create mode 100755 keyboards/joshajohnson/hub16/keymaps/via/keymap.c create mode 100644 keyboards/joshajohnson/hub16/keymaps/via/rules.mk create mode 100644 keyboards/joshajohnson/hub16/matrix.c create mode 100755 keyboards/joshajohnson/hub16/readme.md create mode 100755 keyboards/joshajohnson/hub16/rules.mk (limited to 'keyboards/joshajohnson/hub16') diff --git a/keyboards/joshajohnson/hub16/config.h b/keyboards/joshajohnson/hub16/config.h new file mode 100755 index 0000000000..68576635a8 --- /dev/null +++ b/keyboards/joshajohnson/hub16/config.h @@ -0,0 +1,32 @@ +/* +Copyright 2019 Josh Johnson + +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 . +*/ + +#pragma once + + +#define MATRIX_ROW_PINS \ + { F0, C7, C6, B6, E6} +#define MATRIX_COL_PINS \ + { F4, F1, D5, D3 } + +/* COL2ROW, ROW2COL*/ +#define DIODE_DIRECTION COL2ROW + +/* 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 diff --git a/keyboards/joshajohnson/hub16/info.json b/keyboards/joshajohnson/hub16/info.json new file mode 100644 index 0000000000..920b42feec --- /dev/null +++ b/keyboards/joshajohnson/hub16/info.json @@ -0,0 +1,69 @@ +{ + "keyboard_name": "Hub16", + "manufacturer": "Josh Johnson", + "url": "https://joshajohnson.com/hub16-keyboard/", + "maintainer": "Josh Johnson", + "usb": { + "vid": "0x6A6A", + "pid": "0x4810", + "device_version": "0.0.1" + }, + "encoder": { + "rotary": [ + {"pin_a": "F5", "pin_b": "F6"}, + {"pin_a": "B5", "pin_b": "B4"} + ] + }, + "rgblight": { + "saturation_steps": 8, + "brightness_steps": 8, + "led_count": 11, + "sleep": true, + "animations": { + "breathing": true, + "rainbow_mood": true, + "rainbow_swirl": true, + "snake": true, + "knight": true, + "christmas": true, + "static_gradient": true, + "rgb_test": true, + "alternating": true, + "twinkle": true + } + }, + "ws2812": { + "pin": "D1" + }, + "processor": "atmega32u4", + "bootloader": "caterina", + "debounce": 20, + "layouts": { + "LAYOUT": { + "layout": [ + {"matrix": [4, 0], "x": 0.5, "y": 0}, + {"matrix": [4, 1], "x": 2.5, "y": 0}, + + {"matrix": [0, 0], "x": 0, "y": 1}, + {"matrix": [0, 1], "x": 1, "y": 1}, + {"matrix": [0, 2], "x": 2, "y": 1}, + {"matrix": [0, 3], "x": 3, "y": 1}, + + {"matrix": [1, 0], "x": 0, "y": 2}, + {"matrix": [1, 1], "x": 1, "y": 2}, + {"matrix": [1, 2], "x": 2, "y": 2}, + {"matrix": [1, 3], "x": 3, "y": 2}, + + {"matrix": [2, 0], "x": 0, "y": 3}, + {"matrix": [2, 1], "x": 1, "y": 3}, + {"matrix": [2, 2], "x": 2, "y": 3}, + {"matrix": [2, 3], "x": 3, "y": 3}, + + {"matrix": [3, 0], "x": 0, "y": 4}, + {"matrix": [3, 1], "x": 1, "y": 4}, + {"matrix": [3, 2], "x": 2, "y": 4}, + {"matrix": [3, 3], "x": 3, "y": 4} + ] + } + } +} diff --git a/keyboards/joshajohnson/hub16/keymaps/default/keymap.c b/keyboards/joshajohnson/hub16/keymaps/default/keymap.c new file mode 100755 index 0000000000..efe10d3743 --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/default/keymap.c @@ -0,0 +1,51 @@ +/* Copyright 2019 Josh Johnson + * + * 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 . + */ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( /* Base */ + KC_MUTE, KC_MPLY, + KC_7, KC_8, KC_9, KC_PAST, + KC_4, KC_5, KC_6, KC_PMNS, + KC_1, KC_2, KC_3, KC_PPLS, + MO(1), KC_0, KC_PDOT,KC_PENT + ), + + [1] = LAYOUT( /* LED Control */ + _______, _______, + _______, RGB_MOD, RGB_RMOD, RGB_TOG, + RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI, + RGB_SAD, RGB_SAI, _______, _______, + _______, _______, QK_BOOT, _______ + ), +}; + +bool encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { /* Left Encoder */ + if (clockwise) { + tap_code(KC_VOLD); + } else { + tap_code(KC_VOLU); + } + } else if (index == 1) { /* Right Encoder */ + if (clockwise) { + tap_code(KC_MPRV); + } else { + tap_code(KC_MNXT); + } + } + return true; +} diff --git a/keyboards/joshajohnson/hub16/keymaps/peepeetee/config.h b/keyboards/joshajohnson/hub16/keymaps/peepeetee/config.h new file mode 100644 index 0000000000..62b0df937b --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/peepeetee/config.h @@ -0,0 +1,45 @@ +/* +Copyright 2019 Josh Johnson + +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 . +*/ + +#pragma once + +#define RGBLIGHT_SLEEP /* If defined, the RGB lighting will be switched off when the host goes to sleep */ +// /*== 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 20 + +// Time out one shot layers after 3 seconds +#define ONESHOT_TIMEOUT 3000 + +// Undef and redefine default brightness to half of 255 +#undef RGBLIGHT_LIMIT_VAL +#define RGBLIGHT_LIMIT_VAL 255 + +//Define a preview timeout for RGB reviews +#define PREVIEW_TIMEOUT 5000 + +// Enable Light Layers implementation +#define RGBLIGHT_LAYERS +// Allow Light Layers to override RGB off configuration +#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF diff --git a/keyboards/joshajohnson/hub16/keymaps/peepeetee/keymap.c b/keyboards/joshajohnson/hub16/keymaps/peepeetee/keymap.c new file mode 100644 index 0000000000..dac88c8482 --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/peepeetee/keymap.c @@ -0,0 +1,209 @@ +/* +Copyright 2019 Josh Johnson 2021 peepeetee + +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 . +*/ + +#include QMK_KEYBOARD_H + +#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_LAYERS) +static uint32_t rgb_preview_timer = 0; +#endif + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + + // Layer 0 - Base Layer (F13 to F24, and One Shot Layer 1,2,3 or Toggle Layer 4) + [0] = LAYOUT( + KC_MPLY, KC_MUTE, + TG(3), TG(2), TG(1), TG(0), + KC_PSCR, KC_SCRL, KC_PAUS, A(KC_F4), + KC_INS, KC_HOME, KC_PGUP, KC_F12, //Transparent to let you go between layers + KC_DEL, A(KC_F4), KC_PGDN, KC_CALCULATOR + + ), + + [1] = LAYOUT( + KC_MPLY, KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_F7, KC_F8, KC_F9, KC_F10, + KC_F4, KC_F5, KC_F6, KC_F11, + KC_F1, KC_F2, KC_F3, KC_F12 //Transparent to let you go between layers + ), + + + //Layer 5 - Keyboard Lights, Programming and Special Functions + [2] = LAYOUT( + KC_MPLY, KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, //Transparent to let you go between layers + RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, + RGB_RMOD, RGB_HUD, RGB_SAD, RGB_VAD, + RGB_TOG, EE_CLR, QK_BOOT, KC_TRNS + ), + + [3] = LAYOUT( + KC_MPLY, KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, //Transparent to let you go between layers + RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, + RGB_RMOD, RGB_HUD, RGB_SAD, RGB_VAD, + RGB_TOG, EE_CLR, QK_BOOT, KC_TRNS + ) + + + //Layer 0 - Base Layer (F13 to F24, and One Shot Layer 1,2,3 or Toggle Layer 4) + // [0] = LAYOUT( + // KC_MPLY, KC_MUTE, + // KC_F13, KC_F14, KC_F15, KC_F16, + // KC_F17, KC_F18, KC_F19, KC_F20, + // KC_F21, KC_F22, KC_F23, KC_F24, + // OSL(1), OSL(2), OSL(3), TG(4) //Transparent to let you go between layers + // ), + + // [1] = LAYOUT( + // KC_MPLY, KC_MUTE, + // LALT(KC_F13), LALT(KC_F14), LALT(KC_F15), LALT(KC_F16), + // LALT(KC_F17), LALT(KC_F18), LALT(KC_F19), LALT(KC_F20), + // LALT(KC_F21), LALT(KC_F22), LALT(KC_F23), LALT(KC_F24), + // KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS //Transparent to let you go between layers + // ), + + //Layer 2 - Shift + Function Key Layer + // [2] = LAYOUT( + // KC_MPLY, KC_MUTE, + // LSFT(KC_F13), LSFT(KC_F14), LSFT(KC_F15), LSFT(KC_F16), + // LSFT(KC_F17), LSFT(KC_F18), LSFT(KC_F19), LSFT(KC_F20), + // LSFT(KC_F21), LSFT(KC_F22), LSFT(KC_F23), LSFT(KC_F24), + // KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS //Transparent to let you go between layers + // ), + + // //Layer 3 - Control + Function Key + // [3] = LAYOUT( + // KC_MPLY, KC_MUTE, + // LCTL(KC_F13), LCTL(KC_F14), LCTL(KC_F15), LCTL(KC_F16), + // LCTL(KC_F17), LCTL(KC_F18), LCTL(KC_F19), LCTL(KC_F20), + // LCTL(KC_F21), LCTL(KC_F22), LCTL(KC_F23), LCTL(KC_F24), + // KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS //Transparent to let you go between layers + // ), + + // //Layer 4 - Multimedia + // [4] = LAYOUT( + // KC_MPLY, KC_MUTE, + // KC_MPRV, KC_MPLY, KC_U, KC_K, + // KC_NO, KC_NO, KC_ENT, KC_X, + // KC_NO, QK_BOOT, LSFT(KC_HASH), KC_J, + // TG(5), KC_TRNS, KC_TRNS, KC_TRNS //Transparent to let you go between layers + // ), + + // //Layer 5 - Keyboard Lights, Programming and Special Functions + // [5] = LAYOUT( + // KC_MPLY, KC_MUTE, + // RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, + // RGB_RMOD, RGB_HUD, RGB_SAD, RGB_VAD, + // RGB_TOG, EE_CLR, QK_BOOT, KC_LSFT, + // KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS //Transparent to let you go between layers + // ), +}; + +const rgblight_segment_t PROGMEM my_layer0_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {0,16,HSV_WHITE} + ); +const rgblight_segment_t PROGMEM my_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {0,16,HSV_ORANGE} + ); + const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {0,16,HSV_RED} + ); + const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {0,16,HSV_BLUE} + ); +// const rgblight_segment_t PROGMEM my_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS( +// {0,16,HSV_WHITE} +// ); +// const rgblight_segment_t PROGMEM my_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS( +// {0,16,HSV_TEAL} +// ); +const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST( + my_layer0_layer, + my_layer1_layer, + my_layer2_layer, + my_layer3_layer//, + // my_layer4_layer, + // my_layer5_layer + ); + +bool encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { /* Left Encoder */ + if (clockwise) { + tap_code(KC_MPRV); + } else { + tap_code(KC_MNXT); + } + } else if (index == 1) { /* Right Encoder */ + if (clockwise) { + tap_code(KC_VOLD); + } else { + tap_code(KC_VOLU); + } + } + return true; +} +void post_process_record_user(uint16_t keycode, keyrecord_t *record) { + // Allow for a preview of changes when modifying RGB +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_LAYERS) + switch (keycode) { + case RGB_TOG ... QK_VELOCIKEY_TOGGLE: + for (uint8_t i = 0; i < RGBLIGHT_MAX_LAYERS; i++) { + rgblight_set_layer_state(i, false); + } + rgb_preview_timer = timer_read32(); + break; + } +# endif + return; +} + +//Set the appropriate layer color +layer_state_t layer_state_set_user(layer_state_t state) { + rgblight_set_layer_state(0, false); + rgblight_set_layer_state(1, layer_state_cmp(state, 1)); + rgblight_set_layer_state(2, layer_state_cmp(state, 2)); + rgblight_set_layer_state(3, layer_state_cmp(state, 3)); + // rgblight_set_layer_state(4, layer_state_cmp(state, 4)); + // rgblight_set_layer_state(5, layer_state_cmp(state, 5)); + return state; +} + +void keyboard_post_init_user(void) { + //Enable the LED layers + rgblight_layers = my_rgb_layers; + layer_state_set_user(layer_state); +} + +void matrix_scan_user(void) { +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_LAYERS) + // Allow preview for + if (rgb_preview_timer && TIMER_DIFF_32(timer_read32(), rgb_preview_timer) > PREVIEW_TIMEOUT) { + rgb_preview_timer = 0; + default_layer_state_set_user(default_layer_state); + layer_state_set_user(layer_state); + led_update_user((led_t) host_keyboard_leds()); + } +# endif +} + +//EEPROM Reset Function +void eeconfig_init_user(void) { + rgblight_enable(); // Enable RGB by default + rgblight_sethsv(HSV_ORANGE); // Set it to orange by default +} diff --git a/keyboards/joshajohnson/hub16/keymaps/peepeetee/rules.mk b/keyboards/joshajohnson/hub16/keymaps/peepeetee/rules.mk new file mode 100644 index 0000000000..f6737b8e4a --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/peepeetee/rules.mk @@ -0,0 +1 @@ +BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite \ No newline at end of file diff --git a/keyboards/joshajohnson/hub16/keymaps/via/keymap.c b/keyboards/joshajohnson/hub16/keymaps/via/keymap.c new file mode 100755 index 0000000000..1f5a4d4b12 --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/via/keymap.c @@ -0,0 +1,67 @@ +/* Copyright 2019 Josh Johnson + * + * 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 . + */ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( /* Base */ + KC_MUTE, KC_MPLY, + KC_7, KC_8, KC_9, KC_PAST, + KC_4, KC_5, KC_6, KC_PMNS, + KC_1, KC_2, KC_3, KC_PPLS, + MO(1), KC_0, KC_PDOT, KC_PENT + ), + + [1] = LAYOUT( /* LED Control */ + _______, _______, + _______, RGB_MOD, RGB_RMOD, RGB_TOG, + RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI, + RGB_SAD, RGB_SAI, _______, _______, + _______, _______, QK_BOOT, _______ + ), + + [2] = LAYOUT( + _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______ + ), + + [3] = LAYOUT( + _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______, + _______, _______, _______, _______ + ), +}; + +bool encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { /* Left Encoder */ + if (clockwise) { + tap_code(KC_VOLD); + } else { + tap_code(KC_VOLU); + } + } else if (index == 1) { /* Right Encoder */ + if (clockwise) { + tap_code(KC_MPRV); + } else { + tap_code(KC_MNXT); + } + } + return true; +} diff --git a/keyboards/joshajohnson/hub16/keymaps/via/rules.mk b/keyboards/joshajohnson/hub16/keymaps/via/rules.mk new file mode 100644 index 0000000000..1e5b99807c --- /dev/null +++ b/keyboards/joshajohnson/hub16/keymaps/via/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = yes diff --git a/keyboards/joshajohnson/hub16/matrix.c b/keyboards/joshajohnson/hub16/matrix.c new file mode 100644 index 0000000000..4f32070e66 --- /dev/null +++ b/keyboards/joshajohnson/hub16/matrix.c @@ -0,0 +1,128 @@ +/* +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 . +*/ +#include +#include +#include "wait.h" +#include "util.h" +#include "matrix.h" +#include "quantum.h" + +// Encoder things +#define SWITCH_1 F7 +#define SWITCH_2 D7 +static bool read_encoder_switches(matrix_row_t current_matrix[], uint8_t current_row); + +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +/* matrix state(1:on, 0:off) */ +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +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 init_pins(void) { + unselect_rows(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinInputHigh(col_pins[x]); + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[current_row]; + + // Clear data in matrix row + current_matrix[current_row] = 0; + + // Select row and wait for row selecton to stabilize + select_row(current_row); + wait_us(30); + + // For each col... + for (uint8_t col_index = 0; col_index < 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 + current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); + } + + // Unselect row + unselect_row(current_row); + + return (last_row_value != current_matrix[current_row]); +} + + +void matrix_init_custom(void) { + // initialize key pins + setPinInput(SWITCH_1); + setPinInput(SWITCH_2); + init_pins(); +} + +bool matrix_scan_custom(void) { + bool changed = false; + + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + changed |= read_cols_on_row(raw_matrix, current_row); + } + + // Read encoder switches, already debounced + changed |= read_encoder_switches(matrix, 4); + + return changed; +} + +static bool read_encoder_switches(matrix_row_t current_matrix[], uint8_t current_row) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[current_row]; + + // Clear data in matrix row + current_matrix[current_row] = 0; + + // Debounce the encoder buttons using a shift register + static uint8_t btn_1_array; + static uint8_t btn_2_array; + bool btn_1_rise = 0; + bool btn_2_rise = 0; + btn_1_array <<= 1; + btn_2_array <<= 1; + btn_1_array |= readPin(SWITCH_1); + btn_2_array |= readPin(SWITCH_2); + (btn_1_array == 0b01111111) ? (btn_1_rise = 1) : (btn_1_rise = 0); + (btn_2_array == 0b01111111) ? (btn_2_rise = 1) : (btn_2_rise = 0); + + // Populate the matrix row with the state of the encoder + current_matrix[current_row] |= btn_1_rise ? (1 << 0) : 0; + current_matrix[current_row] |= btn_2_rise ? (1 << 1) : 0; + + return (last_row_value != current_matrix[current_row]); +} diff --git a/keyboards/joshajohnson/hub16/readme.md b/keyboards/joshajohnson/hub16/readme.md new file mode 100755 index 0000000000..9735079e24 --- /dev/null +++ b/keyboards/joshajohnson/hub16/readme.md @@ -0,0 +1,24 @@ +# Hub16 + +Hub16 is a 16 Key Macro Pad with an inbuilt USB 2.0 hub and dual rotary encoders. + +For more information regarding the keyboard, please visit the [Hub16 Website](https://www.joshajohnson.com/hub16-keyboard/) or [GitHub Repo](https://github.com/joshajohnson/Hub16). + +* Keyboard Maintainer: [Josh Johnson](https://github.com/joshajohnson) +* Hardware Supported: Hub16 PCB (atmega32u4) +* Hardware Availability: [Josh Johnson](https://www.joshajohnson.com/hub16-keyboard/) + +Make example for this keyboard (after setting up your build environment): + + make joshajohnson/hub16:default + +Flashing example for this keyboard: + + make joshajohnson/hub16:default:flash + +To reset the board into bootloader mode, do one of the following: + +* Press the reset switch between the center two USB-C ports while the board is plugged in +* Hold the top left key while connecting the USB cable (also erases persistent settings) + +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/joshajohnson/hub16/rules.mk b/keyboards/joshajohnson/hub16/rules.mk new file mode 100755 index 0000000000..51fa8f6ee6 --- /dev/null +++ b/keyboards/joshajohnson/hub16/rules.mk @@ -0,0 +1,16 @@ +# Build Options +# change yes to no to disable +# +CUSTOM_MATRIX = lite # Custom scanning of matrix +BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite +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 +NKRO_ENABLE = no # Enable N-Key Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow +AUDIO_ENABLE = no # Audio output +ENCODER_ENABLE = yes # Rotary Encoder support + +SRC = matrix.c -- cgit v1.2.3