Merge branch 'next-0.5' into vial

This commit is contained in:
Ilya Zhuravlev 2022-04-09 17:16:59 -06:00
commit 7bda0967f3
53 changed files with 377 additions and 25 deletions

View File

@ -555,6 +555,7 @@ ifeq ($(strip $(VIAL_ENABLE)), yes)
QMK_SETTINGS ?= yes
TAP_DANCE_ENABLE ?= yes
COMBO_ENABLE ?= yes
KEY_OVERRIDE_ENABLE ?= yes
SRC += $(QUANTUM_DIR)/vial.c
EXTRAINCDIRS += $(KEYMAP_OUTPUT)
OPT_DEFS += -DVIAL_ENABLE -DNO_DEBUG -DSERIAL_NUMBER=\"vial:f64c2b3c\"

View File

@ -3,4 +3,5 @@ VIAL_ENABLE = yes
VIAL_ENCODERS_ENABLE = yes
LTO_ENABLE = yes
COMBO_ENABLE = no
QMK_SETTINGS = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -4,3 +4,4 @@ VIAL_ENABLE = yes
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -3,4 +3,5 @@ VIAL_ENABLE = yes
LTO_ENABLE = yes
# to reduce firmware size
QMK_SETTINGS = no
TAP_DANCE_ENABLE = no
TAP_DANCE_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -7,3 +7,4 @@ VIAL_COMBO_ENABLE = yes
TAP_DANCE_ENABLE = yes
VIAL_TAP_DANCE_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -2,4 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
TAP_DANCE_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ LTO_ENABLE = yes
VIA_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ LTO_ENABLE = yes
VIA_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -17,5 +17,6 @@ VIALRGB_ENABLE = yes
QMK_SETTINGS = no
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no
SRC += oled.c
SRC += oled.c

View File

@ -5,3 +5,4 @@ CONSOLE_ENABLE = no
VIAL_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -7,4 +7,5 @@ MIDI_ENABLE = no
BLUETOOTH_ENABLE = no
KEY_LOCK_ENABLE = no
TERMINAL_ENABLE = no
LTO_ENABLE = yes
LTO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -6,3 +6,4 @@ COMBO_ENABLE = yes
TAPDANCE_ENABLE = yes
LTO_ENABLE = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
VIAL_ENCODERS_ENABLE = yes
LTO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -3,4 +3,4 @@ VIAL_ENABLE = yes
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -3,4 +3,4 @@ VIAL_ENABLE = yes
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -3,3 +3,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -5,3 +5,4 @@
#define VIAL_UNLOCK_COMBO_ROWS { 0, 0 }
#define VIAL_UNLOCK_COMBO_COLS { 0, 15 }
#define VIAL_COMBO_ENTRIES 6

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
TAP_DANCE_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
LTO_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -3,3 +3,4 @@ LTO_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -13,3 +13,4 @@ COMBO_ENABLE = no # ~2408 bytes
#SPACE_CADET_ENABLE = no # ~324 bytes
#MAGIC_ENABLE = no # ~584 bytes
KEY_OVERRIDE_ENABLE = no

View File

