From 92a61aa0cd9a28056e6979f01a72b8742702dbfe Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sat, 16 Apr 2022 19:13:05 +0100 Subject: [PATCH 1/8] Implement XAP 'secure' core requirements (#16843) Co-authored-by: Drashna Jaelre Co-authored-by: Stefan Kerkmann --- builddefs/generic_features.mk | 1 + builddefs/show_options.mk | 3 +- data/mappings/info_config.json | 3 + data/mappings/info_rules.json | 1 + data/schemas/keyboard.jsonschema | 24 +++++++ lib/python/qmk/cli/generate/config_h.py | 7 +- lib/python/qmk/info.py | 56 ++++++++++++--- quantum/keyboard.c | 4 ++ quantum/process_keycode/process_secure.c | 39 +++++++++++ quantum/process_keycode/process_secure.h | 15 ++++ quantum/quantum.c | 9 +++ quantum/quantum.h | 5 ++ quantum/quantum_keycodes.h | 4 ++ quantum/secure.c | 87 ++++++++++++++++++++++++ quantum/secure.h | 67 ++++++++++++++++++ 15 files changed, 312 insertions(+), 13 deletions(-) create mode 100644 quantum/process_keycode/process_secure.c create mode 100644 quantum/process_keycode/process_secure.h create mode 100644 quantum/secure.c create mode 100644 quantum/secure.h diff --git a/builddefs/generic_features.mk b/builddefs/generic_features.mk index 53d4e16fd42..0475a2ff09b 100644 --- a/builddefs/generic_features.mk +++ b/builddefs/generic_features.mk @@ -32,6 +32,7 @@ GENERIC_FEATURES = \ KEY_OVERRIDE \ LEADER \ PROGRAMMABLE_BUTTON \ + SECURE \ SPACE_CADET \ SWAP_HANDS \ TAP_DANCE \ diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk index b30399a56ca..16b69ef0ea8 100644 --- a/builddefs/show_options.mk +++ b/builddefs/show_options.mk @@ -80,7 +80,8 @@ OTHER_OPTION_NAMES = \ LED_MIRRORED \ RGBLIGHT_FULL_POWER \ LTO_ENABLE \ - PROGRAMMABLE_BUTTON_ENABLE + PROGRAMMABLE_BUTTON_ENABLE \ + SECURE_ENABLE define NAME_ECHO @printf " %-30s = %-16s # %s\\n" "$1" "$($1)" "$(origin $1)" diff --git a/data/mappings/info_config.json b/data/mappings/info_config.json index 2121741d199..02ad3226c28 100644 --- a/data/mappings/info_config.json +++ b/data/mappings/info_config.json @@ -78,6 +78,9 @@ "QMK_KEYS_PER_SCAN": {"info_key": "qmk.keys_per_scan", "value_type": "int"}, "QMK_LED": {"info_key": "qmk_lufa_bootloader.led"}, "QMK_SPEAKER": {"info_key": "qmk_lufa_bootloader.speaker"}, + "SECURE_UNLOCK_SEQUENCE": {"info_key": "secure.unlock_sequence", "value_type": "array.array.int", "to_json": false}, + "SECURE_UNLOCK_TIMEOUT": {"info_key": "secure.unlock_timeout", "value_type": "int"}, + "SECURE_IDLE_TIMEOUT": {"info_key": "secure.idle_timeout", "value_type": "int"}, "SENDSTRING_BELL": {"info_key": "audio.macro_beep", "value_type": "bool"}, "SPLIT_MODS_ENABLE": {"info_key": "split.transport.sync_modifiers", "value_type": "bool"}, "SPLIT_TRANSPORT_MIRROR": {"info_key": "split.transport.sync_matrix_state", "value_type": "bool"}, diff --git a/data/mappings/info_rules.json b/data/mappings/info_rules.json index 237e9f10246..4b0fde56297 100644 --- a/data/mappings/info_rules.json +++ b/data/mappings/info_rules.json @@ -20,6 +20,7 @@ "MOUSEKEY_ENABLE": {"info_key": "mouse_key.enabled", "value_type": "bool"}, "NO_USB_STARTUP_CHECK": {"info_key": "usb.no_startup_check", "value_type": "bool"}, "PIN_COMPATIBLE": {"info_key": "pin_compatible"}, + "SECURE_ENABLE": {"info_key": "secure.enabled", "value_type": "bool"}, "SPLIT_KEYBOARD": {"info_key": "split.enabled", "value_type": "bool"}, "SPLIT_TRANSPORT": {"info_key": "split.transport.protocol", "to_c": false}, "WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"} diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 68a02420a41..6b1e543e485 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -244,6 +244,30 @@ } } }, + "secure": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": {"type": "boolean"}, + "unlock_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}, + "idle_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}, + "unlock_sequence": { + "type": "array", + "minLength": 1, + "maxLength": 5, + "items": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "type": "number", + "min": 0, + "multipleOf": 1 + } + } + } + } + }, "split": { "type": "object", "additionalProperties": false, diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 20c9595ed7d..893892c4794 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -94,7 +94,12 @@ def generate_config_items(kb_info_json, config_h_lines): except KeyError: continue - if key_type.startswith('array'): + if key_type.startswith('array.array'): + config_h_lines.append('') + config_h_lines.append(f'#ifndef {config_key}') + config_h_lines.append(f'# define {config_key} {{ {", ".join(["{" + ",".join(list(map(str, x))) + "}" for x in config_value])} }}') + config_h_lines.append(f'#endif // {config_key}') + elif key_type.startswith('array'): config_h_lines.append('') config_h_lines.append(f'#ifndef {config_key}') config_h_lines.append(f'# define {config_key} {{ {", ".join(map(str, config_value))} }}') diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index c5a7d338486..49d10545190 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -168,28 +168,46 @@ def _extract_pins(pins): return [_pin_name(pin) for pin in pins.split(',')] -def _extract_direct_matrix(direct_pins): +def _extract_2d_array(raw): + """Return a 2d array of strings """ - """ - direct_pin_array = [] + out_array = [] - while direct_pins[-1] != '}': - direct_pins = direct_pins[:-1] + while raw[-1] != '}': + raw = raw[:-1] - for row in direct_pins.split('},{'): + for row in raw.split('},{'): if row.startswith('{'): row = row[1:] if row.endswith('}'): row = row[:-1] - direct_pin_array.append([]) + out_array.append([]) - for pin in row.split(','): - if pin == 'NO_PIN': - pin = None + for val in row.split(','): + out_array[-1].append(val) - direct_pin_array[-1].append(pin) + return out_array + + +def _extract_2d_int_array(raw): + """Return a 2d array of ints + """ + ret = _extract_2d_array(raw) + + return [list(map(int, x)) for x in ret] + + +def _extract_direct_matrix(direct_pins): + """extract direct_matrix + """ + direct_pin_array = _extract_2d_array(direct_pins) + + for i in range(len(direct_pin_array)): + for j in range(len(direct_pin_array[i])): + if direct_pin_array[i][j] == 'NO_PIN': + direct_pin_array[i][j] = None return direct_pin_array @@ -207,6 +225,21 @@ def _extract_audio(info_data, config_c): info_data['audio'] = {'pins': audio_pins} +def _extract_secure_unlock(info_data, config_c): + """Populate data about the secure unlock sequence + """ + unlock = config_c.get('SECURE_UNLOCK_SEQUENCE', '').replace(' ', '')[1:-1] + if unlock: + unlock_array = _extract_2d_int_array(unlock) + if 'secure' not in info_data: + info_data['secure'] = {} + + if 'unlock_sequence' in info_data['secure']: + _log_warning(info_data, 'Secure unlock sequence is specified in both config.h (SECURE_UNLOCK_SEQUENCE) and info.json (secure.unlock_sequence) (Value: %s), the config.h value wins.' % info_data['secure']['unlock_sequence']) + + info_data['secure']['unlock_sequence'] = unlock_array + + def _extract_split_main(info_data, config_c): """Populate data about the split configuration """ @@ -466,6 +499,7 @@ def _extract_config_h(info_data, config_c): # Pull data that easily can't be mapped in json _extract_matrix_info(info_data, config_c) _extract_audio(info_data, config_c) + _extract_secure_unlock(info_data, config_c) _extract_split_main(info_data, config_c) _extract_split_transport(info_data, config_c) _extract_split_right_pins(info_data, config_c) diff --git a/quantum/keyboard.c b/quantum/keyboard.c index fc8a2fe8e39..63236f0b20b 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -562,6 +562,10 @@ void quantum_task(void) { #ifdef AUTO_SHIFT_ENABLE autoshift_matrix_scan(); #endif + +#ifdef SECURE_ENABLE + secure_task(); +#endif } /** \brief Keyboard task: Do keyboard routine jobs diff --git a/quantum/process_keycode/process_secure.c b/quantum/process_keycode/process_secure.c new file mode 100644 index 00000000000..827ace597a8 --- /dev/null +++ b/quantum/process_keycode/process_secure.c @@ -0,0 +1,39 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "secure.h" +#include "process_secure.h" +#include "quantum_keycodes.h" + +bool preprocess_secure(uint16_t keycode, keyrecord_t *record) { + if (secure_is_unlocking()) { + if (!record->event.pressed) { + secure_keypress_event(record->event.key.row, record->event.key.col); + } + + // Normal keypresses should be disabled until the sequence is completed + return false; + } + + return true; +} + +bool process_secure(uint16_t keycode, keyrecord_t *record) { +#ifndef SECURE_DISABLE_KEYCODES + if (!record->event.pressed) { + if (keycode == SECURE_LOCK) { + secure_lock(); + return false; + } + if (keycode == SECURE_UNLOCK) { + secure_unlock(); + return false; + } + if (keycode == SECURE_TOGGLE) { + secure_is_locked() ? secure_unlock() : secure_lock(); + return false; + } + } +#endif + return true; +} \ No newline at end of file diff --git a/quantum/process_keycode/process_secure.h b/quantum/process_keycode/process_secure.h new file mode 100644 index 00000000000..2814264b92f --- /dev/null +++ b/quantum/process_keycode/process_secure.h @@ -0,0 +1,15 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include "action.h" + +/** \brief Intercept keycodes and detect unlock sequences + */ +bool preprocess_secure(uint16_t keycode, keyrecord_t *record); + +/** \brief Handle any secure specific keycodes + */ +bool process_secure(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index d4e91ddd37f..673ea91b11f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -212,6 +212,12 @@ bool process_record_quantum(keyrecord_t *record) { // return false; // } +#if defined(SECURE_ENABLE) + if (!preprocess_secure(keycode, record)) { + return false; + } +#endif + #ifdef VELOCIKEY_ENABLE if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); @@ -247,6 +253,9 @@ bool process_record_quantum(keyrecord_t *record) { process_record_via(keycode, record) && #endif process_record_kb(keycode, record) && +#if defined(SECURE_ENABLE) + process_secure(keycode, record) && +#endif #if defined(SEQUENCER_ENABLE) process_sequencer(keycode, record) && #endif diff --git a/quantum/quantum.h b/quantum/quantum.h index 9ce3c1f5d62..d021e7c05c1 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -200,6 +200,11 @@ extern layer_state_t layer_state; # include "process_dynamic_macro.h" #endif +#ifdef SECURE_ENABLE +# include "secure.h" +# include "process_secure.h" +#endif + #ifdef DYNAMIC_KEYMAP_ENABLE # include "dynamic_keymap.h" #endif diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index dacfe5bdcd2..c7b4ea593fe 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -597,6 +597,10 @@ enum quantum_keycodes { QK_MAKE, + SECURE_LOCK, + SECURE_UNLOCK, + SECURE_TOGGLE, + // Start of custom keycode range for keyboards and keymaps - always leave at the end SAFE_RANGE }; diff --git a/quantum/secure.c b/quantum/secure.c new file mode 100644 index 00000000000..00048bd6dd5 --- /dev/null +++ b/quantum/secure.c @@ -0,0 +1,87 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "secure.h" +#include "timer.h" + +#ifndef SECURE_UNLOCK_TIMEOUT +# define SECURE_UNLOCK_TIMEOUT 5000 +#endif + +#ifndef SECURE_IDLE_TIMEOUT +# define SECURE_IDLE_TIMEOUT 60000 +#endif + +#ifndef SECURE_UNLOCK_SEQUENCE +# define SECURE_UNLOCK_SEQUENCE \ + { \ + { 0, 0 } \ + } +#endif + +static secure_status_t secure_status = SECURE_LOCKED; +static uint32_t unlock_time = 0; +static uint32_t idle_time = 0; + +secure_status_t secure_get_status(void) { + return secure_status; +} + +void secure_lock(void) { + secure_status = SECURE_LOCKED; +} + +void secure_unlock(void) { + secure_status = SECURE_UNLOCKED; + idle_time = timer_read32(); +} + +void secure_request_unlock(void) { + if (secure_status == SECURE_LOCKED) { + secure_status = SECURE_PENDING; + unlock_time = timer_read32(); + } +} + +void secure_activity_event(void) { + if (secure_status == SECURE_UNLOCKED) { + idle_time = timer_read32(); + } +} + +void secure_keypress_event(uint8_t row, uint8_t col) { + static const uint8_t sequence[][2] = SECURE_UNLOCK_SEQUENCE; + static const uint8_t sequence_len = sizeof(sequence) / sizeof(sequence[0]); + + static uint8_t offset = 0; + if ((sequence[offset][0] == row) && (sequence[offset][1] == col)) { + offset++; + if (offset == sequence_len) { + offset = 0; + secure_unlock(); + } + } else { + offset = 0; + secure_lock(); + } +} + +void secure_task(void) { +#if SECURE_UNLOCK_TIMEOUT != 0 + // handle unlock timeout + if (secure_status == SECURE_PENDING) { + if (timer_elapsed32(unlock_time) >= SECURE_UNLOCK_TIMEOUT) { + secure_lock(); + } + } +#endif + +#if SECURE_IDLE_TIMEOUT != 0 + // handle idle timeout + if (secure_status == SECURE_UNLOCKED) { + if (timer_elapsed32(idle_time) >= SECURE_IDLE_TIMEOUT) { + secure_lock(); + } + } +#endif +} diff --git a/quantum/secure.h b/quantum/secure.h new file mode 100644 index 00000000000..04507fd5b13 --- /dev/null +++ b/quantum/secure.h @@ -0,0 +1,67 @@ +// Copyright 2022 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +/** \file + * + * Exposes a set of functionality to act as a virtual padlock for your device + * ... As long as that padlock is made of paper and its currently raining. + */ + +#include +#include + +/** \brief Available secure states + */ +typedef enum { + SECURE_LOCKED, + SECURE_PENDING, + SECURE_UNLOCKED, +} secure_status_t; + +/** \brief Query current secure state + */ +secure_status_t secure_get_status(void); + +/** \brief Helper to check if unlocking is currently locked + */ +#define secure_is_locked() (secure_get_status() == SECURE_LOCKED) + +/** \brief Helper to check if unlocking is currently in progress + */ +#define secure_is_unlocking() (secure_get_status() == SECURE_PENDING) + +/** \brief Helper to check if unlocking is currently unlocked + */ +#define secure_is_unlocked() (secure_get_status() == SECURE_UNLOCKED) + +/** \brief Lock down the device + */ +void secure_lock(void); + +/** \brief Force unlock the device + * + * \warning bypasses user unlock sequence + */ +void secure_unlock(void); + +/** \brief Begin listening for an unlock sequence + */ +void secure_request_unlock(void); + +/** \brief Flag to the secure subsystem that user activity has happened + * + * Call when some user activity has happened and the device should remain unlocked + */ +void secure_activity_event(void); + +/** \brief Flag to the secure subsystem that user has triggered a keypress + * + * Call to trigger processing of the unlock sequence + */ +void secure_keypress_event(uint8_t row, uint8_t col); + +/** \brief Handle various secure subsystem background tasks + */ +void secure_task(void); From 7d75f88ac9c5532c45e4d2dcbe3bde8a1a0b065e Mon Sep 17 00:00:00 2001 From: X-Bows Tech <41098278+XBowsTech@users.noreply.github.com> Date: Sun, 17 Apr 2022 02:19:24 +0800 Subject: [PATCH 2/8] [Keyboard] Update X-Bows Keyboard (#16765) Co-authored-by: Ryan Co-authored-by: Drashna Jaelre Co-authored-by: Shulin --- keyboards/xbows/knight/config.h | 4 ++-- keyboards/xbows/knight/keymaps/via/rules.mk | 1 + keyboards/xbows/knight_plus/config.h | 4 ++-- keyboards/xbows/knight_plus/keymaps/via/rules.mk | 1 + keyboards/xbows/nature/config.h | 6 +++--- keyboards/xbows/nature/keymaps/via/rules.mk | 1 + keyboards/xbows/nature/rules.mk | 1 - keyboards/xbows/numpad/config.h | 4 ++-- keyboards/xbows/numpad/keymaps/via/rules.mk | 1 + keyboards/xbows/ranger/config.h | 4 ++-- keyboards/xbows/ranger/keymaps/via/rules.mk | 1 + 11 files changed, 16 insertions(+), 12 deletions(-) diff --git a/keyboards/xbows/knight/config.h b/keyboards/xbows/knight/config.h index be7b2bfe9f4..013bb4e7d42 100644 --- a/keyboards/xbows/knight/config.h +++ b/keyboards/xbows/knight/config.h @@ -17,8 +17,8 @@ #include "config_common.h" -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x1225 +#define VENDOR_ID 0x5842 +#define PRODUCT_ID 0x4B6E #define DEVICE_VER 0x0001 #define MANUFACTURER X-BOWS #define PRODUCT KNIGHT diff --git a/keyboards/xbows/knight/keymaps/via/rules.mk b/keyboards/xbows/knight/keymaps/via/rules.mk index 1e5b99807cb..36b7ba9cbc9 100644 --- a/keyboards/xbows/knight/keymaps/via/rules.mk +++ b/keyboards/xbows/knight/keymaps/via/rules.mk @@ -1 +1,2 @@ VIA_ENABLE = yes +LTO_ENABLE = yes diff --git a/keyboards/xbows/knight_plus/config.h b/keyboards/xbows/knight_plus/config.h index e9e82c13dfc..414b5a86b7c 100644 --- a/keyboards/xbows/knight_plus/config.h +++ b/keyboards/xbows/knight_plus/config.h @@ -17,8 +17,8 @@ #include "config_common.h" -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x1227 +#define VENDOR_ID 0x5842 +#define PRODUCT_ID 0x4B50 #define DEVICE_VER 0x0001 #define MANUFACTURER X-BOWS #define PRODUCT KNIGHT_PLUS diff --git a/keyboards/xbows/knight_plus/keymaps/via/rules.mk b/keyboards/xbows/knight_plus/keymaps/via/rules.mk index 1e5b99807cb..36b7ba9cbc9 100644 --- a/keyboards/xbows/knight_plus/keymaps/via/rules.mk +++ b/keyboards/xbows/knight_plus/keymaps/via/rules.mk @@ -1 +1,2 @@ VIA_ENABLE = yes +LTO_ENABLE = yes diff --git a/keyboards/xbows/nature/config.h b/keyboards/xbows/nature/config.h index 0fc0accb590..d9d6a2753eb 100644 --- a/keyboards/xbows/nature/config.h +++ b/keyboards/xbows/nature/config.h @@ -17,8 +17,8 @@ #include "config_common.h" -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x1226 +#define VENDOR_ID 0x5842 +#define PRODUCT_ID 0x4E61 #define DEVICE_VER 0x0001 #define MANUFACTURER X-BOWS #define PRODUCT NATURE @@ -35,7 +35,7 @@ # define RGB_MATRIX_LED_FLUSH_LIMIT 16 # define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects # define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended -// # define RGB_MATRIX_KEYPRESSES +# define RGB_MATRIX_KEYPRESSES # define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 # define RGB_MATRIX_CENTER \ { 92, 33 } diff --git a/keyboards/xbows/nature/keymaps/via/rules.mk b/keyboards/xbows/nature/keymaps/via/rules.mk index 1e5b99807cb..36b7ba9cbc9 100644 --- a/keyboards/xbows/nature/keymaps/via/rules.mk +++ b/keyboards/xbows/nature/keymaps/via/rules.mk @@ -1 +1,2 @@ VIA_ENABLE = yes +LTO_ENABLE = yes diff --git a/keyboards/xbows/nature/rules.mk b/keyboards/xbows/nature/rules.mk index 5ff72e1df86..9dec74c970f 100644 --- a/keyboards/xbows/nature/rules.mk +++ b/keyboards/xbows/nature/rules.mk @@ -16,6 +16,5 @@ NKRO_ENABLE = yes # Enable N-Key Rollover BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output -SLEEP_LED_ENABLE = yes RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = IS31FL3731 diff --git a/keyboards/xbows/numpad/config.h b/keyboards/xbows/numpad/config.h index 04604676bc1..c36ee1a52c2 100644 --- a/keyboards/xbows/numpad/config.h +++ b/keyboards/xbows/numpad/config.h @@ -17,8 +17,8 @@ #include "config_common.h" -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x1228 +#define VENDOR_ID 0x5842 +#define PRODUCT_ID 0x4E75 #define DEVICE_VER 0x0001 #define MANUFACTURER X-BOWS #define PRODUCT NUMPAD diff --git a/keyboards/xbows/numpad/keymaps/via/rules.mk b/keyboards/xbows/numpad/keymaps/via/rules.mk index 1e5b99807cb..36b7ba9cbc9 100644 --- a/keyboards/xbows/numpad/keymaps/via/rules.mk +++ b/keyboards/xbows/numpad/keymaps/via/rules.mk @@ -1 +1,2 @@ VIA_ENABLE = yes +LTO_ENABLE = yes diff --git a/keyboards/xbows/ranger/config.h b/keyboards/xbows/ranger/config.h index a7bcee7b4fc..73a1bc3a747 100644 --- a/keyboards/xbows/ranger/config.h +++ b/keyboards/xbows/ranger/config.h @@ -17,8 +17,8 @@ #include "config_common.h" -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0x1229 +#define VENDOR_ID 0x5842 +#define PRODUCT_ID 0x5261 #define DEVICE_VER 0x0001 #define MANUFACTURER X-BOWS #define PRODUCT Ranger diff --git a/keyboards/xbows/ranger/keymaps/via/rules.mk b/keyboards/xbows/ranger/keymaps/via/rules.mk index 1e5b99807cb..36b7ba9cbc9 100644 --- a/keyboards/xbows/ranger/keymaps/via/rules.mk +++ b/keyboards/xbows/ranger/keymaps/via/rules.mk @@ -1 +1,2 @@ VIA_ENABLE = yes +LTO_ENABLE = yes From 8f585153c470b07bb0c529ff49b39ef45f68d37e Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Sat, 16 Apr 2022 20:24:09 +0200 Subject: [PATCH 3/8] Add GET_TAPPING_TERM macro to reduce duplicate code (#16681) * Add GET_TAPPING_TERM macro to reduce duplicate code The macro gives the right tapping term depending on whether per-key tapping terms and/or dynamic tapping terms are enabled. Unnecessary function calls and variable resolution are avoided. Fixes #16472. * Use GET_TAPPING_TERM for Cirque trackpads Co-authored-by: Stefan Kerkmann --- docs/tap_hold.md | 2 +- quantum/action_tapping.c | 27 ++++++++----------- quantum/action_tapping.h | 8 ++++++ quantum/pointing_device_drivers.c | 14 +++------- quantum/process_keycode/process_auto_shift.c | 7 +---- quantum/process_keycode/process_space_cadet.c | 7 +---- quantum/process_keycode/process_tap_dance.c | 6 +---- 7 files changed, 26 insertions(+), 45 deletions(-) diff --git a/docs/tap_hold.md b/docs/tap_hold.md index 39fa84a9f34..601aef0493e 100644 --- a/docs/tap_hold.md +++ b/docs/tap_hold.md @@ -112,7 +112,7 @@ uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { } ``` -The reason being that `TAPPING_TERM` is a macro that expands to a constant integer and thus cannot be changed at runtime whereas `g_tapping_term` is a variable whose value can be changed at runtime. If you want, you can temporarily enable `DYNAMIC_TAPPING_TERM_ENABLE` to find a suitable tapping term value and then disable that feature and revert back to using the classic syntax for per-key tapping term settings. +The reason being that `TAPPING_TERM` is a macro that expands to a constant integer and thus cannot be changed at runtime whereas `g_tapping_term` is a variable whose value can be changed at runtime. If you want, you can temporarily enable `DYNAMIC_TAPPING_TERM_ENABLE` to find a suitable tapping term value and then disable that feature and revert back to using the classic syntax for per-key tapping term settings. In case you need to access the tapping term from elsewhere in your code, you can use the `GET_TAPPING_TERM(keycode, record)` macro. This macro will expand to whatever is the appropriate access pattern given the current configuration. ## Tap-Or-Hold Decision Modes diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index e4366194289..3c8b5678b79 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c @@ -24,17 +24,20 @@ # else # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) # endif +# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_TAPPING_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) +# ifdef DYNAMIC_TAPPING_TERM_ENABLE uint16_t g_tapping_term = TAPPING_TERM; - -__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { - return g_tapping_term; -} +# endif # ifdef TAPPING_TERM_PER_KEY -# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_record_keycode(&tapping_key, false), &tapping_key)) -# else -# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < g_tapping_term) +__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { +# ifdef DYNAMIC_TAPPING_TERM_ENABLE + return g_tapping_term; +# else + return TAPPING_TERM; +# endif +} # endif # ifdef TAPPING_FORCE_HOLD_PER_KEY @@ -165,15 +168,7 @@ bool process_tapping(keyrecord_t *keyp) { else if ( ( ( - ( -# ifdef TAPPING_TERM_PER_KEY - get_tapping_term(tapping_keycode, &tapping_key) -# else - g_tapping_term -# endif - >= 500 - ) - + GET_TAPPING_TERM(tapping_keycode, &tapping_key) >= 500 # ifdef PERMISSIVE_HOLD_PER_KEY || get_permissive_hold(tapping_keycode, &tapping_key) # elif defined(PERMISSIVE_HOLD) diff --git a/quantum/action_tapping.h b/quantum/action_tapping.h index b2feb6850ce..9b64c931200 100644 --- a/quantum/action_tapping.h +++ b/quantum/action_tapping.h @@ -44,3 +44,11 @@ bool get_retro_tapping(uint16_t keycode, keyrecord_t *record); #ifdef DYNAMIC_TAPPING_TERM_ENABLE extern uint16_t g_tapping_term; #endif + +#ifdef TAPPING_TERM_PER_KEY +# define GET_TAPPING_TERM(keycode, record) get_tapping_term(keycode, record) +#elif defined(DYNAMIC_TAPPING_TERM_ENABLE) +# define GET_TAPPING_TERM(keycode, record) g_tapping_term +#else +# define GET_TAPPING_TERM(keycode, record) (TAPPING_TERM) +#endif diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index b8ef6e67e58..11cbf6594e2 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -98,17 +98,9 @@ const pointing_device_driver_t pointing_device_driver = { // clang-format on #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) # ifndef CIRQUE_PINNACLE_TAPPING_TERM -# ifdef TAPPING_TERM_PER_KEY -# include "action.h" -# include "action_tapping.h" -# define CIRQUE_PINNACLE_TAPPING_TERM get_tapping_term(KC_BTN1, &(keyrecord_t){}) -# else -# ifdef TAPPING_TERM -# define CIRQUE_PINNACLE_TAPPING_TERM TAPPING_TERM -# else -# define CIRQUE_PINNACLE_TAPPING_TERM 200 -# endif -# endif +# include "action.h" +# include "action_tapping.h" +# define CIRQUE_PINNACLE_TAPPING_TERM GET_TAPPING_TERM(KC_BTN1, &(keyrecord_t){}) # endif # ifndef CIRQUE_PINNACLE_TOUCH_DEBOUNCE # define CIRQUE_PINNACLE_TOUCH_DEBOUNCE (CIRQUE_PINNACLE_TAPPING_TERM * 8) diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 2150edd7b28..e6a7c01f2ae 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -182,12 +182,7 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) # endif ) && # endif - TIMER_DIFF_16(now, autoshift_time) < -# ifdef TAPPING_TERM_PER_KEY - get_tapping_term(autoshift_lastkey, record) -# else - TAPPING_TERM -# endif + TIMER_DIFF_16(now, autoshift_time) < GET_TAPPING_TERM(autoshift_lastkey, record) ) { // clang-format on // Allow a tap-then-hold for keyrepeat. diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c index 46b2648c35e..0997e7b7f3b 100644 --- a/quantum/process_keycode/process_space_cadet.c +++ b/quantum/process_keycode/process_space_cadet.c @@ -93,12 +93,7 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM register_mods(MOD_BIT(holdMod)); } } else { -#ifdef TAPPING_TERM_PER_KEY - if (sc_last == holdMod && timer_elapsed(sc_timer) < get_tapping_term(sc_keycode, record)) -#else - if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) -#endif - { + if (sc_last == holdMod && timer_elapsed(sc_timer) < GET_TAPPING_TERM(sc_keycode, record)) { if (holdMod != tapMod) { if (IS_MOD(holdMod)) { unregister_mods(MOD_BIT(holdMod)); diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index e99119b2aee..db8df5f8705 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -174,11 +174,7 @@ void tap_dance_task() { if (action->custom_tapping_term > 0) { tap_user_defined = action->custom_tapping_term; } else { -#ifdef TAPPING_TERM_PER_KEY - tap_user_defined = get_tapping_term(action->state.keycode, &(keyrecord_t){}); -#else - tap_user_defined = TAPPING_TERM; -#endif + tap_user_defined = GET_TAPPING_TERM(action->state.keycode, &(keyrecord_t){}); } if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) { process_tap_dance_action_on_dance_finished(action); From 6d13199ed0e6502f91719d528f86b03ce7f6acae Mon Sep 17 00:00:00 2001 From: Amber Cronin Date: Sat, 16 Apr 2022 19:27:51 +0100 Subject: [PATCH 4/8] Fix Xorg segfault with KeebCats PCBs (#16434) --- keyboards/cutie_club/keebcats/denis/config.h | 2 +- keyboards/cutie_club/keebcats/dougal/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/cutie_club/keebcats/denis/config.h b/keyboards/cutie_club/keebcats/denis/config.h index 473b6906346..f7c21efe5e6 100644 --- a/keyboards/cutie_club/keebcats/denis/config.h +++ b/keyboards/cutie_club/keebcats/denis/config.h @@ -23,7 +23,7 @@ #define PRODUCT_ID 0xB260 #define DEVICE_VER 0x0000 #define MANUFACTURER Cutie Club -#define PRODUCT Keebcats Denis 60% +#define PRODUCT Keebcats Denis 60 /* key matrix size */ #define MATRIX_ROWS 5 diff --git a/keyboards/cutie_club/keebcats/dougal/config.h b/keyboards/cutie_club/keebcats/dougal/config.h index 05160322c4b..00d3f3a82da 100644 --- a/keyboards/cutie_club/keebcats/dougal/config.h +++ b/keyboards/cutie_club/keebcats/dougal/config.h @@ -23,7 +23,7 @@ #define PRODUCT_ID 0xB265 #define DEVICE_VER 0x0000 #define MANUFACTURER Cutie Club -#define PRODUCT Keebcats Dougal 65% +#define PRODUCT Keebcats Dougal 65 /* key matrix size */ #define MATRIX_ROWS 5 From 3b6e48b012fa10e87e6cf1aa051cdcf353077a5a Mon Sep 17 00:00:00 2001 From: moyi4681 Date: Sat, 16 Apr 2022 11:28:16 -0700 Subject: [PATCH 5/8] [Keyboard] Add Phase One keyboard (#16430) Co-authored-by: Ryan --- keyboards/kbdfans/phaseone/config.h | 62 +++++++++++++++++++ .../kbdfans/phaseone/keymaps/default/keymap.c | 47 ++++++++++++++ .../kbdfans/phaseone/keymaps/via/keymap.c | 47 ++++++++++++++ .../kbdfans/phaseone/keymaps/via/rules.mk | 2 + keyboards/kbdfans/phaseone/phaseone.c | 20 ++++++ keyboards/kbdfans/phaseone/phaseone.h | 60 ++++++++++++++++++ keyboards/kbdfans/phaseone/readme.md | 21 +++++++ keyboards/kbdfans/phaseone/rules.mk | 18 ++++++ 8 files changed, 277 insertions(+) create mode 100644 keyboards/kbdfans/phaseone/config.h create mode 100644 keyboards/kbdfans/phaseone/keymaps/default/keymap.c create mode 100644 keyboards/kbdfans/phaseone/keymaps/via/keymap.c create mode 100644 keyboards/kbdfans/phaseone/keymaps/via/rules.mk create mode 100644 keyboards/kbdfans/phaseone/phaseone.c create mode 100644 keyboards/kbdfans/phaseone/phaseone.h create mode 100644 keyboards/kbdfans/phaseone/readme.md create mode 100644 keyboards/kbdfans/phaseone/rules.mk diff --git a/keyboards/kbdfans/phaseone/config.h b/keyboards/kbdfans/phaseone/config.h new file mode 100644 index 00000000000..42fcdedc6a4 --- /dev/null +++ b/keyboards/kbdfans/phaseone/config.h @@ -0,0 +1,62 @@ +/* Copyright 2022 Dztech + * + * 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 +#include "config_common.h" +/* USB Device descriptor parameter */ +#define VENDOR_ID 0x4B42 +#define PRODUCT_ID 0x0103 +#define DEVICE_VER 0x0001 +#define MANUFACTURER KBDFans +#define PRODUCT phaseone +/* key matrix size */ +#define MATRIX_ROWS 5 +#define MATRIX_COLS 15 +#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4 } +#define MATRIX_COL_PINS { B5, C6, C7, F7, F6, F5, F4, F1, E6, B7, D0, D1, D2, D3, D5 } +#define UNUSED_PINS +#define LED_NUM_LOCK_PIN D7 +#define LED_CAPS_LOCK_PIN D6 +#define LED_PIN_ON_STATE 0 +/* COL2ROW or ROW2COL */ +#define DIODE_DIRECTION COL2ROW +/* 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 B6 +#ifdef RGB_DI_PIN +#define RGBLIGHT_EFFECT_BREATHING +#define RGBLIGHT_EFFECT_RAINBOW_MOOD +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL +#define RGBLIGHT_EFFECT_SNAKE +#define RGBLIGHT_EFFECT_KNIGHT +#define RGBLIGHT_EFFECT_CHRISTMAS +#define RGBLIGHT_EFFECT_STATIC_GRADIENT +#define RGBLIGHT_EFFECT_RGB_TEST +#define RGBLIGHT_EFFECT_ALTERNATING +#define RGBLIGHT_EFFECT_TWINKLE +#define RGBLIGHT_DEFAULT_MODE (RGBLIGHT_EFFECT_RAINBOW_MOOD + 6) +#define RGBLIGHT_DEFAULT_SPD 15 +#define RGBLED_NUM 4 +#define RGBLIGHT_HUE_STEP 10 +#define RGBLIGHT_SAT_STEP 10 +#define RGBLIGHT_VAL_STEP 10 +#define RGBLIGHT_SLEEP +#endif +#define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 2 \ No newline at end of file diff --git a/keyboards/kbdfans/phaseone/keymaps/default/keymap.c b/keyboards/kbdfans/phaseone/keymaps/default/keymap.c new file mode 100644 index 00000000000..a74be0ce503 --- /dev/null +++ b/keyboards/kbdfans/phaseone/keymaps/default/keymap.c @@ -0,0 +1,47 @@ +/* Copyright 2022 Dztech + * + * 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] = { +[0] = LAYOUT_all( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, KC_HOME, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN, + KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RCTL, KC_RALT, KC_LEFT, KC_DOWN, KC_RGHT +), +[1] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +), +[2] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +), +[3] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +) +}; diff --git a/keyboards/kbdfans/phaseone/keymaps/via/keymap.c b/keyboards/kbdfans/phaseone/keymaps/via/keymap.c new file mode 100644 index 00000000000..a74be0ce503 --- /dev/null +++ b/keyboards/kbdfans/phaseone/keymaps/via/keymap.c @@ -0,0 +1,47 @@ +/* Copyright 2022 Dztech + * + * 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] = { +[0] = LAYOUT_all( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, KC_HOME, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN, + KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RCTL, KC_RALT, KC_LEFT, KC_DOWN, KC_RGHT +), +[1] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +), +[2] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +), +[3] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, KC_INS, + _______, _______, KC_UP, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, _______, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END, KC_PGDN, KC_DOWN, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_END +) +}; diff --git a/keyboards/kbdfans/phaseone/keymaps/via/rules.mk b/keyboards/kbdfans/phaseone/keymaps/via/rules.mk new file mode 100644 index 00000000000..36b7ba9cbc9 --- /dev/null +++ b/keyboards/kbdfans/phaseone/keymaps/via/rules.mk @@ -0,0 +1,2 @@ +VIA_ENABLE = yes +LTO_ENABLE = yes diff --git a/keyboards/kbdfans/phaseone/phaseone.c b/keyboards/kbdfans/phaseone/phaseone.c new file mode 100644 index 00000000000..f83d14c1b32 --- /dev/null +++ b/keyboards/kbdfans/phaseone/phaseone.c @@ -0,0 +1,20 @@ +/* Copyright 2022 Dztech + * + * 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 "phaseone.h" +void keyboard_pre_init_kb(void) { + setPinOutput(D4); +} diff --git a/keyboards/kbdfans/phaseone/phaseone.h b/keyboards/kbdfans/phaseone/phaseone.h new file mode 100644 index 00000000000..28a176a059e --- /dev/null +++ b/keyboards/kbdfans/phaseone/phaseone.h @@ -0,0 +1,60 @@ +/* Copyright 2022 Dztech + * + * 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 + +#include "quantum.h" + +#define LAYOUT_all( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K2C, K0E, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2E, \ + K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, \ + K40, K41, K42, K46, K4A, K4B, K4C, K4D, K4E \ +) { \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E}, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E}, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E}, \ + { K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E}, \ + { K40, K41, K42, KC_NO, KC_NO, KC_NO, K46, KC_NO, KC_NO, KC_NO, K4A, K4B, K4C, K4D, K4E}, \ +} + +#define LAYOUT_65_ansi_blocker( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2E, \ + K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, \ + K40, K41, K42, K46, K4A, K4B, K4C, K4D, K4E \ +) { \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E}, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E}, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, KC_NO, K2D, K2E}, \ + { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E}, \ + { K40, K41, K42, KC_NO, KC_NO, KC_NO, K46, KC_NO, KC_NO, KC_NO, K4A, K4B, K4C, K4D, K4E}, \ +} + +#define LAYOUT_65_ansi_wkl( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2E, \ + K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, \ + K40, K42, K46, K4B, K4C, K4D, K4E \ +) { \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E}, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E}, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, KC_NO, K2D, K2E}, \ + { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E}, \ + { K40, KC_NO, K42, KC_NO, KC_NO, KC_NO, K46, KC_NO, KC_NO, KC_NO, KC_NO, K4B, K4C, K4D, K4E}, \ +} diff --git a/keyboards/kbdfans/phaseone/readme.md b/keyboards/kbdfans/phaseone/readme.md new file mode 100644 index 00000000000..b5b21da672d --- /dev/null +++ b/keyboards/kbdfans/phaseone/readme.md @@ -0,0 +1,21 @@ +# PHASEONE + +A 65% keyboard, include 3 layouts: WK HOTSWAP; WKL HOTSWAP and SOLDERED. + +* Keyboard Maintainer: [moyi4681](https://github.com/moyi4681) +* Hardware Supported: KBDFANS PHASEONE +* Hardware Availability: [KBDfans](https://kbdfans.com/) + +## Bootloader + +Enter the bootloader in 3 ways: + +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix +* **Physical reset button**: Briefly press the button on the back of the PCB +* **Keycode in layout**: Press the key mapped to `RESET` if it is available + +Make example for this keyboard (after setting up your build environment): + + make kbdfans/phaseone:default + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/kbdfans/phaseone/rules.mk b/keyboards/kbdfans/phaseone/rules.mk new file mode 100644 index 00000000000..b5761555d40 --- /dev/null +++ b/keyboards/kbdfans/phaseone/rules.mk @@ -0,0 +1,18 @@ +# MCU name +MCU = atmega32u4 + +# Bootloader selection +BOOTLOADER = atmel-dfu + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite +MOUSEKEY_ENABLE = no # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +NKRO_ENABLE = yes # Enable N-Key Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow +AUDIO_ENABLE = no # Audio output From e5918cf968f3e2c4a62858ee789748443ba58d10 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Sun, 17 Apr 2022 02:34:07 +0800 Subject: [PATCH 6/8] Heatmap incorrect matrix effect workaround (#16315) --- docs/feature_rgb_matrix.md | 13 +++++++------ quantum/rgb_matrix/animations/typing_heatmap_anim.h | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index a8793be328e..b2fc61e51e1 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -657,18 +657,19 @@ You can enable a single effect by defining `ENABLE_[EFFECT_NAME]` in your `confi ### RGB Matrix Effect Typing Heatmap :id=rgb-matrix-effect-typing-heatmap -This effect will color the RGB matrix according to a heatmap of recently pressed -keys. Whenever a key is pressed its "temperature" increases as well as that of -its neighboring keys. The temperature of each key is then decreased -automatically every 25 milliseconds by default. +This effect will color the RGB matrix according to a heatmap of recently pressed keys. Whenever a key is pressed its "temperature" increases as well as that of its neighboring keys. The temperature of each key is then decreased automatically every 25 milliseconds by default. -In order to change the delay of temperature decrease define -`RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS`: +In order to change the delay of temperature decrease define `RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS`: ```c #define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 50 ``` +Heatmap effect may not light up the correct adjacent LEDs for certain key matrix layout such as split keyboards. The following define will limit the effect to pressed keys only: +```c +#define RGB_MATRIX_TYPING_HEATMAP_SLIM +``` + ## Custom RGB Matrix Effects :id=custom-rgb-matrix-effects By setting `RGB_MATRIX_CUSTOM_USER = yes` in `rules.mk`, new effects can be defined directly from your keymap or userspace, without having to edit any QMK core files. To declare new effects, create a `rgb_matrix_user.inc` file in the user keymap directory or userspace folder. diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h index f3a94280c06..4b17c4c3edc 100644 --- a/quantum/rgb_matrix/animations/typing_heatmap_anim.h +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -7,6 +7,10 @@ RGB_MATRIX_EFFECT(TYPING_HEATMAP) # endif void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { +# ifdef RGB_MATRIX_TYPING_HEATMAP_SLIM + // Limit effect to pressed keys + g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); +# else uint8_t m_row = row - 1; uint8_t p_row = row + 1; uint8_t m_col = col - 1; @@ -27,6 +31,7 @@ void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { g_rgb_frame_buffer[m_row][col] = qadd8(g_rgb_frame_buffer[m_row][col], 16); if (p_col < MATRIX_COLS) g_rgb_frame_buffer[m_row][p_col] = qadd8(g_rgb_frame_buffer[m_row][p_col], 13); } +# endif } // A timer to track the last time we decremented all heatmap values. From 5841c755ae0b5629deb4c139eb535a82437112a2 Mon Sep 17 00:00:00 2001 From: Simon Arlott <70171+nomis@users.noreply.github.com> Date: Sat, 16 Apr 2022 23:02:32 +0100 Subject: [PATCH 7/8] rgblight: Add functions to stop blinking one or all but one layer (#16859) --- docs/feature_rgblight.md | 13 +++++++++++++ quantum/rgblight/rgblight.c | 15 +++++++++++++++ quantum/rgblight/rgblight.h | 20 +++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index 08e820c0a63..11d4f899501 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md @@ -326,6 +326,19 @@ void post_process_record_user(uint16_t keycode, keyrecord_t *record) { ``` would turn the layer 0 (or 1) on and off again three times when `DEBUG` is pressed. +Blinking accumulates layers so if multiple layers are set blinking at the same time they will all blink for the duration and repeat times of the last layer to be blinked. +To stop these other layers from blinking use `rgblight_unblink_layer` or `rgblight_unblink_all_but_layer`: + +```c +rgblight_blink_layer(1, 500); +rgblight_unblink_all_but_layer(1); +``` + +```c +rgblight_unblink_layer(3); +rgblight_blink_layer(2, 500); +``` + !> Lighting layers on split keyboards will require layer state synced to the slave half (e.g. `#define SPLIT_LAYER_STATE_ENABLE`). See [data sync options](feature_split_keyboard.md#data-sync-options) for more details. ### Overriding RGB Lighting on/off status diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index f4ddb81e923..1f8b68ee592 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -826,6 +826,21 @@ void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t ti _repeat_timer = sync_timer_read() + duration_ms; } +void rgblight_unblink_layer(uint8_t layer) { + rgblight_set_layer_state(layer, false); + _blinking_layer_mask &= ~((rgblight_layer_mask_t)1 << layer); +} + +void rgblight_unblink_all_but_layer(uint8_t layer) { + for (uint8_t i = 0; i < RGBLIGHT_MAX_LAYERS; i++) { + if (i != layer) { + if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << i) != 0) { + rgblight_unblink_layer(i); + } + } + } +} + void rgblight_blink_layer_repeat_helper(void) { if (_blinking_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h index 7076dc41ac8..fdab0e987a0 100644 --- a/quantum/rgblight/rgblight.h +++ b/quantum/rgblight/rgblight.h @@ -216,7 +216,25 @@ extern const rgblight_segment_t *const *rgblight_layers; # ifdef RGBLIGHT_LAYER_BLINK # define RGBLIGHT_USE_TIMER void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms); -void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times); +void rgblight_blink_layer_repeat(uint8_t layer, uint16_ duration_ms, uint8_t times); +/** + * \brief Stop blinking on one layer. + * + * Stop a layer that is blinking. If the layer is not blinking it will + * be unaffected. + * + * \param layer Layer number to stop blinking. + */ +void rgblight_unblink_layer(uint8_t layer); +/** + * \brief Stop blinking all layers except one. + * + * Stop all layers that are blinking except for one specific layer. + * Layers that are not blinking are unaffected. + * + * \param layer Layer number to keep blinking. + */ +void rgblight_unblink_all_but_layer(uint8_t layer); # endif #endif From 147e57fd5930a1c18596a2401c9ee6f30730b86f Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Sun, 17 Apr 2022 00:30:51 +0200 Subject: [PATCH 8/8] [QP] Check BPP capabilities before loading the palette (#16863) --- quantum/painter/qp_draw_image.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c index 5134ae7e99a..5822758dce9 100644 --- a/quantum/painter/qp_draw_image.c +++ b/quantum/painter/qp_draw_image.c @@ -131,6 +131,12 @@ static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device, // Ensure we aren't reusing any palette qp_internal_invalidate_palette(); + if (!qp_internal_bpp_capable(info->bpp)) { + qp_dprintf("qp_drawimage_recolor: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)info->bpp); + qp_comms_stop(device); + return false; + } + // Handle palette if needed const uint16_t palette_entries = 1u << info->bpp; bool needs_pixconvert = false; @@ -146,12 +152,6 @@ static bool qp_drawimage_prepare_frame_for_stream_read(painter_device_t device, needs_pixconvert = qp_internal_interpolate_palette(fg_hsv888, bg_hsv888, palette_entries); } - if (!qp_internal_bpp_capable(info->bpp)) { - qp_dprintf("qp_drawimage_recolor: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)info->bpp); - qp_comms_stop(device); - return false; - } - if (needs_pixconvert) { // Convert the palette to native format if (!driver->driver_vtable->palette_convert(device, palette_entries, qp_internal_global_pixel_lookup_table)) {