From 51baecc8dd8c6eafae2429b69761bf484ea9ed41 Mon Sep 17 00:00:00 2001 From: kemonine Date: Thu, 29 Oct 2020 18:56:08 -0400 Subject: [PATCH] First attempt at implementing encoder push / tilt support --- keyboards/qvex/lynepad/README.md | 6 +- keyboards/qvex/lynepad/config.h | 19 ++++ keyboards/qvex/lynepad/keymap.c | 106 ++++++++++++++++++ qmk/keyboards/qvex/lynepad/config.h | 23 ++++ .../qvex/lynepad/keymaps/default/keymap.c | 67 +++++++++-- qmk/keyboards/qvex/lynepad/matrix.c | 76 +++++++++++++ qmk/keyboards/qvex/lynepad/rules.mk | 4 + 7 files changed, 286 insertions(+), 15 deletions(-) create mode 100644 keyboards/qvex/lynepad/config.h create mode 100644 keyboards/qvex/lynepad/keymap.c create mode 100644 qmk/keyboards/qvex/lynepad/matrix.c diff --git a/keyboards/qvex/lynepad/README.md b/keyboards/qvex/lynepad/README.md index e70c547b..7ea3ccba 100644 --- a/keyboards/qvex/lynepad/README.md +++ b/keyboards/qvex/lynepad/README.md @@ -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 diff --git a/keyboards/qvex/lynepad/config.h b/keyboards/qvex/lynepad/config.h new file mode 100644 index 00000000..a8f43420 --- /dev/null +++ b/keyboards/qvex/lynepad/config.h @@ -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 . + */ + +#pragma once + +// place overrides here diff --git a/keyboards/qvex/lynepad/keymap.c b/keyboards/qvex/lynepad/keymap.c new file mode 100644 index 00000000..9882ac35 --- /dev/null +++ b/keyboards/qvex/lynepad/keymap.c @@ -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 . + */ +#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; +} diff --git a/qmk/keyboards/qvex/lynepad/config.h b/qmk/keyboards/qvex/lynepad/config.h index 21af6341..e812df23 100644 --- a/qmk/keyboards/qvex/lynepad/config.h +++ b/qmk/keyboards/qvex/lynepad/config.h @@ -61,3 +61,26 @@ along with this program. If not, see . #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; diff --git a/qmk/keyboards/qvex/lynepad/keymaps/default/keymap.c b/qmk/keyboards/qvex/lynepad/keymaps/default/keymap.c index 373c8ff3..2c9879cc 100644 --- a/qmk/keyboards/qvex/lynepad/keymaps/default/keymap.c +++ b/qmk/keyboards/qvex/lynepad/keymaps/default/keymap.c @@ -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) { - -} - -void matrix_scan_user(void) { - -} - -void led_set_user(uint8_t usb_led) { +// 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; } diff --git a/qmk/keyboards/qvex/lynepad/matrix.c b/qmk/keyboards/qvex/lynepad/matrix.c new file mode 100644 index 00000000..b736f96c --- /dev/null +++ b/qmk/keyboards/qvex/lynepad/matrix.c @@ -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 . + */ + +#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; +} diff --git a/qmk/keyboards/qvex/lynepad/rules.mk b/qmk/keyboards/qvex/lynepad/rules.mk index cf828217..706dd0c6 100644 --- a/qmk/keyboards/qvex/lynepad/rules.mk +++ b/qmk/keyboards/qvex/lynepad/rules.mk @@ -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