First attempt at implementing encoder push / tilt support
This commit is contained in:
parent
cd46e529bb
commit
51baecc8dd
|
@ -1,5 +1 @@
|
|||
# QVEX Lynepad
|
||||
|
||||
The information, keymaps, firmware and keyboard layout for KemoNine's setup on the [QVEX Lynepad](https://www.tindie.com/products/qvex_tech/qvex-lynepad-macro-keypad/) macro board.
|
||||
|
||||
Layout files were generated by [www.keyboard-layout-editor.com](http://www.keyboard-layout-editor.com/)
|
||||
# The default keymap for lynepad
|
||||
|
|
19
keyboards/qvex/lynepad/config.h
Normal file
19
keyboards/qvex/lynepad/config.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* Copyright 2020 KemoNine
|
||||
*
|
||||
* 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
|
||||
|
||||
// place overrides here
|
106
keyboards/qvex/lynepad/keymap.c
Normal file
106
keyboards/qvex/lynepad/keymap.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/* Copyright 2020 KemoNine
|
||||
*
|
||||
* 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] = {
|
||||
/* Keymap (Base Layer) Default Layer
|
||||
* |----------------------------|
|
||||
* | 1 | 2 | 3 | 4 | |
|
||||
* | 5 | 6 | 7 | 8 | |
|
||||
* | 9 | 10 | 11 | |
|
||||
* |----------------------------|
|
||||
*/
|
||||
[0] = LAYOUT(
|
||||
KC_NO, KC_MS_BTN2, KC_MS_UP, KC_MS_BTN1,
|
||||
KC_NO, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT,
|
||||
KC_NO, KC_NO, KC_NO
|
||||
)
|
||||
};
|
||||
|
||||
// Standard encoder functionality
|
||||
void encoder_update_user(uint8_t index, bool clockwise) {
|
||||
// Process encoder rotational movements
|
||||
if (index == 0) { /* First encoder */
|
||||
if (clockwise) {
|
||||
tap_code(KC_MS_WH_RIGHT);
|
||||
} else {
|
||||
tap_code(KC_MS_WH_LEFT);
|
||||
}
|
||||
} else if (index == 1) { /* Second encoder */
|
||||
if (clockwise) {
|
||||
tap_code(KC_MS_WH_DOWN);
|
||||
} else {
|
||||
tap_code(KC_MS_WH_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Encoder press / tilt event handling
|
||||
// the core lynepad implementation will trigger a matrix event if a push/tilt
|
||||
// happens on the encoders so we can process it in the standard areas for handling key codes
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (enc1Center != enc1CenterPrev) {
|
||||
if (enc1Center < ENC_TILT_THRESHOLD) {
|
||||
register_code16(RESET);
|
||||
}
|
||||
else {
|
||||
unregister_code16(RESET);
|
||||
}
|
||||
}
|
||||
if (enc2Center != enc2CenterPrev) {
|
||||
if (enc2Center < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_MS_BTN3);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_MS_BTN3);
|
||||
}
|
||||
}
|
||||
if (enc2Up != enc2UpPrev) {
|
||||
if (enc2Up < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_UP);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_UP);
|
||||
}
|
||||
}
|
||||
if (enc2Down != enc2DownPrev) {
|
||||
if (enc2Down < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_DOWN);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_DOWN);
|
||||
}
|
||||
}
|
||||
if (enc2Left != enc2LeftPrev) {
|
||||
if (enc2Left < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_LEFT);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_LEFT);
|
||||
}
|
||||
}
|
||||
if (enc2Right != enc2RightPrev) {
|
||||
if (enc2Right < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_DOWN);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure standard handling happens as we're ignoring the keycode/record values passed
|
||||
return true;
|
||||
}
|
|
@ -61,3 +61,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define RGBLIGHT_LIMIT_VAL 240
|
||||
#define RGBLIGHT_SLEEP
|
||||
#endif
|
||||
|
||||
// Definitions for encoder tilt/press support
|
||||
#define ENC_TILT_THRESHOLD 3 // 0 - 1023 per the analogReadPin docs -- higher == more tilt
|
||||
|
||||
#define PIN_TW_SW PD2 // Center
|
||||
#define PIN_RJ_SW PC6 // Center
|
||||
#define PIN_RJ_DIR_A PD4 // Up
|
||||
#define PIN_RJ_DIR_B PD7 // Left
|
||||
#define PIN_RJ_DIR_C PB6 // Down
|
||||
#define PIN_RJ_DIR_D PB4 // Right
|
||||
|
||||
extern int16_t enc1Center;
|
||||
extern int16_t enc1CenterPrev;
|
||||
extern int16_t enc2Center;
|
||||
extern int16_t enc2CenterPrev;
|
||||
extern int16_t enc2Up;
|
||||
extern int16_t enc2UpPrev;
|
||||
extern int16_t enc2Down;
|
||||
extern int16_t enc2DownPrev;
|
||||
extern int16_t enc2Left;
|
||||
extern int16_t enc2LeftPrev;
|
||||
extern int16_t enc2Right;
|
||||
extern int16_t enc2RightPrev;
|
||||
|
|
|
@ -26,11 +26,13 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||
[0] = LAYOUT(
|
||||
KC_NO, KC_MS_BTN2, KC_MS_UP, KC_MS_BTN1,
|
||||
KC_NO, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT,
|
||||
TO(0), TO(0), KC_NO
|
||||
KC_NO, KC_NO, KC_NO
|
||||
)
|
||||
};
|
||||
|
||||
// Standard encoder functionality
|
||||
void encoder_update_user(uint8_t index, bool clockwise) {
|
||||
// Process encoder rotational movements
|
||||
if (index == 0) { /* First encoder */
|
||||
if (clockwise) {
|
||||
tap_code(KC_MS_WH_RIGHT);
|
||||
|
@ -46,14 +48,59 @@ void encoder_update_user(uint8_t index, bool clockwise) {
|
|||
}
|
||||
}
|
||||
|
||||
void matrix_init_user(void) {
|
||||
|
||||
// Encoder press / tilt event handling
|
||||
// the core lynepad implementation will trigger a matrix event if a push/tilt
|
||||
// happens on the encoders so we can process it in the standard areas for handling key codes
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (enc1Center != enc1CenterPrev) {
|
||||
if (enc1Center < ENC_TILT_THRESHOLD) {
|
||||
register_code16(RESET);
|
||||
}
|
||||
else {
|
||||
unregister_code16(RESET);
|
||||
}
|
||||
}
|
||||
if (enc2Center != enc2CenterPrev) {
|
||||
if (enc2Center < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_MS_BTN3);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_MS_BTN3);
|
||||
}
|
||||
}
|
||||
if (enc2Up != enc2UpPrev) {
|
||||
if (enc2Up < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_UP);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_UP);
|
||||
}
|
||||
}
|
||||
if (enc2Down != enc2DownPrev) {
|
||||
if (enc2Down < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_DOWN);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_DOWN);
|
||||
}
|
||||
}
|
||||
if (enc2Left != enc2LeftPrev) {
|
||||
if (enc2Left < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_LEFT);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_LEFT);
|
||||
}
|
||||
}
|
||||
if (enc2Right != enc2RightPrev) {
|
||||
if (enc2Right < ENC_TILT_THRESHOLD) {
|
||||
register_code16(KC_DOWN);
|
||||
}
|
||||
else {
|
||||
unregister_code16(KC_DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
void matrix_scan_user(void) {
|
||||
|
||||
}
|
||||
|
||||
void led_set_user(uint8_t usb_led) {
|
||||
|
||||
// Ensure standard handling happens as we're ignoring the keycode/record values passed
|
||||
return true;
|
||||
}
|
||||
|
|
76
qmk/keyboards/qvex/lynepad/matrix.c
Normal file
76
qmk/keyboards/qvex/lynepad/matrix.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* Copyright 2020 KemoNine
|
||||
*
|
||||
* 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 "quantum.h"
|
||||
#include "analog.h"
|
||||
|
||||
int16_t enc1Center = 0;
|
||||
int16_t enc1CenterPrev = 0;
|
||||
int16_t enc2Center = 0;
|
||||
int16_t enc2CenterPrev = 0;
|
||||
int16_t enc2Up = 0;
|
||||
int16_t enc2UpPrev = 0;
|
||||
int16_t enc2Down = 0;
|
||||
int16_t enc2DownPrev = 0;
|
||||
int16_t enc2Left = 0;
|
||||
int16_t enc2LeftPrev = 0;
|
||||
int16_t enc2Right = 0;
|
||||
int16_t enc2RightPrev = 0;
|
||||
|
||||
void matrix_init_custom(void) {
|
||||
}
|
||||
|
||||
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
||||
bool matrix_has_changed = false;
|
||||
|
||||
enc1CenterPrev = enc1Center;
|
||||
enc1Center = analogReadPin(PIN_TW_SW);
|
||||
if (enc1CenterPrev != enc1Center) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
enc2CenterPrev = enc2Center;
|
||||
enc2Center = analogReadPin(PIN_RJ_SW);
|
||||
if (enc2CenterPrev != enc2Center) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
enc2UpPrev = enc2Up;
|
||||
enc2Up = analogReadPin(PIN_RJ_DIR_A);
|
||||
if (enc2UpPrev != enc2Up) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
enc2DownPrev = enc2Down;
|
||||
enc2Down = analogReadPin(PIN_RJ_DIR_C);
|
||||
if (enc2DownPrev != enc2Down) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
enc2LeftPrev = enc2Left;
|
||||
enc2Left = analogReadPin(PIN_RJ_DIR_B);
|
||||
if (enc2LeftPrev != enc2Left) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
enc2RightPrev = enc2Right;
|
||||
enc2Right = analogReadPin(PIN_RJ_DIR_D);
|
||||
if (enc2RightPrev != enc2Right) {
|
||||
matrix_has_changed = true;
|
||||
}
|
||||
|
||||
return matrix_has_changed;
|
||||
}
|
|
@ -32,3 +32,7 @@ AUDIO_ENABLE = no # Audio output on port C6
|
|||
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
|
||||
HD44780_ENABLE = no # Enable support for HD44780 based LCDs
|
||||
ENCODER_ENABLE = yes # Enable the encoders
|
||||
|
||||
# Enable encoder buttons / tilts
|
||||
CUSTOM_MATRIX = lite
|
||||
SRC += analog.c matrix.c
|
||||
|
|
Loading…
Reference in a new issue