Further bring up of the qvex lynepad ; includes handling of encoder push/tilt and better default keymap

This commit is contained in:
kemonine 2020-10-30 22:02:16 -04:00
parent 385276cee4
commit 3b86e1e3ec
8 changed files with 191 additions and 172 deletions

View File

@ -1 +1,5 @@
# The default keymap for lynepad
# 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/)

View File

@ -15,6 +15,8 @@
*/
#include QMK_KEYBOARD_H
#include <print.h>
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap (Base Layer) Default Layer
* |----------------------------|
@ -23,10 +25,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* | 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
[0] = LAYOUT_Lynepad(
KC_MS_BTN4, KC_MS_BTN2, KC_MS_UP, KC_MS_BTN1,
KC_MS_BTN5, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT,
KC_MS_ACCEL0, KC_MS_ACCEL1, KC_MS_ACCEL2
)
};
@ -35,29 +37,42 @@ 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);
tap_code(KC_AUDIO_VOL_DOWN);
} else {
tap_code(KC_MS_WH_LEFT);
tap_code(KC_AUDIO_VOL_UP);
}
} else if (index == 1) { /* Second encoder */
if (clockwise) {
tap_code(KC_MS_WH_DOWN);
} else {
tap_code(KC_MS_WH_UP);
} else {
tap_code(KC_MS_WH_DOWN);
}
}
}
// 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) {
// the core lynepad implementation will update the below variables on each matrix scan
// Update the various codes below for customizing the tilt / push config
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;
void matrix_scan_user(void) {
if (enc1Center != enc1CenterPrev) {
if (enc1Center < ENC_TILT_THRESHOLD) {
register_code16(RESET);
}
else {
unregister_code16(RESET);
reset_keyboard();
}
}
if (enc2Center != enc2CenterPrev) {
@ -67,40 +82,42 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
else {
unregister_code16(KC_MS_BTN3);
}
/*
* Encoder sets ALL values when center is pressed so bail out at this point\
* to avoid the rest of the encoder buttons registering events
*/
return;
}
if (enc2Up != enc2UpPrev) {
if (enc2Up < ENC_TILT_THRESHOLD) {
register_code16(KC_UP);
register_code16(RGB_VAI);
}
else {
unregister_code16(KC_UP);
unregister_code16(RGB_VAI);
}
}
if (enc2Down != enc2DownPrev) {
if (enc2Down < ENC_TILT_THRESHOLD) {
register_code16(KC_DOWN);
register_code16(RGB_VAD);
}
else {
unregister_code16(KC_DOWN);
unregister_code16(RGB_VAD);
}
}
if (enc2Left != enc2LeftPrev) {
if (enc2Left < ENC_TILT_THRESHOLD) {
register_code16(KC_LEFT);
register_code16(RGB_TOG);
}
else {
unregister_code16(KC_LEFT);
unregister_code16(RGB_TOG);
}
}
if (enc2Right != enc2RightPrev) {
if (enc2Right < ENC_TILT_THRESHOLD) {
register_code16(KC_DOWN);
register_code16(RGB_MODE_FORWARD);
}
else {
unregister_code16(KC_DOWN);
unregister_code16(RGB_MODE_FORWARD);
}
}
// Ensure standard handling happens as we're ignoring the keycode/record values passed
return true;
}

View File