@ -3,3 +3,4 @@ LTO_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
TAP_DANCE_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -6,3 +6,4 @@ QMK_SETTINGS = no
COMBO_ENABLE = no
BACKLIGHT_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -6,3 +6,4 @@ VIALRGB_ENABLE = no
QMK_SETTINGS = no
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -0,0 +1,26 @@
#pragma once
#define VIAL_KEYBOARD_UID {0x58, 0x55, 0xE7, 0x22, 0xE7, 0x2F, 0xD2, 0x9A}
#define VIAL_UNLOCK_COMBO_ROWS { 0, 0 }
#define VIAL_UNLOCK_COMBO_COLS { 0, 3 }
// Reduce firmware size by decreasing number of functions:
#define DYNAMIC_KEYMAP_LAYER_COUNT 4
#define DYNAMIC_KEYMAP_MACRO_COUNT 16
#define VIAL_COMBO_ENTRIES 4
#define VIAL_KEY_OVERRIDE_ENTRIES 4
#define VIAL_TAP_DANCE_ENTRIES 4
// Reduce firmware size by removing unneeded animations:
#undef RGBLIGHT_ANIMATIONS
#define RGBLIGHT_EFFECT_ALTERNATING
#define RGBLIGHT_EFFECT_BREATHING
#define RGBLIGHT_EFFECT_CHRISTMAS
#define RGBLIGHT_EFFECT_KNIGHT
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
#define RGBLIGHT_EFFECT_RGB_TEST
#define RGBLIGHT_EFFECT_SNAKE
#define RGBLIGHT_EFFECT_STATIC_GRADIENT
// #define RGBLIGHT_EFFECT_TWINKLE

View File

