Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keymap] Add VIA support for Hub16 #9638

Merged
merged 6 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions keyboards/hub16/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config_common.h"

/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x8F73
#define VENDOR_ID 0x6A6A
#define PRODUCT_ID 0x4810
#define DEVICE_VER 0x0001
#define MANUFACTURER Josh Johnson
#define PRODUCT Hub16
Expand All @@ -42,9 +42,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define MATRIX_ROW_PINS \
{ F0, C7, C6, B6, E6}
{ F0, C7, C6, B6, E6}
#define MATRIX_COL_PINS \
{ F4, F1, D5, D3 }
{ F4, F1, D5, D3 }

/* COL2ROW, ROW2COL*/
#define DIODE_DIRECTION COL2ROW
Expand Down
66 changes: 66 additions & 0 deletions keyboards/hub16/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* 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 */
_______, _______,
_______, RGB_MOD, RGB_RMOD, RGB_TOG,
RGB_VAD, RGB_VAI, RGB_HUD, RGB_HUI,
RGB_SAD, RGB_SAI, _______, _______,
_______, _______, RESET, _______
),

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

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

void 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);
}
}
}
4 changes: 4 additions & 0 deletions keyboards/hub16/keymaps/via/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VIA_ENABLE = yes
CONSOLE_ENABLE = no
COMMAND_ENABLE = no
TAP_DANCE_ENABLE = no
25 changes: 6 additions & 19 deletions keyboards/hub16/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Encoder things
#define SWITCH_1 F7
#define SWITCH_2 D7
static bool read_encoder_values(matrix_row_t current_matrix[], uint8_t current_row);
bool read_encoder_switches(matrix_row_t current_matrix[], uint8_t current_row);

#ifdef MATRIX_MASKED
extern const matrix_row_t matrix_mask[];
Expand Down Expand Up @@ -222,8 +222,7 @@ uint8_t matrix_scan(void) {

debounce(raw_matrix, matrix, MATRIX_ROWS, changed);

// Read encoder switches, already debounced
changed |= read_encoder_values(matrix, 4);
changed |= read_encoder_switches(matrix, 4);
joshajohnson marked this conversation as resolved.
Show resolved Hide resolved

matrix_scan_quantum();
return (uint8_t)changed;
Expand All @@ -243,28 +242,16 @@ void matrix_print(void){

}

static bool read_encoder_values(matrix_row_t current_matrix[], uint8_t current_row) {
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_rising = 0;
bool btn_2_rising = 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_rising = 1) : (btn_1_rising = 0);
(btn_2_array == 0b01111111) ? (btn_2_rising = 1) : (btn_2_rising = 0);

// Populate the matrix row with the state of the encoder
current_matrix[current_row] |= btn_1_rising ? (1 << 0) : 0;
current_matrix[current_row] |= btn_2_rising ? (1 << 1) : 0;
// Populate the matrix row with the state of the encoder switch
current_matrix[current_row] |= readPin(SWITCH_1) ? (1 << 0) : 0;
current_matrix[current_row] |= readPin(SWITCH_2) ? (1 << 1) : 0;

return (last_row_value != current_matrix[current_row]);
}