@ -20,38 +20,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config_common.h"
/* USB Device descriptor parameter */
#define VENDOR_ID 0x4B42 // FIXME: Update to match Lynepad
#define PRODUCT_ID 0x6067 // FIXME: Update to match Lynepad
#define DEVICE_VER 0x0002 // FIXME: Update to match Lynepad
#define VENDOR_ID 0x5156
#define PRODUCT_ID 0x4C50
#define DEVICE_VER 0x0001
#define MANUFACTURER QVEX
#define PRODUCT Lynepad
#define DESCRIPTION Macro Keypad
/* key matrix size */
#define MATRIX_ROWS 7
#define MATRIX_COLS 6
#define MATRIX_ROWS 3
#define MATRIX_COLS 4
#define MATRIX_ROW_PINS { PC7, PF7, PF6 }
#define MATRIX_COL_PINS { PF0, PF1, PF4, PF5 }
/* Basic matrix config */
#define MATRIX_ROW_PINS { C7, F7, F6}
#define MATRIX_COL_PINS { F0, F1, F4, F5 }
#define UNUSED_PINS
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW // FIXME: Double check this actually works
#define DIODE_DIRECTION COL2ROW
/* Encoders */
#define ENCODERS_PAD_A { PD0, PB5 }
#define ENCODERS_PAD_B { PD1, PD6 }
#define ENCODERS_PAD_A { D0, B5 }
#define ENCODERS_PAD_B { D1, D6 }
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5
/* 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
#define RGB_DI_PIN PD3
/* LEDs */
#define RGB_DI_PIN D3
#ifdef RGB_DI_PIN
#undef RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4
@ -59,29 +52,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGBLIGHT_SAT_STEP 8
#define RGBLIGHT_VAL_STEP 8
#define RGBLIGHT_LIMIT_VAL 240
#define RGBLIGHT_SLEEP
#endif
// Definitions for encoder tilt/press support
#define ENC_TILT_THRESHOLD 0 // 0 - 1023 per the analogReadPin docs -- higher == more tilt
// Encoder is digital so this can be 0 as anything > 0 == press/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;
/* Definitions for encoder tilt/press support */
#define ENC_TILT_THRESHOLD 1
#define PIN_TW_SW D2 // Center
#define PIN_RJ_SW C6 // Center
#define PIN_RJ_DIR_A D4 // Up
#define PIN_RJ_DIR_B D7 // Left
#define PIN_RJ_DIR_C B6 // Down
#define PIN_RJ_DIR_D B4 // Right

View File

