Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Firmware/hub16_new/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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 <http://www.gnu.org/licenses/>.
*/

#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
82 changes: 82 additions & 0 deletions Firmware/hub16_new/keyboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"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",
"features": {
"bootmagic": true,
"mousekey": true,
"extrakey": true,
"rgblight": true,
"encoder": true
},
"qmk": {
"locking": {
"enabled": true,
"resync": true
}
},
"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}
]
}
}
}
51 changes: 51 additions & 0 deletions Firmware/hub16_new/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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 */
_______, _______,
_______, UG_NEXT, UG_PREV, UG_TOGG,
UG_VALD, UG_VALU, UG_HUED, UG_HUEU,
UG_SATD, UG_SATU, _______, _______,
_______, _______, 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;
}
59 changes: 59 additions & 0 deletions Firmware/hub16_new/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
#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 */
_______, _______,
_______, UG_NEXT, UG_PREV, UG_TOGG,
UG_VALD, UG_VALU, UG_HUED, UG_HUEU,
UG_SATD, UG_SATU, _______, _______,
_______, _______, QK_BOOT, _______
),

[2] = LAYOUT(
_______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______
),

[3] = LAYOUT(
_______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______,
_______, _______, _______, _______
),
};

#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MPRV, KC_MNXT) },
[1] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MPRV, KC_MNXT) },
[2] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MPRV, KC_MNXT) },
[3] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MPRV, KC_MNXT) },
};
#endif
3 changes: 3 additions & 0 deletions Firmware/hub16_new/keymaps/via/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VIA_ENABLE = yes
ENCODER_ENABLE = yes
ENCODER_MAP_ENABLE = yes
125 changes: 125 additions & 0 deletions Firmware/hub16_new/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "wait.h"
#include "util.h"
#include "matrix.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) {
gpio_set_pin_output(row_pins[row]);
gpio_write_pin_low(row_pins[row]);
}

static void unselect_row(uint8_t row) { gpio_set_pin_input_high(row_pins[row]); }

static void unselect_rows(void) {
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
gpio_set_pin_input_high(row_pins[x]);
}
}

static void init_pins(void) {
unselect_rows();
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
gpio_set_pin_input_high(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 = gpio_read_pin(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
gpio_set_pin_input(SWITCH_1);
gpio_set_pin_input(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 |= gpio_read_pin(SWITCH_1);
btn_2_array |= gpio_read_pin(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]);
}
24 changes: 24 additions & 0 deletions Firmware/hub16_new/readme.md
Original file line number Diff line number Diff line change
@@ -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).
3 changes: 3 additions & 0 deletions Firmware/hub16_new/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CUSTOM_MATRIX = lite # Custom scanning of matrix
VIA_ENABLE = yes
SRC = matrix.c
Loading