@ -0,0 +1,43 @@
/* Copyright 2022
*
* 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_ortho_4x4(
KC_P7, KC_P8, KC_P9, KC_PMNS,
KC_P4, KC_P5, KC_P6, KC_PPLS,
KC_P1, KC_P2, KC_P3, KC_PENT,
KC_P0, KC_PDOT, KC_SPC, MO(1)
),
[1] = LAYOUT_ortho_4x4(
RESET, KC_PAST, KC_PSLS, _______,
BL_TOGG, BL_DEC, BL_INC, BL_STEP,
RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD,
RGB_SAI, RGB_SAD, _______, _______
),
[2] = LAYOUT_ortho_4x4(
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
),
[3] = LAYOUT_ortho_4x4(
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
)
};

View File

@ -0,0 +1,7 @@
# Vial Keymap for BM16a
[Vial] settings for the [KPrepublic BM16a] with a default keymap based on the stock layout that this keypad ships with.
[Vial]: https://get.vial.today
[KPrepublic BM16a]: https://kprepublic.com/collections/bm16/products/bm16a-16-keys-custom-mechanical-keyboard-pcb-plate-programmed-numpad-layouts-qmk-firmware-with-rgb-bottom-underglow-alps-mx

View File

@ -0,0 +1,7 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
# Reduce firmware size:
LTO_ENABLE = yes
MAGIC_ENABLE = no
QMK_SETTINGS = no

View File

@ -0,0 +1,15 @@
{
"name": "KPrepublic BM16a",
"vendorId": "0x4B50",
"productId": "0x016A",
"lighting": "qmk_backlight_rgblight",
"matrix": { "rows": 4, "cols": 4 },
"layouts": {
"keymap": [
["0,0","0,1","0,2","0,3"],
["1,0","1,1","1,2","1,3"],
["2,0","2,1","2,2","2,3"],
["3,0","3,1","3,2","3,3"]
]
}
}

View File

@ -1,4 +1,5 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
COMBO_ENABLE = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -7,3 +7,4 @@ COMBO_ENABLE = yes
TAP_DANCE_ENABLE = no
LTO_ENABLE = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -4,3 +4,4 @@ LTO_ENABLE = yes
QMK_SETTINGS = no
COMBO_ENABLE = no
TAP_DANCE_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -17,3 +17,4 @@ CONSOLE_ENABLE = no
QMK_SETTINGS = yes
LTO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
RGBLIGHT_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -1,3 +1,4 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -3,3 +3,4 @@ VIA_ENABLE = yes
QMK_SETTINGS = no
VIAL_ENABLE = yes
VIAL_ENCODERS_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -1,2 +1,3 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -3,3 +3,4 @@ VIAL_ENABLE = yes
VIAL_ENCODERS_ENABLE = yes
QMK_SETTINGS = no
COMBO_ENABLE = no
KEY_OVERRIDE_ENABLE = no

View File

@ -4,3 +4,4 @@ LTO_ENABLE = yes
QMK_SETTINGS = no
VIAL_ENCODERS_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -1,4 +1,5 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
QMK_SETTINGS = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -1,4 +1,5 @@
VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
QMK_SETTINGS = no
QMK_SETTINGS = no
KEY_OVERRIDE_ENABLE = no

View File

@ -2,3 +2,4 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes
MOUSEKEY_ENABLE = yes
KEY_OVERRIDE_ENABLE = no

View File

@ -392,11 +392,11 @@ if (QS_oneshot_tap_toggle > 1) {
# endif
case MODS_TAP_TOGGLE:
if (event.pressed) {
if (tap_count <= TAPPING_TOGGLE) {
if (tap_count <= QS_tapping_toggle) {
register_mods(mods);
}
} else {
if (tap_count < TAPPING_TOGGLE) {
if (tap_count < QS_tapping_toggle) {
unregister_mods(mods);
}
}
@ -549,11 +549,11 @@ if (QS_oneshot_tap_toggle > 1) {
case OP_TAP_TOGGLE:
/* tap toggle */
if (event.pressed) {
if (tap_count < TAPPING_TOGGLE) {
if (tap_count < QS_tapping_toggle) {
layer_invert(action.layer_tap.val);
}
} else {
if (tap_count <= TAPPING_TOGGLE) {
if (tap_count <= QS_tapping_toggle) {
layer_invert(action.layer_tap.val);
}
}
@ -688,7 +688,7 @@ if (QS_oneshot_tap_toggle > 1) {
swap_hands = !swap_hands;
}
} else {
if (tap_count < TAPPING_TOGGLE) {
if (tap_count < QS_tapping_toggle) {
swap_hands = !swap_hands;
}
}

View File

@ -20,6 +20,7 @@
#include "quantum.h" // for send_string()
#include "dynamic_keymap.h"
#include "via.h" // for default VIA_EEPROM_ADDR_END
#include <string.h>
#ifdef VIAL_ENABLE
#include "vial.h"
@ -101,9 +102,18 @@ static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
#define VIAL_COMBO_SIZE 0
#endif
// Key overrides
#define VIAL_KEY_OVERRIDE_EEPROM_ADDR (VIAL_COMBO_EEPROM_ADDR + VIAL_COMBO_SIZE)
#ifdef VIAL_KEY_OVERRIDE_ENABLE
#define VIAL_KEY_OVERRIDE_SIZE (sizeof(vial_key_override_entry_t) * VIAL_KEY_OVERRIDE_ENTRIES)
#else
#define VIAL_KEY_OVERRIDE_SIZE 0
#endif
// Dynamic macro
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (VIAL_COMBO_EEPROM_ADDR + VIAL_COMBO_SIZE)
# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (VIAL_KEY_OVERRIDE_EEPROM_ADDR + VIAL_KEY_OVERRIDE_SIZE)
#endif
// Sanity check that dynamic keymaps fit in available EEPROM
@ -246,6 +256,28 @@ int dynamic_keymap_set_combo(uint8_t index, const vial_combo_entry_t *entry) {
}
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
int dynamic_keymap_get_key_override(uint8_t index, vial_key_override_entry_t *entry) {
if (index >= VIAL_KEY_OVERRIDE_ENTRIES)
return -1;
void *address = (void*)(VIAL_KEY_OVERRIDE_EEPROM_ADDR + index * sizeof(vial_key_override_entry_t));
eeprom_read_block(entry, address, sizeof(vial_key_override_entry_t));
return 0;
}
int dynamic_keymap_set_key_override(uint8_t index, const vial_key_override_entry_t *entry) {
if (index >= VIAL_KEY_OVERRIDE_ENTRIES)
return -1;
void *address = (void*)(VIAL_KEY_OVERRIDE_EEPROM_ADDR + index * sizeof(vial_key_override_entry_t));
eeprom_write_block(entry, address, sizeof(vial_key_override_entry_t));
return 0;
}
#endif
#if defined(VIAL_ENCODERS_ENABLE) && defined(VIAL_ENCODER_DEFAULT)
static const uint16_t PROGMEM vial_encoder_default[] = VIAL_ENCODER_DEFAULT;
_Static_assert(sizeof(vial_encoder_default)/sizeof(*vial_encoder_default) == 2 * DYNAMIC_KEYMAP_LAYER_COUNT * NUMBER_OF_ENCODERS,
@ -299,6 +331,14 @@ void dynamic_keymap_reset(void) {
dynamic_keymap_set_combo(i, &combo);
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
vial_key_override_entry_t ko = { 0 };
ko.layers = ~0;
ko.options = vial_ko_option_activation_negative_mod_up | vial_ko_option_activation_required_mod_down | vial_ko_option_activation_trigger_down;
for (size_t i = 0; i < VIAL_KEY_OVERRIDE_ENTRIES; ++i)
dynamic_keymap_set_key_override(i, &ko);
#endif
#ifdef VIAL_ENABLE
/* re-lock the keyboard */
vial_unlocked = vial_unlocked_prev;
@ -441,6 +481,13 @@ void dynamic_keymap_macro_reset(void) {
}
}
static uint16_t decode_keycode(uint16_t kc) {
/* map 0xFF01 => 0x0100; 0xFF02 => 0x0200, etc */
if (kc > 0xFF00)
return (kc & 0xFF) << 8;
return kc;
}
void dynamic_keymap_macro_send(uint8_t id) {
if (id >= DYNAMIC_KEYMAP_MACRO_COUNT) {
return;
@ -495,6 +542,27 @@ void dynamic_keymap_macro_send(uint8_t id) {
data[2] = eeprom_read_byte(p++);
if (data[2] != 0)
send_string(data);
} else if (data[1] == VIAL_MACRO_EXT_TAP || data[1] == VIAL_MACRO_EXT_DOWN || data[1] == VIAL_MACRO_EXT_UP) {
data[2] = eeprom_read_byte(p++);
if (data[2] != 0) {
data[3] = eeprom_read_byte(p++);
if (data[3] != 0) {
uint16_t kc;
memcpy(&kc, &data[2], sizeof(kc));
kc = decode_keycode(kc);
switch (data[1]) {
case VIAL_MACRO_EXT_TAP:
vial_keycode_tap(kc);
break;
case VIAL_MACRO_EXT_DOWN:
vial_keycode_down(kc);
break;
case VIAL_MACRO_EXT_UP:
vial_keycode_up(kc);
break;
}
}
}
} else if (data[1] == SS_DELAY_CODE) {
// For delay, decode the delay and wait_ms for that amount
uint8_t d0 = eeprom_read_byte(p++);

View File

@ -46,6 +46,10 @@ int dynamic_keymap_set_tap_dance(uint8_t index, const vial_tap_dance_entry_t *en
int dynamic_keymap_get_combo(uint8_t index, vial_combo_entry_t *entry);
int dynamic_keymap_set_combo(uint8_t index, const vial_combo_entry_t *entry);
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
int dynamic_keymap_get_key_override(uint8_t index, vial_key_override_entry_t *entry);
int dynamic_keymap_set_key_override(uint8_t index, const vial_key_override_entry_t *entry);
#endif
void dynamic_keymap_reset(void);
// These get/set the keycodes as stored in the EEPROM buffer
// Data is big-endian 16-bit values (the keycodes)

View File

@ -18,6 +18,7 @@
#include "quantum_keycodes.h"
#include "action_tapping.h"
#include "usb_device_state.h"
#include "qmk_settings.h"
__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
@ -26,7 +27,7 @@ __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t
if (record->tap.count == 0) return false;
break;
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
if (record->tap.count != TAPPING_TOGGLE) return false;
if (record->tap.count != QS_tapping_toggle) return false;
break;
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
if (record->tap.count == 0) return false;

View File

@ -54,6 +54,7 @@ static const qmk_settings_proto_t protos[] PROGMEM = {
#endif
DECLARE_SETTING(18, tap_code_delay),
DECLARE_SETTING(19, tap_hold_caps_delay),
DECLARE_SETTING(20, tapping_toggle),
};
static const qmk_settings_proto_t *find_setting(uint16_t qsid) {
@ -116,6 +117,7 @@ void qmk_settings_reset(void) {
QS.tapping = 0;
QS.tap_code_delay = TAP_CODE_DELAY;
QS.tap_hold_caps_delay = TAP_HOLD_CAPS_DELAY;
QS.tapping_toggle = TAPPING_TOGGLE;
save_settings();
/* to trigger all callbacks */

View File

@ -120,8 +120,10 @@ typedef struct {
uint8_t tapping;
uint16_t tap_code_delay;
uint16_t tap_hold_caps_delay;
uint8_t tapping_toggle;
uint8_t unused;
} qmk_settings_t;
_Static_assert(sizeof(qmk_settings_t) == 34, "unexpected size of the qmk_settings_t structure");
_Static_assert(sizeof(qmk_settings_t) == 36, "unexpected size of the qmk_settings_t structure");
typedef void (*qmk_setting_callback_t)(void);
@ -170,6 +172,9 @@ extern qmk_settings_t QS;
#define QS_tap_code_delay (QS.tap_code_delay)
#define QS_tap_hold_caps_delay (QS.tap_hold_caps_delay)
/* Tapping Toggle */
#define QS_tapping_toggle (QS.tapping_toggle)
#else
/* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */
@ -202,6 +207,9 @@ extern qmk_settings_t QS;
#define QS_tap_code_delay TAP_CODE_DELAY
#define QS_tap_hold_caps_delay TAP_HOLD_CAPS_DELAY
/* Tapping Toggle */
#define QS_tapping_toggle TAPPING_TOGGLE
#endif
#if defined(__AVR__) && defined(QMK_SETTINGS)

View File

@ -58,6 +58,10 @@ static void reload_tap_dance(void);
static void reload_combo(void);
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
static void reload_key_override(void);
#endif
void vial_init(void) {
#ifdef VIAL_TAP_DANCE_ENABLE
reload_tap_dance();
@ -65,6 +69,9 @@ void vial_init(void) {
#ifdef VIAL_COMBO_ENABLE
reload_combo();
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
reload_key_override();
#endif
}
void vial_handle_cmd(uint8_t *msg, uint8_t length) {
@ -214,6 +221,7 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {
memset(msg, 0, length);
msg[0] = VIAL_TAP_DANCE_ENTRIES;
msg[1] = VIAL_COMBO_ENTRIES;
msg[2] = VIAL_KEY_OVERRIDE_ENTRIES;
break;
}
#ifdef VIAL_TAP_DANCE_ENABLE
@ -249,6 +257,23 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {
reload_combo();
break;
}
#endif
#ifdef VIAL_KEY_OVERRIDE_ENABLE
case dynamic_vial_key_override_get: {
uint8_t idx = msg[3];
vial_key_override_entry_t entry = { 0 };
msg[0] = dynamic_keymap_get_key_override(idx, &entry);
memcpy(&msg[1], &entry, sizeof(entry));
break;
}
case dynamic_vial_key_override_set: {
uint8_t idx = msg[3];
vial_key_override_entry_t entry;
memcpy(&entry, &msg[4], sizeof(entry));
msg[0] = dynamic_keymap_set_key_override(idx, &entry);
reload_key_override();
break;
}
#endif
}
@ -259,7 +284,7 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {
uint16_t g_vial_magic_keycode_override;
static void vial_keycode_down(uint16_t keycode) {
void vial_keycode_down(uint16_t keycode) {
g_vial_magic_keycode_override = keycode;
if (keycode <= QK_MODS_MAX) {
@ -271,7 +296,7 @@ static void vial_keycode_down(uint16_t keycode) {
}
}
static void vial_keycode_up(uint16_t keycode) {
void vial_keycode_up(uint16_t keycode) {
g_vial_magic_keycode_override = keycode;
if (keycode <= QK_MODS_MAX) {
@ -283,9 +308,7 @@ static void vial_keycode_up(uint16_t keycode) {
}
}
static void vial_keycode_tap(uint16_t keycode) __attribute__((unused));
static void vial_keycode_tap(uint16_t keycode) {
void vial_keycode_tap(uint16_t keycode) {
vial_keycode_down(keycode);
qs_wait_ms(QS_tap_code_delay);
vial_keycode_up(keycode);
@ -544,3 +567,48 @@ bool process_record_vial(uint16_t keycode, keyrecord_t *record) {
return true;
}
#ifdef VIAL_KEY_OVERRIDE_ENABLE
static bool vial_key_override_disabled = 0;
static key_override_t overrides[VIAL_KEY_OVERRIDE_ENTRIES] = { 0 };
static key_override_t *override_ptrs[VIAL_KEY_OVERRIDE_ENTRIES + 1] = { 0 };
const key_override_t **key_overrides = (const key_override_t**)override_ptrs;
static int vial_get_key_override(uint8_t index, key_override_t *out) {
vial_key_override_entry_t entry;
int ret;
if ((ret = dynamic_keymap_get_key_override(index, &entry)) != 0)
return ret;
memset(out, 0, sizeof(*out));
out->trigger = entry.trigger;
out->trigger_mods = entry.trigger_mods;
out->layers = entry.layers;
out->negative_mod_mask = entry.negative_mod_mask;
out->suppressed_mods = entry.suppressed_mods;
out->replacement = entry.replacement;
out->options = 0;
uint8_t opt = entry.options;
if (opt & vial_ko_enabled)
out->enabled = NULL;
else
out->enabled = &vial_key_override_disabled;
/* right now these options match one-to-one so this isn't strictly necessary,
nevertheless future-proof the code by parsing them out to ensure "stable" abi */
if (opt & vial_ko_option_activation_trigger_down) out->options |= ko_option_activation_trigger_down;
if (opt & vial_ko_option_activation_required_mod_down) out->options |= ko_option_activation_required_mod_down;
if (opt & vial_ko_option_activation_negative_mod_up) out->options |= ko_option_activation_negative_mod_up;
if (opt & vial_ko_option_one_mod) out->options |= ko_option_one_mod;
if (opt & vial_ko_option_no_reregister_trigger) out->options |= ko_option_no_reregister_trigger;
if (opt & vial_ko_option_no_unregister_on_other_key_down) out->options |= ko_option_no_unregister_on_other_key_down;
return 0;
}
static void reload_key_override(void) {
for (size_t i = 0; i < VIAL_KEY_OVERRIDE_ENTRIES; ++i) {
override_ptrs[i] = &overrides[i];
vial_get_key_override(i, &overrides[i]);
}
}
#endif

View File

@ -22,7 +22,7 @@
#include "eeprom.h"
#include "action.h"
#define VIAL_PROTOCOL_VERSION ((uint32_t)0x00000004)
#define VIAL_PROTOCOL_VERSION ((uint32_t)0x00000005)
#define VIAL_RAW_EPSIZE 32
void vial_init(void);
@ -59,14 +59,24 @@ enum {
dynamic_vial_tap_dance_set = 0x02,
dynamic_vial_combo_get = 0x03,
dynamic_vial_combo_set = 0x04,
dynamic_vial_key_override_get = 0x05,
dynamic_vial_key_override_set = 0x06,
};
#define VIAL_MACRO_EXT_TAP 5
#define VIAL_MACRO_EXT_DOWN 6
#define VIAL_MACRO_EXT_UP 7
void vial_keycode_down(uint16_t keycode);
void vial_keycode_up(uint16_t keycode);
void vial_keycode_tap(uint16_t keycode);
/* Fake position in keyboard matrix, can't use 255 as that is immediately rejected by IS_NOEVENT
used to send arbitrary keycodes thru process_record_quantum_helper */
#define VIAL_MATRIX_MAGIC 254
#ifdef TAP_DANCE_ENABLE
#ifdef TAP_DANCE_ENABLE
#define VIAL_TAP_DANCE_ENABLE
#ifndef VIAL_TAP_DANCE_ENTRIES
@ -95,6 +105,7 @@ _Static_assert(sizeof(vial_tap_dance_entry_t) == 10, "Unexpected size of the via
#define VIAL_TAP_DANCE_ENTRIES 0
#endif
#ifdef COMBO_ENABLE
#define VIAL_COMBO_ENABLE
@ -127,3 +138,49 @@ _Static_assert(sizeof(vial_combo_entry_t) == 10, "Unexpected size of the vial_co
#undef VIAL_COMBO_ENTRIES
#define VIAL_COMBO_ENTRIES 0
#endif
#ifdef KEY_OVERRIDE_ENABLE
#define VIAL_KEY_OVERRIDE_ENABLE
#include "process_key_override.h"
#ifndef VIAL_KEY_OVERRIDE_ENTRIES
#if TOTAL_EEPROM_BYTE_COUNT > 4000
#define VIAL_KEY_OVERRIDE_ENTRIES 32
#elif TOTAL_EEPROM_BYTE_COUNT > 2000
#define VIAL_KEY_OVERRIDE_ENTRIES 16
#elif TOTAL_EEPROM_BYTE_COUNT > 1000
#define VIAL_KEY_OVERRIDE_ENTRIES 8
#else
#define VIAL_KEY_OVERRIDE_ENTRIES 4
#endif
#endif
/* the key override structure as it is stored in eeprom and transferred to vial-gui;
it is deserialized into key_override_t by vial_get_key_override */
typedef struct {
uint16_t trigger;
uint16_t replacement;
uint16_t layers;
uint8_t trigger_mods;
uint8_t negative_mod_mask;
uint8_t suppressed_mods;
uint8_t options;
} vial_key_override_entry_t;
_Static_assert(sizeof(vial_key_override_entry_t) == 10, "Unexpected size of the vial_key_override_entry_t structure");
enum {
vial_ko_option_activation_trigger_down = (1 << 0),
vial_ko_option_activation_required_mod_down = (1 << 1),
vial_ko_option_activation_negative_mod_up = (1 << 2),
vial_ko_option_one_mod = (1 << 3),
vial_ko_option_no_reregister_trigger = (1 << 4),
vial_ko_option_no_unregister_on_other_key_down = (1 << 5),
vial_ko_enabled = (1 << 7),
};
#else
#undef VIAL_KEY_OVERRIDE_ENTRIES
#define VIAL_KEY_OVERRIDE_ENTRIES 0
#endif

View File

@ -490,3 +490,13 @@ _Static_assert(MI_MODSD == 0x5CB7, "");
_Static_assert(MI_MODSU == 0x5CB8, "");
_Static_assert(MI_BENDD == 0x5CB9, "");
_Static_assert(MI_BENDU == 0x5CBA, "");
_Static_assert(KC_ASUP == 0x5C17, "");
_Static_assert(KC_ASDN == 0x5C18, "");
_Static_assert(KC_ASRP == 0x5C19, "");
_Static_assert(KC_ASTG == 0x5C1A, "");
_Static_assert(KC_ASON == 0x5C1B, "");
_Static_assert(KC_ASOFF == 0x5C1C, "");
_Static_assert(CMB_ON == 0x5CF7, "");
_Static_assert(CMB_OFF == 0x5CF8, "");
_Static_assert(CMB_TOG == 0x5CF9, "");