@ -15,6 +15,8 @@
*/
#include QMK_KEYBOARD_H
#include <print.h>
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap (Base Layer) Default Layer
* |----------------------------|
@ -23,7 +25,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* | 9 | 10 | 11 | |
* |----------------------------|
*/
[0] = LAYOUT(
[0] = LAYOUT_Lynepad(
KC_MS_BTN4, KC_MS_BTN2, KC_MS_UP, KC_MS_BTN1,
KC_MS_BTN5, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT,
KC_MS_ACCEL0, KC_MS_ACCEL1, KC_MS_ACCEL2
@ -35,29 +37,42 @@ void encoder_update_user(uint8_t index, bool clockwise) {
// Process encoder rotational movements
if (index == 0) { /* First encoder */
if (clockwise) {
tap_code(KC_AUDIO_VOL_UP);
tap_code(KC_AUDIO_VOL_DOWN);
} else {
tap_code(KC_AUDIO_VOL_UP);
}
} else if (index == 1) { /* Second encoder */
if (clockwise) {
tap_code(KC_MS_WH_DOWN);
} else {
tap_code(KC_MS_WH_UP);
} else {
tap_code(KC_MS_WH_DOWN);
}
}
}
// 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) {
// the core lynepad implementation will update the below variables on each matrix scan
// Update the various codes below for customizing the tilt / push config
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;
void matrix_scan_user(void) {
if (enc1Center != enc1CenterPrev) {
if (enc1Center < ENC_TILT_THRESHOLD) {
register_code16(RESET);
}
else {
unregister_code16(RESET);
reset_keyboard();
}
}
if (enc2Center != enc2CenterPrev) {
@ -67,6 +82,11 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
else {
unregister_code16(KC_MS_BTN3);
}
/*
* Encoder sets ALL values when center is pressed so bail out at this point\
* to avoid the rest of the encoder buttons registering events
*/
return;
}
if (enc2Up != enc2UpPrev) {
if (enc2Up < ENC_TILT_THRESHOLD) {
@ -100,7 +120,4 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
unregister_code16(RGB_MODE_FORWARD);
}
}
// Ensure standard handling happens as we're ignoring the keycode/record values passed
return true;
}

View File

@ -1,2 +1,86 @@
#include "lynepad.h"
#include <print.h>
void keyboard_pre_init_kb(void) {
// Encoder pins
setPinInput(PIN_TW_SW);
setPinInput(PIN_RJ_SW);
setPinInput(PIN_RJ_DIR_A);
setPinInput(PIN_RJ_DIR_C);
setPinInput(PIN_RJ_DIR_B);
setPinInput(PIN_RJ_DIR_D);
// Matrix pins
setPinInput(C7);
setPinInput(F7);
setPinInput(F6);
setPinInput(F0);
setPinInput(F1);
setPinInput(F4);
setPinInput(F5);
}
void keyboard_post_init_user(void) {
// Customise these values to desired behaviour
debug_enable=true;
debug_matrix=true;
debug_keyboard=true;
debug_mouse=true;
}
int16_t enc1Center = 1;
int16_t enc1CenterPrev = 1;
int16_t enc2Center = 1;
int16_t enc2CenterPrev = 1;
int16_t enc2Up = 1;
int16_t enc2UpPrev = 1;
int16_t enc2Down = 1;
int16_t enc2DownPrev = 1;
int16_t enc2Left = 1;
int16_t enc2LeftPrev = 1;
int16_t enc2Right = 1;
int16_t enc2RightPrev = 1;
void matrix_scan_kb(void) {
enc1CenterPrev = enc1Center;
enc1Center = readPin(PIN_TW_SW);
enc2CenterPrev = enc2Center;
enc2Center = readPin(PIN_RJ_SW);
enc2UpPrev = enc2Up;
enc2Up = readPin(PIN_RJ_DIR_A);
enc2DownPrev = enc2Down;
enc2Down = readPin(PIN_RJ_DIR_C);
enc2LeftPrev = enc2Left;
enc2Left = readPin(PIN_RJ_DIR_B);
enc2RightPrev = enc2Right;
enc2Right = readPin(PIN_RJ_DIR_D);
// printf("==================\n");
// print("Encoders\n");
// uprintf(" E1CP: %d\n", enc1CenterPrev);
// uprintf(" E1C: %d\n", enc1Center);
// uprintf(" E2CP: %d\n", enc2CenterPrev);
// uprintf(" E2C: %d\n", enc2Center);
// uprintf(" E2UP: %d\n", enc2UpPrev);
// uprintf(" E2U: %d\n", enc2Up);
// uprintf(" E2DP: %d\n", enc2DownPrev);
// uprintf(" E2D: %d\n", enc2Down);
// uprintf(" E2LP: %d\n", enc2LeftPrev);
// uprintf(" E2L: %d\n", enc2Left);
// uprintf(" E2RP: %d\n", enc2RightPrev);
// uprintf(" E2R: %d\n", enc2Right);
// print("Rows\n");
// uprintf(" C7: %d\n", readPin(C7));
// uprintf(" F7: %d\n", readPin(F7));
// uprintf(" F6: %d\n", readPin(F6));
// print("Cols\n");
// uprintf(" F0: %d\n", readPin(F0));
// uprintf(" F1: %d\n", readPin(F1));
// uprintf(" F4: %d\n", readPin(F4));
// uprintf(" F5: %d\n", readPin(F5));
// Ensure any user customizations are called (for some reason this wasn't happening by default)
matrix_scan_user();
}

View File

@ -25,13 +25,13 @@
* The second converts the arguments into a two-dimensional array which
* represents the switch matrix.
*/
#define LAYOUT( \
K00, K01, K02, K03, \
K10, K11, K12, K13, \
K20, K21, K22 \
#define LAYOUT_Lynepad( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
k20, k21, k22 \
) \
{ \
{ K00, K01, K02, K03 }, \
{ K10, K11, K12, K13 }, \
{ K20, K21, K22, KC_NO } \
{ k00, k01, k02, k03 }, \
{ k10, k11, k12, k13 }, \
{ k20, k21, k22, KC_NO } \
}

View File

@ -1,76 +0,0 @@
/* 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;
}

View File

@ -9,7 +9,7 @@ MCU = atmega32u4
# QMK DFU qmk-dfu
# ATmega32A bootloadHID
# ATmega328P USBasp
BOOTLOADER = atmel-dfu
BOOTLOADER = caterina
# Build Options
# change yes to no to disable
@ -17,13 +17,13 @@ BOOTLOADER = atmel-dfu
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
CONSOLE_ENABLE = yes # Console for debug
COMMAND_ENABLE = no # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE = no # USB Nkey Rollover
BACKLIGHT_ENABLE = false # Enable keyboard backlight functionality on B7 by default
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
MIDI_ENABLE = no # MIDI support
UNICODE_ENABLE = no # Unicode
@ -32,7 +32,3 @@ 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