diff options
Diffstat (limited to 'quantum')
196 files changed, 4097 insertions, 2297 deletions
diff --git a/quantum/action.c b/quantum/action.c index 5e81efb671..2bb1c34985 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "led.h" #include "action_layer.h" #include "action_tapping.h" -#include "action_macro.h" #include "action_util.h" #include "action.h" #include "wait.h" @@ -54,14 +53,20 @@ int retro_tapping_counter = 0; #endif #ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY -__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { + return false; +} #endif #ifdef RETRO_TAPPING_PER_KEY -__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { + return false; +} #endif -__attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { return true; } +__attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { + return true; +} /** \brief Called to execute an action. * @@ -164,10 +169,14 @@ void process_record_nocache(keyrecord_t *record) { disable_action_cache = false; } #else -void process_record_nocache(keyrecord_t *record) { process_record(record); } +void process_record_nocache(keyrecord_t *record) { + process_record(record); +} #endif -__attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { + return true; +} __attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {} @@ -634,12 +643,7 @@ void process_action(keyrecord_t *record, action_t action) { break; # endif #endif - /* Extentions */ -#ifndef NO_ACTION_MACRO - case ACT_MACRO: - action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); - break; -#endif + #ifdef SWAP_HANDS_ENABLE case ACT_SWAP_HANDS: switch (action.swap.code) { @@ -694,7 +698,7 @@ void process_action(keyrecord_t *record, action_t action) { /* tap key */ if (tap_count > 0) { if (swap_held) { - swap_hands = !swap_hands; // undo hold set up in _tap_hint + swap_hands = !swap_hands; // undo hold set up in _tap_hint swap_held = false; } if (event.pressed) { @@ -702,22 +706,17 @@ void process_action(keyrecord_t *record, action_t action) { } else { wait_ms(TAP_CODE_DELAY); unregister_code(action.swap.code); - *record = (keyrecord_t){}; // hack: reset tap mode + *record = (keyrecord_t){}; // hack: reset tap mode } } else { if (swap_held && !event.pressed) { - swap_hands = !swap_hands; // undo hold set up in _tap_hint + swap_hands = !swap_hands; // undo hold set up in _tap_hint swap_held = false; } } # endif } #endif -#ifndef NO_ACTION_FUNCTION - case ACT_FUNCTION: - action_function(record, action.func.id, action.func.opt); - break; -#endif default: break; } @@ -794,7 +793,7 @@ void process_action(keyrecord_t *record, action_t action) { * * FIXME: Needs documentation. */ -void register_code(uint8_t code) { +__attribute__((weak)) void register_code(uint8_t code) { if (code == KC_NO) { return; } @@ -873,9 +872,13 @@ void register_code(uint8_t code) { } #ifdef EXTRAKEY_ENABLE else if - IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); } + IS_SYSTEM(code) { + host_system_send(KEYCODE2SYSTEM(code)); + } else if - IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); } + IS_CONSUMER(code) { + host_consumer_send(KEYCODE2CONSUMER(code)); + } #endif #ifdef MOUSEKEY_ENABLE else if @@ -890,7 +893,7 @@ void register_code(uint8_t code) { * * FIXME: Needs documentation. */ -void unregister_code(uint8_t code) { +__attribute__((weak)) void unregister_code(uint8_t code) { if (code == KC_NO) { return; } @@ -938,9 +941,13 @@ void unregister_code(uint8_t code) { send_keyboard_report(); } else if - IS_SYSTEM(code) { host_system_send(0); } + IS_SYSTEM(code) { + host_system_send(0); + } else if - IS_CONSUMER(code) { host_consumer_send(0); } + IS_CONSUMER(code) { + host_consumer_send(0); + } #ifdef MOUSEKEY_ENABLE else if IS_MOUSEKEY(code) { @@ -955,7 +962,7 @@ void unregister_code(uint8_t code) { * \param code The basic keycode to tap. * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it. */ -void tap_code_delay(uint8_t code, uint16_t delay) { +__attribute__((weak)) void tap_code_delay(uint8_t code, uint16_t delay) { register_code(code); for (uint16_t i = delay; i > 0; i--) { wait_ms(1); @@ -967,13 +974,15 @@ void tap_code_delay(uint8_t code, uint16_t delay) { * * \param code The basic keycode to tap. If `code` is `KC_CAPS_LOCK`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined. */ -void tap_code(uint8_t code) { tap_code_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); } +__attribute__((weak)) void tap_code(uint8_t code) { + tap_code_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); +} /** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately. * * \param mods A bitfield of modifiers to register. */ -void register_mods(uint8_t mods) { +__attribute__((weak)) void register_mods(uint8_t mods) { if (mods) { add_mods(mods); send_keyboard_report(); @@ -984,7 +993,7 @@ void register_mods(uint8_t mods) { * * \param mods A bitfield of modifiers to unregister. */ -void unregister_mods(uint8_t mods) { +__attribute__((weak)) void unregister_mods(uint8_t mods) { if (mods) { del_mods(mods); send_keyboard_report(); @@ -995,7 +1004,7 @@ void unregister_mods(uint8_t mods) { * * \param mods A bitfield of modifiers to register. */ -void register_weak_mods(uint8_t mods) { +__attribute__((weak)) void register_weak_mods(uint8_t mods) { if (mods) { add_weak_mods(mods); send_keyboard_report(); @@ -1006,7 +1015,7 @@ void register_weak_mods(uint8_t mods) { * * \param mods A bitfield of modifiers to unregister. */ -void unregister_weak_mods(uint8_t mods) { +__attribute__((weak)) void unregister_weak_mods(uint8_t mods) { if (mods) { del_weak_mods(mods); send_keyboard_report(); @@ -1041,7 +1050,6 @@ void clear_keyboard_but_mods_and_keys() { host_consumer_send(0); #endif clear_weak_mods(); - clear_macro_mods(); send_keyboard_report(); #ifdef MOUSEKEY_ENABLE mousekey_clear(); @@ -1104,12 +1112,6 @@ bool is_tap_action(action_t action) { return true; } return false; - case ACT_MACRO: - case ACT_FUNCTION: - if (action.func.opt & FUNC_TAP) { - return true; - } - return false; } return false; } @@ -1118,7 +1120,9 @@ bool is_tap_action(action_t action) { * * FIXME: Needs documentation. */ -void debug_event(keyevent_t event) { dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); } +void debug_event(keyevent_t event) { + dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); +} /** \brief Debug print (FIXME: Needs better description) * * FIXME: Needs documentation. @@ -1166,12 +1170,6 @@ void debug_action(action_t action) { case ACT_LAYER_TAP_EXT: dprint("ACT_LAYER_TAP_EXT"); break; - case ACT_MACRO: - dprint("ACT_MACRO"); - break; - case ACT_FUNCTION: - dprint("ACT_FUNCTION"); - break; case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break; diff --git a/quantum/action.h b/quantum/action.h index b562f18c5b..39b5da63b8 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -19,25 +19,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdint.h> #include <stdbool.h> +#include "progmem.h" #include "keyboard.h" #include "keycode.h" #include "action_code.h" -#include "action_macro.h" #ifdef __cplusplus extern "C" { #endif -/* Disable macro and function features when LTO is enabled, since they break */ -#ifdef LTO_ENABLE -# ifndef NO_ACTION_MACRO -# define NO_ACTION_MACRO -# endif -# ifndef NO_ACTION_FUNCTION -# define NO_ACTION_FUNCTION -# endif -#endif - #ifndef TAP_CODE_DELAY # define TAP_CODE_DELAY 0 #endif @@ -72,12 +62,6 @@ void action_exec(keyevent_t event); action_t action_for_key(uint8_t layer, keypos_t key); action_t action_for_keycode(uint16_t keycode); -/* macro */ -const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); - -/* user defined special function */ -void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); - /* keyboard-specific key event (pre)processing */ bool process_record_quantum(keyrecord_t *record); diff --git a/quantum/action_code.h b/quantum/action_code.h index eb18c36ae8..20b3e459d2 100644 --- a/quantum/action_code.h +++ b/quantum/action_code.h @@ -79,19 +79,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. * 101E|LLLL|1111 0100 One Shot Layer (0xF4) [TAP] * 101E|LLLL|1111 xxxx Reserved (0xF5-FF) * ELLLL: layer 0-31(E: extra bit for layer 16-31) - * - * Extensions(11xx) - * ---------------- - * ACT_MACRO(1100): - * 1100|opt | id(8) Macro play? - * 1100|1111| id(8) Macro record? - * - * 1101|xxxx xxxx xxxx (reserved) - * 1110|xxxx xxxx xxxx (reserved) - * - * ACT_FUNCTION(1111): - * 1111| address(12) Function? - * 1111|opt | id(8) Function? */ enum action_kind_id { /* Key Actions */ @@ -111,9 +98,6 @@ enum action_kind_id { ACT_LAYER_MODS = 0b1001, ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */ ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */ - /* Extensions */ - ACT_MACRO = 0b1100, - ACT_FUNCTION = 0b1111 }; /** \brief Action Code Struct @@ -164,11 +148,6 @@ typedef union { uint8_t page : 2; uint8_t kind : 4; } usage; - struct action_function { - uint8_t id : 8; - uint8_t opt : 4; - uint8_t kind : 4; - } func; struct action_swap { uint8_t code : 8; uint8_t opt : 4; @@ -275,17 +254,6 @@ enum layer_param_tap_op { #define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0) #define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0) -/* Macro */ -#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) -#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP << 8 | (id)) -#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt) << 8 | (id)) -/* Function */ -enum function_opts { - FUNC_TAP = 0x8, /* indciates function is tappable */ -}; -#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) -#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP << 8 | (id)) -#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt) << 8 | (id)) /* OneHand Support */ enum swap_hands_param_tap_op { OP_SH_TOGGLE = 0xF0, diff --git a/quantum/action_layer.c b/quantum/action_layer.c index ed1a4bd20d..e20eedee40 100644 --- a/quantum/action_layer.c +++ b/quantum/action_layer.c @@ -18,13 +18,17 @@ layer_state_t default_layer_state = 0; * * Run user code on default layer state change */ -__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state) { return state; } +__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state) { + return state; +} /** \brief Default Layer State Set At Keyboard Level * * Run keyboard code on default layer state change */ -__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state) { return default_layer_state_set_user(state); } +__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state) { + return default_layer_state_set_user(state); +} /** \brief Default Layer State Set * @@ -39,9 +43,9 @@ static void default_layer_state_set(layer_state_t state) { default_layer_debug(); debug("\n"); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } @@ -49,30 +53,40 @@ static void default_layer_state_set(layer_state_t state) { * * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. */ -void default_layer_debug(void) { dprintf("%08lX(%u)", default_layer_state, get_highest_layer(default_layer_state)); } +void default_layer_debug(void) { + dprintf("%08lX(%u)", default_layer_state, get_highest_layer(default_layer_state)); +} /** \brief Default Layer Set * * Sets the default layer state. */ -void default_layer_set(layer_state_t state) { default_layer_state_set(state); } +void default_layer_set(layer_state_t state) { + default_layer_state_set(state); +} #ifndef NO_ACTION_LAYER /** \brief Default Layer Or * * Turns on the default layer based on matching bits between specifed layer and existing layer state */ -void default_layer_or(layer_state_t state) { default_layer_state_set(default_layer_state | state); } +void default_layer_or(layer_state_t state) { + default_layer_state_set(default_layer_state | state); +} /** \brief Default Layer And * * Turns on default layer based on matching enabled bits between specifed layer and existing layer state */ -void default_layer_and(layer_state_t state) { default_layer_state_set(default_layer_state & state); } +void default_layer_and(layer_state_t state) { + default_layer_state_set(default_layer_state & state); +} /** \brief Default Layer Xor * * Turns on default layer based on non-matching bits between specifed layer and existing layer state */ -void default_layer_xor(layer_state_t state) { default_layer_state_set(default_layer_state ^ state); } +void default_layer_xor(layer_state_t state) { + default_layer_state_set(default_layer_state ^ state); +} #endif #ifndef NO_ACTION_LAYER @@ -84,13 +98,17 @@ layer_state_t layer_state = 0; * * Runs user code on layer state change */ -__attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) { return state; } +__attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) { + return state; +} /** \brief Layer state set keyboard * * Runs keyboard code on layer state change */ -__attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) { return layer_state_set_user(state); } +__attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) { + return layer_state_set_user(state); +} /** \brief Layer state set * @@ -105,9 +123,9 @@ void layer_state_set(layer_state_t state) { layer_debug(); dprintln(); # ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys # else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys # endif } @@ -115,13 +133,17 @@ void layer_state_set(layer_state_t state) { * * Turn off all layers */ -void layer_clear(void) { layer_state_set(0); } +void layer_clear(void) { + layer_state_set(0); +} /** \brief Layer state is * * Return whether the given state is on (it might still be shadowed by a higher state, though) */ -bool layer_state_is(uint8_t layer) { return layer_state_cmp(layer_state, layer); } +bool layer_state_is(uint8_t layer) { + return layer_state_cmp(layer_state, layer); +} /** \brief Layer state compare * @@ -138,47 +160,63 @@ bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) { * * Turns on the given layer and turn off all other layers */ -void layer_move(uint8_t layer) { layer_state_set((layer_state_t)1 << layer); } +void layer_move(uint8_t layer) { + layer_state_set((layer_state_t)1 << layer); +} /** \brief Layer on * * Turns on given layer */ -void layer_on(uint8_t layer) { layer_state_set(layer_state | ((layer_state_t)1 << layer)); } +void layer_on(uint8_t layer) { + layer_state_set(layer_state | ((layer_state_t)1 << layer)); +} /** \brief Layer off * * Turns off given layer */ -void layer_off(uint8_t layer) { layer_state_set(layer_state & ~((layer_state_t)1 << layer)); } +void layer_off(uint8_t layer) { + layer_state_set(layer_state & ~((layer_state_t)1 << layer)); +} /** \brief Layer invert * * Toggle the given layer (set it if it's unset, or unset it if it's set) */ -void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ ((layer_state_t)1 << layer)); } +void layer_invert(uint8_t layer) { + layer_state_set(layer_state ^ ((layer_state_t)1 << layer)); +} /** \brief Layer or * * Turns on layers based on matching bits between specifed layer and existing layer state */ -void layer_or(layer_state_t state) { layer_state_set(layer_state | state); } +void layer_or(layer_state_t state) { + layer_state_set(layer_state | state); +} /** \brief Layer and * * Turns on layers based on matching enabled bits between specifed layer and existing layer state */ -void layer_and(layer_state_t state) { layer_state_set(layer_state & state); } +void layer_and(layer_state_t state) { + layer_state_set(layer_state & state); +} /** \brief Layer xor * * Turns on layers based on non-matching bits between specifed layer and existing layer state */ -void layer_xor(layer_state_t state) { layer_state_set(layer_state ^ state); } +void layer_xor(layer_state_t state) { + layer_state_set(layer_state ^ state); +} /** \brief Layer debug printing * * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. */ -void layer_debug(void) { dprintf("%08lX(%u)", layer_state, get_highest_layer(layer_state)); } +void layer_debug(void) { + dprintf("%08lX(%u)", layer_state, get_highest_layer(layer_state)); +} #endif #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) @@ -276,4 +314,6 @@ uint8_t layer_switch_get_layer(keypos_t key) { * * Gets action code based on key position */ -action_t layer_switch_get_action(keypos_t key) { return action_for_key(layer_switch_get_layer(key), key); } +action_t layer_switch_get_action(keypos_t key) { + return action_for_key(layer_switch_get_layer(key), key); +} diff --git a/quantum/action_macro.c b/quantum/action_macro.c deleted file mode 100644 index 92228c0ba8..0000000000 --- a/quantum/action_macro.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2013 Jun Wako <wakojun@gmail.com> - -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 "action.h" -#include "action_util.h" -#include "action_macro.h" -#include "wait.h" - -#ifdef DEBUG_ACTION -# include "debug.h" -#else -# include "nodebug.h" -#endif - -#ifndef NO_ACTION_MACRO - -# define MACRO_READ() (macro = MACRO_GET(macro_p++)) -/** \brief Action Macro Play - * - * FIXME: Needs doc - */ -void action_macro_play(const macro_t *macro_p) { - macro_t macro = END; - uint8_t interval = 0; - - if (!macro_p) return; - while (true) { - switch (MACRO_READ()) { - case KEY_DOWN: - MACRO_READ(); - dprintf("KEY_DOWN(%02X)\n", macro); - if (IS_MOD(macro)) { - add_macro_mods(MOD_BIT(macro)); - send_keyboard_report(); - } else { - register_code(macro); - } - break; - case KEY_UP: - MACRO_READ(); - dprintf("KEY_UP(%02X)\n", macro); - if (IS_MOD(macro)) { - del_macro_mods(MOD_BIT(macro)); - send_keyboard_report(); - } else { - unregister_code(macro); - } - break; - case WAIT: - MACRO_READ(); - dprintf("WAIT(%u)\n", macro); - { - uint8_t ms = macro; - while (ms--) wait_ms(1); - } - break; - case INTERVAL: - interval = MACRO_READ(); - dprintf("INTERVAL(%u)\n", interval); - break; - case 0x04 ... 0x73: - dprintf("DOWN(%02X)\n", macro); - register_code(macro); - break; - case 0x84 ... 0xF3: - dprintf("UP(%02X)\n", macro); - unregister_code(macro & 0x7F); - break; - case END: - default: - return; - } - // interval - { - uint8_t ms = interval; - while (ms--) wait_ms(1); - } - } -} -#endif diff --git a/quantum/action_macro.h b/quantum/action_macro.h deleted file mode 100644 index 685e2c6ffc..0000000000 --- a/quantum/action_macro.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -Copyright 2013 Jun Wako <wakojun@gmail.com> - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#pragma once - -#include <stdint.h> -#include "progmem.h" - -typedef uint8_t macro_t; - -#define MACRO_NONE (macro_t *)0 -#define MACRO(...) \ - ({ \ - static const macro_t __m[] PROGMEM = {__VA_ARGS__}; \ - &__m[0]; \ - }) -#define MACRO_GET(p) pgm_read_byte(p) - -// Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped -#define MACRO_TAP_HOLD(record, press, release, tap_macro) (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE) : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release))) - -// Holds down the modifier mod when the macro key is held, or sends macro instead when tapped -#define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) - -// Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) -#define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod) - -// Momentary switch layer when held, sends macro if tapped -#define MACRO_TAP_HOLD_LAYER(record, macro, layer) \ - (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({ \ - layer_on((layer)); \ - MACRO_NONE; \ - }) \ - : MACRO_NONE) \ - : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({ \ - layer_off((layer)); \ - MACRO_NONE; \ - }))) - -// Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) -#define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer) - -#ifndef NO_ACTION_MACRO -void action_macro_play(const macro_t *macro_p); -#else -# define action_macro_play(macro) -#endif - -/* Macro commands - * code(0x04-73) // key down(1byte) - * code(0x04-73) | 0x80 // key up(1byte) - * { KEY_DOWN, code(0x04-0xff) } // key down(2bytes) - * { KEY_UP, code(0x04-0xff) } // key up(2bytes) - * WAIT // wait milli-seconds - * INTERVAL // set interval between macro commands - * END // stop macro execution - * - * Ideas(Not implemented): - * modifiers - * system usage - * consumer usage - * unicode usage - * function call - * conditionals - * loop - */ -enum macro_command_id { - /* 0x00 - 0x03 */ - END = 0x00, - KEY_DOWN, - KEY_UP, - - /* 0x04 - 0x73 (reserved for keycode down) */ - - /* 0x74 - 0x83 */ - WAIT = 0x74, - INTERVAL, - - /* 0x84 - 0xf3 (reserved for keycode up) */ - - /* 0xf4 - 0xff */ -}; - -/* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed - * if keycode between 0x04 and 0x73 - * keycode / (keycode|0x80) - * else - * {KEY_DOWN, keycode} / {KEY_UP, keycode} - */ -#define DOWN(key) KEY_DOWN, (key) -#define UP(key) KEY_UP, (key) -#define TYPE(key) DOWN(key), UP(key) -#define WAIT(ms) WAIT, (ms) -#define INTERVAL(ms) INTERVAL, (ms) - -/* key down */ -#define D(key) DOWN(KC_##key) -/* key up */ -#define U(key) UP(KC_##key) -/* key type */ -#define T(key) TYPE(KC_##key) -/* wait */ -#define W(ms) WAIT(ms) -/* interval */ -#define I(ms) INTERVAL(ms) - -/* for backward comaptibility */ -#define MD(key) DOWN(KC_##key) -#define MU(key) UP(KC_##key) diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index d2c93f85e3..6f8b4f8c56 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c @@ -26,7 +26,9 @@ uint16_t g_tapping_term = TAPPING_TERM; -__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return g_tapping_term; } +__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { + return g_tapping_term; +} # 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)) @@ -35,15 +37,21 @@ __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *r # endif # ifdef TAPPING_FORCE_HOLD_PER_KEY -__attribute__((weak)) bool get_tapping_force_hold(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_tapping_force_hold(uint16_t keycode, keyrecord_t *record) { + return false; +} # endif # ifdef PERMISSIVE_HOLD_PER_KEY -__attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) { + return false; +} # endif # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY -__attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { + return false; +} # endif # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) @@ -124,7 +132,7 @@ bool process_tapping(keyrecord_t *keyp) { # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) || ( # ifdef RETRO_TAPPING_PER_KEY - get_retro_tapping(tapping_keycode, keyp) && + get_retro_tapping(tapping_keycode, &tapping_key) && # endif (RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0) ) @@ -158,7 +166,7 @@ bool process_tapping(keyrecord_t *keyp) { ( ( # ifdef TAPPING_TERM_PER_KEY - get_tapping_term(tapping_keycode, keyp) + get_tapping_term(tapping_keycode, &tapping_key) # else g_tapping_term # endif @@ -166,7 +174,7 @@ bool process_tapping(keyrecord_t *keyp) { ) # ifdef PERMISSIVE_HOLD_PER_KEY - || get_permissive_hold(tapping_keycode, keyp) + || get_permissive_hold(tapping_keycode, &tapping_key) # elif defined(PERMISSIVE_HOLD) || true # endif @@ -177,7 +185,7 @@ bool process_tapping(keyrecord_t *keyp) { # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) || ( # ifdef RETRO_TAPPING_PER_KEY - get_retro_tapping(tapping_keycode, keyp) && + get_retro_tapping(tapping_keycode, &tapping_key) && # endif ( // Rolled over the two keys. @@ -188,7 +196,7 @@ bool process_tapping(keyrecord_t *keyp) { || ( IS_LT(tapping_keycode) # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY - && get_hold_on_other_key_press(tapping_keycode, keyp) + && get_hold_on_other_key_press(tapping_keycode, &tapping_key) # endif ) # endif @@ -196,7 +204,7 @@ bool process_tapping(keyrecord_t *keyp) { || ( IS_MT(tapping_keycode) # ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY - && !get_ignore_mod_tap_interrupt(tapping_keycode, keyp) + && !get_ignore_mod_tap_interrupt(tapping_keycode, &tapping_key) # endif ) # endif @@ -252,7 +260,7 @@ bool process_tapping(keyrecord_t *keyp) { tapping_key.tap.interrupted = true; # if defined(HOLD_ON_OTHER_KEY_PRESS) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) # if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) - if (get_hold_on_other_key_press(tapping_keycode, keyp)) + if (get_hold_on_other_key_press(tapping_keycode, &tapping_key)) # endif { debug("Tapping: End. No tap. Interfered by pressed key\n"); @@ -360,7 +368,7 @@ bool process_tapping(keyrecord_t *keyp) { # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) || ( # ifdef RETRO_TAPPING_PER_KEY - get_retro_tapping(tapping_keycode, keyp) && + get_retro_tapping(tapping_keycode, &tapping_key) && # endif (RETRO_SHIFT + 0) != 0 && TIMER_DIFF_16(event.time, tapping_key.event.time) < (RETRO_SHIFT + 0) ) @@ -373,7 +381,7 @@ bool process_tapping(keyrecord_t *keyp) { # if !defined(TAPPING_FORCE_HOLD) || defined(TAPPING_FORCE_HOLD_PER_KEY) if ( # ifdef TAPPING_FORCE_HOLD_PER_KEY - !get_tapping_force_hold(tapping_keycode, keyp) && + !get_tapping_force_hold(tapping_keycode, &tapping_key) && # endif !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { // sequential tap. diff --git a/quantum/action_util.c b/quantum/action_util.c index 78e02aec18..64a1b6b30d 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -21,12 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "action_layer.h" #include "timer.h" #include "keycode_config.h" +#include <string.h> extern keymap_config_t keymap_config; -static uint8_t real_mods = 0; -static uint8_t weak_mods = 0; -static uint8_t macro_mods = 0; +static uint8_t real_mods = 0; +static uint8_t weak_mods = 0; #ifdef KEY_OVERRIDE_ENABLE static uint8_t weak_override_mods = 0; static uint8_t suppressed_mods = 0; @@ -43,8 +43,10 @@ extern inline void clear_keys(void); #ifndef NO_ACTION_ONESHOT static uint8_t oneshot_mods = 0; static uint8_t oneshot_locked_mods = 0; -uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } -void set_oneshot_locked_mods(uint8_t mods) { +uint8_t get_oneshot_locked_mods(void) { + return oneshot_locked_mods; +} +void set_oneshot_locked_mods(uint8_t mods) { if (mods != oneshot_locked_mods) { oneshot_locked_mods = mods; oneshot_locked_mods_changed_kb(oneshot_locked_mods); @@ -58,9 +60,13 @@ void clear_oneshot_locked_mods(void) { } # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_time = 0; -bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; } +bool has_oneshot_mods_timed_out(void) { + return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; +} # else -bool has_oneshot_mods_timed_out(void) { return false; } +bool has_oneshot_mods_timed_out(void) { + return false; +} # endif #endif @@ -74,24 +80,32 @@ bool has_oneshot_mods_timed_out(void) { return false; } */ static int8_t oneshot_layer_data = 0; -inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } -inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } +inline uint8_t get_oneshot_layer(void) { + return oneshot_layer_data >> 3; +} +inline uint8_t get_oneshot_layer_state(void) { + return oneshot_layer_data & 0b111; +} # ifdef SWAP_HANDS_ENABLE enum { SHO_OFF, - SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet - SHO_PRESSED, // Swap hands button is currently pressed - SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys + SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet + SHO_PRESSED, // Swap hands button is currently pressed + SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys } swap_hands_oneshot = SHO_OFF; # endif # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_layer_time = 0; -inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); } +inline bool has_oneshot_layer_timed_out() { + return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); +} # ifdef SWAP_HANDS_ENABLE static uint16_t oneshot_swaphands_time = 0; -inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && (swap_hands_oneshot == SHO_ACTIVE); } +inline bool has_oneshot_swaphands_timed_out() { + return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && (swap_hands_oneshot == SHO_ACTIVE); +} # endif # endif @@ -179,7 +193,9 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) { * * FIXME: needs doc */ -bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } +bool is_oneshot_layer_active(void) { + return get_oneshot_layer_state(); +} /** \brief set oneshot * @@ -198,21 +214,29 @@ void oneshot_set(bool active) { * * FIXME: needs doc */ -void oneshot_toggle(void) { oneshot_set(!keymap_config.oneshot_disable); } +void oneshot_toggle(void) { + oneshot_set(!keymap_config.oneshot_disable); +} /** \brief enable oneshot * * FIXME: needs doc */ -void oneshot_enable(void) { oneshot_set(true); } +void oneshot_enable(void) { + oneshot_set(true); +} /** \brief disable oneshot * * FIXME: needs doc */ -void oneshot_disable(void) { oneshot_set(false); } +void oneshot_disable(void) { + oneshot_set(false); +} -bool is_oneshot_enabled(void) { return keymap_config.oneshot_disable; } +bool is_oneshot_enabled(void) { + return keymap_config.oneshot_disable; +} #endif @@ -223,7 +247,6 @@ bool is_oneshot_enabled(void) { return keymap_config.oneshot_disable; } void send_keyboard_report(void) { keyboard_report->mods = real_mods; keyboard_report->mods |= weak_mods; - keyboard_report->mods |= macro_mods; #ifndef NO_ACTION_ONESHOT if (oneshot_mods) { @@ -247,110 +270,119 @@ void send_keyboard_report(void) { keyboard_report->mods |= weak_override_mods; #endif - host_keyboard_send(keyboard_report); + static report_keyboard_t last_report; + + /* Only send the report if there are changes to propagate to the host. */ + if (memcmp(keyboard_report, &last_report, sizeof(report_keyboard_t)) != 0) { + memcpy(&last_report, keyboard_report, sizeof(report_keyboard_t)); + host_keyboard_send(keyboard_report); + } } /** \brief Get mods * * FIXME: needs doc */ -uint8_t get_mods(void) { return real_mods; } +uint8_t get_mods(void) { + return real_mods; +} /** \brief add mods * * FIXME: needs doc */ -void add_mods(uint8_t mods) { real_mods |= mods; } +void add_mods(uint8_t mods) { + real_mods |= mods; +} /** \brief del mods * * FIXME: needs doc */ -void del_mods(uint8_t mods) { real_mods &= ~mods; } +void del_mods(uint8_t mods) { + real_mods &= ~mods; +} /** \brief set mods * * FIXME: needs doc */ -void set_mods(uint8_t mods) { real_mods = mods; } +void set_mods(uint8_t mods) { + real_mods = mods; +} /** \brief clear mods * * FIXME: needs doc */ -void clear_mods(void) { real_mods = 0; } +void clear_mods(void) { + real_mods = 0; +} /** \brief get weak mods * * FIXME: needs doc */ -uint8_t get_weak_mods(void) { return weak_mods; } +uint8_t get_weak_mods(void) { + return weak_mods; +} /** \brief add weak mods * * FIXME: needs doc */ -void add_weak_mods(uint8_t mods) { weak_mods |= mods; } +void add_weak_mods(uint8_t mods) { + weak_mods |= mods; +} /** \brief del weak mods * * FIXME: needs doc */ -void del_weak_mods(uint8_t mods) { weak_mods &= ~mods; } +void del_weak_mods(uint8_t mods) { + weak_mods &= ~mods; +} /** \brief set weak mods * * FIXME: needs doc */ -void set_weak_mods(uint8_t mods) { weak_mods = mods; } +void set_weak_mods(uint8_t mods) { + weak_mods = mods; +} /** \brief clear weak mods * * FIXME: needs doc */ -void clear_weak_mods(void) { weak_mods = 0; } +void clear_weak_mods(void) { + weak_mods = 0; +} #ifdef KEY_OVERRIDE_ENABLE /** \brief set weak mods used by key overrides. DO not call this manually */ -void set_weak_override_mods(uint8_t mods) { weak_override_mods = mods; } +void set_weak_override_mods(uint8_t mods) { + weak_override_mods = mods; +} /** \brief clear weak mods used by key overrides. DO not call this manually */ -void clear_weak_override_mods(void) { weak_override_mods = 0; } +void clear_weak_override_mods(void) { + weak_override_mods = 0; +} /** \brief set suppressed mods used by key overrides. DO not call this manually */ -void set_suppressed_override_mods(uint8_t mods) { suppressed_mods = mods; } +void set_suppressed_override_mods(uint8_t mods) { + suppressed_mods = mods; +} /** \brief clear suppressed mods used by key overrides. DO not call this manually */ -void clear_suppressed_override_mods(void) { suppressed_mods = 0; } +void clear_suppressed_override_mods(void) { + suppressed_mods = 0; +} #endif -/* macro modifier */ -/** \brief get macro mods - * - * FIXME: needs doc - */ -uint8_t get_macro_mods(void) { return macro_mods; } -/** \brief add macro mods - * - * FIXME: needs doc - */ -void add_macro_mods(uint8_t mods) { macro_mods |= mods; } -/** \brief del macro mods - * - * FIXME: needs doc - */ -void del_macro_mods(uint8_t mods) { macro_mods &= ~mods; } -/** \brief set macro mods - * - * FIXME: needs doc - */ -void set_macro_mods(uint8_t mods) { macro_mods = mods; } -/** \brief clear macro mods - * - * FIXME: needs doc - */ -void clear_macro_mods(void) { macro_mods = 0; } - #ifndef NO_ACTION_ONESHOT /** \brief get oneshot mods * * FIXME: needs doc */ -uint8_t get_oneshot_mods(void) { return oneshot_mods; } +uint8_t get_oneshot_mods(void) { + return oneshot_mods; +} void add_oneshot_mods(uint8_t mods) { if ((oneshot_mods & mods) != mods) { @@ -413,7 +445,9 @@ __attribute__((weak)) void oneshot_locked_mods_changed_user(uint8_t mods) {} * * \param mods Contains the active modifiers active after the change. */ -__attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) { oneshot_locked_mods_changed_user(mods); } +__attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) { + oneshot_locked_mods_changed_user(mods); +} /** \brief Called when the one shot modifiers have been changed. * @@ -425,7 +459,9 @@ __attribute__((weak)) void oneshot_mods_changed_user(uint8_t mods) {} * * \param mods Contains the active modifiers active after the change. */ -__attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) { oneshot_mods_changed_user(mods); } +__attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) { + oneshot_mods_changed_user(mods); +} /** \brief Called when the one shot layers have been changed. * @@ -437,10 +473,14 @@ __attribute__((weak)) void oneshot_layer_changed_user(uint8_t layer) {} * * \param layer Contains the layer that is toggled on, or zero when toggled off. */ -__attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { oneshot_layer_changed_user(layer); } +__attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { + oneshot_layer_changed_user(layer); +} /** \brief inspect keyboard state * * FIXME: needs doc */ -uint8_t has_anymod(void) { return bitpop(real_mods); } +uint8_t has_anymod(void) { + return bitpop(real_mods); +} diff --git a/quantum/action_util.h b/quantum/action_util.h index f2b3897ae5..6f1f09c4bd 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -29,11 +29,17 @@ extern report_keyboard_t *keyboard_report; void send_keyboard_report(void); /* key */ -inline void add_key(uint8_t key) { add_key_to_report(keyboard_report, key); } +inline void add_key(uint8_t key) { + add_key_to_report(keyboard_report, key); +} -inline void del_key(uint8_t key) { del_key_from_report(keyboard_report, key); } +inline void del_key(uint8_t key) { + del_key_from_report(keyboard_report, key); +} -inline void clear_keys(void) { clear_keys_from_report(keyboard_report); } +inline void clear_keys(void) { + clear_keys_from_report(keyboard_report); +} /* modifier */ uint8_t get_mods(void); @@ -49,13 +55,6 @@ void del_weak_mods(uint8_t mods); void set_weak_mods(uint8_t mods); void clear_weak_mods(void); -/* macro modifier */ -uint8_t get_macro_mods(void); -void add_macro_mods(uint8_t mods); -void del_macro_mods(uint8_t mods); -void set_macro_mods(uint8_t mods); -void clear_macro_mods(void); - /* oneshot modifier */ uint8_t get_oneshot_mods(void); void add_oneshot_mods(uint8_t mods); diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 49bb309e80..c6523b908c 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -64,21 +64,21 @@ #ifndef AUDIO_TONE_STACKSIZE # define AUDIO_TONE_STACKSIZE 8 #endif -uint8_t active_tones = 0; // number of tones pushed onto the stack by audio_play_tone - might be more than the hardware is able to reproduce at any single time -musical_tone_t tones[AUDIO_TONE_STACKSIZE]; // stack of currently active tones +uint8_t active_tones = 0; // number of tones pushed onto the stack by audio_play_tone - might be more than the hardware is able to reproduce at any single time +musical_tone_t tones[AUDIO_TONE_STACKSIZE]; // stack of currently active tones -bool playing_melody = false; // playing a SONG? -bool playing_note = false; // or (possibly multiple simultaneous) tones -bool state_changed = false; // global flag, which is set if anything changes with the active_tones +bool playing_melody = false; // playing a SONG? +bool playing_note = false; // or (possibly multiple simultaneous) tones +bool state_changed = false; // global flag, which is set if anything changes with the active_tones // melody/SONG related state variables -float (*notes_pointer)[][2]; // SONG, an array of MUSICAL_NOTEs -uint16_t notes_count; // length of the notes_pointer array -bool notes_repeat; // PLAY_SONG or PLAY_LOOP? -uint16_t melody_current_note_duration = 0; // duration of the currently playing note from the active melody, in ms -uint8_t note_tempo = TEMPO_DEFAULT; // beats-per-minute -uint16_t current_note = 0; // index into the array at notes_pointer -bool note_resting = false; // if a short pause was introduced between two notes with the same frequency while playing a melody +float (*notes_pointer)[][2]; // SONG, an array of MUSICAL_NOTEs +uint16_t notes_count; // length of the notes_pointer array +bool notes_repeat; // PLAY_SONG or PLAY_LOOP? +uint16_t melody_current_note_duration = 0; // duration of the currently playing note from the active melody, in ms +uint8_t note_tempo = TEMPO_DEFAULT; // beats-per-minute +uint16_t current_note = 0; // index into the array at notes_pointer +bool note_resting = false; // if a short pause was introduced between two notes with the same frequency while playing a melody uint16_t last_timestamp = 0; #ifdef AUDIO_ENABLE_TONE_MULTIPLEXING @@ -86,7 +86,7 @@ uint16_t last_timestamp = 0; # define AUDIO_MAX_SIMULTANEOUS_TONES 3 # endif uint16_t tone_multiplexing_rate = AUDIO_TONE_MULTIPLEXING_RATE_DEFAULT; -uint8_t tone_multiplexing_index_shift = 0; // offset used on active-tone array access +uint8_t tone_multiplexing_index_shift = 0; // offset used on active-tone array access #endif // provided and used by voices.c @@ -123,12 +123,12 @@ void audio_init() { eeconfig_init(); } audio_config.raw = eeconfig_read_audio(); -#else // EEPROM settings +#else // EEPROM settings audio_config.enable = true; # ifdef AUDIO_CLICKY_ON audio_config.clicky_enable = true; # endif -#endif // EEPROM settings +#endif // EEPROM settings for (uint8_t i = 0; i < AUDIO_TONE_STACKSIZE; i++) { tones[i] = (musical_tone_t){.time_started = 0, .pitch = -1.0f, .duration = 0}; @@ -160,6 +160,8 @@ void audio_toggle(void) { eeconfig_update_audio(audio_config.raw); if (audio_config.enable) { audio_on_user(); + } else { + audio_off_user(); } } @@ -172,13 +174,16 @@ void audio_on(void) { void audio_off(void) { PLAY_SONG(audio_off_song); + audio_off_user(); wait_ms(100); audio_stop_all(); audio_config.enable = 0; eeconfig_update_audio(audio_config.raw); } -bool audio_is_on(void) { return (audio_config.enable != 0); } +bool audio_is_on(void) { + return (audio_config.enable != 0); +} void audio_stop_all() { if (audio_driver_stopped) { @@ -265,7 +270,7 @@ void audio_play_note(float pitch, uint16_t duration) { tones[j] = tones[j + 1]; tones[j + 1] = (musical_tone_t){.time_started = timer_read(), .pitch = pitch, .duration = duration}; } - return; // since this frequency played already, the hardware was already started + return; // since this frequency played already, the hardware was already started } } @@ -283,7 +288,7 @@ void audio_play_note(float pitch, uint16_t duration) { tones[active_tones - 1] = (musical_tone_t){.time_started = timer_read(), .pitch = pitch, .duration = duration}; // TODO: needs to be handled per note/tone -> use its timestamp instead? - voices_timer = timer_read(); // reset to zero, for the effects added by voices.c + voices_timer = timer_read(); // reset to zero, for the effects added by voices.c if (audio_driver_stopped) { audio_driver_start(); @@ -291,7 +296,9 @@ void audio_play_note(float pitch, uint16_t duration) { } } -void audio_play_tone(float pitch) { audio_play_note(pitch, 0xffff); } +void audio_play_tone(float pitch) { + audio_play_note(pitch, 0xffff); +} void audio_play_melody(float (*np)[][2], uint16_t n_count, bool n_repeat) { if (!audio_config.enable) { @@ -313,7 +320,7 @@ void audio_play_melody(float (*np)[][2], uint16_t n_count, bool n_repeat) { notes_count = n_count; notes_repeat = n_repeat; - current_note = 0; // note in the melody-array/list at note_pointer + current_note = 0; // note in the melody-array/list at note_pointer // start first note manually, which also starts the audio_driver // all following/remaining notes are played by 'audio_update_state' @@ -344,11 +351,17 @@ void audio_play_click(uint16_t delay, float pitch, uint16_t duration) { } } -bool audio_is_playing_note(void) { return playing_note; } +bool audio_is_playing_note(void) { + return playing_note; +} -bool audio_is_playing_melody(void) { return playing_melody; } +bool audio_is_playing_melody(void) { + return playing_melody; +} -uint8_t audio_get_number_of_active_tones(void) { return active_tones; } +uint8_t audio_get_number_of_active_tones(void) { + return active_tones; +} float audio_get_frequency(uint8_t tone_index) { if (tone_index >= active_tones) { @@ -367,7 +380,7 @@ float audio_get_processed_frequency(uint8_t tone_index) { #ifdef AUDIO_ENABLE_TONE_MULTIPLEXING index = index - tone_multiplexing_index_shift; - if (index < 0) // wrap around + if (index < 0) // wrap around index += active_tones; #endif @@ -393,7 +406,7 @@ bool audio_update_state(void) { last_timestamp = current_time; uint16_t previous_note = current_note; current_note++; - voices_timer = timer_read(); // reset to zero, for the effects added by voices.c + voices_timer = timer_read(); // reset to zero, for the effects added by voices.c if (current_note >= notes_count) { if (notes_repeat) { @@ -463,11 +476,11 @@ bool audio_update_state(void) { // housekeeping: stop notes that have no playtime left for (int i = 0; i < active_tones; i++) { - if ((tones[i].duration != 0xffff) // indefinitely playing notes, started by 'audio_play_tone' - && (tones[i].duration != 0) // 'uninitialized' + if ((tones[i].duration != 0xffff) // indefinitely playing notes, started by 'audio_play_tone' + && (tones[i].duration != 0) // 'uninitialized' ) { if (timer_elapsed(tones[i].time_started) >= tones[i].duration) { - audio_stop_tone(tones[i].pitch); // also sets 'state_changed=true' + audio_stop_tone(tones[i].pitch); // also sets 'state_changed=true' } } } @@ -484,9 +497,15 @@ bool audio_update_state(void) { // Tone-multiplexing functions #ifdef AUDIO_ENABLE_TONE_MULTIPLEXING -void audio_set_tone_multiplexing_rate(uint16_t rate) { tone_multiplexing_rate = rate; } -void audio_enable_tone_multiplexing(void) { tone_multiplexing_rate = AUDIO_TONE_MULTIPLEXING_RATE_DEFAULT; } -void audio_disable_tone_multiplexing(void) { tone_multiplexing_rate = 0; } +void audio_set_tone_multiplexing_rate(uint16_t rate) { + tone_multiplexing_rate = rate; +} +void audio_enable_tone_multiplexing(void) { + tone_multiplexing_rate = AUDIO_TONE_MULTIPLEXING_RATE_DEFAULT; +} +void audio_disable_tone_multiplexing(void) { + tone_multiplexing_rate = 0; +} void audio_increase_tone_multiplexing_rate(uint16_t change) { if ((0xffff - change) > tone_multiplexing_rate) { tone_multiplexing_rate += change; diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index 290d461f5a..fe23cf3ed1 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -54,9 +54,9 @@ typedef union { * "A musical tone is characterized by its duration, pitch, intensity (or loudness), and timbre (or quality)" */ typedef struct { - uint16_t time_started; // timestamp the tone/note was started, system time runs with 1ms resolution -> 16bit timer overflows every ~64 seconds, long enough under normal circumstances; but might be too soon for long-duration notes when the note_tempo is set to a very low value - float pitch; // aka frequency, in Hz - uint16_t duration; // in ms, converted from the musical_notes.h unit which has 64parts to a beat, factoring in the current tempo in beats-per-minute + uint16_t time_started; // timestamp the tone/note was started, system time runs with 1ms resolution -> 16bit timer overflows every ~64 seconds, long enough under normal circumstances; but might be too soon for long-duration notes when the note_tempo is set to a very low value + float pitch; // aka frequency, in Hz + uint16_t duration; // in ms, converted from the musical_notes.h unit which has 64parts to a beat, factoring in the current tempo in beats-per-minute // float intensity; // aka volume [0,1] TODO: not used at the moment; pwm drivers can't handle it // uint8_t timbre; // range: [0,100] TODO: this currently kept track of globally, should we do this per tone instead? } musical_tone_t; diff --git a/quantum/audio/song_list.h b/quantum/audio/song_list.h index 8e80a016aa..3e425abb47 100644 --- a/quantum/audio/song_list.h +++ b/quantum/audio/song_list.h @@ -22,7 +22,7 @@ #if __has_include("user_song_list.h") # include "user_song_list.h" -#endif // if file exists +#endif // if file exists #define NO_SOUND diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 8988d827e9..1c08a3af36 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -32,11 +32,17 @@ voice_type voice = AUDIO_VOICE_DEFAULT; voice_type voice = default_voice; #endif -void set_voice(voice_type v) { voice = v; } +void set_voice(voice_type v) { + voice = v; +} -void voice_iterate() { voice = (voice + 1) % number_of_voices; } +void voice_iterate() { + voice = (voice + 1) % number_of_voices; +} -void voice_deiterate() { voice = (voice - 1 + number_of_voices) % number_of_voices; } +void voice_deiterate() { + voice = (voice - 1 + number_of_voices) % number_of_voices; +} #ifdef AUDIO_VOICES float mod(float a, int b) { @@ -67,8 +73,8 @@ float voice_envelope(float frequency) { // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz // __attribute__((unused)) uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency)); #ifdef AUDIO_VOICES - uint16_t envelope_index = timer_elapsed(voices_timer); // TODO: multiply in some factor? - uint16_t compensated_index = envelope_index / 100; // TODO: correct factor would be? + uint16_t envelope_index = timer_elapsed(voices_timer); // TODO: multiply in some factor? + uint16_t compensated_index = envelope_index / 100; // TODO: correct factor would be? #endif switch (voice) { @@ -303,7 +309,7 @@ float voice_envelope(float frequency) { // note_timbre = TIMBRE_25; // break; -#endif // AUDIO_VOICES +#endif // AUDIO_VOICES default: break; @@ -318,19 +324,31 @@ float voice_envelope(float frequency) { // TODO: where to keep track of the start-frequency? // frequency = voice_add_glissando(??, frequency); } -#endif // AUDIO_VOICES +#endif // AUDIO_VOICES return frequency; } // Vibrato functions -void voice_set_vibrato_rate(float rate) { vibrato_rate = rate; } -void voice_increase_vibrato_rate(float change) { vibrato_rate *= change; } -void voice_decrease_vibrato_rate(float change) { vibrato_rate /= change; } -void voice_set_vibrato_strength(float strength) { vibrato_strength = strength; } -void voice_increase_vibrato_strength(float change) { vibrato_strength *= change; } -void voice_decrease_vibrato_strength(float change) { vibrato_strength /= change; } +void voice_set_vibrato_rate(float rate) { + vibrato_rate = rate; +} +void voice_increase_vibrato_rate(float change) { + vibrato_rate *= change; +} +void voice_decrease_vibrato_rate(float change) { + vibrato_rate /= change; +} +void voice_set_vibrato_strength(float strength) { + vibrato_strength = strength; +} +void voice_increase_vibrato_strength(float change) { + vibrato_strength *= change; +} +void voice_decrease_vibrato_strength(float change) { + vibrato_strength /= change; +} // Timbre functions @@ -339,4 +357,6 @@ void voice_set_timbre(uint8_t timbre) { note_timbre = timbre; } } -uint8_t voice_get_timbre(void) { return note_timbre; } +uint8_t voice_get_timbre(void) { + return note_timbre; +} diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h index 1f402e7e12..fcab9db556 100644 --- a/quantum/audio/voices.h +++ b/quantum/audio/voices.h @@ -40,7 +40,7 @@ typedef enum { // duty_third_down, // duty_fifth_third_down, #endif - number_of_voices // important that this is last + number_of_voices // important that this is last } voice_type; void set_voice(voice_type v); diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index dfb98419e6..52ec086bb0 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c @@ -95,10 +95,10 @@ void backlight_toggle(void) { * FIXME: needs doc */ void backlight_enable(void) { - if (backlight_config.enable) return; // do nothing if backlight is already on + if (backlight_config.enable) return; // do nothing if backlight is already on backlight_config.enable = true; - if (backlight_config.raw == 1) // enabled but level == 0 + if (backlight_config.raw == 1) // enabled but level == 0 backlight_config.level = 1; eeconfig_update_backlight(backlight_config.raw); dprintf("backlight enable\n"); @@ -110,7 +110,7 @@ void backlight_enable(void) { * FIXME: needs doc */ void backlight_disable(void) { - if (!backlight_config.enable) return; // do nothing if backlight is already off + if (!backlight_config.enable) return; // do nothing if backlight is already off backlight_config.enable = false; eeconfig_update_backlight(backlight_config.raw); @@ -122,7 +122,9 @@ void backlight_disable(void) { * * FIXME: needs doc */ -bool is_backlight_enabled(void) { return backlight_config.enable; } +bool is_backlight_enabled(void) { + return backlight_config.enable; +} /** \brief Backlight step through levels * @@ -158,11 +160,17 @@ void backlight_level(uint8_t level) { eeconfig_update_backlight(backlight_config.raw); } -uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } +uint8_t eeconfig_read_backlight(void) { + return eeprom_read_byte(EECONFIG_BACKLIGHT); +} -void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); } +void eeconfig_update_backlight(uint8_t val) { + eeprom_update_byte(EECONFIG_BACKLIGHT, val); +} -void eeconfig_update_backlight_current(void) { eeconfig_update_backlight(backlight_config.raw); } +void eeconfig_update_backlight_current(void) { + eeconfig_update_backlight(backlight_config.raw); +} void eeconfig_update_backlight_default(void) { backlight_config.enable = 1; @@ -179,7 +187,9 @@ void eeconfig_update_backlight_default(void) { * * FIXME: needs doc */ -uint8_t get_backlight_level(void) { return backlight_config.level; } +uint8_t get_backlight_level(void) { + return backlight_config.level; +} #ifdef BACKLIGHT_BREATHING /** \brief Backlight breathing toggle @@ -200,7 +210,7 @@ void backlight_toggle_breathing(void) { * FIXME: needs doc */ void backlight_enable_breathing(void) { - if (backlight_config.breathing) return; // do nothing if breathing is already on + if (backlight_config.breathing) return; // do nothing if breathing is already on backlight_config.breathing = true; eeconfig_update_backlight(backlight_config.raw); @@ -213,7 +223,7 @@ void backlight_enable_breathing(void) { * FIXME: needs doc */ void backlight_disable_breathing(void) { - if (!backlight_config.breathing) return; // do nothing if breathing is already off + if (!backlight_config.breathing) return; // do nothing if breathing is already off backlight_config.breathing = false; eeconfig_update_backlight(backlight_config.raw); @@ -225,18 +235,30 @@ void backlight_disable_breathing(void) { * * FIXME: needs doc */ -bool is_backlight_breathing(void) { return backlight_config.breathing; } +bool is_backlight_breathing(void) { + return backlight_config.breathing; +} // following are marked as weak purely for backwards compatibility -__attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; } +__attribute__((weak)) void breathing_period_set(uint8_t value) { + breathing_period = value ? value : 1; +} -__attribute__((weak)) uint8_t get_breathing_period(void) { return breathing_period; } +__attribute__((weak)) uint8_t get_breathing_period(void) { + return breathing_period; +} -__attribute__((weak)) void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } +__attribute__((weak)) void breathing_period_default(void) { + breathing_period_set(BREATHING_PERIOD); +} -__attribute__((weak)) void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } +__attribute__((weak)) void breathing_period_inc(void) { + breathing_period_set(breathing_period + 1); +} -__attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } +__attribute__((weak)) void breathing_period_dec(void) { + breathing_period_set(breathing_period - 1); +} __attribute__((weak)) void breathing_toggle(void) { if (is_breathing()) diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index c30c70fd62..ff9c8de420 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h @@ -39,7 +39,7 @@ typedef union { struct { bool enable : 1; bool breathing : 1; - uint8_t reserved : 1; // Reserved for possible future backlight modes + uint8_t reserved : 1; // Reserved for possible future backlight modes uint8_t level : 5; }; } backlight_config_t; diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index 9c972ae02e..f3a0252270 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c @@ -136,7 +136,7 @@ # define TCCRxB TCCR1B # define TIMERx_COMPA_vect TIMER1_COMPA_vect # define TIMERx_OVF_vect TIMER1_OVF_vect -# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register +# if defined(__AVR_ATmega32A__) // This MCU has only one TIMSK register # define TIMSKx TIMSK # else # define TIMSKx TIMSK1 @@ -166,7 +166,7 @@ error("Please set 'BACKLIGHT_DRIVER = custom' within rules.mk") error("Please set 'BACKLIGHT_DRIVER = software' within rules.mk") #endif -#ifndef BACKLIGHT_PWM_TIMER // pwm through software +#ifndef BACKLIGHT_PWM_TIMER // pwm through software static inline void enable_pwm(void) { # if BACKLIGHT_ON_STATE == 1 @@ -203,7 +203,9 @@ static inline void disable_pwm(void) { // or F_CPU/BACKLIGHT_CUSTOM_RESOLUTION if used. // Triggered when the counter reaches the OCRx value -ISR(TIMERx_COMPA_vect) { backlight_pins_off(); } +ISR(TIMERx_COMPA_vect) { + backlight_pins_off(); +} // Triggered when the counter reaches the TOP value // this one triggers at F_CPU/ICRx = 16MHz/65536 =~ 244 Hz @@ -232,15 +234,15 @@ ISR(TIMERx_OVF_vect) { // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { - if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max + if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max { - return v / 9; // Same as dividing by 900% + return v / 9; // Same as dividing by 900% } else { // In the next two lines values are bit-shifted. This is to avoid loosing decimals in integer math. - uint32_t y = (((uint32_t)v + (uint32_t)ICRx / 6) << 5) / ((uint32_t)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) - uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing) + uint32_t y = (((uint32_t)v + (uint32_t)ICRx / 6) << 5) / ((uint32_t)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) + uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing) - if (out > ICRx) // Avoid overflows + if (out > ICRx) // Avoid overflows { out = ICRx; } @@ -249,10 +251,14 @@ static uint16_t cie_lightness(uint16_t v) { } // rescale the supplied backlight value to be in terms of the value limit // range for val is [0..ICRx]. PWM pin is high while the timer count is below val. -static uint32_t rescale_limit_val(uint32_t val) { return (val * (BACKLIGHT_LIMIT_VAL + 1)) / 256; } +static uint32_t rescale_limit_val(uint32_t val) { + return (val * (BACKLIGHT_LIMIT_VAL + 1)) / 256; +} // range for val is [0..ICRx]. PWM pin is high while the timer count is below val. -static inline void set_pwm(uint16_t val) { OCRxx = val; } +static inline void set_pwm(uint16_t val) { + OCRxx = val; +} void backlight_set(uint8_t level) { if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; @@ -303,7 +309,9 @@ static uint16_t breathing_freq_scale_factor = 2; # ifdef BACKLIGHT_PWM_TIMER static bool breathing = false; -bool is_breathing(void) { return breathing; } +bool is_breathing(void) { + return breathing; +} # define breathing_interrupt_enable() \ do { \ @@ -315,7 +323,9 @@ bool is_breathing(void) { return breathing; } } while (0) # else -bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); } +bool is_breathing(void) { + return !!(TIMSKx & _BV(TOIEx)); +} # define breathing_interrupt_enable() \ do { \ @@ -370,7 +380,9 @@ void breathing_self_disable(void) { static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Use this before the cie_lightness function. -static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } +static inline uint16_t scale_backlight(uint16_t v) { + return v / BACKLIGHT_LEVELS * get_backlight_level(); +} # ifdef BACKLIGHT_PWM_TIMER void breathing_task(void) @@ -403,7 +415,7 @@ ISR(TIMERx_OVF_vect) set_pwm(cie_lightness(rescale_limit_val(scale_backlight((uint16_t)pgm_read_byte(&breathing_table[index]) * ICRx / 255)))); } -#endif // BACKLIGHT_BREATHING +#endif // BACKLIGHT_BREATHING void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. @@ -415,10 +427,10 @@ void backlight_init_ports(void) { #ifdef BACKLIGHT_PWM_TIMER // TimerX setup, Fast PWM mode count to TOP set in ICRx - TCCRxA = _BV(WGM11); // = 0b00000010; + TCCRxA = _BV(WGM11); // = 0b00000010; // clock select clk/1 - TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; -#else // hardware PWM + TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; +#else // hardware PWM // Pin PB7 = OCR1C (Timer 1, Channel C) // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 // (i.e. start high, go low when counter matches.) @@ -430,8 +442,8 @@ void backlight_init_ports(void) { "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." */ - TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; - TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; + TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; + TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; #endif #ifdef BACKLIGHT_CUSTOM_RESOLUTION diff --git a/quantum/backlight/backlight_chibios.c b/quantum/backlight/backlight_chibios.c index 7c6edd10d6..e8f9e70f78 100644 --- a/quantum/backlight/backlight_chibios.c +++ b/quantum/backlight/backlight_chibios.c @@ -53,14 +53,14 @@ static PWMConfig pwmCFG = {0xFFFF, /* PWM clock frequency */ // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { - if (v <= 5243) // if below 8% of max - return v / 9; // same as dividing by 900% + if (v <= 5243) // if below 8% of max + return v / 9; // same as dividing by 900% else { - uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare + uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare // to get a useful result with integer division, we shift left in the expression above // and revert what we've done again after squaring. y = y * y * y >> 8; - if (y > 0xFFFFUL) // prevent overflow + if (y > 0xFFFFUL) // prevent overflow return 0xFFFFU; else return (uint16_t)y; @@ -117,7 +117,9 @@ static const uint8_t breathing_table[BREATHING_STEPS] = {0, 0, 0, 0, 0, 0, 0, 0, void breathing_callback(PWMDriver *pwmp); -bool is_breathing(void) { return pwmCFG.callback != NULL; } +bool is_breathing(void) { + return pwmCFG.callback != NULL; +} void breathing_enable(void) { pwmCFG.callback = breathing_callback; @@ -133,7 +135,9 @@ void breathing_disable(void) { } // Use this before the cie_lightness function. -static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } +static inline uint16_t scale_backlight(uint16_t v) { + return v / BACKLIGHT_LEVELS * get_backlight_level(); +} void breathing_callback(PWMDriver *pwmp) { uint8_t breathing_period = get_breathing_period(); diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c index 270a43c67e..e4c2e90b5f 100644 --- a/quantum/backlight/backlight_driver_common.c +++ b/quantum/backlight/backlight_driver_common.c @@ -44,6 +44,10 @@ void backlight_pins_init(void) { FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);) } -void backlight_pins_on(void) { FOR_EACH_LED(backlight_on(backlight_pin);) } +void backlight_pins_on(void) { + FOR_EACH_LED(backlight_on(backlight_pin);) +} -void backlight_pins_off(void) { FOR_EACH_LED(backlight_off(backlight_pin);) } +void backlight_pins_off(void) { + FOR_EACH_LED(backlight_off(backlight_pin);) +} diff --git a/quantum/backlight/backlight_software.c b/quantum/backlight/backlight_software.c index 709304f559..3d412cab52 100644 --- a/quantum/backlight/backlight_software.c +++ b/quantum/backlight/backlight_software.c @@ -30,11 +30,17 @@ static const uint16_t backlight_duty_table[] = { // clang-format on -static uint8_t scale_backlight(uint8_t v) { return v * (backlight_duty_table_size - 1) / BACKLIGHT_LEVELS; } +static uint8_t scale_backlight(uint8_t v) { + return v * (backlight_duty_table_size - 1) / BACKLIGHT_LEVELS; +} -void backlight_init_ports(void) { backlight_pins_init(); } +void backlight_init_ports(void) { + backlight_pins_init(); +} -void backlight_set(uint8_t level) { s_duty_pattern = backlight_duty_table[scale_backlight(level)]; } +void backlight_set(uint8_t level) { + s_duty_pattern = backlight_duty_table[scale_backlight(level)]; +} void backlight_task(void) { static uint8_t backlight_tick = 0; diff --git a/quantum/backlight/backlight_timer.c b/quantum/backlight/backlight_timer.c index c32c35c154..82fb6a6a83 100644 --- a/quantum/backlight/backlight_timer.c +++ b/quantum/backlight/backlight_timer.c @@ -14,14 +14,14 @@ static uint16_t backlight_timer_get_duty(void); // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { - if (v <= 5243) // if below 8% of max - return v / 9; // same as dividing by 900% + if (v <= 5243) // if below 8% of max + return v / 9; // same as dividing by 900% else { - uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare + uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare // to get a useful result with integer division, we shift left in the expression above // and revert what we've done again after squaring. y = y * y * y >> 8; - if (y > 0xFFFFUL) // prevent overflow + if (y > 0xFFFFUL) // prevent overflow return 0xFFFFU; else return (uint16_t)y; @@ -61,7 +61,9 @@ static void backlight_timer_top(void) { } } -static void backlight_timer_cmp(void) { backlight_pins_off(); } +static void backlight_timer_cmp(void) { + backlight_pins_off(); +} void backlight_task(void) {} @@ -77,7 +79,9 @@ static uint16_t breathing_counter = 0; static const uint8_t breathing_table[BREATHING_STEPS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Use this before the cie_lightness function. -static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } +static inline uint16_t scale_backlight(uint16_t v) { + return v / BACKLIGHT_LEVELS * get_backlight_level(); +} void breathing_task(void) { uint8_t breathing_period = get_breathing_period(); @@ -91,13 +95,17 @@ void breathing_task(void) { backlight_timer_set_duty(cie_lightness(scale_backlight((uint16_t)breathing_table[index] * 256))); } -bool is_breathing(void) { return breathing; } +bool is_breathing(void) { + return breathing; +} void breathing_enable(void) { breathing_counter = 0; breathing = true; } -void breathing_disable(void) { breathing = false; } +void breathing_disable(void) { + breathing = false; +} void breathing_pulse(void) { backlight_set(is_backlight_enabled() ? 0 : BACKLIGHT_LEVELS); @@ -140,8 +148,12 @@ static void timerCallback(void) { } } -static void backlight_timer_set_duty(uint16_t duty) { s_duty = duty; } -static uint16_t backlight_timer_get_duty(void) { return s_duty; } +static void backlight_timer_set_duty(uint16_t duty) { + s_duty = duty; +} +static uint16_t backlight_timer_get_duty(void) { + return s_duty; +} // ChibiOS - Map GPT timer onto Software PWM static void gptTimerCallback(GPTDriver *gptp) { diff --git a/quantum/bitwise.c b/quantum/bitwise.c index 861cca0054..1868e14932 100644 --- a/quantum/bitwise.c +++ b/quantum/bitwise.c @@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // bit population - return number of on-bit __attribute__((noinline)) uint8_t bitpop(uint8_t bits) { uint8_t c; - for (c = 0; bits; c++) bits &= bits - 1; + for (c = 0; bits; c++) + bits &= bits - 1; return c; /* const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; @@ -30,13 +31,15 @@ __attribute__((noinline)) uint8_t bitpop(uint8_t bits) { uint8_t bitpop16(uint16_t bits) { uint8_t c; - for (c = 0; bits; c++) bits &= bits - 1; + for (c = 0; bits; c++) + bits &= bits - 1; return c; } uint8_t bitpop32(uint32_t bits) { uint8_t c; - for (c = 0; bits; c++) bits &= bits - 1; + for (c = 0; bits; c++) + bits &= bits - 1; return c; } diff --git a/quantum/bootmagic/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c index 54bbf5a2ee..f63c71fc6b 100644 --- a/quantum/bootmagic/bootmagic_lite.c +++ b/quantum/bootmagic/bootmagic_lite.c @@ -19,7 +19,9 @@ * * ...just incase someone wants to only change the eeprom behaviour */ -__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { eeconfig_disable(); } +__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { + eeconfig_disable(); +} /** \brief The lite version of TMK's bootmagic based on Wilba. * @@ -57,4 +59,6 @@ __attribute__((weak)) void bootmagic_lite(void) { } } -void bootmagic(void) { bootmagic_lite(); } +void bootmagic(void) { + bootmagic_lite(); +} diff --git a/quantum/color.c b/quantum/color.c index 1c5128e4a2..c80078dbf2 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -104,7 +104,9 @@ RGB hsv_to_rgb(HSV hsv) { #endif } -RGB hsv_to_rgb_nocie(HSV hsv) { return hsv_to_rgb_impl(hsv, false); } +RGB hsv_to_rgb_nocie(HSV hsv) { + return hsv_to_rgb_impl(hsv, false); +} #ifdef RGBW # ifndef MIN diff --git a/quantum/color.h b/quantum/color.h index e2cfc46927..135ad623b5 100644 --- a/quantum/color.h +++ b/quantum/color.h @@ -60,7 +60,7 @@ #define HSV_GOLDENROD 30, 218, 218 #define HSV_GREEN 85, 255, 255 #define HSV_MAGENTA 213, 255, 255 -#define HSV_ORANGE 28, 255, 255 +#define HSV_ORANGE 21, 255, 255 #define HSV_PINK 234, 128, 255 #define HSV_PURPLE 191, 255, 255 #define HSV_RED 0, 255, 255 diff --git a/quantum/command.c b/quantum/command.c index 6d56a25ea1..f90d73207c 100644 --- a/quantum/command.c +++ b/quantum/command.c @@ -446,7 +446,7 @@ static bool command_common(uint8_t code) { // NKRO toggle case MAGIC_KC(MAGIC_KEY_NKRO): - clear_keyboard(); // clear to prevent stuck keys + clear_keyboard(); // clear to prevent stuck keys keymap_config.nkro = !keymap_config.nkro; if (keymap_config.nkro) { print("NKRO: on\n"); diff --git a/quantum/debounce.h b/quantum/debounce.h index 5043868289..3532d9cd7b 100644 --- a/quantum/debounce.h +++ b/quantum/debounce.h @@ -6,8 +6,6 @@ // changed is true if raw has changed since the last call void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); -bool debounce_active(void); - void debounce_init(uint8_t num_rows); void debounce_free(void); diff --git a/quantum/debounce/asym_eager_defer_pk.c b/quantum/debounce/asym_eager_defer_pk.c index 81f39383c4..b1eb4a2b7b 100644 --- a/quantum/debounce/asym_eager_defer_pk.c +++ b/quantum/debounce/asym_eager_defer_pk.c @@ -165,7 +165,6 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui } } -bool debounce_active(void) { return true; } #else # include "none.c" #endif diff --git a/quantum/debounce/none.c b/quantum/debounce/none.c index b03892bc5b..8a85cc04a8 100644 --- a/quantum/debounce/none.c +++ b/quantum/debounce/none.c @@ -26,6 +26,4 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool } } -bool debounce_active(void) { return false; } - void debounce_free(void) {} diff --git a/quantum/debounce/sym_defer_g.c b/quantum/debounce/sym_defer_g.c index 9155eb914c..47450992a4 100644 --- a/quantum/debounce/sym_defer_g.c +++ b/quantum/debounce/sym_defer_g.c @@ -44,9 +44,7 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool } } -bool debounce_active(void) { return debouncing; } - void debounce_free(void) {} -#else // no debouncing. +#else // no debouncing. # include "none.c" #endif diff --git a/quantum/debounce/sym_defer_pk.c b/quantum/debounce/sym_defer_pk.c index 1b698ba347..9dee29e28e 100644 --- a/quantum/debounce/sym_defer_pk.c +++ b/quantum/debounce/sym_defer_pk.c @@ -134,7 +134,6 @@ static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], u } } -bool debounce_active(void) { return true; } #else # include "none.c" #endif diff --git a/quantum/debounce/sym_defer_pr.c b/quantum/debounce/sym_defer_pr.c new file mode 100644 index 0000000000..ce24f0922f --- /dev/null +++ b/quantum/debounce/sym_defer_pr.c @@ -0,0 +1,74 @@ +/* +Copyright 2021 Chad Austin <chad@chadaustin.me> +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/>. +*/ + +/* +Symmetric per-row debounce algorithm. Changes only apply when +DEBOUNCE milliseconds have elapsed since the last change. +*/ + +#include "matrix.h" +#include "timer.h" +#include "quantum.h" +#include <stdlib.h> + +#ifndef DEBOUNCE +# define DEBOUNCE 5 +#endif + +static uint16_t last_time; +// [row] milliseconds until key's state is considered debounced. +static uint8_t* countdowns; +// [row] +static matrix_row_t* last_raw; + +void debounce_init(uint8_t num_rows) { + countdowns = (uint8_t*)calloc(num_rows, sizeof(uint8_t)); + last_raw = (matrix_row_t*)calloc(num_rows, sizeof(matrix_row_t)); + + last_time = timer_read(); +} + +void debounce_free(void) { + free(countdowns); + countdowns = NULL; + free(last_raw); + last_raw = NULL; +} + +void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + uint16_t now = timer_read(); + uint16_t elapsed16 = TIMER_DIFF_16(now, last_time); + last_time = now; + uint8_t elapsed = (elapsed16 > 255) ? 255 : elapsed16; + + uint8_t* countdown = countdowns; + + for (uint8_t row = 0; row < num_rows; ++row, ++countdown) { + matrix_row_t raw_row = raw[row]; + + if (raw_row != last_raw[row]) { + *countdown = DEBOUNCE; + last_raw[row] = raw_row; + } else if (*countdown > elapsed) { + *countdown -= elapsed; + } else if (*countdown) { + cooked[row] = raw_row; + *countdown = 0; + } + } +} + +bool debounce_active(void) { + return true; +} diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c index 9da000ea9a..fe3e88bb06 100644 --- a/quantum/debounce/sym_eager_pk.c +++ b/quantum/debounce/sym_eager_pk.c @@ -131,7 +131,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui if (*debounce_pointer == DEBOUNCE_ELAPSED) { *debounce_pointer = DEBOUNCE; counters_need_update = true; - existing_row ^= col_mask; // flip the bit. + existing_row ^= col_mask; // flip the bit. } } debounce_pointer++; @@ -140,7 +140,6 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui } } -bool debounce_active(void) { return true; } #else # include "none.c" #endif diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c index eda92a263b..29b0cabefb 100644 --- a/quantum/debounce/sym_eager_pr.c +++ b/quantum/debounce/sym_eager_pr.c @@ -132,7 +132,6 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui } } -bool debounce_active(void) { return true; } #else # include "none.c" #endif diff --git a/quantum/debounce/tests/debounce_test_common.cpp b/quantum/debounce/tests/debounce_test_common.cpp index f9414e571d..0d5a7bb766 100644 --- a/quantum/debounce/tests/debounce_test_common.cpp +++ b/quantum/debounce/tests/debounce_test_common.cpp @@ -31,7 +31,9 @@ void set_time(uint32_t t); void advance_time(uint32_t ms); } -void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { events_.insert(events_.end(), events.begin(), events.end()); } +void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { + events_.insert(events_.end(), events.begin(), events.end()); +} void DebounceTest::runEvents() { /* Run the test multiple times, from 1kHz to 10kHz scan rate */ diff --git a/quantum/debounce/tests/rules.mk b/quantum/debounce/tests/rules.mk index e908dd6f67..8318b1c668 100644 --- a/quantum/debounce/tests/rules.mk +++ b/quantum/debounce/tests/rules.mk @@ -28,6 +28,11 @@ debounce_sym_defer_pk_SRC := $(DEBOUNCE_COMMON_SRC) \ $(QUANTUM_PATH)/debounce/sym_defer_pk.c \ $(QUANTUM_PATH)/debounce/tests/sym_defer_pk_tests.cpp +debounce_sym_defer_pr_DEFS := $(DEBOUNCE_COMMON_DEFS) +debounce_sym_defer_pr_SRC := $(DEBOUNCE_COMMON_SRC) \ + $(QUANTUM_PATH)/debounce/sym_defer_pr.c \ + $(QUANTUM_PATH)/debounce/tests/sym_defer_pr_tests.cpp + debounce_sym_eager_pk_DEFS := $(DEBOUNCE_COMMON_DEFS) debounce_sym_eager_pk_SRC := $(DEBOUNCE_COMMON_SRC) \ $(QUANTUM_PATH)/debounce/sym_eager_pk.c \ diff --git a/quantum/debounce/tests/sym_defer_pr_tests.cpp b/quantum/debounce/tests/sym_defer_pr_tests.cpp new file mode 100644 index 0000000000..417e1f4ca2 --- /dev/null +++ b/quantum/debounce/tests/sym_defer_pr_tests.cpp @@ -0,0 +1,238 @@ +/* Copyright 2021 Simon Arlott + * + * 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 "gtest/gtest.h" + +#include "debounce_test_common.h" + +TEST_F(DebounceTest, OneKeyShort1) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}}}, + /* 0ms delay (fast scan rate) */ + {5, {{0, 1, UP}}, {}}, + + {10, {}, {{0, 1, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyShort2) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}}}, + /* 1ms delay */ + {6, {{0, 1, UP}}, {}}, + + {11, {}, {{0, 1, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyShort3) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}}}, + /* 2ms delay */ + {7, {{0, 1, UP}}, {}}, + + {12, {}, {{0, 1, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyTooQuick1) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + /* Release key exactly on the debounce time */ + {5, {{0, 1, UP}}, {}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyTooQuick2) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}}}, + {6, {{0, 1, UP}}, {}}, + + /* Press key exactly on the debounce time */ + {11, {{0, 1, DOWN}}, {}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyBouncing1) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + {1, {{0, 1, UP}}, {}}, + {2, {{0, 1, DOWN}}, {}}, + {3, {{0, 1, UP}}, {}}, + {4, {{0, 1, DOWN}}, {}}, + {5, {{0, 1, UP}}, {}}, + {6, {{0, 1, DOWN}}, {}}, + {11, {}, {{0, 1, DOWN}}}, /* 5ms after DOWN at time 7 */ + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyBouncing2) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + {5, {}, {{0, 1, DOWN}}}, + {6, {{0, 1, UP}}, {}}, + {7, {{0, 1, DOWN}}, {}}, + {8, {{0, 1, UP}}, {}}, + {9, {{0, 1, DOWN}}, {}}, + {10, {{0, 1, UP}}, {}}, + {15, {}, {{0, 1, UP}}}, /* 5ms after UP at time 10 */ + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyLong) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}}}, + + {25, {{0, 1, UP}}, {}}, + + {30, {}, {{0, 1, UP}}}, + + {50, {{0, 1, DOWN}}, {}}, + + {55, {}, {{0, 1, DOWN}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, TwoKeysShort) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + {1, {{0, 2, DOWN}}, {}}, + + {6, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, + + {7, {{0, 1, UP}}, {}}, + {8, {{0, 2, UP}}, {}}, + + {13, {}, {{0, 1, UP}, {0, 2, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, TwoKeysSimultaneous1) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}}, + + {5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, + {6, {{0, 1, UP}, {0, 2, UP}}, {}}, + + {11, {}, {{0, 1, UP}, {0, 2, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, TwoKeysSimultaneous2) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + {1, {{0, 2, DOWN}}, {}}, + + {6, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, + {7, {{0, 2, UP}}, {}}, + {9, {{0, 1, UP}}, {}}, + + // Debouncing loses the specific ordering -- both events report simultaneously. + {14, {}, {{0, 1, UP}, {0, 2, UP}}}, + }); + runEvents(); +} + +TEST_F(DebounceTest, OneKeyDelayedScan1) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + /* Processing is very late */ + {300, {}, {{0, 1, DOWN}}}, + /* Immediately release key */ + {300, {{0, 1, UP}}, {}}, + + {305, {}, {{0, 1, UP}}}, + }); + time_jumps_ = true; + runEvents(); +} + +TEST_F(DebounceTest, OneKeyDelayedScan2) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + /* Processing is very late */ + {300, {}, {{0, 1, DOWN}}}, + /* Release key after 1ms */ + {301, {{0, 1, UP}}, {}}, + + {306, {}, {{0, 1, UP}}}, + }); + time_jumps_ = true; + runEvents(); +} + +TEST_F(DebounceTest, OneKeyDelayedScan3) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + /* Release key before debounce expires */ + {300, {{0, 1, UP}}, {}}, + }); + time_jumps_ = true; + runEvents(); +} + +TEST_F(DebounceTest, OneKeyDelayedScan4) { + addEvents({ + /* Time, Inputs, Outputs */ + {0, {{0, 1, DOWN}}, {}}, + + /* Processing is a bit late */ + {50, {}, {{0, 1, DOWN}}}, + /* Release key after 1ms */ + {51, {{0, 1, UP}}, {}}, + + {56, {}, {{0, 1, UP}}}, + }); + time_jumps_ = true; + runEvents(); +} diff --git a/quantum/debounce/tests/testlist.mk b/quantum/debounce/tests/testlist.mk index c54c45aa63..f7bd520698 100644 --- a/quantum/debounce/tests/testlist.mk +++ b/quantum/debounce/tests/testlist.mk @@ -1,6 +1,7 @@ TEST_LIST += \ debounce_sym_defer_g \ debounce_sym_defer_pk \ + debounce_sym_defer_pr \ debounce_sym_eager_pk \ debounce_sym_eager_pr \ debounce_asym_eager_defer_pk diff --git a/quantum/deferred_exec.c b/quantum/deferred_exec.c index 5b0a5b1425..a0046a9648 100644 --- a/quantum/deferred_exec.c +++ b/quantum/deferred_exec.c @@ -9,32 +9,27 @@ # define MAX_DEFERRED_EXECUTORS 8 #endif -typedef struct deferred_executor_t { - deferred_token token; - uint32_t trigger_time; - deferred_exec_callback callback; - void * cb_arg; -} deferred_executor_t; - -static deferred_token current_token = 0; -static uint32_t last_deferred_exec_check = 0; -static deferred_executor_t executors[MAX_DEFERRED_EXECUTORS] = {0}; - -static inline bool token_can_be_used(deferred_token token) { +//------------------------------------ +// Helpers +// + +static deferred_token current_token = 0; + +static inline bool token_can_be_used(deferred_executor_t *table, size_t table_count, deferred_token token) { if (token == INVALID_DEFERRED_TOKEN) { return false; } - for (int i = 0; i < MAX_DEFERRED_EXECUTORS; ++i) { - if (executors[i].token == token) { + for (int i = 0; i < table_count; ++i) { + if (table[i].token == token) { return false; } } return true; } -static inline deferred_token allocate_token(void) { +static inline deferred_token allocate_token(deferred_executor_t *table, size_t table_count) { deferred_token first = ++current_token; - while (!token_can_be_used(current_token)) { + while (!token_can_be_used(table, table_count, current_token)) { ++current_token; if (current_token == first) { // If we've looped back around to the first, everything is already allocated (yikes!). Need to exit with a failure. @@ -44,18 +39,22 @@ static inline deferred_token allocate_token(void) { return current_token; } -deferred_token defer_exec(uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg) { - // Ignore queueing if it's a zero-time delay, or invalid callback - if (delay_ms == 0 || !callback) { +//------------------------------------ +// Advanced API: used when a custom-allocated table is used, primarily for core code. +// + +deferred_token defer_exec_advanced(deferred_executor_t *table, size_t table_count, uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg) { + // Ignore queueing if the table isn't valid, it's a zero-time delay, or the token is not valid + if (!table || table_count == 0 || delay_ms == 0 || !callback) { return INVALID_DEFERRED_TOKEN; } // Find an unused slot and claim it - for (int i = 0; i < MAX_DEFERRED_EXECUTORS; ++i) { - deferred_executor_t *entry = &executors[i]; + for (int i = 0; i < table_count; ++i) { + deferred_executor_t *entry = &table[i]; if (entry->token == INVALID_DEFERRED_TOKEN) { // Work out the new token value, dropping out if none were available - deferred_token token = allocate_token(); + deferred_token token = allocate_token(table, table_count); if (token == INVALID_DEFERRED_TOKEN) { return false; } @@ -73,15 +72,15 @@ deferred_token defer_exec(uint32_t delay_ms, deferred_exec_callback callback, vo return INVALID_DEFERRED_TOKEN; } -bool extend_deferred_exec(deferred_token token, uint32_t delay_ms) { - // Ignore queueing if it's a zero-time delay, or the token is not valid - if (delay_ms == 0 || token == INVALID_DEFERRED_TOKEN) { +bool extend_deferred_exec_advanced(deferred_executor_t *table, size_t table_count, deferred_token token, uint32_t delay_ms) { + // Ignore queueing if the table isn't valid, it's a zero-time delay, or the token is not valid + if (!table || table_count == 0 || delay_ms == 0 || token == INVALID_DEFERRED_TOKEN) { return false; } // Find the entry corresponding to the token - for (int i = 0; i < MAX_DEFERRED_EXECUTORS; ++i) { - deferred_executor_t *entry = &executors[i]; + for (int i = 0; i < table_count; ++i) { + deferred_executor_t *entry = &table[i]; if (entry->token == token) { // Found it, extend the delay entry->trigger_time = timer_read32() + delay_ms; @@ -93,15 +92,15 @@ bool extend_deferred_exec(deferred_token token, uint32_t delay_ms) { return false; } -bool cancel_deferred_exec(deferred_token token) { - // Ignore request if the token is not valid - if (token == INVALID_DEFERRED_TOKEN) { +bool cancel_deferred_exec_advanced(deferred_executor_t *table, size_t table_count, deferred_token token) { + // Ignore request if the table/token are not valid + if (!table || table_count == 0 || token == INVALID_DEFERRED_TOKEN) { return false; } // Find the entry corresponding to the token - for (int i = 0; i < MAX_DEFERRED_EXECUTORS; ++i) { - deferred_executor_t *entry = &executors[i]; + for (int i = 0; i < table_count; ++i) { + deferred_executor_t *entry = &table[i]; if (entry->token == token) { // Found it, cancel and clear the table entry entry->token = INVALID_DEFERRED_TOKEN; @@ -116,16 +115,16 @@ bool cancel_deferred_exec(deferred_token token) { return false; } -void deferred_exec_task(void) { +void deferred_exec_advanced_task(deferred_executor_t *table, size_t table_count, uint32_t *last_execution_time) { uint32_t now = timer_read32(); // Throttle only once per millisecond - if (((int32_t)TIMER_DIFF_32(now, last_deferred_exec_check)) > 0) { - last_deferred_exec_check = now; + if (((int32_t)TIMER_DIFF_32(now, (*last_execution_time))) > 0) { + *last_execution_time = now; // Run through each of the executors - for (int i = 0; i < MAX_DEFERRED_EXECUTORS; ++i) { - deferred_executor_t *entry = &executors[i]; + for (int i = 0; i < table_count; ++i) { + deferred_executor_t *entry = &table[i]; // Check if we're supposed to execute this entry if (entry->token != INVALID_DEFERRED_TOKEN && ((int32_t)TIMER_DIFF_32(entry->trigger_time, now)) <= 0) { @@ -150,3 +149,23 @@ void deferred_exec_task(void) { } } } + +//------------------------------------ +// Basic API: used by user-mode code, guaranteed to not collide with core deferred execution +// + +static uint32_t last_deferred_exec_check = 0; +static deferred_executor_t basic_executors[MAX_DEFERRED_EXECUTORS] = {0}; + +deferred_token defer_exec(uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg) { + return defer_exec_advanced(basic_executors, MAX_DEFERRED_EXECUTORS, delay_ms, callback, cb_arg); +} +bool extend_deferred_exec(deferred_token token, uint32_t delay_ms) { + return extend_deferred_exec_advanced(basic_executors, MAX_DEFERRED_EXECUTORS, token, delay_ms); +} +bool cancel_deferred_exec(deferred_token token) { + return cancel_deferred_exec_advanced(basic_executors, MAX_DEFERRED_EXECUTORS, token); +} +void deferred_exec_task(void) { + deferred_exec_advanced_task(basic_executors, MAX_DEFERRED_EXECUTORS, &last_deferred_exec_check); +} diff --git a/quantum/deferred_exec.h b/quantum/deferred_exec.h index f80d353169..97ef0f6c0e 100644 --- a/quantum/deferred_exec.h +++ b/quantum/deferred_exec.h @@ -5,34 +5,117 @@ #include <stdbool.h> #include <stdint.h> +#include <stdlib.h> -// A token that can be used to cancel an existing deferred execution. +//------------------------------------ +// Common +//------------------------------------ + +/** + * @typedef A token that can be used to cancel or extend an existing deferred execution. + */ typedef uint8_t deferred_token; + +/** + * @def The constant used to denote an invalid deferred execution token. + */ #define INVALID_DEFERRED_TOKEN 0 -// Callback to execute. -// -- Parameter trigger_time: the intended trigger time to execute the callback -- equivalent time-space as timer_read32() -// cb_arg: the callback argument specified when enqueueing the deferred executor -// -- Return value: Non-zero re-queues the callback to execute after the returned number of milliseconds. Zero cancels repeated execution. +/** + * @typedef Callback to execute. + * @param trigger_time[in] the intended trigger time to execute the callback -- equivalent time-space as timer_read32() + * @param cb_arg[in] the callback argument specified when enqueueing the deferred executor + * @return non-zero re-queues the callback to execute after the returned number of milliseconds. Zero cancels repeated execution. + */ typedef uint32_t (*deferred_exec_callback)(uint32_t trigger_time, void *cb_arg); -// Configures the supplied deferred executor to be executed after the required number of milliseconds. -// -- Parameter delay_ms: the number of milliseconds before executing the callback -// -- callback: the executor to invoke -// -- cb_arg: the argument to pass to the executor, may be NULL if unused by the executor -// -- Return value: a token usable for cancellation, or INVALID_DEFERRED_TOKEN if an error occurred +//------------------------------------ +// Basic API: used by user-mode code, guaranteed to not collide with core deferred execution +//------------------------------------ + +/** + * Configures the supplied deferred executor to be executed after the required number of milliseconds. + * + * @param delay_ms[in] the number of milliseconds before executing the callback + * @param callback[in] the executor to invoke + * @param cb_arg[in] the argument to pass to the executor, may be NULL if unused by the executor + * @return a token usable for extension/cancellation, or INVALID_DEFERRED_TOKEN if an error occurred + */ deferred_token defer_exec(uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg); -// Allows for extending the timeframe before an existing deferred execution is invoked. -// -- Parameter token: the returned value from defer_exec for the deferred execution you wish to extend. -// -- delay_ms: the new delay (with respect to the current time) -// -- Return value: if the token was found, and the delay was extended +/** + * Allows for extending the timeframe before an existing deferred execution is invoked. + * + * @param token[in] the returned value from defer_exec for the deferred execution you wish to extend + * @param delay_ms[in] the number of milliseconds before executing the callback + * @return true if the token was extended successfully, otherwise false + */ bool extend_deferred_exec(deferred_token token, uint32_t delay_ms); -// Allows for cancellation of an existing deferred execution. -// -- Parameter token: the returned value from defer_exec for the deferred execution you wish to cancel. -// -- Return value: if the token was found, and the executor was cancelled +/** + * Allows for cancellation of an existing deferred execution. + * + * @param token[in] the returned value from defer_exec for the deferred execution you wish to cancel + * @return true if the token was cancelled successfully, otherwise false + */ bool cancel_deferred_exec(deferred_token token); -// Forward declaration for the main loop in order to execute any deferred executors. Should not be invoked by keyboard/user code. +/** + * Forward declaration for the main loop in order to execute any deferred executors. Should not be invoked by keyboard/user code. + */ void deferred_exec_task(void); + +//------------------------------------ +// Advanced API: used when a custom-allocated table is used, primarily for core code. +//------------------------------------ + +/** + * @struct Structure for containing self-hosted deferred executor tables. + * @brief Core-side code can use this to create their own tables without impacting on the use of users' ability to add deferred execution. + * Code outside deferred_exec.c should not worry about internals of this struct, and should just allocate the required number in an array. + */ +typedef struct deferred_executor_t { + deferred_token token; + uint32_t trigger_time; + deferred_exec_callback callback; + void * cb_arg; +} deferred_executor_t; + +/** + * Configures the supplied deferred executor to be executed after the required number of milliseconds. + * + * @param table[in] the custom table used for storage + * @param table_count[in] the number of available items in the table + * @param delay_ms[in] the number of milliseconds before executing the callback + * @param callback[in] the executor to invoke + * @param cb_arg[in] the argument to pass to the executor, may be NULL if unused by the executor + * @return a token usable for extension/cancellation, or INVALID_DEFERRED_TOKEN if an error occurred + */ +deferred_token defer_exec_advanced(deferred_executor_t *table, size_t table_count, uint32_t delay_ms, deferred_exec_callback callback, void *cb_arg); + +/** + * Allows for extending the timeframe before an existing deferred execution is invoked. + * + * @param token[in] the returned value from defer_exec for the deferred execution you wish to extend + * @param delay_ms[in] the number of milliseconds before executing the callback + * @return true if the token was extended successfully, otherwise false + */ +bool extend_deferred_exec_advanced(deferred_executor_t *table, size_t table_count, deferred_token token, uint32_t delay_ms); + +/** + * Allows for cancellation of an existing deferred execution. + * + * @param token[in] the returned value from defer_exec for the deferred execution you wish to cancel + * @return true if the token was cancelled successfully, otherwise false + */ +bool cancel_deferred_exec_advanced(deferred_executor_t *table, size_t table_count, deferred_token token); + +/** + * Forward declaration for the main loop in order to execute any custom table deferred executors. Should not be invoked by keyboard/user code. + * Needed for any custom-allocated deferred execution tables. Any core tasks should add appropriate invocation to quantum/main.c. + * + * @param table[in] the custom table used for storage + * @param table_count[in] the number of available items in the table + * @param last_execution_time[in,out] the last execution time -- this will be checked first to determine if execution is needed, and updated if execution occurred + */ +void deferred_exec_advanced_task(deferred_executor_t *table, size_t table_count, uint32_t *last_execution_time); diff --git a/quantum/digitizer.c b/quantum/digitizer.c index e299867429..7925129d0c 100644 --- a/quantum/digitizer.c +++ b/quantum/digitizer.c @@ -24,9 +24,13 @@ __attribute__((weak)) void digitizer_send(void) { } } -__attribute__((weak)) void digitizer_task(void) { digitizer_send(); } +__attribute__((weak)) void digitizer_task(void) { + digitizer_send(); +} -digitizer_t digitizer_get_report(void) { return digitizerReport; } +digitizer_t digitizer_get_report(void) { + return digitizerReport; +} void digitizer_set_report(digitizer_t newDigitizerReport) { digitizerReport = newDigitizerReport; diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index 133ec85027..eee29aaf91 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -52,13 +52,21 @@ static uint16_t scan_count; static bool dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; static bool last_dip_switch_state[NUMBER_OF_DIP_SWITCHES] = {0}; -__attribute__((weak)) bool dip_switch_update_user(uint8_t index, bool active) { return true; } +__attribute__((weak)) bool dip_switch_update_user(uint8_t index, bool active) { + return true; +} -__attribute__((weak)) bool dip_switch_update_kb(uint8_t index, bool active) { return dip_switch_update_user(index, active); } +__attribute__((weak)) bool dip_switch_update_kb(uint8_t index, bool active) { + return dip_switch_update_user(index, active); +} -__attribute__((weak)) bool dip_switch_update_mask_user(uint32_t state) { return true; } +__attribute__((weak)) bool dip_switch_update_mask_user(uint32_t state) { + return true; +} -__attribute__((weak)) bool dip_switch_update_mask_kb(uint32_t state) { return dip_switch_update_mask_user(state); } +__attribute__((weak)) bool dip_switch_update_mask_kb(uint32_t state) { + return dip_switch_update_mask_user(state); +} void dip_switch_init(void) { #ifdef DIP_SWITCH_PINS diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 19a6bea59a..f070375ff3 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -14,12 +14,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "keymap.h" // to get keymaps[][][] +#include "keymap.h" // to get keymaps[][][] #include "eeprom.h" -#include "progmem.h" // to read default from flash -#include "quantum.h" // for send_string() +#include "progmem.h" // to read default from flash +#include "quantum.h" // for send_string() #include "dynamic_keymap.h" -#include "via.h" // for default VIA_EEPROM_ADDR_END +#include "via.h" // for default VIA_EEPROM_ADDR_END #ifndef DYNAMIC_KEYMAP_LAYER_COUNT # define DYNAMIC_KEYMAP_LAYER_COUNT 4 @@ -29,24 +29,22 @@ # define DYNAMIC_KEYMAP_MACRO_COUNT 16 #endif -// This is the default EEPROM max address to use for dynamic keymaps. -// The default is the ATmega32u4 EEPROM max address. -// Explicitly override it if the keyboard uses a microcontroller with -// more EEPROM *and* it makes sense to increase it. +#ifndef TOTAL_EEPROM_BYTE_COUNT +# error Unknown total EEPROM size. Cannot derive maximum for dynamic keymaps. +#endif + #ifndef DYNAMIC_KEYMAP_EEPROM_MAX_ADDR -# if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 -# elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 4095 -# elif defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATtiny85__) -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 511 -# else -# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 1023 -# endif +# define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR (TOTAL_EEPROM_BYTE_COUNT - 1) +#endif + +#if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > (TOTAL_EEPROM_BYTE_COUNT - 1) +# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > " STR((TOTAL_EEPROM_BYTE_COUNT - 1)) +# error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR is configured to use more space than what is available for the selected EEPROM driver #endif // Due to usage of uint16_t check for max 65535 #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR > 65535 +# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) " > 65535" # error DYNAMIC_KEYMAP_EEPROM_MAX_ADDR must be less than 65536 #endif @@ -71,6 +69,7 @@ // or DYNAMIC_KEYMAP_EEPROM_MAX_ADDR to increase it, *only if* the microcontroller has // more than the default. #if DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR < 100 +# pragma message STR(DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) " < 100" # error Dynamic keymaps are configured to use more EEPROM than is available. #endif @@ -80,7 +79,9 @@ # define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (DYNAMIC_KEYMAP_EEPROM_MAX_ADDR - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + 1) #endif -uint8_t dynamic_keymap_get_layer_count(void) { return DYNAMIC_KEYMAP_LAYER_COUNT; } +uint8_t dynamic_keymap_get_layer_count(void) { + return DYNAMIC_KEYMAP_LAYER_COUNT; +} void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) { // TODO: optimize this with some left shifts @@ -152,9 +153,13 @@ uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { } } -uint8_t dynamic_keymap_macro_get_count(void) { return DYNAMIC_KEYMAP_MACRO_COUNT; } +uint8_t dynamic_keymap_macro_get_count(void) { + return DYNAMIC_KEYMAP_MACRO_COUNT; +} -uint16_t dynamic_keymap_macro_get_buffer_size(void) { return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; } +uint16_t dynamic_keymap_macro_get_buffer_size(void) { + return DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; +} void dynamic_keymap_macro_get_buffer(uint16_t offset, uint16_t size, uint8_t *data) { void * source = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + offset); diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 4c2ad2490c..14cd5887f4 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -49,7 +49,7 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); - eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default + eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default eeprom_update_dword(EECONFIG_RGBLIGHT, 0); eeprom_update_byte(EECONFIG_STENOMODE, 0); eeprom_update_dword(EECONFIG_HAPTIC, 0); @@ -90,13 +90,17 @@ void eeconfig_init_quantum(void) { * * FIXME: needs doc */ -void eeconfig_init(void) { eeconfig_init_quantum(); } +void eeconfig_init(void) { + eeconfig_init_quantum(); +} /** \brief eeconfig enable * * FIXME: needs doc */ -void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); } +void eeconfig_enable(void) { + eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); +} /** \brief eeconfig disable * @@ -141,29 +145,39 @@ bool eeconfig_is_disabled(void) { * * FIXME: needs doc */ -uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } +uint8_t eeconfig_read_debug(void) { + return eeprom_read_byte(EECONFIG_DEBUG); +} /** \brief eeconfig update debug * * FIXME: needs doc */ -void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); } +void eeconfig_update_debug(uint8_t val) { + eeprom_update_byte(EECONFIG_DEBUG, val); +} /** \brief eeconfig read default layer * * FIXME: needs doc */ -uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } +uint8_t eeconfig_read_default_layer(void) { + return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); +} /** \brief eeconfig update default layer * * FIXME: needs doc */ -void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); } +void eeconfig_update_default_layer(uint8_t val) { + eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); +} /** \brief eeconfig read keymap * * FIXME: needs doc */ -uint16_t eeconfig_read_keymap(void) { return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); } +uint16_t eeconfig_read_keymap(void) { + return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); +} /** \brief eeconfig update keymap * * FIXME: needs doc @@ -177,53 +191,73 @@ void eeconfig_update_keymap(uint16_t val) { * * FIXME: needs doc */ -uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); } +uint8_t eeconfig_read_audio(void) { + return eeprom_read_byte(EECONFIG_AUDIO); +} /** \brief eeconfig update audio * * FIXME: needs doc */ -void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); } +void eeconfig_update_audio(uint8_t val) { + eeprom_update_byte(EECONFIG_AUDIO, val); +} /** \brief eeconfig read kb * * FIXME: needs doc */ -uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); } +uint32_t eeconfig_read_kb(void) { + return eeprom_read_dword(EECONFIG_KEYBOARD); +} /** \brief eeconfig update kb * * FIXME: needs doc */ -void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); } +void eeconfig_update_kb(uint32_t val) { + eeprom_update_dword(EECONFIG_KEYBOARD, val); +} /** \brief eeconfig read user * * FIXME: needs doc */ -uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); } +uint32_t eeconfig_read_user(void) { + return eeprom_read_dword(EECONFIG_USER); +} /** \brief eeconfig update user * * FIXME: needs doc */ -void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); } +void eeconfig_update_user(uint32_t val) { + eeprom_update_dword(EECONFIG_USER, val); +} /** \brief eeconfig read haptic * * FIXME: needs doc */ -uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); } +uint32_t eeconfig_read_haptic(void) { + return eeprom_read_dword(EECONFIG_HAPTIC); +} /** \brief eeconfig update haptic * * FIXME: needs doc */ -void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); } +void eeconfig_update_haptic(uint32_t val) { + eeprom_update_dword(EECONFIG_HAPTIC, val); +} /** \brief eeconfig read split handedness * * FIXME: needs doc */ -bool eeconfig_read_handedness(void) { return !!eeprom_read_byte(EECONFIG_HANDEDNESS); } +bool eeconfig_read_handedness(void) { + return !!eeprom_read_byte(EECONFIG_HANDEDNESS); +} /** \brief eeconfig update split handedness * * FIXME: needs doc */ -void eeconfig_update_handedness(bool val) { eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); } +void eeconfig_update_handedness(bool val) { + eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); +} diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index 22d874273c..f3cd1867ab 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h @@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdbool.h> #ifndef EECONFIG_MAGIC_NUMBER -# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE9 // When changing, decrement this value to avoid future re-init issues +# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE9 // When changing, decrement this value to avoid future re-init issues #endif #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF @@ -112,28 +112,30 @@ void eeconfig_update_haptic(uint32_t val); bool eeconfig_read_handedness(void); void eeconfig_update_handedness(bool val); -#define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \ - static uint8_t dirty_##name = false; \ - \ - static inline void eeconfig_init_##name(void) { \ - eeprom_read_block(&config, offset, sizeof(config)); \ - dirty_##name = false; \ - } \ - static inline void eeconfig_flush_##name(bool force) { \ - if (force || dirty_##name) { \ - eeprom_update_block(&config, offset, sizeof(config)); \ - dirty_##name = false; \ - } \ - } \ - static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \ - static uint16_t flush_timer = 0; \ - if (timer_elapsed(flush_timer) > timeout) { \ - eeconfig_flush_##name(false); \ - flush_timer = timer_read(); \ - } \ - } \ - static inline void eeconfig_flag_##name(bool v) { dirty_##name |= v; } \ - static inline void eeconfig_write_##name(typeof(config) conf) { \ - memcpy(&config, &conf, sizeof(config)); \ - eeconfig_flag_##name(true); \ +#define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \ + static uint8_t dirty_##name = false; \ + \ + static inline void eeconfig_init_##name(void) { \ + eeprom_read_block(&config, offset, sizeof(config)); \ + dirty_##name = false; \ + } \ + static inline void eeconfig_flush_##name(bool force) { \ + if (force || dirty_##name) { \ + eeprom_update_block(&config, offset, sizeof(config)); \ + dirty_##name = false; \ + } \ + } \ + static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \ + static uint16_t flush_timer = 0; \ + if (timer_elapsed(flush_timer) > timeout) { \ + eeconfig_flush_##name(false); \ + flush_timer = timer_read(); \ + } \ + } \ + static inline void eeconfig_flag_##name(bool v) { \ + dirty_##name |= v; \ + } \ + static inline void eeconfig_write_##name(typeof(config) conf) { \ + memcpy(&config, &conf, sizeof(config)); \ + eeconfig_flag_##name(true); \ } diff --git a/quantum/encoder.c b/quantum/encoder.c index 8fb87281c2..59133f872a 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -59,9 +59,13 @@ static uint8_t thisHand, thatHand; static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; #endif -__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; } +__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { + return true; +} -__attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { return encoder_update_user(index, clockwise); } +__attribute__((weak)) bool encoder_update_kb(uint8_t index, bool clockwise) { + return encoder_update_user(index, clockwise); +} void encoder_init(void) { #if defined(SPLIT_KEYBOARD) && defined(ENCODERS_PAD_A_RIGHT) && defined(ENCODERS_PAD_B_RIGHT) @@ -113,7 +117,7 @@ static bool encoder_update(uint8_t index, uint8_t state) { changed = true; encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); } - if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise + if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise encoder_value[index]--; changed = true; encoder_update_kb(index, ENCODER_CLOCKWISE); @@ -140,7 +144,9 @@ bool encoder_read(void) { #ifdef SPLIT_KEYBOARD void last_encoder_activity_trigger(void); -void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } +void encoder_state_raw(uint8_t* slave_state) { + memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); +} void encoder_update_raw(uint8_t* slave_state) { bool changed = false; diff --git a/quantum/encoder/tests/mock.c b/quantum/encoder/tests/mock.c index d0506a938f..10a00cb8f2 100644 --- a/quantum/encoder/tests/mock.c +++ b/quantum/encoder/tests/mock.c @@ -26,7 +26,9 @@ uint8_t mockSetPinInputHigh(pin_t pin) { return 0; } -bool mockReadPin(pin_t pin) { return pins[pin]; } +bool mockReadPin(pin_t pin) { + return pins[pin]; +} bool setPin(pin_t pin, bool val) { pins[pin] = val; diff --git a/quantum/encoder/tests/mock_split.c b/quantum/encoder/tests/mock_split.c index 68bf3af599..dd3c26d958 100644 --- a/quantum/encoder/tests/mock_split.c +++ b/quantum/encoder/tests/mock_split.c @@ -26,7 +26,9 @@ uint8_t mockSetPinInputHigh(pin_t pin) { return 0; } -bool mockReadPin(pin_t pin) { return pins[pin]; } +bool mockReadPin(pin_t pin) { + return pins[pin]; +} bool setPin(pin_t pin, bool val) { pins[pin] = val; diff --git a/quantum/haptic.c b/quantum/haptic.c index f915acf946..31d1114806 100644 --- a/quantum/haptic.c +++ b/quantum/haptic.c @@ -247,7 +247,9 @@ void haptic_set_dwell(uint8_t dwell) { xprintf("haptic_config.dwell = %u\n", haptic_config.dwell); } -uint8_t haptic_get_enable(void) { return haptic_config.enable; } +uint8_t haptic_get_enable(void) { + return haptic_config.enable; +} uint8_t haptic_get_mode(void) { if (!haptic_config.enable) { diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 3bca05aab7..ba5609f0aa 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -16,9 +16,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdint.h> +#include "quantum.h" #include "keyboard.h" #include "matrix.h" #include "keymap.h" +#include "magic.h" #include "host.h" #include "led.h" #include "keycode.h" @@ -100,20 +102,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifdef SLEEP_LED_ENABLE # include "sleep_led.h" #endif +#ifdef SPLIT_KEYBOARD +# include "split_util.h" +#endif +#ifdef BLUETOOTH_ENABLE +# include "outputselect.h" +#endif static uint32_t last_input_modification_time = 0; -uint32_t last_input_activity_time(void) { return last_input_modification_time; } -uint32_t last_input_activity_elapsed(void) { return timer_elapsed32(last_input_modification_time); } +uint32_t last_input_activity_time(void) { + return last_input_modification_time; +} +uint32_t last_input_activity_elapsed(void) { + return timer_elapsed32(last_input_modification_time); +} static uint32_t last_matrix_modification_time = 0; -uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; } -uint32_t last_matrix_activity_elapsed(void) { return timer_elapsed32(last_matrix_modification_time); } -void last_matrix_activity_trigger(void) { last_matrix_modification_time = last_input_modification_time = timer_read32(); } +uint32_t last_matrix_activity_time(void) { + return last_matrix_modification_time; +} +uint32_t last_matrix_activity_elapsed(void) { + return timer_elapsed32(last_matrix_modification_time); +} +void last_matrix_activity_trigger(void) { + last_matrix_modification_time = last_input_modification_time = timer_read32(); +} static uint32_t last_encoder_modification_time = 0; -uint32_t last_encoder_activity_time(void) { return last_encoder_modification_time; } -uint32_t last_encoder_activity_elapsed(void) { return timer_elapsed32(last_encoder_modification_time); } -void last_encoder_activity_trigger(void) { last_encoder_modification_time = last_input_modification_time = timer_read32(); } +uint32_t last_encoder_activity_time(void) { + return last_encoder_modification_time; +} +uint32_t last_encoder_activity_elapsed(void) { + return timer_elapsed32(last_encoder_modification_time); +} +void last_encoder_activity_trigger(void) { + last_encoder_modification_time = last_input_modification_time = timer_read32(); +} // Only enable this if console is enabled to print to #if defined(DEBUG_MATRIX_SCAN_RATE) @@ -135,7 +159,9 @@ void matrix_scan_perf_task(void) { } } -uint32_t get_matrix_scan_rate(void) { return last_matrix_scan_count; } +uint32_t get_matrix_scan_rate(void) { + return last_matrix_scan_count; +} #else # define matrix_scan_perf_task() #endif @@ -155,7 +181,7 @@ static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) { } static inline bool popcount_more_than_one(matrix_row_t rowdata) { - rowdata &= rowdata - 1; // if there are less than two bits (keys) set, rowdata will become zero + rowdata &= rowdata - 1; // if there are less than two bits (keys) set, rowdata will become zero return rowdata; } @@ -212,7 +238,9 @@ __attribute__((weak)) void keyboard_pre_init_user(void) {} * * FIXME: needs doc */ -__attribute__((weak)) void keyboard_pre_init_kb(void) { keyboard_pre_init_user(); } +__attribute__((weak)) void keyboard_pre_init_kb(void) { + keyboard_pre_init_user(); +} /** \brief keyboard_post_init_user * @@ -226,7 +254,9 @@ __attribute__((weak)) void keyboard_post_init_user() {} * FIXME: needs doc */ -__attribute__((weak)) void keyboard_post_init_kb(void) { keyboard_post_init_user(); } +__attribute__((weak)) void keyboard_post_init_kb(void) { + keyboard_post_init_user(); +} /** \brief keyboard_setup * @@ -250,13 +280,17 @@ void keyboard_setup(void) { * * FIXME: needs doc */ -__attribute__((weak)) bool is_keyboard_master(void) { return true; } +__attribute__((weak)) bool is_keyboard_master(void) { + return true; +} /** \brief is_keyboard_left * * FIXME: needs doc */ -__attribute__((weak)) bool is_keyboard_left(void) { return true; } +__attribute__((weak)) bool is_keyboard_left(void) { + return true; +} #endif @@ -265,7 +299,9 @@ __attribute__((weak)) bool is_keyboard_left(void) { return true; } * Override this function if you have a condition where keypresses processing should change: * - splits where the slave side needs to process for rgb/oled functionality */ -__attribute__((weak)) bool should_process_keypress(void) { return is_keyboard_master(); } +__attribute__((weak)) bool should_process_keypress(void) { + return is_keyboard_master(); +} /** \brief housekeeping_task_kb * @@ -290,6 +326,36 @@ void housekeeping_task(void) { housekeeping_task_user(); } +/** \brief Init tasks previously located in matrix_init_quantum + * + * TODO: rationalise against keyboard_init and current split role + */ +void quantum_init(void) { + magic(); + led_init_ports(); +#ifdef BACKLIGHT_ENABLE + backlight_init_ports(); +#endif +#ifdef AUDIO_ENABLE + audio_init(); +#endif +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_init(); +#endif +#if defined(UNICODE_COMMON_ENABLE) + unicode_input_mode_init(); +#endif +#ifdef HAPTIC_ENABLE + haptic_init(); +#endif +#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE) + set_output(OUTPUT_AUTO); +#endif +} + /** \brief keyboard_init * * FIXME: needs doc @@ -300,7 +366,11 @@ void keyboard_init(void) { #ifdef VIA_ENABLE via_init(); #endif +#ifdef SPLIT_KEYBOARD + split_pre_init(); +#endif matrix_init(); + quantum_init(); #if defined(CRC_ENABLE) crc_init(); #endif @@ -341,6 +411,9 @@ void keyboard_init(void) { #ifdef VIRTSER_ENABLE virtser_init(); #endif +#ifdef SPLIT_KEYBOARD + split_post_init(); +#endif #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) debug_enable = true; @@ -363,28 +436,17 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) { #endif } -/** \brief Keyboard task: Do keyboard routine jobs - * - * Do routine keyboard jobs: +/** \brief Perform scan of keyboard matrix * - * * scan matrix - * * handle mouse movements - * * handle midi commands - * * light LEDs - * - * This is repeatedly called as fast as possible. + * Any detected changes in state are sent out as part of the processing */ -void keyboard_task(void) { +bool matrix_scan_task(void) { static matrix_row_t matrix_prev[MATRIX_ROWS]; - static uint8_t led_status = 0; matrix_row_t matrix_row = 0; matrix_row_t matrix_change = 0; #ifdef QMK_KEYS_PER_SCAN uint8_t keys_processed = 0; #endif -#ifdef ENCODER_ENABLE - bool encoders_changed = false; -#endif uint8_t matrix_changed = matrix_scan(); if (matrix_changed) last_matrix_activity_trigger(); @@ -431,10 +493,94 @@ void keyboard_task(void) { MATRIX_LOOP_END: -#ifdef DEBUG_MATRIX_SCAN_RATE matrix_scan_perf_task(); + return matrix_changed; +} + +/** \brief Tasks previously located in matrix_scan_quantum + * + * TODO: rationalise against keyboard_task and current split role + */ +void quantum_task(void) { +#ifdef SPLIT_KEYBOARD + // some tasks should only run on master + if (!is_keyboard_master()) return; +#endif + +#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY) + // There are some tasks that need to be run a little bit + // after keyboard startup, or else they will not work correctly + // because of interaction with the USB device state, which + // may still be in flux... + // + // At the moment the only feature that needs this is the + // startup song. + static bool delayed_tasks_run = false; + static uint16_t delayed_task_timer = 0; + if (!delayed_tasks_run) { + if (!delayed_task_timer) { + delayed_task_timer = timer_read(); + } else if (timer_elapsed(delayed_task_timer) > 300) { + audio_startup(); + delayed_tasks_run = true; + } + } +#endif + +#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) + music_task(); +#endif + +#ifdef KEY_OVERRIDE_ENABLE + key_override_task(); +#endif + +#ifdef SEQUENCER_ENABLE + sequencer_task(); +#endif + +#ifdef TAP_DANCE_ENABLE + tap_dance_task(); #endif +#ifdef COMBO_ENABLE + combo_task(); +#endif + +#ifdef WPM_ENABLE + decay_wpm(); +#endif + +#ifdef HAPTIC_ENABLE + haptic_task(); +#endif + +#ifdef DIP_SWITCH_ENABLE + dip_switch_read(false); +#endif + +#ifdef AUTO_SHIFT_ENABLE + autoshift_matrix_scan(); +#endif +} + +/** \brief Keyboard task: Do keyboard routine jobs + * + * Do routine keyboard jobs: + * + * * scan matrix + * * handle mouse movements + * * handle midi commands + * * light LEDs + * + * This is repeatedly called as fast as possible. + */ +void keyboard_task(void) { + bool matrix_changed = matrix_scan_task(); + (void)matrix_changed; + + quantum_task(); + #if defined(RGBLIGHT_ENABLE) rgblight_task(); #endif @@ -453,7 +599,7 @@ MATRIX_LOOP_END: #endif #ifdef ENCODER_ENABLE - encoders_changed = encoder_read(); + bool encoders_changed = encoder_read(); if (encoders_changed) last_encoder_activity_trigger(); #endif @@ -516,22 +662,5 @@ MATRIX_LOOP_END: programmable_button_send(); #endif - // update LED - if (led_status != host_keyboard_leds()) { - led_status = host_keyboard_leds(); - keyboard_set_leds(led_status); - } -} - -/** \brief keyboard set leds - * - * FIXME: needs doc - */ -void keyboard_set_leds(uint8_t leds) { - if (debug_keyboard) { - debug("keyboard_set_led: "); - debug_hex8(leds); - debug("\n"); - } - led_set(leds); + led_task(); } diff --git a/quantum/keyboard.h b/quantum/keyboard.h index 08f4e84f94..e122b38264 100644 --- a/quantum/keyboard.h +++ b/quantum/keyboard.h @@ -44,13 +44,21 @@ typedef struct { * 1) (time == 0) to handle (keyevent_t){} as empty event * 2) Matrix(255, 255) to make TICK event available */ -static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); } -static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); } -static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); } +static inline bool IS_NOEVENT(keyevent_t event) { + return event.time == 0 || (event.key.row == 255 && event.key.col == 255); +} +static inline bool IS_PRESSED(keyevent_t event) { + return (!IS_NOEVENT(event) && event.pressed); +} +static inline bool IS_RELEASED(keyevent_t event) { + return (!IS_NOEVENT(event) && !event.pressed); +} /* Tick event */ -#define TICK \ - (keyevent_t) { .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) } +#define TICK \ + (keyevent_t) { \ + .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) \ + } /* it runs once at early stage of startup before keyboard_init. */ void keyboard_setup(void); @@ -58,8 +66,6 @@ void keyboard_setup(void); void keyboard_init(void); /* it runs repeatedly in main loop */ void keyboard_task(void); -/* it runs when host LED status is updated */ -void keyboard_set_leds(uint8_t leds); /* it runs whenever code has to behave differently on a slave */ bool is_keyboard_master(void); /* it runs whenever code has to behave differently on left vs right split */ @@ -70,18 +76,18 @@ void keyboard_pre_init_user(void); void keyboard_post_init_kb(void); void keyboard_post_init_user(void); -void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol -void housekeeping_task_kb(void); // To be overridden by keyboard-level code -void housekeeping_task_user(void); // To be overridden by user/keymap-level code +void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol +void housekeeping_task_kb(void); // To be overridden by keyboard-level code +void housekeeping_task_user(void); // To be overridden by user/keymap-level code -uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity -uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity +uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity +uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity -uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity -uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity +uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity +uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity -uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity -uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity +uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity +uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity uint32_t get_matrix_scan_rate(void); diff --git a/quantum/keycode.h b/quantum/keycode.h index 38a29b439b..3c80a386d1 100644 --- a/quantum/keycode.h +++ b/quantum/keycode.h @@ -35,8 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE) #define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID) -#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) - #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) #define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN8) @@ -62,11 +60,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) #define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) -#define FN_BIT(code) (1 << FN_INDEX(code)) -#define FN_INDEX(code) ((code)-KC_FN0) -#define FN_MIN KC_FN0 -#define FN_MAX KC_FN31 - // clang-format off /* @@ -258,7 +251,7 @@ enum hid_keyboard_keypad_usage { KC_J, KC_K, KC_L, - KC_M, // 0x10 + KC_M, // 0x10 KC_N, KC_O, KC_P, @@ -274,7 +267,7 @@ enum hid_keyboard_keypad_usage { KC_Z, KC_1, KC_2, - KC_3, // 0x20 + KC_3, // 0x20 KC_4, KC_5, KC_6, @@ -290,7 +283,7 @@ enum hid_keyboard_keypad_usage { KC_MINUS, KC_EQUAL, KC_LEFT_BRACKET, - KC_RIGHT_BRACKET, // 0x30 + KC_RIGHT_BRACKET, // 0x30 KC_BACKSLASH, KC_NONUS_HASH, KC_SEMICOLON, @@ -306,7 +299,7 @@ enum hid_keyboard_keypad_usage { KC_F4, KC_F5, KC_F6, - KC_F7, // 0x40 + KC_F7, // 0x40 KC_F8, KC_F9, KC_F10, @@ -322,7 +315,7 @@ enum hid_keyboard_keypad_usage { KC_END, KC_PAGE_DOWN, KC_RIGHT, - KC_LEFT, // 0x50 + KC_LEFT, // 0x50 KC_DOWN, KC_UP, KC_NUM_LOCK, @@ -338,7 +331,7 @@ enum hid_keyboard_keypad_usage { KC_KP_5, KC_KP_6, KC_KP_7, - KC_KP_8, // 0x60 + KC_KP_8, // 0x60 KC_KP_9, KC_KP_0, KC_KP_DOT, @@ -354,7 +347,7 @@ enum hid_keyboard_keypad_usage { KC_F18, KC_F19, KC_F20, - KC_F21, // 0x70 + KC_F21, // 0x70 KC_F22, KC_F23, KC_F24, @@ -370,7 +363,7 @@ enum hid_keyboard_keypad_usage { KC_PASTE, KC_FIND, KC_KB_MUTE, - KC_KB_VOLUME_UP, // 0x80 + KC_KB_VOLUME_UP, // 0x80 KC_KB_VOLUME_DOWN, KC_LOCKING_CAPS_LOCK, KC_LOCKING_NUM_LOCK, @@ -386,7 +379,7 @@ enum hid_keyboard_keypad_usage { KC_INTERNATIONAL_7, KC_INTERNATIONAL_8, KC_INTERNATIONAL_9, - KC_LANGUAGE_1, // 0x90 + KC_LANGUAGE_1, // 0x90 KC_LANGUAGE_2, KC_LANGUAGE_3, KC_LANGUAGE_4, @@ -402,7 +395,7 @@ enum hid_keyboard_keypad_usage { KC_PRIOR, KC_RETURN, KC_SEPARATOR, - KC_OUT, // 0xA0 + KC_OUT, // 0xA0 KC_OPER, KC_CLEAR_AGAIN, KC_CRSEL, @@ -495,7 +488,7 @@ enum internal_special_keycodes { KC_MEDIA_STOP, KC_MEDIA_PLAY_PAUSE, KC_MEDIA_SELECT, - KC_MEDIA_EJECT, // 0xB0 + KC_MEDIA_EJECT, // 0xB0 KC_MAIL, KC_CALCULATOR, KC_MY_COMPUTER, @@ -509,41 +502,7 @@ enum internal_special_keycodes { KC_MEDIA_FAST_FORWARD, KC_MEDIA_REWIND, KC_BRIGHTNESS_UP, - KC_BRIGHTNESS_DOWN, - - /* Fn keys */ - KC_FN0 = 0xC0, - KC_FN1, - KC_FN2, - KC_FN3, - KC_FN4, - KC_FN5, - KC_FN6, - KC_FN7, - KC_FN8, - KC_FN9, - KC_FN10, - KC_FN11, - KC_FN12, - KC_FN13, - KC_FN14, - KC_FN15, - KC_FN16, // 0xD0 - KC_FN17, - KC_FN18, - KC_FN19, - KC_FN20, - KC_FN21, - KC_FN22, - KC_FN23, - KC_FN24, - KC_FN25, - KC_FN26, - KC_FN27, - KC_FN28, - KC_FN29, - KC_FN30, - KC_FN31 + KC_BRIGHTNESS_DOWN }; enum mouse_keys { @@ -555,7 +514,7 @@ enum mouse_keys { #endif KC_MS_DOWN, KC_MS_LEFT, - KC_MS_RIGHT, // 0xF0 + KC_MS_RIGHT, // 0xF0 KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3, @@ -580,7 +539,7 @@ enum mouse_keys { /* Acceleration */ KC_MS_ACCEL0, KC_MS_ACCEL1, - KC_MS_ACCEL2 // 0xFF + KC_MS_ACCEL2 // 0xFF }; #include "keycode_legacy.h" diff --git a/quantum/keymap.h b/quantum/keymap.h index 191e813977..2ee2e1b576 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -27,7 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include <ch.h> #endif #include "keycode.h" -#include "action_macro.h" #include "report.h" #include "host.h" // #include "print.h" @@ -35,9 +34,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "keycode_config.h" // ChibiOS uses RESET in its FlagStatus enumeration -// Therefore define it as QK_RESET here, to avoid name collision +// Therefore define it as QK_BOOTLOADER here, to avoid name collision #if defined(PROTOCOL_CHIBIOS) -# define RESET QK_RESET +# define RESET QK_BOOTLOADER #endif // Gross hack, remove me and change RESET keycode to QK_BOOT #if defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) @@ -49,8 +48,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // translates key to keycode uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); -// translates function id to action -uint16_t keymap_function_id_to_action(uint16_t function_id); - extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; -extern const uint16_t fn_actions[]; diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 5007f15f11..a91b2a0b36 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "keycode.h" #include "action_layer.h" #include "action.h" -#include "action_macro.h" #include "debug.h" #include "quantum.h" @@ -78,26 +77,8 @@ action_t action_for_keycode(uint16_t keycode) { case QK_MODS ... QK_MODS_MAX:; // Has a modifier // Split it up - action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key + action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key break; -#ifndef NO_ACTION_FUNCTION - case KC_FN0 ... KC_FN31: - action.code = keymap_function_id_to_action(FN_INDEX(keycode)); - break; - case QK_FUNCTION ... QK_FUNCTION_MAX:; - // Is a shortcut for function action_layer, pull last 12bits - // This means we have 4,096 FN macros at our disposal - action.code = keymap_function_id_to_action((int)keycode & 0xFFF); - break; -#endif -#ifndef NO_ACTION_MACRO - case QK_MACRO ... QK_MACRO_MAX: - if (keycode & 0x800) // tap macros have upper bit set - action.code = ACTION_MACRO_TAP(keycode & 0xFF); - else - action.code = ACTION_MACRO(keycode & 0xFF); - break; -#endif #ifndef NO_ACTION_LAYER case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); @@ -165,30 +146,8 @@ action_t action_for_keycode(uint16_t keycode) { return action; } -__attribute__((weak)) const uint16_t PROGMEM fn_actions[] = { - -}; - -/* Macro */ -__attribute__((weak)) const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } - -/* Function */ -__attribute__((weak)) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} - // translates key to keycode __attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { // Read entire word (16bits) return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); } - -// translates function id to action -__attribute__((weak)) uint16_t keymap_function_id_to_action(uint16_t function_id) { -// The compiler sees the empty (weak) fn_actions and generates a warning -// This function should not be called in that case, so the warning is too strict -// If this function is called however, the keymap should have overridden fn_actions, and then the compile -// is comparing against the wrong array -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" - return pgm_read_word(&fn_actions[function_id]); -#pragma GCC diagnostic pop -} diff --git a/quantum/keymap_extras/keymap_nordic.h b/quantum/keymap_extras/keymap_nordic.h index 76d2f4f6b0..55a58a25b0 100644 --- a/quantum/keymap_extras/keymap_nordic.h +++ b/quantum/keymap_extras/keymap_nordic.h @@ -24,7 +24,7 @@ #define NO_ACUT KC_EQL #define NO_AM KC_LBRC -#define NO_QUOT KC_RBRC // this is the "umlaut" char on Nordic keyboards, Apple layout +#define NO_QUOT KC_RBRC // this is the "umlaut" char on Nordic keyboards, Apple layout #define NO_AE KC_SCLN #define NO_OSLH KC_QUOT #define NO_APOS KC_NUHS diff --git a/quantum/keymap_extras/keymap_steno.h b/quantum/keymap_extras/keymap_steno.h index 310aa07409..e888ccd643 100644 --- a/quantum/keymap_extras/keymap_steno.h +++ b/quantum/keymap_extras/keymap_steno.h @@ -70,7 +70,7 @@ enum steno_keycodes { STN_NB, STN_NC, STN_ZR, - STN__MAX = STN_ZR, // must be less than QK_STENO_BOLT + STN__MAX = STN_ZR, // must be less than QK_STENO_BOLT }; #ifdef STENO_COMBINEDMAP diff --git a/quantum/led.c b/quantum/led.c index 8f0eccf55d..c5ddbc22c5 100644 --- a/quantum/led.c +++ b/quantum/led.c @@ -13,21 +13,26 @@ * 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 "led.h" +#include "host.h" +#include "debug.h" +#include "gpio.h" -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" +#ifdef BACKLIGHT_CAPS_LOCK +# ifdef BACKLIGHT_ENABLE +# include "backlight.h" extern backlight_config_t backlight_config; -#else -// Cannot use BACKLIGHT_CAPS_LOCK without backlight being enabled -# undef BACKLIGHT_CAPS_LOCK +# else +# pragma message "Cannot use BACKLIGHT_CAPS_LOCK without backlight being enabled" +# undef BACKLIGHT_CAPS_LOCK +# endif #endif #ifndef LED_PIN_ON_STATE # define LED_PIN_ON_STATE 1 #endif -#if defined(BACKLIGHT_CAPS_LOCK) +#ifdef BACKLIGHT_CAPS_LOCK /** \brief Caps Lock indicator using backlight (for keyboards without dedicated LED) */ static void handle_backlight_caps_lock(led_t led_state) { @@ -59,13 +64,17 @@ __attribute__((weak)) void led_set_user(uint8_t usb_led) {} * * \deprecated Use led_update_kb() instead. */ -__attribute__((weak)) void led_set_kb(uint8_t usb_led) { led_set_user(usb_led); } +__attribute__((weak)) void led_set_kb(uint8_t usb_led) { + led_set_user(usb_led); +} /** \brief Lock LED update callback - keymap/user level * * \return True if led_update_kb() should run its own code, false otherwise. */ -__attribute__((weak)) bool led_update_user(led_t led_state) { return true; } +__attribute__((weak)) bool led_update_user(led_t led_state) { + return true; +} /** \brief Lock LED update callback - keyboard level * @@ -135,3 +144,43 @@ __attribute__((weak)) void led_set(uint8_t usb_led) { led_set_kb(usb_led); led_update_kb((led_t)usb_led); } + +/** \brief Trigger behaviour on transition to suspend + */ +void led_suspend(void) { + uint8_t leds_off = 0; +#ifdef BACKLIGHT_CAPS_LOCK + if (is_backlight_enabled()) { + // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off + leds_off |= (1 << USB_LED_CAPS_LOCK); + } +#endif + led_set(leds_off); +} + +/** \brief Trigger behaviour on transition from suspend + */ +void led_wakeup(void) { + led_set(host_keyboard_leds()); +} + +/** \brief set host led state + * + * Only sets state if change detected + */ +void led_task(void) { + static uint8_t last_led_status = 0; + + // update LED + uint8_t led_status = host_keyboard_leds(); + if (last_led_status != led_status) { + last_led_status = led_status; + + if (debug_keyboard) { + debug("led_task: "); + debug_hex8(led_status); + debug("\n"); + } + led_set(led_status); + } +} diff --git a/quantum/led.h b/quantum/led.h index 0fe38ea035..934d25312c 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -49,6 +49,18 @@ void led_set(uint8_t usb_led); void led_init_ports(void); +void led_suspend(void); + +void led_wakeup(void); + +void led_task(void); + +/* Callbacks */ +void led_set_user(uint8_t usb_led); +void led_set_kb(uint8_t usb_led); +bool led_update_user(led_t led_state); +bool led_update_kb(led_t led_state); + #ifdef __cplusplus } #endif diff --git a/quantum/led_matrix/animations/alpha_mods_anim.h b/quantum/led_matrix/animations/alpha_mods_anim.h index 4d017894a1..01acb3f933 100644 --- a/quantum/led_matrix/animations/alpha_mods_anim.h +++ b/quantum/led_matrix/animations/alpha_mods_anim.h @@ -20,5 +20,5 @@ bool ALPHAS_MODS(effect_params_t* params) { return led_matrix_check_finished_leds(led_max); } -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_ALPHAS_MODS +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_ALPHAS_MODS diff --git a/quantum/led_matrix/animations/band_anim.h b/quantum/led_matrix/animations/band_anim.h index 293be4f67a..d9491849ea 100644 --- a/quantum/led_matrix/animations/band_anim.h +++ b/quantum/led_matrix/animations/band_anim.h @@ -7,7 +7,9 @@ static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(v < 0 ? 0 : v, val); } -bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); } +bool BAND(effect_params_t* params) { + return effect_runner_i(params, &BAND_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_BAND +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_BAND diff --git a/quantum/led_matrix/animations/band_pinwheel_anim.h b/quantum/led_matrix/animations/band_pinwheel_anim.h index f47a3869ce..482d183eb6 100644 --- a/quantum/led_matrix/animations/band_pinwheel_anim.h +++ b/quantum/led_matrix/animations/band_pinwheel_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(BAND_PINWHEEL) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); } +static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { + return scale8(val - time - atan2_8(dy, dx) * 3, val); +} -bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); } +bool BAND_PINWHEEL(effect_params_t* params) { + return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_BAND_PINWHEEL +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_BAND_PINWHEEL diff --git a/quantum/led_matrix/animations/band_spiral_anim.h b/quantum/led_matrix/animations/band_spiral_anim.h index a4bd382181..ef93d19270 100644 --- a/quantum/led_matrix/animations/band_spiral_anim.h +++ b/quantum/led_matrix/animations/band_spiral_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(BAND_SPIRAL) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); } +static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + return scale8(val + dist - time - atan2_8(dy, dx), val); +} -bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); } +bool BAND_SPIRAL(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_BAND_SPIRAL +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_BAND_SPIRAL diff --git a/quantum/led_matrix/animations/breathing_anim.h b/quantum/led_matrix/animations/breathing_anim.h index 899925f516..0bd4cb0cc3 100644 --- a/quantum/led_matrix/animations/breathing_anim.h +++ b/quantum/led_matrix/animations/breathing_anim.h @@ -15,5 +15,5 @@ bool BREATHING(effect_params_t* params) { return led_matrix_check_finished_leds(led_max); } -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_BREATHING +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_BREATHING diff --git a/quantum/led_matrix/animations/cycle_left_right_anim.h b/quantum/led_matrix/animations/cycle_left_right_anim.h index 1a8999b831..0a339e6d62 100644 --- a/quantum/led_matrix/animations/cycle_left_right_anim.h +++ b/quantum/led_matrix/animations/cycle_left_right_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); } +static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { + return scale8(g_led_config.point[i].x - time, val); +} -bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_CYCLE_LEFT_RIGHT +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/led_matrix/animations/cycle_out_in_anim.h b/quantum/led_matrix/animations/cycle_out_in_anim.h index 77d3a14b6f..8311d97fe8 100644 --- a/quantum/led_matrix/animations/cycle_out_in_anim.h +++ b/quantum/led_matrix/animations/cycle_out_in_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(CYCLE_OUT_IN) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); } +static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + return scale8(3 * dist / 2 + time, val); +} -bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } +bool CYCLE_OUT_IN(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_CYCLE_OUT_IN +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_CYCLE_OUT_IN diff --git a/quantum/led_matrix/animations/cycle_up_down_anim.h b/quantum/led_matrix/animations/cycle_up_down_anim.h index b25947199c..7e2d71a0f1 100644 --- a/quantum/led_matrix/animations/cycle_up_down_anim.h +++ b/quantum/led_matrix/animations/cycle_up_down_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(CYCLE_UP_DOWN) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); } +static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { + return scale8(g_led_config.point[i].y - time, val); +} -bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } +bool CYCLE_UP_DOWN(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_UP_DOWN_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_CYCLE_UP_DOWN +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/led_matrix/animations/dual_beacon_anim.h b/quantum/led_matrix/animations/dual_beacon_anim.h index 81735e323c..1dfb5ffe52 100644 --- a/quantum/led_matrix/animations/dual_beacon_anim.h +++ b/quantum/led_matrix/animations/dual_beacon_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(DUAL_BEACON) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); } +static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); +} -bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } +bool DUAL_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_DUAL_BEACON +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_DUAL_BEACON diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive.h b/quantum/led_matrix/animations/runners/effect_runner_reactive.h index be3090aa53..8468458744 100644 --- a/quantum/led_matrix/animations/runners/effect_runner_reactive.h +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive.h @@ -25,4 +25,4 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { return led_matrix_check_finished_leds(led_max); } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h index f6ffc825a1..aec4a6ffda 100644 --- a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h @@ -23,4 +23,4 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react return led_matrix_check_finished_leds(led_max); } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_anim.h b/quantum/led_matrix/animations/solid_anim.h index c728dbcc98..895542e152 100644 --- a/quantum/led_matrix/animations/solid_anim.h +++ b/quantum/led_matrix/animations/solid_anim.h @@ -12,4 +12,4 @@ bool SOLID(effect_params_t* params) { return led_matrix_check_finished_leds(led_max); } -#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/led_matrix/animations/solid_reactive_cross.h b/quantum/led_matrix/animations/solid_reactive_cross.h index a149e9a929..55a2556996 100644 --- a/quantum/led_matrix/animations/solid_reactive_cross.h +++ b/quantum/led_matrix/animations/solid_reactive_cross.h @@ -23,13 +23,17 @@ static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, int16_t dx, int16_t dy, ui } # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_CROSS -bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); +} # endif # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS -bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } +bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); +} # endif -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_nexus.h b/quantum/led_matrix/animations/solid_reactive_nexus.h index 5a86e48c6c..b1ec54e3b1 100644 --- a/quantum/led_matrix/animations/solid_reactive_nexus.h +++ b/quantum/led_matrix/animations/solid_reactive_nexus.h @@ -20,13 +20,17 @@ static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, ui } # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS -bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); +} # endif # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS -bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } +bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); +} # endif -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_simple_anim.h b/quantum/led_matrix/animations/solid_reactive_simple_anim.h index 14f5e90730..3b289c78dd 100644 --- a/quantum/led_matrix/animations/solid_reactive_simple_anim.h +++ b/quantum/led_matrix/animations/solid_reactive_simple_anim.h @@ -3,10 +3,14 @@ LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); } +static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { + return scale8(255 - offset, val); +} -bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // ENABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // ENABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_wide.h b/quantum/led_matrix/animations/solid_reactive_wide.h index 9f039c45d4..dda54eab2c 100644 --- a/quantum/led_matrix/animations/solid_reactive_wide.h +++ b/quantum/led_matrix/animations/solid_reactive_wide.h @@ -18,13 +18,17 @@ static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uin } # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_WIDE -bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); +} # endif # ifdef ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE -bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } +bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); +} # endif -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || defined(ENABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_splash_anim.h b/quantum/led_matrix/animations/solid_splash_anim.h index 17b692a09a..b8b6e8ea5e 100644 --- a/quantum/led_matrix/animations/solid_splash_anim.h +++ b/quantum/led_matrix/animations/solid_splash_anim.h @@ -18,13 +18,17 @@ uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uin } # ifdef ENABLE_LED_MATRIX_SOLID_SPLASH -bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } +bool SOLID_SPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); +} # endif # ifdef ENABLE_LED_MATRIX_SOLID_MULTISPLASH -bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } +bool SOLID_MULTISPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); +} # endif -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // defined(ENABLE_LED_MATRIX_SPLASH) || defined(ENABLE_LED_MATRIX_MULTISPLASH) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // defined(ENABLE_LED_MATRIX_SPLASH) || defined(ENABLE_LED_MATRIX_MULTISPLASH) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/wave_left_right_anim.h b/quantum/led_matrix/animations/wave_left_right_anim.h index 76487f8515..8dedd64738 100644 --- a/quantum/led_matrix/animations/wave_left_right_anim.h +++ b/quantum/led_matrix/animations/wave_left_right_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); } +static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { + return scale8(sin8(g_led_config.point[i].x - time), val); +} -bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); } +bool WAVE_LEFT_RIGHT(effect_params_t* params) { + return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_WAVE_LEFT_RIGHT +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_WAVE_LEFT_RIGHT diff --git a/quantum/led_matrix/animations/wave_up_down_anim.h b/quantum/led_matrix/animations/wave_up_down_anim.h index 94710f5c6e..4564f3e493 100644 --- a/quantum/led_matrix/animations/wave_up_down_anim.h +++ b/quantum/led_matrix/animations/wave_up_down_anim.h @@ -2,9 +2,13 @@ LED_MATRIX_EFFECT(WAVE_UP_DOWN) # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS -static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); } +static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { + return scale8(sin8(g_led_config.point[i].y - time), val); +} -bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); } +bool WAVE_UP_DOWN(effect_params_t* params) { + return effect_runner_i(params, &WAVE_UP_DOWN_math); +} -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_LED_MATRIX_WAVE_UP_DOWN +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_LED_MATRIX_WAVE_UP_DOWN diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index be1494e884..38ed79bed0 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -88,14 +88,14 @@ const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; #endif // globals -led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr +led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_led_timer; #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; -#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS +#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS #ifdef LED_MATRIX_KEYREACTIVE_ENABLED last_hit_t g_last_hit_tracker; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED // internals static bool suspend_state = false; @@ -105,13 +105,13 @@ static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; static led_task_states led_task_state = SYNCING; #if LED_DISABLE_TIMEOUT > 0 static uint32_t led_anykey_timer; -#endif // LED_DISABLE_TIMEOUT > 0 +#endif // LED_DISABLE_TIMEOUT > 0 // double buffers static uint32_t led_timer_buffer; #ifdef LED_MATRIX_KEYREACTIVE_ENABLED static last_hit_t last_hit_buffer; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED // split led matrix #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) @@ -120,7 +120,9 @@ const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; EECONFIG_DEBOUNCE_HELPER(led_matrix, EECONFIG_LED_MATRIX, led_matrix_eeconfig); -void eeconfig_update_led_matrix(void) { eeconfig_flush_led_matrix(true); } +void eeconfig_update_led_matrix(void) { + eeconfig_flush_led_matrix(true); +} void eeconfig_update_led_matrix_default(void) { dprintf("eeconfig_update_led_matrix_default\n"); @@ -141,7 +143,9 @@ void eeconfig_debug_led_matrix(void) { dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags); } -__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } +__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { + return 0; +} uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i); @@ -153,7 +157,9 @@ uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l return led_count; } -void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } +void led_matrix_update_pwm_buffers(void) { + led_matrix_driver.flush(); +} void led_matrix_set_value(int index, uint8_t value) { #ifdef USE_CIE1931_CURVE @@ -164,7 +170,8 @@ void led_matrix_set_value(int index, uint8_t value) { void led_matrix_set_value_all(uint8_t value) { #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) + led_matrix_set_value(i, value); #else # ifdef USE_CIE1931_CURVE led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value])); @@ -180,7 +187,7 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { #endif #if LED_DISABLE_TIMEOUT > 0 led_anykey_timer = 0; -#endif // LED_DISABLE_TIMEOUT > 0 +#endif // LED_DISABLE_TIMEOUT > 0 #ifdef LED_MATRIX_KEYREACTIVE_ENABLED uint8_t led[LED_HITS_TO_REMEMBER]; @@ -190,7 +197,7 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { if (!pressed) # elif defined(LED_MATRIX_KEYPRESSES) if (pressed) -# endif // defined(LED_MATRIX_KEYRELEASES) +# endif // defined(LED_MATRIX_KEYRELEASES) { led_count = led_matrix_map_row_column_to_led(row, col, led); } @@ -198,7 +205,7 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit + memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); last_hit_buffer.count = LED_HITS_TO_REMEMBER - led_count; } @@ -211,13 +218,13 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { last_hit_buffer.tick[index] = 0; last_hit_buffer.count++; } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED #if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_LED_MATRIX_TYPING_HEATMAP) if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) { process_led_matrix_typing_heatmap(row, col); } -#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_LED_MATRIX_TYPING_HEATMAP) +#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_LED_MATRIX_TYPING_HEATMAP) } static bool led_matrix_none(effect_params_t *params) { @@ -232,7 +239,7 @@ static bool led_matrix_none(effect_params_t *params) { static void led_task_timers(void) { #if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer); -#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 +#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 led_timer_buffer = sync_timer_read32(); // Update double buffer timers @@ -244,7 +251,7 @@ static void led_task_timers(void) { led_anykey_timer += deltaTime; } } -#endif // LED_DISABLE_TIMEOUT > 0 +#endif // LED_DISABLE_TIMEOUT > 0 // Update double buffer last hit timers #ifdef LED_MATRIX_KEYREACTIVE_ENABLED @@ -256,7 +263,7 @@ static void led_task_timers(void) { } last_hit_buffer.tick[i] += deltaTime; } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED } static void led_task_sync(void) { @@ -273,7 +280,7 @@ static void led_task_start(void) { g_led_timer = led_timer_buffer; #ifdef LED_MATRIX_KEYREACTIVE_ENABLED g_last_hit_tracker = last_hit_buffer; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED // next task led_task_state = RENDERING; @@ -352,7 +359,7 @@ void led_matrix_task(void) { bool suspend_backlight = suspend_state || #if LED_DISABLE_TIMEOUT > 0 (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || -#endif // LED_DISABLE_TIMEOUT > 0 +#endif // LED_DISABLE_TIMEOUT > 0 false; uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode; @@ -421,7 +428,7 @@ void led_matrix_init(void) { for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { last_hit_buffer.tick[i] = UINT16_MAX; } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED if (!eeconfig_is_enabled()) { dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); @@ -434,20 +441,22 @@ void led_matrix_init(void) { dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_led_matrix_default(); } - eeconfig_debug_led_matrix(); // display current eeprom values + eeconfig_debug_led_matrix(); // display current eeprom values } void led_matrix_set_suspend_state(bool state) { #ifdef LED_DISABLE_WHEN_USB_SUSPENDED - if (state && !suspend_state && is_keyboard_master()) { // only run if turning off, and only once - led_task_render(0); // turn off all LEDs when suspending - led_task_flush(0); // and actually flash led state to LEDs + if (state && !suspend_state && is_keyboard_master()) { // only run if turning off, and only once + led_task_render(0); // turn off all LEDs when suspending + led_task_flush(0); // and actually flash led state to LEDs } suspend_state = state; #endif } -bool led_matrix_get_suspend_state(void) { return suspend_state; } +bool led_matrix_get_suspend_state(void) { + return suspend_state; +} void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { led_matrix_eeconfig.enable ^= 1; @@ -455,8 +464,12 @@ void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { eeconfig_flag_led_matrix(write_to_eeprom); dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); } -void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } -void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } +void led_matrix_toggle_noeeprom(void) { + led_matrix_toggle_eeprom_helper(false); +} +void led_matrix_toggle(void) { + led_matrix_toggle_eeprom_helper(true); +} void led_matrix_enable(void) { led_matrix_enable_noeeprom(); @@ -478,7 +491,9 @@ void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } -uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; } +uint8_t led_matrix_is_enabled(void) { + return led_matrix_eeconfig.enable; +} void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!led_matrix_eeconfig.enable) { @@ -495,24 +510,38 @@ void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { eeconfig_flag_led_matrix(write_to_eeprom); dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); } -void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } -void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); } +void led_matrix_mode_noeeprom(uint8_t mode) { + led_matrix_mode_eeprom_helper(mode, false); +} +void led_matrix_mode(uint8_t mode) { + led_matrix_mode_eeprom_helper(mode, true); +} -uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } +uint8_t led_matrix_get_mode(void) { + return led_matrix_eeconfig.mode; +} void led_matrix_step_helper(bool write_to_eeprom) { uint8_t mode = led_matrix_eeconfig.mode + 1; led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); } -void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); } -void led_matrix_step(void) { led_matrix_step_helper(true); } +void led_matrix_step_noeeprom(void) { + led_matrix_step_helper(false); +} +void led_matrix_step(void) { + led_matrix_step_helper(true); +} void led_matrix_step_reverse_helper(bool write_to_eeprom) { uint8_t mode = led_matrix_eeconfig.mode - 1; led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); } -void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); } -void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); } +void led_matrix_step_reverse_noeeprom(void) { + led_matrix_step_reverse_helper(false); +} +void led_matrix_step_reverse(void) { + led_matrix_step_reverse_helper(true); +} void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { if (!led_matrix_eeconfig.enable) { @@ -522,37 +551,77 @@ void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { eeconfig_flag_led_matrix(write_to_eeprom); dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); } -void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } -void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); } +void led_matrix_set_val_noeeprom(uint8_t val) { + led_matrix_set_val_eeprom_helper(val, false); +} +void led_matrix_set_val(uint8_t val) { + led_matrix_set_val_eeprom_helper(val, true); +} -uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; } +uint8_t led_matrix_get_val(void) { + return led_matrix_eeconfig.val; +} -void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } -void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); } -void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); } +void led_matrix_increase_val_helper(bool write_to_eeprom) { + led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); +} +void led_matrix_increase_val_noeeprom(void) { + led_matrix_increase_val_helper(false); +} +void led_matrix_increase_val(void) { + led_matrix_increase_val_helper(true); +} -void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } -void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); } -void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } +void led_matrix_decrease_val_helper(bool write_to_eeprom) { + led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); +} +void led_matrix_decrease_val_noeeprom(void) { + led_matrix_decrease_val_helper(false); +} +void led_matrix_decrease_val(void) { + led_matrix_decrease_val_helper(true); +} void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { led_matrix_eeconfig.speed = speed; eeconfig_flag_led_matrix(write_to_eeprom); dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); } -void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } -void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); } +void led_matrix_set_speed_noeeprom(uint8_t speed) { + led_matrix_set_speed_eeprom_helper(speed, false); +} +void led_matrix_set_speed(uint8_t speed) { + led_matrix_set_speed_eeprom_helper(speed, true); +} -uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; } +uint8_t led_matrix_get_speed(void) { + return led_matrix_eeconfig.speed; +} -void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } -void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); } -void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); } +void led_matrix_increase_speed_helper(bool write_to_eeprom) { + led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); +} +void led_matrix_increase_speed_noeeprom(void) { + led_matrix_increase_speed_helper(false); +} +void led_matrix_increase_speed(void) { + led_matrix_increase_speed_helper(true); +} -void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } -void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); } -void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); } +void led_matrix_decrease_speed_helper(bool write_to_eeprom) { + led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); +} +void led_matrix_decrease_speed_noeeprom(void) { + led_matrix_decrease_speed_helper(false); +} +void led_matrix_decrease_speed(void) { + led_matrix_decrease_speed_helper(true); +} -led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; } +led_flags_t led_matrix_get_flags(void) { + return led_matrix_eeconfig.flags; +} -void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; } +void led_matrix_set_flags(led_flags_t flags) { + led_matrix_eeconfig.flags = flags; +} diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index e42be64661..d21f36e295 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -2,6 +2,7 @@ * Copyright 2017 Jack Humbert * Copyright 2018 Yiancar * Copyright 2019 Clueboard + * Copyright 2021 Leo Deng * * 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 @@ -26,6 +27,11 @@ #ifdef IS31FL3731 # include "is31fl3731-simple.h" +#elif defined(IS31FLCOMMON) +# include "is31flcommon.h" +#endif +#ifdef IS31FL3733 +# include "is31fl3733-simple.h" #endif #ifndef LED_MATRIX_LED_FLUSH_LIMIT diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c index 2157619a0b..847ca1c310 100644 --- a/quantum/led_matrix/led_matrix_drivers.c +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -25,7 +25,7 @@ * in their own files. */ -#if defined(IS31FL3731) || defined(IS31FL3733) +#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FLCOMMON) # include "i2c_master.h" static void init(void) { @@ -66,6 +66,18 @@ static void init(void) { # endif # endif # endif + +# elif defined(IS31FLCOMMON) + IS31FL_common_init(DRIVER_ADDR_1, ISSI_SSR_1); +# if defined(LED_DRIVER_ADDR_2) + IS31FL_common_init(DRIVER_ADDR_2, ISSI_SSR_2); +# if defined(LED_DRIVER_ADDR_3) + IS31FL_common_init(DRIVER_ADDR_3, ISSI_SSR_3); +# if defined(LED_DRIVER_ADDR_4) + IS31FL_common_init(DRIVER_ADDR_4, ISSI_SSR_4); +# endif +# endif +# endif # endif for (int index = 0; index < DRIVER_LED_TOTAL; index++) { @@ -73,6 +85,8 @@ static void init(void) { IS31FL3731_set_led_control_register(index, true); # elif defined(IS31FL3733) IS31FL3733_set_led_control_register(index, true); +# elif defined(IS31FLCOMMON) + IS31FL_simple_set_scaling_buffer(index, true); # endif } @@ -100,6 +114,21 @@ static void init(void) { # endif # endif # endif + +# elif defined(IS31FLCOMMON) +# ifdef ISSI_MANUAL_SCALING + IS31FL_set_manual_scaling_buffer(); +# endif + IS31FL_common_update_scaling_register(DRIVER_ADDR_1, 0); +# if defined(LED_DRIVER_ADDR_2) + IS31FL_common_update_scaling_register(DRIVER_ADDR_2, 1); +# if defined(LED_DRIVER_ADDR_3) + IS31FL_common_update_scaling_register(DRIVER_ADDR_3, 2); +# if defined(LED_DRIVER_ADDR_4) + IS31FL_common_update_scaling_register(DRIVER_ADDR_4, 3); +# endif +# endif +# endif # endif } @@ -144,5 +173,26 @@ const led_matrix_driver_t led_matrix_driver = { .set_value = IS31FL3733_set_value, .set_value_all = IS31FL3733_set_value_all, }; + +# elif defined(IS31FLCOMMON) +static void flush(void) { + IS31FL_common_update_pwm_register(DRIVER_ADDR_1, 0); +# if defined(LED_DRIVER_ADDR_2) + IS31FL_common_update_pwm_register(DRIVER_ADDR_2, 1); +# if defined(LED_DRIVER_ADDR_3) + IS31FL_common_update_pwm_register(DRIVER_ADDR_3, 2); +# if defined(LED_DRIVER_ADDR_4) + IS31FL_common_update_pwm_register(DRIVER_ADDR_4, 3); +# endif +# endif +# endif +} + +const led_matrix_driver_t led_matrix_driver = { + .init = init, + .flush = flush, + .set_value = IS31FL_simple_set_brightness, + .set_value_all = IS31FL_simple_set_brigntness_all, +}; # endif #endif diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h index 61cdbd9b8e..3dc533100f 100644 --- a/quantum/led_matrix/led_matrix_types.h +++ b/quantum/led_matrix/led_matrix_types.h @@ -36,7 +36,7 @@ // Last led hit #ifndef LED_HITS_TO_REMEMBER # define LED_HITS_TO_REMEMBER 8 -#endif // LED_HITS_TO_REMEMBER +#endif // LED_HITS_TO_REMEMBER #ifdef LED_MATRIX_KEYREACTIVE_ENABLED typedef struct PACKED { @@ -46,7 +46,7 @@ typedef struct PACKED { uint8_t index[LED_HITS_TO_REMEMBER]; uint16_t tick[LED_HITS_TO_REMEMBER]; } last_hit_t; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED +#endif // LED_MATRIX_KEYREACTIVE_ENABLED typedef enum led_task_states { STARTING, RENDERING, FLUSHING, SYNCING } led_task_states; @@ -87,7 +87,7 @@ typedef union { uint8_t mode : 6; uint16_t reserved; uint8_t val; - uint8_t speed; // EECONFIG needs to be increased to support this + uint8_t speed; // EECONFIG needs to be increased to support this led_flags_t flags; }; } led_eeconfig_t; diff --git a/quantum/logging/debug.c b/quantum/logging/debug.c index ea62deaa8c..ca7654eda2 100644 --- a/quantum/logging/debug.c +++ b/quantum/logging/debug.c @@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "debug.h" debug_config_t debug_config = { - .enable = false, // - .matrix = false, // - .keyboard = false, // - .mouse = false, // - .reserved = 0 // + .enable = false, // + .matrix = false, // + .keyboard = false, // + .mouse = false, // + .reserved = 0 // }; diff --git a/quantum/logging/print.c b/quantum/logging/print.c index e8440e55ee..50a6b826ee 100644 --- a/quantum/logging/print.c +++ b/quantum/logging/print.c @@ -19,9 +19,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // bind lib/printf to console interface - sendchar -static int8_t null_sendchar_func(uint8_t c) { return 0; } +static int8_t null_sendchar_func(uint8_t c) { + return 0; +} static sendchar_func_t func = null_sendchar_func; -void print_set_sendchar(sendchar_func_t send) { func = send; } +void print_set_sendchar(sendchar_func_t send) { + func = send; +} -void _putchar(char character) { func(character); } +void _putchar(char character) { + func(character); +} diff --git a/quantum/logging/print.h b/quantum/logging/print.h index 8c055f549e..aa72fc7074 100644 --- a/quantum/logging/print.h +++ b/quantum/logging/print.h @@ -37,7 +37,7 @@ void print_set_sendchar(sendchar_func_t func); # include_next "_print.h" /* Include the platforms print.h */ # else // Fall back to lib/printf -# include "printf.h" // lib/printf/printf.h +# include "printf.h" // lib/printf/printf.h // Create user & normal print defines # define print(s) printf(s) diff --git a/quantum/logging/sendchar.c b/quantum/logging/sendchar.c index 9422382f6f..5bc744b743 100644 --- a/quantum/logging/sendchar.c +++ b/quantum/logging/sendchar.c @@ -17,4 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "sendchar.h" /* default noop "null" implementation */ -__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; } +__attribute__((weak)) int8_t sendchar(uint8_t c) { + return 0; +} diff --git a/quantum/main.c b/quantum/main.c index 6ed6b95741..faba668056 100644 --- a/quantum/main.c +++ b/quantum/main.c @@ -45,7 +45,7 @@ void protocol_task(void) { #ifdef DEFERRED_EXEC_ENABLE void deferred_exec_task(void); -#endif // DEFERRED_EXEC_ENABLE +#endif // DEFERRED_EXEC_ENABLE /** \brief Main * @@ -66,7 +66,7 @@ int main(void) { #ifdef DEFERRED_EXEC_ENABLE // Run deferred executions deferred_exec_task(); -#endif // DEFERRED_EXEC_ENABLE +#endif // DEFERRED_EXEC_ENABLE housekeeping_task(); } diff --git a/quantum/matrix.c b/quantum/matrix.c index 8596c2eabd..db59b73754 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -47,33 +47,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #endif #ifdef DIRECT_PINS -static SPLIT_MUTABLE pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS; #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) # ifdef MATRIX_ROW_PINS -static SPLIT_MUTABLE_ROW pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -# endif // MATRIX_ROW_PINS +static SPLIT_MUTABLE_ROW pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS; +# endif // MATRIX_ROW_PINS # ifdef MATRIX_COL_PINS -static SPLIT_MUTABLE_COL pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -# endif // MATRIX_COL_PINS +static SPLIT_MUTABLE_COL pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +# endif // MATRIX_COL_PINS #endif /* matrix state(1:on, 0:off) */ -extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values #ifdef SPLIT_KEYBOARD // row offsets for each hand -uint8_t thisHand, thatHand; +extern uint8_t thisHand, thatHand; #endif // user-defined overridable functions __attribute__((weak)) void matrix_init_pins(void); __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter); -#ifdef SPLIT_KEYBOARD -__attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } -__attribute__((weak)) void matrix_slave_scan_user(void) {} -#endif static inline void setPinOutput_writeLow(pin_t pin) { ATOMIC_BLOCK_FORCEON { @@ -90,7 +86,9 @@ static inline void setPinOutput_writeHigh(pin_t pin) { } static inline void setPinInputHigh_atomic(pin_t pin) { - ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } + ATOMIC_BLOCK_FORCEON { + setPinInputHigh(pin); + } } static inline uint8_t readMatrixPin(pin_t pin) { @@ -106,7 +104,7 @@ static inline uint8_t readMatrixPin(pin_t pin) { #ifdef DIRECT_PINS __attribute__((weak)) void matrix_init_pins(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { + for (int row = 0; row < ROWS_PER_HAND; row++) { for (int col = 0; col < MATRIX_COLS; col++) { pin_t pin = direct_pins[row][col]; if (pin != NO_PIN) { @@ -175,8 +173,8 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] // Start with a clear matrix row matrix_row_t current_row_value = 0; - if (!select_row(current_row)) { // Select row - return; // skip NO_PIN row + if (!select_row(current_row)) { // Select row + return; // skip NO_PIN row } matrix_output_select_delay(); @@ -191,7 +189,7 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] // Unselect row unselect_row(current_row); - matrix_output_unselect_delay(current_row, current_row_value != 0); // wait for all Col signals to go HIGH + matrix_output_unselect_delay(current_row, current_row_value != 0); // wait for all Col signals to go HIGH // Update the matrix current_matrix[current_row] = current_row_value; @@ -238,8 +236,8 @@ __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[] bool key_pressed = false; // Select col - if (!select_col(current_col)) { // select col - return; // skip NO_PIN col + if (!select_col(current_col)) { // select col + return; // skip NO_PIN col } matrix_output_select_delay(); @@ -258,34 +256,32 @@ __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[] // Unselect col unselect_col(current_col); - matrix_output_unselect_delay(current_col, key_pressed); // wait for all Row signals to go HIGH + matrix_output_unselect_delay(current_col, key_pressed); // wait for all Row signals to go HIGH } # else # error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! # endif -# endif // defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) +# endif // defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) #else # error DIODE_DIRECTION is not defined! #endif void matrix_init(void) { #ifdef SPLIT_KEYBOARD - split_pre_init(); - // Set pinout for right half if pinout for that half is defined if (!isLeftHand) { # ifdef DIRECT_PINS_RIGHT - const pin_t direct_pins_right[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_RIGHT; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + const pin_t direct_pins_right[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS_RIGHT; + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { for (uint8_t j = 0; j < MATRIX_COLS; j++) { direct_pins[i][j] = direct_pins_right[i][j]; } } # endif # ifdef MATRIX_ROW_PINS_RIGHT - const pin_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + const pin_t row_pins_right[ROWS_PER_HAND] = MATRIX_ROW_PINS_RIGHT; + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { row_pins[i] = row_pins_right[i]; } # endif @@ -311,46 +307,13 @@ void matrix_init(void) { debounce_init(ROWS_PER_HAND); matrix_init_quantum(); - -#ifdef SPLIT_KEYBOARD - split_post_init(); -#endif } #ifdef SPLIT_KEYBOARD // Fallback implementation for keyboards not using the standard split_util.c __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { transport_master(master_matrix, slave_matrix); - return true; // Treat the transport as always connected -} - -bool matrix_post_scan(void) { - bool changed = false; - if (is_keyboard_master()) { - static bool last_connected = false; - matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; - if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { - changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0; - - last_connected = true; - } else if (last_connected) { - // reset other half when disconnected - memset(slave_matrix, 0, sizeof(slave_matrix)); - changed = true; - - last_connected = false; - } - - if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix)); - - matrix_scan_quantum(); - } else { - transport_slave(matrix + thatHand, matrix + thisHand); - - matrix_slave_scan_kb(); - } - - return changed; + return true; // Treat the transport as always connected } #endif diff --git a/quantum/matrix.h b/quantum/matrix.h index 5c696622fc..d968efeb0f 100644 --- a/quantum/matrix.h +++ b/quantum/matrix.h @@ -46,8 +46,6 @@ void matrix_setup(void); void matrix_init(void); /* scan all key states on matrix */ uint8_t matrix_scan(void); -/* whether modified from previous scan. used after matrix_scan. */ -bool matrix_is_modified(void) __attribute__((deprecated)); /* whether a switch is on */ bool matrix_is_on(uint8_t row, uint8_t col); /* matrix state on row */ @@ -75,6 +73,7 @@ void matrix_init_user(void); void matrix_scan_user(void); #ifdef SPLIT_KEYBOARD +bool matrix_post_scan(void); void matrix_slave_scan_kb(void); void matrix_slave_scan_user(void); #endif diff --git a/quantum/matrix_common.c b/quantum/matrix_common.c index 66c89970b1..1497ceae71 100644 --- a/quantum/matrix_common.c +++ b/quantum/matrix_common.c @@ -4,6 +4,15 @@ #include "wait.h" #include "print.h" #include "debug.h" +#ifdef SPLIT_KEYBOARD +# include "split_common/split_util.h" +# include "split_common/transactions.h" +# include <string.h> + +# define ROWS_PER_HAND (MATRIX_ROWS / 2) +#else +# define ROWS_PER_HAND (MATRIX_ROWS) +#endif #ifndef MATRIX_IO_DELAY # define MATRIX_IO_DELAY 30 @@ -13,15 +22,24 @@ matrix_row_t raw_matrix[MATRIX_ROWS]; matrix_row_t matrix[MATRIX_ROWS]; +#ifdef SPLIT_KEYBOARD +// row offsets for each hand +uint8_t thisHand, thatHand; +#endif + #ifdef MATRIX_MASKED extern const matrix_row_t matrix_mask[]; #endif // user-defined overridable functions -__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } +__attribute__((weak)) void matrix_init_kb(void) { + matrix_init_user(); +} -__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } +__attribute__((weak)) void matrix_scan_kb(void) { + matrix_scan_user(); +} __attribute__((weak)) void matrix_init_user(void) {} @@ -29,11 +47,17 @@ __attribute__((weak)) void matrix_scan_user(void) {} // helper functions -inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } +inline uint8_t matrix_rows(void) { + return MATRIX_ROWS; +} -inline uint8_t matrix_cols(void) { return MATRIX_COLS; } +inline uint8_t matrix_cols(void) { + return MATRIX_COLS; +} -inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } +inline bool matrix_is_on(uint8_t row, uint8_t col) { + return (matrix[row] & ((matrix_row_t)1 << col)); +} inline matrix_row_t matrix_get_row(uint8_t row) { // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a @@ -45,12 +69,6 @@ inline matrix_row_t matrix_get_row(uint8_t row) { #endif } -// Deprecated. -bool matrix_is_modified(void) { - if (debounce_active()) return false; - return true; -} - #if (MATRIX_COLS <= 8) # define print_matrix_header() print("\nr/c 01234567\n") # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) @@ -84,18 +102,67 @@ uint8_t matrix_key_count(void) { return count; } -/* `matrix_io_delay ()` exists for backwards compatibility. From now on, use matrix_output_unselect_delay(). */ -__attribute__((weak)) void matrix_io_delay(void) { wait_us(MATRIX_IO_DELAY); } +#ifdef SPLIT_KEYBOARD +bool matrix_post_scan(void) { + bool changed = false; + if (is_keyboard_master()) { + static bool last_connected = false; + matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; + if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { + changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0; + + last_connected = true; + } else if (last_connected) { + // reset other half when disconnected + memset(slave_matrix, 0, sizeof(slave_matrix)); + changed = true; -__attribute__((weak)) void matrix_output_select_delay(void) { waitInputPinDelay(); } -__attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { matrix_io_delay(); } + last_connected = false; + } + + if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix)); + + matrix_scan_quantum(); + } else { + transport_slave(matrix + thatHand, matrix + thisHand); + + matrix_slave_scan_kb(); + } + + return changed; +} +#endif + +/* `matrix_io_delay ()` exists for backwards compatibility. From now on, use matrix_output_unselect_delay(). */ +__attribute__((weak)) void matrix_io_delay(void) { + wait_us(MATRIX_IO_DELAY); +} +__attribute__((weak)) void matrix_output_select_delay(void) { + waitInputPinDelay(); +} +__attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { + matrix_io_delay(); +} // CUSTOM MATRIX 'LITE' __attribute__((weak)) void matrix_init_custom(void) {} +__attribute__((weak)) bool matrix_scan_custom(matrix_row_t current_matrix[]) { + return true; +} -__attribute__((weak)) bool matrix_scan_custom(matrix_row_t current_matrix[]) { return true; } +#ifdef SPLIT_KEYBOARD +__attribute__((weak)) void matrix_slave_scan_kb(void) { + matrix_slave_scan_user(); +} +__attribute__((weak)) void matrix_slave_scan_user(void) {} +#endif __attribute__((weak)) void matrix_init(void) { +#ifdef SPLIT_KEYBOARD + thisHand = isLeftHand ? 0 : (ROWS_PER_HAND); + thatHand = ROWS_PER_HAND - thisHand; +#endif + matrix_init_custom(); // initialize matrix state: all keys off @@ -104,7 +171,7 @@ __attribute__((weak)) void matrix_init(void) { matrix[i] = 0; } - debounce_init(MATRIX_ROWS); + debounce_init(ROWS_PER_HAND); matrix_init_quantum(); } @@ -112,10 +179,17 @@ __attribute__((weak)) void matrix_init(void) { __attribute__((weak)) uint8_t matrix_scan(void) { bool changed = matrix_scan_custom(raw_matrix); - debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - +#ifdef SPLIT_KEYBOARD + debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); + changed = (changed || matrix_post_scan()); +#else + debounce(raw_matrix, matrix, ROWS_PER_HAND, changed); matrix_scan_quantum(); +#endif + return changed; } -__attribute__((weak)) bool peek_matrix(uint8_t row_index, uint8_t col_index, bool raw) { return 0 != ((raw ? raw_matrix[row_index] : matrix[row_index]) & (MATRIX_ROW_SHIFTER << col_index)); } +__attribute__((weak)) bool peek_matrix(uint8_t row_index, uint8_t col_index, bool raw) { + return 0 != ((raw ? raw_matrix[row_index] : matrix[row_index]) & (MATRIX_ROW_SHIFTER << col_index)); +} diff --git a/quantum/mousekey.c b/quantum/mousekey.c index c2291fb397..8bafbf977a 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -487,4 +487,6 @@ static void mousekey_debug(void) { print(")\n"); } -report_mouse_t mousekey_get_report(void) { return mouse_report; } +report_mouse_t mousekey_get_report(void) { + return mouse_report; +} diff --git a/quantum/mousekey.h b/quantum/mousekey.h index 56c91b5f1b..03da5f282a 100644 --- a/quantum/mousekey.h +++ b/quantum/mousekey.h @@ -37,9 +37,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # ifndef MOUSEKEY_MOVE_DELTA # ifndef MK_KINETIC_SPEED -# define MOUSEKEY_MOVE_DELTA 5 +# define MOUSEKEY_MOVE_DELTA 8 # else -# define MOUSEKEY_MOVE_DELTA 25 +# define MOUSEKEY_MOVE_DELTA 5 # endif # endif # ifndef MOUSEKEY_WHEEL_DELTA @@ -47,29 +47,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # endif # ifndef MOUSEKEY_DELAY # ifndef MK_KINETIC_SPEED -# define MOUSEKEY_DELAY 300 +# define MOUSEKEY_DELAY 10 # else -# define MOUSEKEY_DELAY 8 +# define MOUSEKEY_DELAY 5 # endif # endif # ifndef MOUSEKEY_INTERVAL # ifndef MK_KINETIC_SPEED -# define MOUSEKEY_INTERVAL 50 +# define MOUSEKEY_INTERVAL 20 # else -# define MOUSEKEY_INTERVAL 8 +# define MOUSEKEY_INTERVAL 10 # endif # endif # ifndef MOUSEKEY_MAX_SPEED # define MOUSEKEY_MAX_SPEED 10 # endif # ifndef MOUSEKEY_TIME_TO_MAX -# define MOUSEKEY_TIME_TO_MAX 20 +# define MOUSEKEY_TIME_TO_MAX 30 # endif # ifndef MOUSEKEY_WHEEL_DELAY -# define MOUSEKEY_WHEEL_DELAY 300 +# define MOUSEKEY_WHEEL_DELAY 10 # endif # ifndef MOUSEKEY_WHEEL_INTERVAL -# define MOUSEKEY_WHEEL_INTERVAL 100 +# define MOUSEKEY_WHEEL_INTERVAL 80 # endif # ifndef MOUSEKEY_WHEEL_MAX_SPEED # define MOUSEKEY_WHEEL_MAX_SPEED 8 diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 2fefdb67b6..9627cab4b8 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c @@ -18,24 +18,115 @@ #include "pointing_device.h" #include <string.h> +#include "timer.h" #ifdef MOUSEKEY_ENABLE # include "mousekey.h" #endif #if (defined(POINTING_DEVICE_ROTATION_90) + defined(POINTING_DEVICE_ROTATION_180) + defined(POINTING_DEVICE_ROTATION_270)) > 1 # error More than one rotation selected. This is not supported. #endif +#if defined(SPLIT_POINTING_ENABLE) +# include "transactions.h" +# include "keyboard.h" -static report_mouse_t mouseReport = {}; +report_mouse_t shared_mouse_report = {}; +uint16_t shared_cpi = 0; + +/** + * @brief Sets the shared mouse report used be pointing device task + * + * NOTE : Only available when using SPLIT_POINTING_ENABLE + * + * @param[in] new_mouse_report report_mouse_t + */ +void pointing_device_set_shared_report(report_mouse_t new_mouse_report) { + shared_mouse_report = new_mouse_report; +} + +/** + * @brief Gets current pointing device CPI if supported + * + * Gets current cpi of the shared report and returns it as uint16_t + * + * NOTE : Only available when using SPLIT_POINTING_ENABLE + * + * @return cpi value as uint16_t + */ +uint16_t pointing_device_get_shared_cpi(void) { + return shared_cpi; +} + +# if defined(POINTING_DEVICE_LEFT) +# define POINTING_DEVICE_THIS_SIDE is_keyboard_left() +# elif defined(POINTING_DEVICE_RIGHT) +# define POINTING_DEVICE_THIS_SIDE !is_keyboard_left() +# elif defined(POINTING_DEVICE_COMBINED) +# define POINTING_DEVICE_THIS_SIDE true +# endif + +#endif // defined(SPLIT_POINTING_ENABLE) + +static report_mouse_t local_mouse_report = {}; extern const pointing_device_driver_t pointing_device_driver; -__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { return memcmp(&new, &old, sizeof(new)); } +/** + * @brief Compares 2 mouse reports for difference and returns result + * + * @param[in] new report_mouse_t + * @param[in] old report_mouse_t + * @return bool result + */ +__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { + return memcmp(&new, &old, sizeof(new)); +} + +/** + * @brief Keyboard level code pointing device initialisation + * + */ +__attribute__((weak)) void pointing_device_init_kb(void) {} -__attribute__((weak)) void pointing_device_init_kb(void) {} -__attribute__((weak)) void pointing_device_init_user(void) {} -__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); } -__attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { return mouse_report; } +/** + * @brief User level code pointing device initialisation + * + */ +__attribute__((weak)) void pointing_device_init_user(void) {} +/** + * @brief Weak function allowing for keyboard level mouse report modification + * + * Takes report_mouse_t struct allowing modification at keyboard level then returns report_mouse_t. + * + * @param[in] mouse_report report_mouse_t + * @return report_mouse_t + */ +__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { + return pointing_device_task_user(mouse_report); +} + +/** + * @brief Weak function allowing for user level mouse report modification + * + * Takes report_mouse_t struct allowing modification at user level then returns report_mouse_t. + * + * @param[in] mouse_report report_mouse_t + * @return report_mouse_t + */ +__attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { + return mouse_report; +} + +/** + * @brief Handles pointing device buttons + * + * Returns modified button bitmask using bool pressed and selected pointing_device_buttons_t button in uint8_t buttons bitmask. + * + * @param buttons[in] uint8_t bitmask + * @param pressed[in] bool + * @param button[in] pointing_device_buttons_t value + * @return Modified uint8_t bitmask buttons + */ __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) { if (pressed) { buttons |= 1 << (button); @@ -45,7 +136,17 @@ __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bo return buttons; } +/** + * @brief Initialises pointing device + * + * Initialises pointing device, perform driver init and optional keyboard/user level code. + */ __attribute__((weak)) void pointing_device_init(void) { +#if defined(SPLIT_POINTING_ENABLE) + if (!(POINTING_DEVICE_THIS_SIDE)) { + return; + } +#endif pointing_device_driver.init(); #ifdef POINTING_DEVICE_MOTION_PIN setPinInputHigh(POINTING_DEVICE_MOTION_PIN); @@ -54,67 +155,303 @@ __attribute__((weak)) void pointing_device_init(void) { pointing_device_init_user(); } +/** + * @brief Sends processed mouse report to host + * + * This sends the mouse report generated by pointing_device_task if changed since the last report. Once send zeros mouse report except buttons. + * + */ __attribute__((weak)) void pointing_device_send(void) { static report_mouse_t old_report = {}; // If you need to do other things, like debugging, this is the place to do it. - if (has_mouse_report_changed(mouseReport, old_report)) { - host_mouse_send(&mouseReport); + if (has_mouse_report_changed(local_mouse_report, old_report)) { + host_mouse_send(&local_mouse_report); } // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device - mouseReport.x = 0; - mouseReport.y = 0; - mouseReport.v = 0; - mouseReport.h = 0; + local_mouse_report.x = 0; + local_mouse_report.y = 0; + local_mouse_report.v = 0; + local_mouse_report.h = 0; - memcpy(&old_report, &mouseReport, sizeof(mouseReport)); + memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report)); } -__attribute__((weak)) void pointing_device_task(void) { - // Gather report info -#ifdef POINTING_DEVICE_MOTION_PIN - if (!readPin(POINTING_DEVICE_MOTION_PIN)) -#endif - mouseReport = pointing_device_driver.get_report(mouseReport); - - // Support rotation of the sensor data +/** + * @brief Adjust mouse report by any optional common pointing configuration defines + * + * This applies rotation or inversion to the mouse report as selected by the pointing device common configuration defines. + * + * @param mouse_report[in] takes a report_mouse_t to be adjusted + * @return report_mouse_t with adjusted values + */ +report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) { + // Support rotation of the sensor data #if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) - int8_t x = mouseReport.x, y = mouseReport.y; + int8_t x = mouse_report.x, y = mouse_report.y; # if defined(POINTING_DEVICE_ROTATION_90) - mouseReport.x = y; - mouseReport.y = -x; + mouse_report.x = y; + mouse_report.y = -x; # elif defined(POINTING_DEVICE_ROTATION_180) - mouseReport.x = -x; - mouseReport.y = -y; + mouse_report.x = -x; + mouse_report.y = -y; # elif defined(POINTING_DEVICE_ROTATION_270) - mouseReport.x = -y; - mouseReport.y = x; + mouse_report.x = -y; + mouse_report.y = x; # else # error "How the heck did you get here?!" # endif #endif // Support Inverting the X and Y Axises #if defined(POINTING_DEVICE_INVERT_X) - mouseReport.x = -mouseReport.x; + mouse_report.x = -mouse_report.x; #endif #if defined(POINTING_DEVICE_INVERT_Y) - mouseReport.y = -mouseReport.y; + mouse_report.y = -mouse_report.y; +#endif + return mouse_report; +} + +/** + * @brief Retrieves and processes pointing device data. + * + * This function is part of the keyboard loop and retrieves the mouse report from the pointing device driver. + * It applies any optional configuration e.g. rotation or axis inversion and then initiates a send. + * + */ +__attribute__((weak)) void pointing_device_task(void) { +#if defined(SPLIT_POINTING_ENABLE) + // Don't poll the target side pointing device. + if (!is_keyboard_master()) { + return; + }; +#endif + +#if (POINTING_DEVICE_TASK_THROTTLE_MS > 0) + static uint32_t last_exec = 0; + if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { + return; + } + last_exec = timer_read32(); +#endif + + // Gather report info +#ifdef POINTING_DEVICE_MOTION_PIN +# if defined(SPLIT_POINTING_ENABLE) +# error POINTING_DEVICE_MOTION_PIN not supported when sharing the pointing device report between sides. +# endif + if (!readPin(POINTING_DEVICE_MOTION_PIN)) #endif +#if defined(SPLIT_POINTING_ENABLE) +# if defined(POINTING_DEVICE_COMBINED) + static uint8_t old_buttons = 0; + local_mouse_report.buttons = old_buttons; + local_mouse_report = pointing_device_driver.get_report(local_mouse_report); + old_buttons = local_mouse_report.buttons; +# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) + local_mouse_report = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(local_mouse_report) : shared_mouse_report; +# else +# error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" +# endif +#else + local_mouse_report = pointing_device_driver.get_report(local_mouse_report); +#endif // defined(SPLIT_POINTING_ENABLE) + // allow kb to intercept and modify report - mouseReport = pointing_device_task_kb(mouseReport); +#if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) + if (is_keyboard_left()) { + local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); + shared_mouse_report = pointing_device_adjust_by_defines_right(shared_mouse_report); + } else { + local_mouse_report = pointing_device_adjust_by_defines_right(local_mouse_report); + shared_mouse_report = pointing_device_adjust_by_defines(shared_mouse_report); + } + local_mouse_report = is_keyboard_left() ? pointing_device_task_combined_kb(local_mouse_report, shared_mouse_report) : pointing_device_task_combined_kb(shared_mouse_report, local_mouse_report); +#else + local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); + local_mouse_report = pointing_device_task_kb(local_mouse_report); +#endif // combine with mouse report to ensure that the combined is sent correctly #ifdef MOUSEKEY_ENABLE report_mouse_t mousekey_report = mousekey_get_report(); - mouseReport.buttons = mouseReport.buttons | mousekey_report.buttons; + local_mouse_report.buttons = local_mouse_report.buttons | mousekey_report.buttons; #endif pointing_device_send(); } -report_mouse_t pointing_device_get_report(void) { return mouseReport; } +/** + * @brief Gets current mouse report used by pointing device task + * + * @return report_mouse_t + */ +report_mouse_t pointing_device_get_report(void) { + return local_mouse_report; +} + +/** + * @brief Sets mouse report used be pointing device task + * + * @param[in] new_mouse_report + */ +void pointing_device_set_report(report_mouse_t new_mouse_report) { + local_mouse_report = new_mouse_report; +} + +/** + * @brief Gets current pointing device CPI if supported + * + * Gets current cpi from pointing device driver if supported and returns it as uint16_t + * + * @return cpi value as uint16_t + */ +uint16_t pointing_device_get_cpi(void) { +#if defined(SPLIT_POINTING_ENABLE) + return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : shared_cpi; +#else + return pointing_device_driver.get_cpi(); +#endif +} -void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } +/** + * @brief Set pointing device CPI if supported + * + * Takes a uint16_t value to set pointing device cpi if supported by driver. + * + * @param[in] cpi uint16_t value. + */ +void pointing_device_set_cpi(uint16_t cpi) { +#if defined(SPLIT_POINTING_ENABLE) + if (POINTING_DEVICE_THIS_SIDE) { + pointing_device_driver.set_cpi(cpi); + } else { + shared_cpi = cpi; + } +#else + pointing_device_driver.set_cpi(cpi); +#endif +} -uint16_t pointing_device_get_cpi(void) { return pointing_device_driver.get_cpi(); } +#if defined(SPLIT_POINTING_ENABLE) && defined(POINTING_DEVICE_COMBINED) +/** + * @brief Set pointing device CPI if supported + * + * Takes a bool and uint16_t and allows setting cpi for a single side when using 2 pointing devices with a split keyboard. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left true = left, false = right. + * @param[in] cpi uint16_t value. + */ +void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { + bool local = (is_keyboard_left() & left) ? true : false; + if (local) { + pointing_device_driver.set_cpi(cpi); + } else { + shared_cpi = cpi; + } +} -void pointing_device_set_cpi(uint16_t cpi) { pointing_device_driver.set_cpi(cpi); } +/** + * @brief clamps int16_t to int8_t + * + * @param[in] int16_t value + * @return int8_t clamped value + */ +static inline int8_t pointing_device_movement_clamp(int16_t value) { + if (value < INT8_MIN) { + return INT8_MIN; + } else if (value > INT8_MAX) { + return INT8_MAX; + } else { + return value; + } +} + +/** + * @brief combines 2 mouse reports and returns 2 + * + * Combines 2 report_mouse_t structs, clamping movement values to int8_t and ignores report_id then returns the resulting report_mouse_t struct. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report left report_mouse_t + * @param[in] right_report right report_mouse_t + * @return combined report_mouse_t of left_report and right_report + */ +report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { + left_report.x = pointing_device_movement_clamp((int16_t)left_report.x + right_report.x); + left_report.y = pointing_device_movement_clamp((int16_t)left_report.y + right_report.y); + left_report.h = pointing_device_movement_clamp((int16_t)left_report.h + right_report.h); + left_report.v = pointing_device_movement_clamp((int16_t)left_report.v + right_report.v); + left_report.buttons |= right_report.buttons; + return left_report; +} + +/** + * @brief Adjust mouse report by any optional right pointing configuration defines + * + * This applies rotation or inversion to the mouse report as selected by the pointing device common configuration defines. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] mouse_report report_mouse_t to be adjusted + * @return report_mouse_t with adjusted values + */ +report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report) { + // Support rotation of the sensor data +# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) + int8_t x = mouse_report.x, y = mouse_report.y; +# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) + mouse_report.x = y; + mouse_report.y = -x; +# elif defined(POINTING_DEVICE_ROTATION_180_RIGHT) + mouse_report.x = -x; + mouse_report.y = -y; +# elif defined(POINTING_DEVICE_ROTATION_270_RIGHT) + mouse_report.x = -y; + mouse_report.y = x; +# else +# error "How the heck did you get here?!" +# endif +# endif + // Support Inverting the X and Y Axises +# if defined(POINTING_DEVICE_INVERT_X_RIGHT) + mouse_report.x = -mouse_report.x; +# endif +# if defined(POINTING_DEVICE_INVERT_Y_RIGHT) + mouse_report.y = -mouse_report.y; +# endif + return mouse_report; +} + +/** + * @brief Weak function allowing for keyboard level mouse report modification + * + * Takes 2 report_mouse_t structs allowing individual modification of sides at keyboard level then returns pointing_device_task_combined_user. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report report_mouse_t + * @param[in] right_report report_mouse_t + * @return pointing_device_task_combined_user(left_report, right_report) by default + */ +__attribute__((weak)) report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report) { + return pointing_device_task_combined_user(left_report, right_report); +} + +/** + * @brief Weak function allowing for user level mouse report modification + * + * Takes 2 report_mouse_t structs allowing individual modification of sides at user level then returns pointing_device_combine_reports. + * + * NOTE: Only available when using SPLIT_POINTING_ENABLE and POINTING_DEVICE_COMBINED + * + * @param[in] left_report report_mouse_t + * @param[in] right_report report_mouse_t + * @return pointing_device_combine_reports(left_report, right_report) by default + */ +__attribute__((weak)) report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report) { + return pointing_device_combine_reports(left_report, right_report); +} +#endif diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index 5106c26660..5f3845227a 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h @@ -47,6 +47,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #elif defined(POINTING_DEVICE_DRIVER_pmw3360) # include "spi_master.h" # include "drivers/sensors/pmw3360.h" +#elif defined(POINTING_DEVICE_DRIVER_pmw3389) +# include "spi_master.h" +# include "drivers/sensors/pmw3389.h" #else void pointing_device_driver_init(void); report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report); @@ -86,3 +89,19 @@ void pointing_device_init_user(void); report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report); report_mouse_t pointing_device_task_user(report_mouse_t mouse_report); uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button); +report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report); + +#if defined(SPLIT_POINTING_ENABLE) +void pointing_device_set_shared_report(report_mouse_t report); +uint16_t pointing_device_get_shared_cpi(void); +# if !defined(POINTING_DEVICE_TASK_THROTTLE_MS) +# define POINTING_DEVICE_TASK_THROTTLE_MS 1 +# endif +# if defined(POINTING_DEVICE_COMBINED) +void pointing_device_set_cpi_on_side(bool left, uint16_t cpi); +report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report); +report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report); +# endif // defined(POINTING_DEVICE_COMBINED) +#endif // defined(SPLIT_POINTING_ENABLE) diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index 9ad5e76ba6..b8ef6e67e5 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -101,7 +101,7 @@ const pointing_device_driver_t pointing_device_driver = { # ifdef TAPPING_TERM_PER_KEY # include "action.h" # include "action_tapping.h" -# define CIRQUE_PINNACLE_TAPPING_TERM get_tapping_term(KC_BTN1, NULL) +# define CIRQUE_PINNACLE_TAPPING_TERM get_tapping_term(KC_BTN1, &(keyrecord_t){}) # else # ifdef TAPPING_TERM # define CIRQUE_PINNACLE_TAPPING_TERM TAPPING_TERM @@ -120,7 +120,7 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) { int8_t report_x = 0, report_y = 0; static bool is_z_down = false; - cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); // Scale coordinates to arbitrary X, Y resolution + cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); // Scale coordinates to arbitrary X, Y resolution if (x && y && touchData.xValue && touchData.yValue) { report_x = (int8_t)(touchData.xValue - x); @@ -165,14 +165,13 @@ const pointing_device_driver_t pointing_device_driver = { // clang-format on #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) -report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { - static fast_timer_t throttle = 0; - static uint16_t debounce = 0; - static uint8_t error_count = 0; - pimoroni_data_t pimoroni_data = {0}; - static int16_t x_offset = 0, y_offset = 0; - - if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT && timer_elapsed_fast(throttle) >= PIMORONI_TRACKBALL_INTERVAL_MS) { +report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) { + static uint16_t debounce = 0; + static uint8_t error_count = 0; + pimoroni_data_t pimoroni_data = {0}; + static int16_t x_offset = 0, y_offset = 0; + + if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) { i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); if (status == I2C_STATUS_SUCCESS) { @@ -195,26 +194,26 @@ report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { } else { error_count++; } - throttle = timer_read_fast(); } return mouse_report; } // clang-format off const pointing_device_driver_t pointing_device_driver = { - .init = pimironi_trackball_device_init, - .get_report = pimorono_trackball_get_report, - .set_cpi = NULL, - .get_cpi = NULL + .init = pimoroni_trackball_device_init, + .get_report = pimoroni_trackball_get_report, + .set_cpi = pimoroni_trackball_set_cpi, + .get_cpi = pimoroni_trackball_get_cpi }; // clang-format on #elif defined(POINTING_DEVICE_DRIVER_pmw3360) - -static void init(void) { pmw3360_init(); } +static void pmw3360_device_init(void) { + pmw3360_init(); +} report_mouse_t pmw3360_get_report(report_mouse_t mouse_report) { report_pmw3360_t data = pmw3360_read_burst(); - static uint16_t MotionStart = 0; // Timer for accel, 0 is resting state + static uint16_t MotionStart = 0; // Timer for accel, 0 is resting state if (data.isOnSurface && data.isMotion) { // Reset timer if stopped moving @@ -239,17 +238,59 @@ report_mouse_t pmw3360_get_report(report_mouse_t mouse_report) { // clang-format off const pointing_device_driver_t pointing_device_driver = { - .init = init, + .init = pmw3360_device_init, .get_report = pmw3360_get_report, .set_cpi = pmw3360_set_cpi, .get_cpi = pmw3360_get_cpi }; // clang-format on +#elif defined(POINTING_DEVICE_DRIVER_pmw3389) +static void pmw3389_device_init(void) { + pmw3389_init(); +} + +report_mouse_t pmw3389_get_report(report_mouse_t mouse_report) { + report_pmw3389_t data = pmw3389_read_burst(); + static uint16_t MotionStart = 0; // Timer for accel, 0 is resting state + + if (data.isOnSurface && data.isMotion) { + // Reset timer if stopped moving + if (!data.isMotion) { + if (MotionStart != 0) MotionStart = 0; + return mouse_report; + } + + // Set timer if new motion + if ((MotionStart == 0) && data.isMotion) { +# ifdef CONSOLE_ENABLE + if (debug_mouse) dprintf("Starting motion.\n"); +# endif + MotionStart = timer_read(); + } + mouse_report.x = constrain_hid(data.dx); + mouse_report.y = constrain_hid(data.dy); + } + + return mouse_report; +} + +// clang-format off +const pointing_device_driver_t pointing_device_driver = { + .init = pmw3389_device_init, + .get_report = pmw3389_get_report, + .set_cpi = pmw3389_set_cpi, + .get_cpi = pmw3389_get_cpi +}; +// clang-format on #else __attribute__((weak)) void pointing_device_driver_init(void) {} -__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { return mouse_report; } -__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) { return 0; } -__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {} +__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { + return mouse_report; +} +__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) { + return 0; +} +__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {} // clang-format off const pointing_device_driver_t pointing_device_driver = { diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index 3b5fa8490b..e7fe453308 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -50,10 +50,17 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { return true; } -void process_audio_noteon(uint8_t note) { play_note(compute_freq_for_midi_note(note), 0xF); } +void process_audio_noteon(uint8_t note) { + play_note(compute_freq_for_midi_note(note), 0xF); +} -void process_audio_noteoff(uint8_t note) { stop_note(compute_freq_for_midi_note(note)); } +void process_audio_noteoff(uint8_t note) { + stop_note(compute_freq_for_midi_note(note)); +} -void process_audio_all_notes_off(void) { stop_all_notes(); } +void process_audio_all_notes_off(void) { + stop_all_notes(); +} __attribute__((weak)) void audio_on_user() {} +__attribute__((weak)) void audio_off_user() {} diff --git a/quantum/process_keycode/process_audio.h b/quantum/process_keycode/process_audio.h index d89a834ea8..42cfab4af2 100644 --- a/quantum/process_keycode/process_audio.h +++ b/quantum/process_keycode/process_audio.h @@ -8,3 +8,4 @@ void process_audio_noteoff(uint8_t note); void process_audio_all_notes_off(void); void audio_on_user(void); +void audio_off_user(void); diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index bbc6367ff1..2150edd7b2 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -62,7 +62,9 @@ static struct { // clang-format on /** \brief Called on physical press, returns whether key should be added to Auto Shift */ -__attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { return false; } +__attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { + return false; +} /** \brief Called on physical press, returns whether is Auto Shift key */ __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) { @@ -82,8 +84,12 @@ __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *r } /** \brief Called to check whether defines should apply if PER_KEY is set for it */ -__attribute__((weak)) bool get_auto_shift_repeat(uint16_t keycode, keyrecord_t *record) { return true; } -__attribute__((weak)) bool get_auto_shift_no_auto_repeat(uint16_t keycode, keyrecord_t *record) { return true; } +__attribute__((weak)) bool get_auto_shift_repeat(uint16_t keycode, keyrecord_t *record) { + return true; +} +__attribute__((weak)) bool get_auto_shift_no_auto_repeat(uint16_t keycode, keyrecord_t *record) { + return true; +} /** \brief Called when an Auto Shift key needs to be pressed */ __attribute__((weak)) void autoshift_press_user(uint16_t keycode, bool shifted, keyrecord_t *record) { @@ -94,7 +100,9 @@ __attribute__((weak)) void autoshift_press_user(uint16_t keycode, bool shifted, } /** \brief Called when an Auto Shift key needs to be released */ -__attribute__((weak)) void autoshift_release_user(uint16_t keycode, bool shifted, keyrecord_t *record) { unregister_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode); } +__attribute__((weak)) void autoshift_release_user(uint16_t keycode, bool shifted, keyrecord_t *record) { + unregister_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode); +} /** \brief Sets the shift state to use when keyrepeating, required by custom shifts */ void set_autoshift_shift_state(uint16_t keycode, bool shifted) { @@ -311,7 +319,9 @@ void autoshift_toggle(void) { autoshift_flush_shift(); } -void autoshift_enable(void) { autoshift_flags.enabled = true; } +void autoshift_enable(void) { + autoshift_flags.enabled = true; +} void autoshift_disable(void) { autoshift_flags.enabled = false; @@ -328,12 +338,20 @@ void autoshift_timer_report(void) { } # endif -bool get_autoshift_state(void) { return autoshift_flags.enabled; } +bool get_autoshift_state(void) { + return autoshift_flags.enabled; +} -uint16_t get_generic_autoshift_timeout() { return autoshift_timeout; } -__attribute__((weak)) uint16_t get_autoshift_timeout(uint16_t keycode, keyrecord_t *record) { return autoshift_timeout; } +uint16_t get_generic_autoshift_timeout() { + return autoshift_timeout; +} +__attribute__((weak)) uint16_t get_autoshift_timeout(uint16_t keycode, keyrecord_t *record) { + return autoshift_timeout; +} -void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } +void set_autoshift_timeout(uint16_t timeout) { + autoshift_timeout = timeout; +} bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { // Note that record->event.time isn't reliable, see: diff --git a/quantum/process_keycode/process_clicky.c b/quantum/process_keycode/process_clicky.c index 6ab382d4aa..9795734984 100644 --- a/quantum/process_keycode/process_clicky.c +++ b/quantum/process_keycode/process_clicky.c @@ -5,40 +5,40 @@ # ifndef AUDIO_CLICKY_DELAY_DURATION # define AUDIO_CLICKY_DELAY_DURATION 1 -# endif // !AUDIO_CLICKY_DELAY_DURATION +# endif // !AUDIO_CLICKY_DELAY_DURATION # ifndef AUDIO_CLICKY_FREQ_DEFAULT # define AUDIO_CLICKY_FREQ_DEFAULT 440.0f -# endif // !AUDIO_CLICKY_FREQ_DEFAULT +# endif // !AUDIO_CLICKY_FREQ_DEFAULT # ifndef AUDIO_CLICKY_FREQ_MIN # define AUDIO_CLICKY_FREQ_MIN 65.0f -# endif // !AUDIO_CLICKY_FREQ_MIN +# endif // !AUDIO_CLICKY_FREQ_MIN # ifndef AUDIO_CLICKY_FREQ_MAX # define AUDIO_CLICKY_FREQ_MAX 1500.0f -# endif // !AUDIO_CLICKY_FREQ_MAX +# endif // !AUDIO_CLICKY_FREQ_MAX # ifndef AUDIO_CLICKY_FREQ_FACTOR # define AUDIO_CLICKY_FREQ_FACTOR 1.18921f -# endif // !AUDIO_CLICKY_FREQ_FACTOR +# endif // !AUDIO_CLICKY_FREQ_FACTOR # ifndef AUDIO_CLICKY_FREQ_RANDOMNESS # define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f -# endif // !AUDIO_CLICKY_FREQ_RANDOMNESS +# endif // !AUDIO_CLICKY_FREQ_RANDOMNESS float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS; // the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky" -float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations +float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations extern audio_config_t audio_config; # ifndef NO_MUSIC_MODE extern bool music_activated; extern bool midi_activated; -# endif // !NO_MUSIC_MODE +# endif // !NO_MUSIC_MODE void clicky_play(void) { # ifndef NO_MUSIC_MODE if (music_activated || midi_activated || !audio_config.enable) return; -# endif // !NO_MUSIC_MODE +# endif // !NO_MUSIC_MODE clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX)))); PLAY_SONG(clicky_song); @@ -58,7 +58,9 @@ void clicky_freq_down(void) { } } -void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; } +void clicky_freq_reset(void) { + clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; +} void clicky_toggle(void) { audio_config.clicky_enable ^= 1; @@ -75,7 +77,9 @@ void clicky_off(void) { eeconfig_update_audio(audio_config.raw); } -bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); } +bool is_clicky_on(void) { + return (audio_config.clicky_enable != 0); +} bool process_clicky(uint16_t keycode, keyrecord_t *record) { if (keycode == CLICKY_TOGGLE && record->event.pressed) { @@ -101,8 +105,8 @@ bool process_clicky(uint16_t keycode, keyrecord_t *record) { } if (audio_config.enable && audio_config.clicky_enable) { - if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound - if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM + if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound + if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM clicky_play(); } } @@ -110,4 +114,4 @@ bool process_clicky(uint16_t keycode, keyrecord_t *record) { return true; } -#endif // AUDIO_CLICKY +#endif // AUDIO_CLICKY diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index a050161edf..efaf8fe0e9 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -17,6 +17,7 @@ #include "print.h" #include "process_combo.h" #include "action_tapping.h" +#include "action.h" #ifdef COMBO_COUNT __attribute__((weak)) combo_t key_combos[COMBO_COUNT]; @@ -29,25 +30,45 @@ extern uint16_t COMBO_LEN; __attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {} #ifdef COMBO_MUST_HOLD_PER_COMBO -__attribute__((weak)) bool get_combo_must_hold(uint16_t index, combo_t *combo) { return false; } +__attribute__((weak)) bool get_combo_must_hold(uint16_t index, combo_t *combo) { + return false; +} #endif #ifdef COMBO_MUST_TAP_PER_COMBO -__attribute__((weak)) bool get_combo_must_tap(uint16_t index, combo_t *combo) { return false; } +__attribute__((weak)) bool get_combo_must_tap(uint16_t index, combo_t *combo) { + return false; +} #endif #ifdef COMBO_TERM_PER_COMBO -__attribute__((weak)) uint16_t get_combo_term(uint16_t index, combo_t *combo) { return COMBO_TERM; } +__attribute__((weak)) uint16_t get_combo_term(uint16_t index, combo_t *combo) { + return COMBO_TERM; +} +#endif + +#ifdef COMBO_MUST_PRESS_IN_ORDER_PER_COMBO +__attribute__((weak)) bool get_combo_must_press_in_order(uint16_t combo_index, combo_t *combo) { + return true; +} #endif #ifdef COMBO_PROCESS_KEY_RELEASE -__attribute__((weak)) bool process_combo_key_release(uint16_t combo_index, combo_t *combo, uint8_t key_index, uint16_t keycode) { return false; } +__attribute__((weak)) bool process_combo_key_release(uint16_t combo_index, combo_t *combo, uint8_t key_index, uint16_t keycode) { + return false; +} +#endif + +#ifdef COMBO_SHOULD_TRIGGER +__attribute__((weak)) bool combo_should_trigger(uint16_t combo_index, combo_t *combo, uint16_t keycode, keyrecord_t *record) { + return true; +} #endif #ifndef COMBO_NO_TIMER static uint16_t timer = 0; #endif -static bool b_combo_enable = true; // defaults to enabled +static bool b_combo_enable = true; // defaults to enabled static uint16_t longest_term = 0; typedef struct { @@ -185,6 +206,9 @@ void clear_combos(void) { static inline void dump_key_buffer(void) { /* First call start from 0 index; recursive calls need to start from i+1 index */ static uint8_t key_buffer_next = 0; +#if TAP_CODE_DELAY > 0 + bool delay_done = false; +#endif if (key_buffer_size == 0) { return; @@ -210,6 +234,15 @@ static inline void dump_key_buffer(void) { #endif } record->event.time = 0; + clear_weak_mods(); + +#if TAP_CODE_DELAY > 0 + // only delay once and for a non-tapping key + if (!delay_done && !is_tap_record(record)) { + delay_done = true; + wait_ms(TAP_CODE_DELAY); + } +#endif } key_buffer_next = key_buffer_size = 0; @@ -350,6 +383,28 @@ combo_t *overlaps(combo_t *combo1, combo_t *combo2) { return combo1; } +#if defined(COMBO_MUST_PRESS_IN_ORDER) || defined(COMBO_MUST_PRESS_IN_ORDER_PER_COMBO) +static bool keys_pressed_in_order(uint16_t combo_index, combo_t *combo, uint16_t key_index, uint16_t keycode, keyrecord_t *record) { +# ifdef COMBO_MUST_PRESS_IN_ORDER_PER_COMBO + if (!get_combo_must_press_in_order(combo_index, combo)) { + return true; + } +# endif + if ( + // The `state` bit for the key being pressed. + (1 << key_index) == + // The *next* combo key's bit. + (COMBO_STATE(combo) + 1) + // E.g. two keys already pressed: `state == 11`. + // Next possible `state` is `111`. + // So the needed bit is `100` which we get with `11 + 1`. + ) { + return true; + } + return false; +} +#endif + static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record, uint16_t combo_index) { uint8_t key_count = 0; uint16_t key_index = -1; @@ -360,7 +415,14 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * return false; } - bool key_is_part_of_combo = !COMBO_DISABLED(combo) && is_combo_enabled(); + bool key_is_part_of_combo = (!COMBO_DISABLED(combo) && is_combo_enabled() +#if defined(COMBO_MUST_PRESS_IN_ORDER) || defined(COMBO_MUST_PRESS_IN_ORDER_PER_COMBO) + && keys_pressed_in_order(combo_index, combo, key_index, keycode, record) +#endif +#ifdef COMBO_SHOULD_TRIGGER + && combo_should_trigger(combo_index, combo, keycode, record) +#endif + ); if (record->event.pressed && key_is_part_of_combo) { uint16_t time = _get_combo_term(combo_index, combo); @@ -412,7 +474,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * // get possible longer waiting time for tap-/hold-only combos. longest_term = _get_wait_time(combo_index, combo); } - } // if timer elapsed end + } // if timer elapsed end } } else { // chord releases @@ -427,7 +489,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t * else if (get_combo_must_tap(combo_index, combo)) { // immediately apply tap-only combo apply_combo(combo_index, combo); - apply_combos(); // also apply other prepared combos and dump key buffer + apply_combos(); // also apply other prepared combos and dump key buffer # ifdef COMBO_PROCESS_KEY_RELEASE if (process_combo_key_release(combo_index, combo, key_index, keycode)) { release_combo(combo_index, combo); @@ -509,7 +571,7 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) { key_buffer[key_buffer_size++] = (queued_record_t){ .record = *record, .keycode = keycode, - .combo_index = -1, // this will be set when applying combos + .combo_index = -1, // this will be set when applying combos }; } } else { @@ -548,7 +610,9 @@ void combo_task(void) { #endif } -void combo_enable(void) { b_combo_enable = true; } +void combo_enable(void) { + b_combo_enable = true; +} void combo_disable(void) { #ifndef COMBO_NO_TIMER @@ -568,4 +632,6 @@ void combo_toggle(void) { } } -bool is_combo_enabled(void) { return b_combo_enable; } +bool is_combo_enabled(void) { + return b_combo_enable; +} diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index 18c8d7ca2e..a1ada2d5a2 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -29,13 +29,21 @@ void dynamic_macro_led_blink(void) { /* User hooks for Dynamic Macros */ -__attribute__((weak)) void dynamic_macro_record_start_user(void) { dynamic_macro_led_blink(); } +__attribute__((weak)) void dynamic_macro_record_start_user(void) { + dynamic_macro_led_blink(); +} -__attribute__((weak)) void dynamic_macro_play_user(int8_t direction) { dynamic_macro_led_blink(); } +__attribute__((weak)) void dynamic_macro_play_user(int8_t direction) { + dynamic_macro_led_blink(); +} -__attribute__((weak)) void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) { dynamic_macro_led_blink(); } +__attribute__((weak)) void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record) { + dynamic_macro_led_blink(); +} -__attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) { dynamic_macro_led_blink(); } +__attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) { + dynamic_macro_led_blink(); +} /* Convenience macros used for retrieving the debug info. All of them * need a `direction` variable accessible at the call site. @@ -82,7 +90,7 @@ void dynamic_macro_play(keyrecord_t *macro_buffer, keyrecord_t *macro_end, int8_ clear_keyboard(); - layer_state = saved_layer_state; + layer_state_set(saved_layer_state); dynamic_macro_play_user(direction); } diff --git a/quantum/process_keycode/process_grave_esc.c b/quantum/process_keycode/process_grave_esc.c index 41c50f5cb8..ddf027391d 100644 --- a/quantum/process_keycode/process_grave_esc.c +++ b/quantum/process_keycode/process_grave_esc.c @@ -15,13 +15,13 @@ */ #include "process_grave_esc.h" -/* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. +/* true if the last press of QK_GRAVE_ESCAPE was shifted (i.e. GUI or SHIFT were pressed), false otherwise. * Used to ensure that the correct keycode is released if the key is released. */ static bool grave_esc_was_shifted = false; bool process_grave_esc(uint16_t keycode, keyrecord_t *record) { - if (keycode == GRAVE_ESC) { + if (keycode == QK_GRAVE_ESCAPE) { const uint8_t mods = get_mods(); uint8_t shifted = mods & MOD_MASK_SG; diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c index 85b2ffcddd..0f07f9ac75 100644 --- a/quantum/process_keycode/process_haptic.c +++ b/quantum/process_keycode/process_haptic.c @@ -35,9 +35,6 @@ __attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t case QK_MOMENTARY ... QK_MOMENTARY_MAX: case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: #endif -#ifdef NO_HAPTIC_FN - case KC_FN0 ... KC_FN31: -#endif #ifdef NO_HAPTIC_ALPHA case KC_A ... KC_Z: #endif diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index fa9c2c1dbc..2fb092c573 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -74,7 +74,9 @@ void restorePinState(pin_t pin, uint16_t restoreState) { #endif } -__attribute__((weak)) bool process_joystick_analogread() { return process_joystick_analogread_quantum(); } +__attribute__((weak)) bool process_joystick_analogread() { + return process_joystick_analogread_quantum(); +} bool process_joystick_analogread_quantum() { #if JOYSTICK_AXES_COUNT > 0 diff --git a/quantum/process_keycode/process_key_lock.c b/quantum/process_keycode/process_key_lock.c index 4bd58f0c1e..941a2c5780 100644 --- a/quantum/process_keycode/process_key_lock.c +++ b/quantum/process_keycode/process_key_lock.c @@ -56,6 +56,11 @@ static inline uint16_t translate_keycode(uint16_t keycode) { } } +void cancel_key_lock(void) { + watching = false; + UNSET_KEY_STATE(0x0); +} + bool process_key_lock(uint16_t *keycode, keyrecord_t *record) { // We start by categorizing the keypress event. In the event of a down // event, there are several possibilities: diff --git a/quantum/process_keycode/process_key_lock.h b/quantum/process_keycode/process_key_lock.h index baa0b39077..5159b0ba02 100644 --- a/quantum/process_keycode/process_key_lock.h +++ b/quantum/process_keycode/process_key_lock.h @@ -18,4 +18,5 @@ #include "quantum.h" +void cancel_key_lock(void); bool process_key_lock(uint16_t *keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_key_override.c b/quantum/process_keycode/process_key_override.c index 09b2725079..ad9683d106 100644 --- a/quantum/process_keycode/process_key_override.c +++ b/quantum/process_keycode/process_key_override.c @@ -106,7 +106,9 @@ void key_override_toggle(void) { } } -bool key_override_is_enabled(void) { return enabled; } +bool key_override_is_enabled(void) { + return enabled; +} // Returns whether the modifiers that are pressed are such that the override should activate static bool key_override_matches_active_modifiers(const key_override_t *override, const uint8_t mods) { @@ -150,7 +152,7 @@ static void schedule_deferred_register(const uint16_t keycode) { } else { // Wait a very short time when a modifier event triggers the override to avoid false activations when e.g. a modifier is pressed just before a key is released (with the intention of pairing the modifier with a different key), or a modifier is lifted shortly before the trigger key is lifted. Operating systems by default reject modifier-events that happen very close to a non-modifier event. defer_reference_time = timer_read32(); - defer_delay = 50; // 50ms + defer_delay = 50; // 50ms } deferred_register = keycode; } @@ -174,8 +176,8 @@ const key_override_t *clear_active_override(const bool allow_reregister) { const uint8_t mod_free_replacement = clear_mods_from(active_override->replacement); - bool unregister_replacement = mod_free_replacement != KC_NO && // KC_NO is never registered - mod_free_replacement < SAFE_RANGE; // Custom keycodes are never registered + bool unregister_replacement = mod_free_replacement != KC_NO && // KC_NO is never registered + mod_free_replacement < SAFE_RANGE; // Custom keycodes are never registered // Try firing the custom handler if (active_override->custom_action != NULL) { @@ -195,11 +197,11 @@ const key_override_t *clear_active_override(const bool allow_reregister) { const uint16_t trigger = active_override->trigger; - const bool reregister_trigger = allow_reregister && // Check if allowed from caller - (active_override->options & ko_option_no_reregister_trigger) == 0 && // Check if override allows - active_override_trigger_is_down && // Check if trigger is even down - trigger != KC_NO && // KC_NO is never registered - trigger < SAFE_RANGE; // A custom keycode should not be registered + const bool reregister_trigger = allow_reregister && // Check if allowed from caller + (active_override->options & ko_option_no_reregister_trigger) == 0 && // Check if override allows + active_override_trigger_is_down && // Check if trigger is even down + trigger != KC_NO && // KC_NO is never registered + trigger < SAFE_RANGE; // A custom keycode should not be registered // Optionally re-register the trigger if it is still down if (reregister_trigger) { @@ -336,8 +338,8 @@ static bool try_activating_override(const uint16_t keycode, const uint8_t layer, const uint16_t mod_free_replacement = clear_mods_from(override->replacement); - bool register_replacement = mod_free_replacement != KC_NO && // KC_NO is never registered - mod_free_replacement < SAFE_RANGE; // Custom keycodes are never registered + bool register_replacement = mod_free_replacement != KC_NO && // KC_NO is never registered + mod_free_replacement < SAFE_RANGE; // Custom keycodes are never registered // Try firing the custom handler if (override->custom_action != NULL) { diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index cf63f25141..c2fd02e5c7 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -51,13 +51,13 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) { if (leading) { # ifndef LEADER_NO_TIMEOUT if (timer_elapsed(leader_time) < LEADER_TIMEOUT) -# endif // LEADER_NO_TIMEOUT +# endif // LEADER_NO_TIMEOUT { # ifndef LEADER_KEY_STRICT_KEY_PROCESSING if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; } -# endif // LEADER_KEY_STRICT_KEY_PROCESSING +# endif // LEADER_KEY_STRICT_KEY_PROCESSING if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c index d5cff4f12a..10161adda3 100644 --- a/quantum/process_keycode/process_magic.c +++ b/quantum/process_keycode/process_magic.c @@ -44,6 +44,7 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) { case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT: case MAGIC_TOGGLE_GUI: + case MAGIC_TOGGLE_CONTROL_CAPSLOCK: /* keymap config */ keymap_config.raw = eeconfig_read_keymap(); switch (keycode) { @@ -75,7 +76,7 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) { keymap_config.swap_backslash_backspace = true; break; case MAGIC_HOST_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys + clear_keyboard(); // clear first buffer to prevent stuck keys keymap_config.nkro = true; break; case MAGIC_SWAP_ALT_GUI: @@ -118,7 +119,7 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) { keymap_config.swap_backslash_backspace = false; break; case MAGIC_UNHOST_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys + clear_keyboard(); // clear first buffer to prevent stuck keys keymap_config.nkro = false; break; case MAGIC_UNSWAP_ALT_GUI: @@ -156,7 +157,7 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) { #endif break; case MAGIC_TOGGLE_NKRO: - clear_keyboard(); // clear first buffer to prevent stuck keys + clear_keyboard(); // clear first buffer to prevent stuck keys keymap_config.nkro = !keymap_config.nkro; break; case MAGIC_EE_HANDS_LEFT: @@ -168,10 +169,13 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) { case MAGIC_TOGGLE_GUI: keymap_config.no_gui = !keymap_config.no_gui; break; + case MAGIC_TOGGLE_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock; + break; } eeconfig_update_keymap(keymap_config.raw); - clear_keyboard(); // clear to prevent stuck keys + clear_keyboard(); // clear to prevent stuck keys return false; } diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 9632d2b757..c49c31a525 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -22,13 +22,19 @@ # ifdef MIDI_BASIC -void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); } +void process_midi_basic_noteon(uint8_t note) { + midi_send_noteon(&midi_device, 0, note, 127); +} -void process_midi_basic_noteoff(uint8_t note) { midi_send_noteoff(&midi_device, 0, note, 0); } +void process_midi_basic_noteoff(uint8_t note) { + midi_send_noteoff(&midi_device, 0, note, 0); +} -void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); } +void process_midi_all_notes_off(void) { + midi_send_cc(&midi_device, 0, 0x7B, 0); +} -# endif // MIDI_BASIC +# endif // MIDI_BASIC # ifdef MIDI_ADVANCED @@ -41,7 +47,9 @@ static int8_t midi_modulation_step; static uint16_t midi_modulation_timer; midi_config_t midi_config; -inline uint8_t compute_velocity(uint8_t setting) { return setting * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN)); } +inline uint8_t compute_velocity(uint8_t setting) { + return setting * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN)); +} void midi_init(void) { midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; @@ -60,7 +68,9 @@ void midi_init(void) { midi_modulation_timer = 0; } -uint8_t midi_compute_note(uint16_t keycode) { return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; } +uint8_t midi_compute_note(uint16_t keycode) { + return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; +} bool process_midi(uint16_t keycode, keyrecord_t *record) { switch (keycode) { @@ -238,7 +248,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { return true; } -# endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED void midi_task(void) { midi_device_process(&midi_device); @@ -263,4 +273,4 @@ void midi_task(void) { # endif } -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index 68c6eda666..e528c6ec0c 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -49,6 +49,6 @@ bool process_midi(uint16_t keycode, keyrecord_t *record); # define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) uint8_t midi_compute_note(uint16_t keycode); -# endif // MIDI_ADVANCED +# endif // MIDI_ADVANCED -#endif // MIDI_ENABLE +#endif // MIDI_ENABLE diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 6822c5e289..eeec0c28a4 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -146,7 +146,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { if (music_activated || midi_activated) { if (record->event.pressed) { - if (keycode == KC_LEFT_CTRL) { // Start recording + if (keycode == KC_LEFT_CTRL) { // Start recording music_all_notes_off(); music_sequence_recording = true; music_sequence_recorded = false; @@ -155,9 +155,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { return false; } - if (keycode == KC_LEFT_ALT) { // Stop recording/playing + if (keycode == KC_LEFT_ALT) { // Stop recording/playing music_all_notes_off(); - if (music_sequence_recording) { // was recording + if (music_sequence_recording) { // was recording music_sequence_recorded = true; } music_sequence_recording = false; @@ -165,7 +165,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { return false; } - if (keycode == KC_LEFT_GUI && music_sequence_recorded) { // Start playing + if (keycode == KC_LEFT_GUI && music_sequence_recorded) { // Start playing music_all_notes_off(); music_sequence_recording = false; music_sequence_playing = true; @@ -230,11 +230,17 @@ bool music_mask(uint16_t keycode) { # endif } -__attribute__((weak)) bool music_mask_kb(uint16_t keycode) { return music_mask_user(keycode); } +__attribute__((weak)) bool music_mask_kb(uint16_t keycode) { + return music_mask_user(keycode); +} -__attribute__((weak)) bool music_mask_user(uint16_t keycode) { return keycode < 0xFF; } +__attribute__((weak)) bool music_mask_user(uint16_t keycode) { + return keycode < 0xFF; +} -bool is_music_on(void) { return (music_activated != 0); } +bool is_music_on(void) { + return (music_activated != 0); +} void music_toggle(void) { if (!music_activated) { @@ -260,7 +266,9 @@ void music_off(void) { # endif } -bool is_midi_on(void) { return (midi_activated != 0); } +bool is_midi_on(void) { + return (midi_activated != 0); +} void midi_toggle(void) { if (!midi_activated) { @@ -315,4 +323,4 @@ __attribute__((weak)) void midi_on_user() {} __attribute__((weak)) void music_scale_user() {} -#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) +#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index e275cd9d26..83726a05ba 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -51,8 +51,10 @@ bool music_mask_kb(uint16_t keycode); bool music_mask_user(uint16_t keycode); # ifndef SCALE -# define SCALE \ - (int8_t[]) { 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), } +# define SCALE \ + (int8_t[]) { \ + 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), \ + } # endif -#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) +#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) diff --git a/quantum/process_keycode/process_printer.c b/quantum/process_keycode/process_printer.c index 82528cc680..6dd1f28c9b 100644 --- a/quantum/process_keycode/process_printer.c +++ b/quantum/process_keycode/process_printer.c @@ -16,16 +16,19 @@ #include "process_printer.h" #include "action_util.h" +#include "uart.h" bool printing_enabled = false; uint8_t character_shift = 0; void enable_printing(void) { printing_enabled = true; - serial_init(); + uart_init(19200); } -void disable_printing(void) { printing_enabled = false; } +void disable_printing(void) { + printing_enabled = false; +} uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; @@ -35,12 +38,13 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0 void print_char(char c) { USB_Disable(); - serial_send(c); + uart_write(c); USB_Init(); } void print_string(char c[]) { - for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]); + for (uint8_t i = 0; i < strlen(c); i++) + print_char(c[i]); } void print_box_string(const char text[]) { diff --git a/quantum/process_keycode/process_printer.h b/quantum/process_keycode/process_printer.h index 3c6d06ff94..6f4d09f333 100644 --- a/quantum/process_keycode/process_printer.h +++ b/quantum/process_keycode/process_printer.h @@ -18,6 +18,4 @@ #include "quantum.h" -#include "protocol/serial.h" - bool process_printer(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_printer_bb.c b/quantum/process_keycode/process_printer_bb.c index 6c91bd27ef..88a9f33994 100644 --- a/quantum/process_keycode/process_printer_bb.c +++ b/quantum/process_keycode/process_printer_bb.c @@ -25,13 +25,21 @@ uint8_t character_shift = 0; #define SERIAL_PIN_MASK _BV(PD3) #define SERIAL_DELAY 52 -inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); } +inline static void serial_delay(void) { + _delay_us(SERIAL_DELAY); +} -inline static void serial_high(void) { SERIAL_PIN_PORT |= SERIAL_PIN_MASK; } +inline static void serial_high(void) { + SERIAL_PIN_PORT |= SERIAL_PIN_MASK; +} -inline static void serial_low(void) { SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; } +inline static void serial_low(void) { + SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; +} -inline static void serial_output(void) { SERIAL_PIN_DDR |= SERIAL_PIN_MASK; } +inline static void serial_output(void) { + SERIAL_PIN_DDR |= SERIAL_PIN_MASK; +} void enable_printing() { printing_enabled = true; @@ -39,7 +47,9 @@ void enable_printing() { serial_high(); } -void disable_printing() { printing_enabled = false; } +void disable_printing() { + printing_enabled = false; +} uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29}; @@ -61,7 +71,8 @@ void print_char(char c) { } void print_string(char c[]) { - for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]); + for (uint8_t i = 0; i < strlen(c); i++) + print_char(c[i]); } bool process_printer(uint16_t keycode, keyrecord_t *record) { diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c index 69853cd5c4..c805bd615d 100644 --- a/quantum/process_keycode/process_rgb.c +++ b/quantum/process_keycode/process_rgb.c @@ -51,12 +51,8 @@ static void __attribute__((noinline, unused)) handleKeycodeRGBMode(const uint8_t * Handle keycodes for both rgblight and rgbmatrix */ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { -#ifndef SPLIT_KEYBOARD - if (record->event.pressed) { -#else - // Split keyboards need to trigger on key-up for edge-case issue + // need to trigger on key-up for edge-case issue if (!record->event.pressed) { -#endif #if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)) uint8_t shifted = get_mods() & MOD_MASK_SHIFT; #endif diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index 5d0bb313b4..12ee898212 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -102,11 +102,17 @@ void steno_set_mode(steno_mode_t new_mode) { /* override to intercept chords right before they get sent. * return zero to suppress normal sending behavior. */ -__attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; } +__attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { + return true; +} -__attribute__((weak)) bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; } +__attribute__((weak)) bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { + return true; +} -__attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) { + return true; +} static void send_steno_chord(void) { if (send_steno_chord_user(mode, chord)) { @@ -114,11 +120,11 @@ static void send_steno_chord(void) { case STENO_MODE_BOLT: send_steno_state(BOLT_STATE_SIZE, false); #ifdef VIRTSER_ENABLE - virtser_send(0); // terminating byte + virtser_send(0); // terminating byte #endif break; case STENO_MODE_GEMINI: - chord[0] |= 0x80; // Indicate start of packet + chord[0] |= 0x80; // Indicate start of packet send_steno_state(GEMINI_STATE_SIZE, true); break; } @@ -126,9 +132,13 @@ static void send_steno_chord(void) { steno_clear_state(); } -uint8_t *steno_get_state(void) { return &state[0]; } +uint8_t *steno_get_state(void) { + return &state[0]; +} -uint8_t *steno_get_chord(void) { return &chord[0]; } +uint8_t *steno_get_chord(void) { + return &chord[0]; +} static bool update_state_bolt(uint8_t key, bool press) { uint8_t boltcode = pgm_read_byte(boltmap + key); diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index c707fdea30..e99119b2ae 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -86,7 +86,9 @@ static inline void _process_tap_dance_action_fn(qk_tap_dance_state_t *state, voi } } -static inline void process_tap_dance_action_on_each_tap(qk_tap_dance_action_t *action) { _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); } +static inline void process_tap_dance_action_on_each_tap(qk_tap_dance_action_t *action) { + _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); +} static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_action_t *action) { if (action->state.finished) return; @@ -173,7 +175,7 @@ void tap_dance_task() { tap_user_defined = action->custom_tapping_term; } else { #ifdef TAPPING_TERM_PER_KEY - tap_user_defined = get_tapping_term(action->state.keycode, NULL); + tap_user_defined = get_tapping_term(action->state.keycode, &(keyrecord_t){}); #else tap_user_defined = TAPPING_TERM; #endif diff --git a/quantum/process_keycode/process_terminal.c b/quantum/process_keycode/process_terminal.c index a059f3a521..da1c4d506f 100644 --- a/quantum/process_keycode/process_terminal.c +++ b/quantum/process_keycode/process_terminal.c @@ -27,12 +27,12 @@ bool terminal_enabled = false; char buffer[80] = ""; char cmd_buffer[CMD_BUFF_SIZE][80]; -bool cmd_buffer_enabled = true; // replace with ifdef? +bool cmd_buffer_enabled = true; // replace with ifdef? char newline[2] = "\n"; char arguments[6][20]; bool firstTime = true; -short int current_cmd_buffer_pos = 0; // used for up/down arrows - keeps track of where you are in the command buffer +short int current_cmd_buffer_pos = 0; // used for up/down arrows - keeps track of where you are in the command buffer __attribute__((weak)) const char terminal_prompt[8] = "> "; @@ -59,7 +59,8 @@ void enable_terminal(void) { terminal_enabled = true; strcpy(buffer, ""); memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); - for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); + for (int i = 0; i < 6; i++) + strcpy(arguments[i], ""); // select all text to start over // SEND_STRING(SS_LCTL("a")); send_string(terminal_prompt); @@ -160,7 +161,7 @@ void print_cmd_buff(void) { for (int i = 0; i < CMD_BUFF_SIZE; i++) { char tmpChar = ' '; itoa(i, &tmpChar, 10); - const char *tmpCnstCharStr = &tmpChar; // because sned_string wont take a normal char * + const char *tmpCnstCharStr = &tmpChar; // because sned_string wont take a normal char * send_string(tmpCnstCharStr); SEND_STRING(". "); send_string(cmd_buffer[i]); @@ -185,7 +186,7 @@ void terminal_help(void) { } void command_not_found(void) { - wait_ms(50); // sometimes buffer isnt grabbed quick enough + wait_ms(50); // sometimes buffer isnt grabbed quick enough SEND_STRING("command \""); send_string(buffer); SEND_STRING("\" not found\n"); @@ -217,15 +218,16 @@ void process_terminal_command(void) { if (terminal_enabled) { strcpy(buffer, ""); - for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); + for (int i = 0; i < 6; i++) + strcpy(arguments[i], ""); SEND_STRING(SS_TAP(X_HOME)); send_string(terminal_prompt); } } void check_pos(void) { - if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { // if over the top, move it back down to the top of the buffer so you can climb back down... + if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { // if over the top, move it back down to the top of the buffer so you can climb back down... current_cmd_buffer_pos = CMD_BUFF_SIZE - 1; - } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up + } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up current_cmd_buffer_pos = 0; } } @@ -278,33 +280,33 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) { case KC_RIGHT: return false; break; - case KC_UP: // 0 = recent - check_pos(); // check our current buffer position is valid - if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { // once we get to the top, dont do anything + case KC_UP: // 0 = recent + check_pos(); // check our current buffer position is valid + if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { // once we get to the top, dont do anything str_len = strlen(buffer); for (int i = 0; i < str_len; ++i) { - send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already + send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already // process_terminal(KC_BACKSPACE,record); } strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 80); send_string(buffer); - ++current_cmd_buffer_pos; // get ready to access the above cmd if up/down is pressed again + ++current_cmd_buffer_pos; // get ready to access the above cmd if up/down is pressed again } return false; break; case KC_DOWN: check_pos(); - if (current_cmd_buffer_pos >= 0) { // once we get to the bottom, dont do anything + if (current_cmd_buffer_pos >= 0) { // once we get to the bottom, dont do anything str_len = strlen(buffer); for (int i = 0; i < str_len; ++i) { - send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already + send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already // process_terminal(KC_BACKSPACE,record); } strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 79); send_string(buffer); - --current_cmd_buffer_pos; // get ready to access the above cmd if down/up is pressed again + --current_cmd_buffer_pos; // get ready to access the above cmd if down/up is pressed again } return false; break; diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index d084d2b66c..6a8d8f0ff6 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -27,7 +27,7 @@ void qk_ucis_start(void) { __attribute__((weak)) void qk_ucis_start_user(void) { unicode_input_start(); - register_hex(0x2328); // ⌨ + register_hex(0x2328); // ⌨ unicode_input_finish(); } diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 7685bb1c99..46b77e14ba 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -54,7 +54,9 @@ void unicode_input_mode_init(void) { dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); } -uint8_t get_unicode_input_mode(void) { return unicode_config.input_mode; } +uint8_t get_unicode_input_mode(void) { + return unicode_config.input_mode; +} void set_unicode_input_mode(uint8_t mode) { unicode_config.input_mode = mode; @@ -76,7 +78,9 @@ void cycle_unicode_input_mode(int8_t offset) { #endif } -void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); } +void persist_unicode_input_mode(void) { + eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); +} __attribute__((weak)) void unicode_input_start(void) { unicode_saved_caps_lock = host_keyboard_led_state().caps_lock; @@ -90,8 +94,8 @@ __attribute__((weak)) void unicode_input_start(void) { tap_code(KC_CAPS_LOCK); } - unicode_saved_mods = get_mods(); // Save current mods - clear_mods(); // Unregister mods to start from a clean state + unicode_saved_mods = get_mods(); // Save current mods + clear_mods(); // Unregister mods to start from a clean state switch (unicode_config.input_mode) { case UC_MAC: @@ -140,7 +144,7 @@ __attribute__((weak)) void unicode_input_finish(void) { break; } - set_mods(unicode_saved_mods); // Reregister previously set mods + set_mods(unicode_saved_mods); // Reregister previously set mods } __attribute__((weak)) void unicode_input_cancel(void) { @@ -165,7 +169,7 @@ __attribute__((weak)) void unicode_input_cancel(void) { break; } - set_mods(unicode_saved_mods); // Reregister previously set mods + set_mods(unicode_saved_mods); // Reregister previously set mods } // clang-format off @@ -262,16 +266,16 @@ void send_unicode_hex_string(const char *str) { static const char *decode_utf8(const char *str, int32_t *code_point) { const char *next; - if (str[0] < 0x80) { // U+0000-007F + if (str[0] < 0x80) { // U+0000-007F *code_point = str[0]; next = str + 1; - } else if ((str[0] & 0xE0) == 0xC0) { // U+0080-07FF + } else if ((str[0] & 0xE0) == 0xC0) { // U+0080-07FF *code_point = ((int32_t)(str[0] & 0x1F) << 6) | ((int32_t)(str[1] & 0x3F) << 0); next = str + 2; - } else if ((str[0] & 0xF0) == 0xE0) { // U+0800-FFFF + } else if ((str[0] & 0xF0) == 0xE0) { // U+0800-FFFF *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0); next = str + 3; - } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF + } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF *code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0); next = str + 4; } else { diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 72defb445e..1a6607c757 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -59,12 +59,12 @@ #define UC_OSX UC_MAC enum unicode_input_modes { - UC_MAC, // macOS using Unicode Hex Input - UC_LNX, // Linux using IBus - UC_WIN, // Windows using EnableHexNumpad - UC_BSD, // BSD (not implemented) - UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) - UC__COUNT // Number of available input modes (always leave at the end) + UC_MAC, // macOS using Unicode Hex Input + UC_LNX, // Linux using IBus + UC_WIN, // Windows using EnableHexNumpad + UC_BSD, // BSD (not implemented) + UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) + UC__COUNT // Number of available input modes (always leave at the end) }; typedef union { diff --git a/quantum/programmable_button.c b/quantum/programmable_button.c index be828fd17c..a3ef42d82b 100644 --- a/quantum/programmable_button.c +++ b/quantum/programmable_button.c @@ -22,16 +22,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. static uint32_t programmable_button_report = 0; -void programmable_button_clear(void) { programmable_button_report = 0; } +void programmable_button_clear(void) { + programmable_button_report = 0; +} -void programmable_button_send(void) { host_programmable_button_send(programmable_button_report); } +void programmable_button_send(void) { + host_programmable_button_send(programmable_button_report); +} -void programmable_button_on(uint8_t index) { programmable_button_report |= REPORT_BIT(index); } +void programmable_button_on(uint8_t index) { + programmable_button_report |= REPORT_BIT(index); +} -void programmable_button_off(uint8_t index) { programmable_button_report &= ~REPORT_BIT(index); } +void programmable_button_off(uint8_t index) { + programmable_button_report &= ~REPORT_BIT(index); +} -bool programmable_button_is_on(uint8_t index) { return !!(programmable_button_report & REPORT_BIT(index)); }; +bool programmable_button_is_on(uint8_t index) { + return !!(programmable_button_report & REPORT_BIT(index)); +}; -uint32_t programmable_button_get_report(void) { return programmable_button_report; }; +uint32_t programmable_button_get_report(void) { + return programmable_button_report; +}; -void programmable_button_set_report(uint32_t report) { programmable_button_report = report; } +void programmable_button_set_report(uint32_t report) { + programmable_button_report = report; +} diff --git a/quantum/quantum.c b/quantum/quantum.c index be43faaf6b..ef6e5ac1df 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -15,7 +15,6 @@ */ #include "quantum.h" -#include "magic.h" #ifdef BLUETOOTH_ENABLE # include "outputselect.h" @@ -47,10 +46,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; # endif #endif -#ifdef AUTO_SHIFT_ENABLE -# include "process_auto_shift.h" -#endif - uint8_t extract_mod_bits(uint16_t code) { switch (code) { case QK_MODS ... QK_MODS_MAX: @@ -61,7 +56,7 @@ uint8_t extract_mod_bits(uint16_t code) { uint8_t mods_to_send = 0; - if (code & QK_RMODS_MIN) { // Right mod flag is set + if (code & QK_RMODS_MIN) { // Right mod flag is set if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RIGHT_CTRL); if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RIGHT_SHIFT); if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RIGHT_ALT); @@ -76,9 +71,11 @@ uint8_t extract_mod_bits(uint16_t code) { return mods_to_send; } -static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); } +void do_code16(uint16_t code, void (*f)(uint8_t)) { + f(extract_mod_bits(code)); +} -void register_code16(uint16_t code) { +__attribute__((weak)) void register_code16(uint16_t code) { if (IS_MOD(code) || code == KC_NO) { do_code16(code, register_mods); } else { @@ -87,7 +84,7 @@ void register_code16(uint16_t code) { register_code(code); } -void unregister_code16(uint16_t code) { +__attribute__((weak)) void unregister_code16(uint16_t code) { unregister_code(code); if (IS_MOD(code) || code == KC_NO) { do_code16(code, unregister_mods); @@ -96,21 +93,31 @@ void unregister_code16(uint16_t code) { } } -void tap_code16(uint16_t code) { +__attribute__((weak)) void tap_code16(uint16_t code) { register_code16(code); -#if TAP_CODE_DELAY > 0 - wait_ms(TAP_CODE_DELAY); -#endif + if (code == KC_CAPS_LOCK) { + wait_ms(TAP_HOLD_CAPS_DELAY); + } else if (TAP_CODE_DELAY > 0) { + wait_ms(TAP_CODE_DELAY); + } unregister_code16(code); } -__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { + return true; +} -__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } +__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + return process_record_user(keycode, record); +} -__attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { + return true; +} -__attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) { post_process_record_user(keycode, record); } +__attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) { + post_process_record_user(keycode, record); +} __attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {} @@ -126,7 +133,8 @@ void reset_keyboard(void) { uint16_t timer_start = timer_read(); PLAY_SONG(goodbye_song); shutdown_user(); - while (timer_elapsed(timer_start) < 250) wait_ms(1); + while (timer_elapsed(timer_start) < 250) + wait_ms(1); stop_all_notes(); #else shutdown_user(); @@ -181,7 +189,7 @@ bool pre_process_record_quantum(keyrecord_t *record) { true)) { return false; } - return true; // continue processing + return true; // continue processing } /* Get keycode, and then call keyboard function */ @@ -263,7 +271,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif -#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) +#if defined(UNICODE_COMMON_ENABLE) process_unicode_common(keycode, record) && #endif #ifdef LEADER_ENABLE @@ -306,12 +314,12 @@ bool process_record_quantum(keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { #ifndef NO_RESET - case RESET: + case QK_BOOTLOADER: reset_keyboard(); return false; #endif #ifndef NO_DEBUG - case DEBUG: + case QK_DEBUG_TOGGLE: debug_enable ^= 1; if (debug_enable) { print("DEBUG: enabled.\n"); @@ -320,7 +328,7 @@ bool process_record_quantum(keyrecord_t *record) { } #endif return false; - case EEPROM_RESET: + case QK_CLEAR_EEPROM: eeconfig_init(); return false; #ifdef VELOCIKEY_ENABLE @@ -370,104 +378,18 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_ return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); } -void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); } +void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { + layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); +} +// TODO: remove legacy api void matrix_init_quantum() { - magic(); - led_init_ports(); -#ifdef BACKLIGHT_ENABLE - backlight_init_ports(); -#endif -#ifdef AUDIO_ENABLE - audio_init(); -#endif -#ifdef LED_MATRIX_ENABLE - led_matrix_init(); -#endif -#ifdef RGB_MATRIX_ENABLE - rgb_matrix_init(); -#endif -#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) - unicode_input_mode_init(); -#endif -#ifdef HAPTIC_ENABLE - haptic_init(); -#endif -#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE) - set_output(OUTPUT_AUTO); -#endif - matrix_init_kb(); } - void matrix_scan_quantum() { -#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY) - // There are some tasks that need to be run a little bit - // after keyboard startup, or else they will not work correctly - // because of interaction with the USB device state, which - // may still be in flux... - // - // At the moment the only feature that needs this is the - // startup song. - static bool delayed_tasks_run = false; - static uint16_t delayed_task_timer = 0; - if (!delayed_tasks_run) { - if (!delayed_task_timer) { - delayed_task_timer = timer_read(); - } else if (timer_elapsed(delayed_task_timer) > 300) { - audio_startup(); - delayed_tasks_run = true; - } - } -#endif - -#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) - music_task(); -#endif - -#ifdef KEY_OVERRIDE_ENABLE - key_override_task(); -#endif - -#ifdef SEQUENCER_ENABLE - sequencer_task(); -#endif - -#ifdef TAP_DANCE_ENABLE - tap_dance_task(); -#endif - -#ifdef COMBO_ENABLE - combo_task(); -#endif - -#ifdef LED_MATRIX_ENABLE - led_matrix_task(); -#endif - -#ifdef WPM_ENABLE - decay_wpm(); -#endif - -#ifdef HAPTIC_ENABLE - haptic_task(); -#endif - -#ifdef DIP_SWITCH_ENABLE - dip_switch_read(false); -#endif - -#ifdef AUTO_SHIFT_ENABLE - autoshift_matrix_scan(); -#endif - matrix_scan_kb(); } -#ifdef HD44780_ENABLED -# include "hd44780.h" -#endif - //------------------------------------------------------------------------------ // Override these functions in your keymap file to play different tunes on // different events such as startup and bootloader jump @@ -476,17 +398,6 @@ __attribute__((weak)) void startup_user() {} __attribute__((weak)) void shutdown_user() {} -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_user(void) {} -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } - void suspend_power_down_quantum(void) { suspend_power_down_kb(); #ifndef NO_SUSPEND_POWER_DOWN @@ -503,14 +414,7 @@ void suspend_power_down_quantum(void) { # endif // Turn off LED indicators - uint8_t leds_off = 0; -# if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) - if (is_backlight_enabled()) { - // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off - leds_off |= (1 << USB_LED_CAPS_LOCK); - } -# endif - led_set(leds_off); + led_suspend(); // Turn off audio # ifdef AUDIO_ENABLE @@ -542,18 +446,6 @@ void suspend_power_down_quantum(void) { #endif } -/** \brief run user level code immediately after wakeup - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_wakeup_init_user(void) {} - -/** \brief run keyboard level code immediately after wakeup - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } - __attribute__((weak)) void suspend_wakeup_init_quantum(void) { // Turn on backlight #ifdef BACKLIGHT_ENABLE @@ -561,7 +453,7 @@ __attribute__((weak)) void suspend_wakeup_init_quantum(void) { #endif // Restore LED indicators - led_set(host_keyboard_leds()); + led_wakeup(); // Wake up underglow #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) diff --git a/quantum/quantum.h b/quantum/quantum.h index 6927884e2f..020e455941 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -109,6 +109,10 @@ extern layer_state_t layer_state; # include "process_unicodemap.h" #endif +#ifdef UNICODE_COMMON_ENABLE +# include "process_unicode_common.h" +#endif + #ifdef KEY_OVERRIDE_ENABLE # include "process_key_override.h" #endif @@ -245,11 +249,6 @@ void register_code16(uint16_t code); void unregister_code16(uint16_t code); void tap_code16(uint16_t code); -void led_set_user(uint8_t usb_led); -void led_set_kb(uint8_t usb_led); -bool led_update_user(led_t led_state); -bool led_update_kb(led_t led_state); - const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad); const char *get_u8_str(uint8_t curr_num, char curr_pad); const char *get_u16_str(uint16_t curr_num, char curr_pad); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index e4d0167aac..2552c48165 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -37,10 +37,6 @@ enum quantum_keycodes { QK_RALT = 0x1400, QK_RGUI = 0x1800, QK_MODS_MAX = 0x1FFF, - QK_FUNCTION = 0x2000, - QK_FUNCTION_MAX = 0x2FFF, - QK_MACRO = 0x3000, - QK_MACRO_MAX = 0x3FFF, QK_LAYER_TAP = 0x4000, QK_LAYER_TAP_MAX = 0x4FFF, QK_TO = 0x5000, @@ -80,422 +76,422 @@ enum quantum_keycodes { QK_UNICODEMAP_PAIR_MAX = 0xFFFF, // Loose keycodes - to be used directly - RESET = 0x5C00, - DEBUG, // 5C01 + QK_BOOTLOADER = 0x5C00, + QK_DEBUG_TOGGLE, // 5C01 // Magic - MAGIC_SWAP_CONTROL_CAPSLOCK, // 5C02 - MAGIC_CAPSLOCK_TO_CONTROL, // 5C03 - MAGIC_SWAP_LALT_LGUI, // 5C04 - MAGIC_SWAP_RALT_RGUI, // 5C05 - MAGIC_NO_GUI, // 5C06 - MAGIC_SWAP_GRAVE_ESC, // 5C07 - MAGIC_SWAP_BACKSLASH_BACKSPACE, // 5C08 - MAGIC_HOST_NKRO, // 5C09 - MAGIC_SWAP_ALT_GUI, // 5C0A - MAGIC_UNSWAP_CONTROL_CAPSLOCK, // 5C0B - MAGIC_UNCAPSLOCK_TO_CONTROL, // 5C0C - MAGIC_UNSWAP_LALT_LGUI, // 5C0D - MAGIC_UNSWAP_RALT_RGUI, // 5C0E - MAGIC_UNNO_GUI, // 5C0F - MAGIC_UNSWAP_GRAVE_ESC, // 5C10 - MAGIC_UNSWAP_BACKSLASH_BACKSPACE, // 5C11 - MAGIC_UNHOST_NKRO, // 5C12 - MAGIC_UNSWAP_ALT_GUI, // 5C13 - MAGIC_TOGGLE_NKRO, // 5C14 - MAGIC_TOGGLE_ALT_GUI, // 5C15 + MAGIC_SWAP_CONTROL_CAPSLOCK, // 5C02 + MAGIC_CAPSLOCK_TO_CONTROL, // 5C03 + MAGIC_SWAP_LALT_LGUI, // 5C04 + MAGIC_SWAP_RALT_RGUI, // 5C05 + MAGIC_NO_GUI, // 5C06 + MAGIC_SWAP_GRAVE_ESC, // 5C07 + MAGIC_SWAP_BACKSLASH_BACKSPACE, // 5C08 + MAGIC_HOST_NKRO, // 5C09 + MAGIC_SWAP_ALT_GUI, // 5C0A + MAGIC_UNSWAP_CONTROL_CAPSLOCK, // 5C0B + MAGIC_UNCAPSLOCK_TO_CONTROL, // 5C0C + MAGIC_UNSWAP_LALT_LGUI, // 5C0D + MAGIC_UNSWAP_RALT_RGUI, // 5C0E + MAGIC_UNNO_GUI, // 5C0F + MAGIC_UNSWAP_GRAVE_ESC, // 5C10 + MAGIC_UNSWAP_BACKSLASH_BACKSPACE, // 5C11 + MAGIC_UNHOST_NKRO, // 5C12 + MAGIC_UNSWAP_ALT_GUI, // 5C13 + MAGIC_TOGGLE_NKRO, // 5C14 + MAGIC_TOGGLE_ALT_GUI, // 5C15 // Grave Escape - GRAVE_ESC, // 5C16 + QK_GRAVE_ESCAPE, // 5C16 // Auto Shift - KC_ASUP, // 5C17 - KC_ASDN, // 5C18 - KC_ASRP, // 5C19 - KC_ASTG, // 5C1A - KC_ASON, // 5C1B - KC_ASOFF, // 5C1C + KC_ASUP, // 5C17 + KC_ASDN, // 5C18 + KC_ASRP, // 5C19 + KC_ASTG, // 5C1A + KC_ASON, // 5C1B + KC_ASOFF, // 5C1C // Audio - AU_ON, // 5C1D - AU_OFF, // 5C1E - AU_TOG, // 5C1F + AU_ON, // 5C1D + AU_OFF, // 5C1E + AU_TOG, // 5C1F // Audio Clicky - CLICKY_TOGGLE, // 5C20 - CLICKY_ENABLE, // 5C21 - CLICKY_DISABLE, // 5C22 - CLICKY_UP, // 5C23 - CLICKY_DOWN, // 5C24 - CLICKY_RESET, // 5C25 + CLICKY_TOGGLE, // 5C20 + CLICKY_ENABLE, // 5C21 + CLICKY_DISABLE, // 5C22 + CLICKY_UP, // 5C23 + CLICKY_DOWN, // 5C24 + CLICKY_RESET, // 5C25 // Music mode - MU_ON, // 5C26 - MU_OFF, // 5C27 - MU_TOG, // 5C28 - MU_MOD, // 5C29 - MUV_IN, // 5C2A - MUV_DE, // 5C2B + MU_ON, // 5C26 + MU_OFF, // 5C27 + MU_TOG, // 5C28 + MU_MOD, // 5C29 + MUV_IN, // 5C2A + MUV_DE, // 5C2B // MIDI - MI_ON, // 5C2C - MI_OFF, // 5C2D - MI_TOG, // 5C2E + MI_ON, // 5C2C + MI_OFF, // 5C2D + MI_TOG, // 5C2E - MI_C, // 5C2F - MI_Cs, // 5C30 + MI_C, // 5C2F + MI_Cs, // 5C30 MI_Db = MI_Cs, - MI_D, // 5C31 - MI_Ds, // 5C32 + MI_D, // 5C31 + MI_Ds, // 5C32 MI_Eb = MI_Ds, - MI_E, // 5C33 - MI_F, // 5C34 - MI_Fs, // 5C35 + MI_E, // 5C33 + MI_F, // 5C34 + MI_Fs, // 5C35 MI_Gb = MI_Fs, - MI_G, // 5C36 - MI_Gs, // 5C37 + MI_G, // 5C36 + MI_Gs, // 5C37 MI_Ab = MI_Gs, - MI_A, // 5C38 - MI_As, // 5C39 + MI_A, // 5C38 + MI_As, // 5C39 MI_Bb = MI_As, - MI_B, // 5C3A + MI_B, // 5C3A - MI_C_1, // 5C3B - MI_Cs_1, // 5C3C + MI_C_1, // 5C3B + MI_Cs_1, // 5C3C MI_Db_1 = MI_Cs_1, - MI_D_1, // 5C3D - MI_Ds_1, // 5C3E + MI_D_1, // 5C3D + MI_Ds_1, // 5C3E MI_Eb_1 = MI_Ds_1, - MI_E_1, // 5C3F - MI_F_1, // 5C40 - MI_Fs_1, // 5C41 + MI_E_1, // 5C3F + MI_F_1, // 5C40 + MI_Fs_1, // 5C41 MI_Gb_1 = MI_Fs_1, - MI_G_1, // 5C42 - MI_Gs_1, // 5C43 + MI_G_1, // 5C42 + MI_Gs_1, // 5C43 MI_Ab_1 = MI_Gs_1, - MI_A_1, // 5C44 - MI_As_1, // 5C45 + MI_A_1, // 5C44 + MI_As_1, // 5C45 MI_Bb_1 = MI_As_1, - MI_B_1, // 5C46 + MI_B_1, // 5C46 - MI_C_2, // 5C47 - MI_Cs_2, // 5C48 + MI_C_2, // 5C47 + MI_Cs_2, // 5C48 MI_Db_2 = MI_Cs_2, - MI_D_2, // 5C49 - MI_Ds_2, // 5C4A + MI_D_2, // 5C49 + MI_Ds_2, // 5C4A MI_Eb_2 = MI_Ds_2, - MI_E_2, // 5C4B - MI_F_2, // 5C4C - MI_Fs_2, // 5C4D + MI_E_2, // 5C4B + MI_F_2, // 5C4C + MI_Fs_2, // 5C4D MI_Gb_2 = MI_Fs_2, - MI_G_2, // 5C4E - MI_Gs_2, // 5C4F + MI_G_2, // 5C4E + MI_Gs_2, // 5C4F MI_Ab_2 = MI_Gs_2, - MI_A_2, // 5C50 - MI_As_2, // 5C51 + MI_A_2, // 5C50 + MI_As_2, // 5C51 MI_Bb_2 = MI_As_2, - MI_B_2, // 5C52 + MI_B_2, // 5C52 - MI_C_3, // 5C53 - MI_Cs_3, // 5C54 + MI_C_3, // 5C53 + MI_Cs_3, // 5C54 MI_Db_3 = MI_Cs_3, - MI_D_3, // 5C55 - MI_Ds_3, // 5C56 + MI_D_3, // 5C55 + MI_Ds_3, // 5C56 MI_Eb_3 = MI_Ds_3, - MI_E_3, // 5C57 - MI_F_3, // 5C58 - MI_Fs_3, // 5C59 + MI_E_3, // 5C57 + MI_F_3, // 5C58 + MI_Fs_3, // 5C59 MI_Gb_3 = MI_Fs_3, - MI_G_3, // 5C5A - MI_Gs_3, // 5C5B + MI_G_3, // 5C5A + MI_Gs_3, // 5C5B MI_Ab_3 = MI_Gs_3, - MI_A_3, // 5C5C - MI_As_3, // 5C5D + MI_A_3, // 5C5C + MI_As_3, // 5C5D MI_Bb_3 = MI_As_3, - MI_B_3, // 5C5E + MI_B_3, // 5C5E - MI_C_4, // 5C5F - MI_Cs_4, // 5C60 + MI_C_4, // 5C5F + MI_Cs_4, // 5C60 MI_Db_4 = MI_Cs_4, - MI_D_4, // 5C61 - MI_Ds_4, // 5C62 + MI_D_4, // 5C61 + MI_Ds_4, // 5C62 MI_Eb_4 = MI_Ds_4, - MI_E_4, // 5C63 - MI_F_4, // 5C64 - MI_Fs_4, // 5C65 + MI_E_4, // 5C63 + MI_F_4, // 5C64 + MI_Fs_4, // 5C65 MI_Gb_4 = MI_Fs_4, - MI_G_4, // 5C66 - MI_Gs_4, // 5C67 + MI_G_4, // 5C66 + MI_Gs_4, // 5C67 MI_Ab_4 = MI_Gs_4, - MI_A_4, // 5C68 - MI_As_4, // 5C69 + MI_A_4, // 5C68 + MI_As_4, // 5C69 MI_Bb_4 = MI_As_4, - MI_B_4, // 5C6A + MI_B_4, // 5C6A - MI_C_5, // 5C6B - MI_Cs_5, // 5C6C + MI_C_5, // 5C6B + MI_Cs_5, // 5C6C MI_Db_5 = MI_Cs_5, - MI_D_5, // 5C6D - MI_Ds_5, // 5C6E + MI_D_5, // 5C6D + MI_Ds_5, // 5C6E MI_Eb_5 = MI_Ds_5, - MI_E_5, // 5C6F - MI_F_5, // 5C70 - MI_Fs_5, // 5C71 + MI_E_5, // 5C6F + MI_F_5, // 5C70 + MI_Fs_5, // 5C71 MI_Gb_5 = MI_Fs_5, - MI_G_5, // 5C72 - MI_Gs_5, // 5C73 + MI_G_5, // 5C72 + MI_Gs_5, // 5C73 MI_Ab_5 = MI_Gs_5, - MI_A_5, // 5C74 - MI_As_5, // 5C75 + MI_A_5, // 5C74 + MI_As_5, // 5C75 MI_Bb_5 = MI_As_5, - MI_B_5, // 5C76 - - MI_OCT_N2, // 5C77 - MI_OCT_N1, // 5C78 - MI_OCT_0, // 5C79 - MI_OCT_1, // 5C7A - MI_OCT_2, // 5C7B - MI_OCT_3, // 5C7C - MI_OCT_4, // 5C7D - MI_OCT_5, // 5C7E - MI_OCT_6, // 5C7F - MI_OCT_7, // 5C80 - MI_OCTD, // 5C81 - MI_OCTU, // 5C82 - - MI_TRNS_N6, // 5C83 - MI_TRNS_N5, // 5C84 - MI_TRNS_N4, // 5C85 - MI_TRNS_N3, // 5C86 - MI_TRNS_N2, // 5C87 - MI_TRNS_N1, // 5C88 - MI_TRNS_0, // 5C89 - MI_TRNS_1, // 5C8A - MI_TRNS_2, // 5C8B - MI_TRNS_3, // 5C8C - MI_TRNS_4, // 5C8D - MI_TRNS_5, // 5C8E - MI_TRNS_6, // 5C8F - MI_TRNSD, // 5C90 - MI_TRNSU, // 5C91 - - MI_VEL_0, // 5C92 + MI_B_5, // 5C76 + + MI_OCT_N2, // 5C77 + MI_OCT_N1, // 5C78 + MI_OCT_0, // 5C79 + MI_OCT_1, // 5C7A + MI_OCT_2, // 5C7B + MI_OCT_3, // 5C7C + MI_OCT_4, // 5C7D + MI_OCT_5, // 5C7E + MI_OCT_6, // 5C7F + MI_OCT_7, // 5C80 + MI_OCTD, // 5C81 + MI_OCTU, // 5C82 + + MI_TRNS_N6, // 5C83 + MI_TRNS_N5, // 5C84 + MI_TRNS_N4, // 5C85 + MI_TRNS_N3, // 5C86 + MI_TRNS_N2, // 5C87 + MI_TRNS_N1, // 5C88 + MI_TRNS_0, // 5C89 + MI_TRNS_1, // 5C8A + MI_TRNS_2, // 5C8B + MI_TRNS_3, // 5C8C + MI_TRNS_4, // 5C8D + MI_TRNS_5, // 5C8E + MI_TRNS_6, // 5C8F + MI_TRNSD, // 5C90 + MI_TRNSU, // 5C91 + + MI_VEL_0, // 5C92 #ifdef VIA_ENABLE MI_VEL_1 = MI_VEL_0, #else - MI_VEL_1, // 5C93 + MI_VEL_1, // 5C93 #endif - MI_VEL_2, // 5C94 - MI_VEL_3, // 5C95 - MI_VEL_4, // 5C96 - MI_VEL_5, // 5C97 - MI_VEL_6, // 5C98 - MI_VEL_7, // 5C99 - MI_VEL_8, // 5C9A - MI_VEL_9, // 5C9B - MI_VEL_10, // 5C9C - MI_VELD, // 5C9D - MI_VELU, // 5C9E - - MI_CH1, // 5C9F - MI_CH2, // 5CA0 - MI_CH3, // 5CA1 - MI_CH4, // 5CA2 - MI_CH5, // 5CA3 - MI_CH6, // 5CA4 - MI_CH7, // 5CA5 - MI_CH8, // 5CA6 - MI_CH9, // 5CA7 - MI_CH10, // 5CA8 - MI_CH11, // 5CA9 - MI_CH12, // 5CAA - MI_CH13, // 5CAB - MI_CH14, // 5CAC - MI_CH15, // 5CAD - MI_CH16, // 5CAE - MI_CHD, // 5CAF - MI_CHU, // 5CB0 - - MI_ALLOFF, // 5CB1 - - MI_SUS, // 5CB2 - MI_PORT, // 5CB3 - MI_SOST, // 5CB4 - MI_SOFT, // 5CB5 - MI_LEG, // 5CB6 - - MI_MOD, // 5CB7 - MI_MODSD, // 5CB8 - MI_MODSU, // 5CB9 - - MI_BENDD, // 5CBA - MI_BENDU, // 5CBB + MI_VEL_2, // 5C94 + MI_VEL_3, // 5C95 + MI_VEL_4, // 5C96 + MI_VEL_5, // 5C97 + MI_VEL_6, // 5C98 + MI_VEL_7, // 5C99 + MI_VEL_8, // 5C9A + MI_VEL_9, // 5C9B + MI_VEL_10, // 5C9C + MI_VELD, // 5C9D + MI_VELU, // 5C9E + + MI_CH1, // 5C9F + MI_CH2, // 5CA0 + MI_CH3, // 5CA1 + MI_CH4, // 5CA2 + MI_CH5, // 5CA3 + MI_CH6, // 5CA4 + MI_CH7, // 5CA5 + MI_CH8, // 5CA6 + MI_CH9, // 5CA7 + MI_CH10, // 5CA8 + MI_CH11, // 5CA9 + MI_CH12, // 5CAA + MI_CH13, // 5CAB + MI_CH14, // 5CAC + MI_CH15, // 5CAD + MI_CH16, // 5CAE + MI_CHD, // 5CAF + MI_CHU, // 5CB0 + + MI_ALLOFF, // 5CB1 + + MI_SUS, // 5CB2 + MI_PORT, // 5CB3 + MI_SOST, // 5CB4 + MI_SOFT, // 5CB5 + MI_LEG, // 5CB6 + + MI_MOD, // 5CB7 + MI_MODSD, // 5CB8 + MI_MODSU, // 5CB9 + + MI_BENDD, // 5CBA + MI_BENDU, // 5CBB // Backlight - BL_ON, // 5CBC - BL_OFF, // 5CBD - BL_DEC, // 5CBE - BL_INC, // 5CBF - BL_TOGG, // 5CC0 - BL_STEP, // 5CC1 - BL_BRTG, // 5CC2 + BL_ON, // 5CBC + BL_OFF, // 5CBD + BL_DEC, // 5CBE + BL_INC, // 5CBF + BL_TOGG, // 5CC0 + BL_STEP, // 5CC1 + BL_BRTG, // 5CC2 // RGB underglow/matrix - RGB_TOG, // 5CC3 - RGB_MODE_FORWARD, // 5CC4 - RGB_MODE_REVERSE, // 5CC5 - RGB_HUI, // 5CC6 - RGB_HUD, // 5CC7 - RGB_SAI, // 5CC8 - RGB_SAD, // 5CC9 - RGB_VAI, // 5CCA - RGB_VAD, // 5CCB - RGB_SPI, // 5CCC - RGB_SPD, // 5CCD - RGB_MODE_PLAIN, // 5CCE - RGB_MODE_BREATHE, // 5CCF - RGB_MODE_RAINBOW, // 5CD0 - RGB_MODE_SWIRL, // 5CD1 - RGB_MODE_SNAKE, // 5CD2 - RGB_MODE_KNIGHT, // 5CD3 - RGB_MODE_XMAS, // 5CD4 - RGB_MODE_GRADIENT, // 5CD5 - RGB_MODE_RGBTEST, // 5CD6 + RGB_TOG, // 5CC3 + RGB_MODE_FORWARD, // 5CC4 + RGB_MODE_REVERSE, // 5CC5 + RGB_HUI, // 5CC6 + RGB_HUD, // 5CC7 + RGB_SAI, // 5CC8 + RGB_SAD, // 5CC9 + RGB_VAI, // 5CCA + RGB_VAD, // 5CCB + RGB_SPI, // 5CCC + RGB_SPD, // 5CCD + RGB_MODE_PLAIN, // 5CCE + RGB_MODE_BREATHE, // 5CCF + RGB_MODE_RAINBOW, // 5CD0 + RGB_MODE_SWIRL, // 5CD1 + RGB_MODE_SNAKE, // 5CD2 + RGB_MODE_KNIGHT, // 5CD3 + RGB_MODE_XMAS, // 5CD4 + RGB_MODE_GRADIENT, // 5CD5 + RGB_MODE_RGBTEST, // 5CD6 // Velocikey - VLK_TOG, // 5CD7 + VLK_TOG, // 5CD7 // Space Cadet - KC_LSPO, // 5CD8 - KC_RSPC, // 5CD9 - KC_SFTENT, // 5CDA + KC_LSPO, // 5CD8 + KC_RSPC, // 5CD9 + KC_SFTENT, // 5CDA // Thermal Printer - PRINT_ON, // 5CDB - PRINT_OFF, // 5CDC + PRINT_ON, // 5CDB + PRINT_OFF, // 5CDC // Bluetooth: output selection - OUT_AUTO, // 5CDD - OUT_USB, // 5CDE + OUT_AUTO, // 5CDD + OUT_USB, // 5CDE // Clear EEPROM - EEPROM_RESET, // 5CDF + QK_CLEAR_EEPROM, // 5CDF // Unicode - UNICODE_MODE_FORWARD, // 5CE0 - UNICODE_MODE_REVERSE, // 5CE1 - UNICODE_MODE_MAC, // 5CE2 - UNICODE_MODE_LNX, // 5CE3 - UNICODE_MODE_WIN, // 5CE4 - UNICODE_MODE_BSD, // 5CE5 - UNICODE_MODE_WINC, // 5CE6 + UNICODE_MODE_FORWARD, // 5CE0 + UNICODE_MODE_REVERSE, // 5CE1 + UNICODE_MODE_MAC, // 5CE2 + UNICODE_MODE_LNX, // 5CE3 + UNICODE_MODE_WIN, // 5CE4 + UNICODE_MODE_BSD, // 5CE5 + UNICODE_MODE_WINC, // 5CE6 // Haptic - HPT_ON, // 5CE7 - HPT_OFF, // 5CE8 - HPT_TOG, // 5CE9 - HPT_RST, // 5CEA - HPT_FBK, // 5CEB - HPT_BUZ, // 5CEC - HPT_MODI, // 5CED - HPT_MODD, // 5CEE - HPT_CONT, // 5CEF - HPT_CONI, // 5CF0 - HPT_COND, // 5CF1 - HPT_DWLI, // 5CF2 - HPT_DWLD, // 5CF3 + HPT_ON, // 5CE7 + HPT_OFF, // 5CE8 + HPT_TOG, // 5CE9 + HPT_RST, // 5CEA + HPT_FBK, // 5CEB + HPT_BUZ, // 5CEC + HPT_MODI, // 5CED + HPT_MODD, // 5CEE + HPT_CONT, // 5CEF + HPT_CONI, // 5CF0 + HPT_COND, // 5CF1 + HPT_DWLI, // 5CF2 + HPT_DWLD, // 5CF3 // Space Cadet (continued) - KC_LCPO, // 5CF4 - KC_RCPC, // 5CF5 - KC_LAPO, // 5CF6 - KC_RAPC, // 5CF7 + KC_LCPO, // 5CF4 + KC_RCPC, // 5CF5 + KC_LAPO, // 5CF6 + KC_RAPC, // 5CF7 // Combos - CMB_ON, // 5CF8 - CMB_OFF, // 5CF9 - CMB_TOG, // 5CFA + CMB_ON, // 5CF8 + CMB_OFF, // 5CF9 + CMB_TOG, // 5CFA // Magic (continued) - MAGIC_SWAP_LCTL_LGUI, // 5CFB - MAGIC_SWAP_RCTL_RGUI, // 5CFC - MAGIC_UNSWAP_LCTL_LGUI, // 5CFD - MAGIC_UNSWAP_RCTL_RGUI, // 5CFE - MAGIC_SWAP_CTL_GUI, // 5CFF - MAGIC_UNSWAP_CTL_GUI, // 5D00 - MAGIC_TOGGLE_CTL_GUI, // 5D01 - MAGIC_EE_HANDS_LEFT, // 5D02 - MAGIC_EE_HANDS_RIGHT, // 5D03 + MAGIC_SWAP_LCTL_LGUI, // 5CFB + MAGIC_SWAP_RCTL_RGUI, // 5CFC + MAGIC_UNSWAP_LCTL_LGUI, // 5CFD + MAGIC_UNSWAP_RCTL_RGUI, // 5CFE + MAGIC_SWAP_CTL_GUI, // 5CFF + MAGIC_UNSWAP_CTL_GUI, // 5D00 + MAGIC_TOGGLE_CTL_GUI, // 5D01 + MAGIC_EE_HANDS_LEFT, // 5D02 + MAGIC_EE_HANDS_RIGHT, // 5D03 // Dynamic Macros - DYN_REC_START1, // 5D04 - DYN_REC_START2, // 5D05 - DYN_REC_STOP, // 5D06 - DYN_MACRO_PLAY1, // 5D07 - DYN_MACRO_PLAY2, // 5D08 + DYN_REC_START1, // 5D04 + DYN_REC_START2, // 5D05 + DYN_REC_STOP, // 5D06 + DYN_MACRO_PLAY1, // 5D07 + DYN_MACRO_PLAY2, // 5D08 // Joystick - JS_BUTTON0, // 5D09 - JS_BUTTON1, // 5D0A - JS_BUTTON2, // 5D0B - JS_BUTTON3, // 5D0C - JS_BUTTON4, // 5D0D - JS_BUTTON5, // 5D0E - JS_BUTTON6, // 5D0F - JS_BUTTON7, // 5D10 - JS_BUTTON8, // 5D11 - JS_BUTTON9, // 5D12 - JS_BUTTON10, // 5D13 - JS_BUTTON11, // 5D14 - JS_BUTTON12, // 5D15 - JS_BUTTON13, // 5D16 - JS_BUTTON14, // 5D17 - JS_BUTTON15, // 5D18 - JS_BUTTON16, // 5D19 - JS_BUTTON17, // 5D1A - JS_BUTTON18, // 5D1B - JS_BUTTON19, // 5D1C - JS_BUTTON20, // 5D1D - JS_BUTTON21, // 5D1E - JS_BUTTON22, // 5D1F - JS_BUTTON23, // 5D20 - JS_BUTTON24, // 5D21 - JS_BUTTON25, // 5D22 - JS_BUTTON26, // 5D23 - JS_BUTTON27, // 5D24 - JS_BUTTON28, // 5D25 - JS_BUTTON29, // 5D26 - JS_BUTTON30, // 5D27 - JS_BUTTON31, // 5D28 + JS_BUTTON0, // 5D09 + JS_BUTTON1, // 5D0A + JS_BUTTON2, // 5D0B + JS_BUTTON3, // 5D0C + JS_BUTTON4, // 5D0D + JS_BUTTON5, // 5D0E + JS_BUTTON6, // 5D0F + JS_BUTTON7, // 5D10 + JS_BUTTON8, // 5D11 + JS_BUTTON9, // 5D12 + JS_BUTTON10, // 5D13 + JS_BUTTON11, // 5D14 + JS_BUTTON12, // 5D15 + JS_BUTTON13, // 5D16 + JS_BUTTON14, // 5D17 + JS_BUTTON15, // 5D18 + JS_BUTTON16, // 5D19 + JS_BUTTON17, // 5D1A + JS_BUTTON18, // 5D1B + JS_BUTTON19, // 5D1C + JS_BUTTON20, // 5D1D + JS_BUTTON21, // 5D1E + JS_BUTTON22, // 5D1F + JS_BUTTON23, // 5D20 + JS_BUTTON24, // 5D21 + JS_BUTTON25, // 5D22 + JS_BUTTON26, // 5D23 + JS_BUTTON27, // 5D24 + JS_BUTTON28, // 5D25 + JS_BUTTON29, // 5D26 + JS_BUTTON30, // 5D27 + JS_BUTTON31, // 5D28 // Leader Key - KC_LEAD, // 5D29 + KC_LEAD, // 5D29 // Bluetooth: output selection (continued) - OUT_BT, // 5D2A + OUT_BT, // 5D2A // Lock Key - KC_LOCK, // 5D2B + KC_LOCK, // 5D2B // Terminal - TERM_ON, // 5D2C - TERM_OFF, // 5D2D + TERM_ON, // 5D2C + TERM_OFF, // 5D2D // Sequencer - SQ_ON, // 5D2E - SQ_OFF, // 5D2F - SQ_TOG, // 5D30 + SQ_ON, // 5D2E + SQ_OFF, // 5D2F + SQ_TOG, // 5D30 - SQ_TMPD, // 5D31 - SQ_TMPU, // 5D32 + SQ_TMPD, // 5D31 + SQ_TMPU, // 5D32 - SQ_RESD, // 5D33 - SQ_RESU, // 5D34 + SQ_RESD, // 5D33 + SQ_RESU, // 5D34 - SQ_SALL, // 5D35 - SQ_SCLR, // 5D36 + SQ_SALL, // 5D35 + SQ_SCLR, // 5D36 - SEQUENCER_STEP_MIN, // 5D37 + SEQUENCER_STEP_MIN, // 5D37 SEQUENCER_STEP_MAX = SEQUENCER_STEP_MIN + SEQUENCER_STEPS, SEQUENCER_RESOLUTION_MIN, @@ -597,6 +593,8 @@ enum quantum_keycodes { MACRO_30, MACRO_31, + MAGIC_TOGGLE_CONTROL_CAPSLOCK, + // Start of custom keycode range for keyboards and keymaps - always leave at the end SAFE_RANGE }; @@ -638,69 +636,69 @@ enum quantum_keycodes { #define MOD_MEH 0x7 // US ANSI shifted keycode aliases -#define KC_TILDE LSFT(KC_GRAVE) // ~ +#define KC_TILDE LSFT(KC_GRAVE) // ~ #define KC_TILD KC_TILDE -#define KC_EXCLAIM LSFT(KC_1) // ! +#define KC_EXCLAIM LSFT(KC_1) // ! #define KC_EXLM KC_EXCLAIM -#define KC_AT LSFT(KC_2) // @ +#define KC_AT LSFT(KC_2) // @ -#define KC_HASH LSFT(KC_3) // # +#define KC_HASH LSFT(KC_3) // # -#define KC_DOLLAR LSFT(KC_4) // $ +#define KC_DOLLAR LSFT(KC_4) // $ #define KC_DLR KC_DOLLAR -#define KC_PERCENT LSFT(KC_5) // % +#define KC_PERCENT LSFT(KC_5) // % #define KC_PERC KC_PERCENT -#define KC_CIRCUMFLEX LSFT(KC_6) // ^ +#define KC_CIRCUMFLEX LSFT(KC_6) // ^ #define KC_CIRC KC_CIRCUMFLEX -#define KC_AMPERSAND LSFT(KC_7) // & +#define KC_AMPERSAND LSFT(KC_7) // & #define KC_AMPR KC_AMPERSAND -#define KC_ASTERISK LSFT(KC_8) // * +#define KC_ASTERISK LSFT(KC_8) // * #define KC_ASTR KC_ASTERISK -#define KC_LEFT_PAREN LSFT(KC_9) // ( +#define KC_LEFT_PAREN LSFT(KC_9) // ( #define KC_LPRN KC_LEFT_PAREN -#define KC_RIGHT_PAREN LSFT(KC_0) // ) +#define KC_RIGHT_PAREN LSFT(KC_0) // ) #define KC_RPRN KC_RIGHT_PAREN -#define KC_UNDERSCORE LSFT(KC_MINUS) // _ +#define KC_UNDERSCORE LSFT(KC_MINUS) // _ #define KC_UNDS KC_UNDERSCORE -#define KC_PLUS LSFT(KC_EQUAL) // + +#define KC_PLUS LSFT(KC_EQUAL) // + -#define KC_LEFT_CURLY_BRACE LSFT(KC_LEFT_BRACKET) // { +#define KC_LEFT_CURLY_BRACE LSFT(KC_LEFT_BRACKET) // { #define KC_LCBR KC_LEFT_CURLY_BRACE -#define KC_RIGHT_CURLY_BRACE LSFT(KC_RIGHT_BRACKET) // } +#define KC_RIGHT_CURLY_BRACE LSFT(KC_RIGHT_BRACKET) // } #define KC_RCBR KC_RIGHT_CURLY_BRACE -#define KC_LEFT_ANGLE_BRACKET LSFT(KC_COMMA) // < +#define KC_LEFT_ANGLE_BRACKET LSFT(KC_COMMA) // < #define KC_LABK KC_LEFT_ANGLE_BRACKET #define KC_LT KC_LEFT_ANGLE_BRACKET -#define KC_RIGHT_ANGLE_BRACKET LSFT(KC_DOT) // > +#define KC_RIGHT_ANGLE_BRACKET LSFT(KC_DOT) // > #define KC_RABK KC_RIGHT_ANGLE_BRACKET #define KC_GT KC_RIGHT_ANGLE_BRACKET -#define KC_COLON LSFT(KC_SEMICOLON) // : +#define KC_COLON LSFT(KC_SEMICOLON) // : #define KC_COLN KC_COLON -#define KC_PIPE LSFT(KC_BACKSLASH) // | +#define KC_PIPE LSFT(KC_BACKSLASH) // | -#define KC_QUESTION LSFT(KC_SLASH) // ? +#define KC_QUESTION LSFT(KC_SLASH) // ? #define KC_QUES KC_QUESTION -#define KC_DOUBLE_QUOTE LSFT(KC_QUOTE) // " +#define KC_DOUBLE_QUOTE LSFT(KC_QUOTE) // " #define KC_DQUO KC_DOUBLE_QUOTE #define KC_DQT KC_DOUBLE_QUOTE -#define KC_DELT KC_DELETE // Del key (four letter code) +#define KC_DELT KC_DELETE // Del key (four letter code) // Modified keycode aliases #define C(kc) LCTL(kc) @@ -708,15 +706,11 @@ enum quantum_keycodes { #define A(kc) LALT(kc) #define G(kc) LGUI(kc) -// Deprecated - do not use -#define F(kc) (QK_FUNCTION | (kc)) -#define M(kc) (QK_MACRO | (kc)) -#define MACROTAP(kc) (QK_MACRO | (FUNC_TAP << 8) | (kc)) -#define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) - -#define KC_GESC GRAVE_ESC +#define QK_GESC QK_GRAVE_ESCAPE -#define EEP_RST EEPROM_RESET +#define QK_BOOT QK_BOOTLOADER +#define DB_TOGG QK_DEBUG_TOGGLE +#define EE_CLR QK_CLEAR_EEPROM // Audio Clicky aliases #define CK_TOGG CLICKY_TOGGLE @@ -749,6 +743,7 @@ enum quantum_keycodes { #define CL_NORM MAGIC_UNSWAP_CONTROL_CAPSLOCK #define CL_CTRL MAGIC_CAPSLOCK_TO_CONTROL #define CL_CAPS MAGIC_UNCAPSLOCK_TO_CONTROL +#define CL_TOGG MAGIC_TOGGLE_CONTROL_CAPSLOCK #define LCG_SWP MAGIC_SWAP_LCTL_LGUI #define LCG_NRM MAGIC_UNSWAP_LCTL_LGUI @@ -846,22 +841,22 @@ enum quantum_keycodes { #define CMD_T(kc) LCMD_T(kc) #define WIN_T(kc) LWIN_T(kc) -#define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc) // Left Control + Shift e.g. for gnome-terminal -#define MEH_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc) // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt -#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left Control + Alt + GUI -#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc) // Right Control + Alt + GUI -#define HYPR_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/ -#define LSG_T(kc) MT(MOD_LSFT | MOD_LGUI, kc) // Left Shift + GUI +#define C_S_T(kc) MT(MOD_LCTL | MOD_LSFT, kc) // Left Control + Shift e.g. for gnome-terminal +#define MEH_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT, kc) // Meh is a less hyper version of the Hyper key -- doesn't include GUI, so just Left Control + Shift + Alt +#define LCAG_T(kc) MT(MOD_LCTL | MOD_LALT | MOD_LGUI, kc) // Left Control + Alt + GUI +#define RCAG_T(kc) MT(MOD_RCTL | MOD_RALT | MOD_RGUI, kc) // Right Control + Alt + GUI +#define HYPR_T(kc) MT(MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/ +#define LSG_T(kc) MT(MOD_LSFT | MOD_LGUI, kc) // Left Shift + GUI #define SGUI_T(kc) LSG_T(kc) #define SCMD_T(kc) LSG_T(kc) #define SWIN_T(kc) LSG_T(kc) -#define LAG_T(kc) MT(MOD_LALT | MOD_LGUI, kc) // Left Alt + GUI -#define RSG_T(kc) MT(MOD_RSFT | MOD_RGUI, kc) // Right Shift + GUI -#define RAG_T(kc) MT(MOD_RALT | MOD_RGUI, kc) // Right Alt + GUI -#define LCA_T(kc) MT(MOD_LCTL | MOD_LALT, kc) // Left Control + Alt -#define LSA_T(kc) MT(MOD_LSFT | MOD_LALT, kc) // Left Shift + Alt -#define RSA_T(kc) MT(MOD_RSFT | MOD_RALT, kc) // Right Shift + Alt -#define RCS_T(kc) MT(MOD_RCTL | MOD_RSFT, kc) // Right Control + Shift +#define LAG_T(kc) MT(MOD_LALT | MOD_LGUI, kc) // Left Alt + GUI +#define RSG_T(kc) MT(MOD_RSFT | MOD_RGUI, kc) // Right Shift + GUI +#define RAG_T(kc) MT(MOD_RALT | MOD_RGUI, kc) // Right Alt + GUI +#define LCA_T(kc) MT(MOD_LCTL | MOD_LALT, kc) // Left Control + Alt +#define LSA_T(kc) MT(MOD_LSFT | MOD_LALT, kc) // Left Shift + Alt +#define RSA_T(kc) MT(MOD_RSFT | MOD_RALT, kc) // Right Shift + Alt +#define RCS_T(kc) MT(MOD_RCTL | MOD_RSFT, kc) // Right Control + Shift #define SAGR_T(kc) RSA_T(kc) #define ALL_T(kc) HYPR_T(kc) @@ -875,14 +870,14 @@ enum quantum_keycodes { #define UC(c) (QK_UNICODE | (c)) // UNICODEMAP_ENABLE - Allows Unicode input up to 0x10FFFF, requires unicode_map #define X(i) (QK_UNICODEMAP | (i)) -#define XP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j +#define XP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j #define UC_MOD UNICODE_MODE_FORWARD #define UC_RMOD UNICODE_MODE_REVERSE #define UC_M_MA UNICODE_MODE_MAC -#define UNICODE_MODE_OSX UNICODE_MODE_MAC // Deprecated alias -#define UC_M_OS UNICODE_MODE_MAC // Deprecated alias +#define UNICODE_MODE_OSX UNICODE_MODE_MAC // Deprecated alias +#define UC_M_OS UNICODE_MODE_MAC // Deprecated alias #define UC_M_LN UNICODE_MODE_LNX #define UC_M_WI UNICODE_MODE_WIN #define UC_M_BS UNICODE_MODE_BSD @@ -961,3 +956,5 @@ enum quantum_keycodes { #define PB_32 PROGRAMMABLE_BUTTON_32 #define PROGRAMMABLE_BUTTON_MIN PROGRAMMABLE_BUTTON_1 #define PROGRAMMABLE_BUTTON_MAX PROGRAMMABLE_BUTTON_32 + +#include "quantum_keycodes_legacy.h" diff --git a/quantum/quantum_keycodes_legacy.h b/quantum/quantum_keycodes_legacy.h new file mode 100644 index 0000000000..ed9455ee74 --- /dev/null +++ b/quantum/quantum_keycodes_legacy.h @@ -0,0 +1,13 @@ +#pragma once + +// clang-format off + +// Deprecated Quantum keycodes + +#define RESET QK_BOOTLOADER +#define DEBUG QK_DEBUG_TOGGLE +#define GRAVE_ESC QK_GRAVE_ESCAPE +#define EEPROM_RESET QK_CLEAR_EEPROM + +#define KC_GESC QK_GRAVE_ESCAPE +#define EEP_RST QK_CLEAR_EEPROM diff --git a/quantum/rgb_matrix/animations/alpha_mods_anim.h b/quantum/rgb_matrix/animations/alpha_mods_anim.h index d6136f1ba4..59b8381d69 100644 --- a/quantum/rgb_matrix/animations/alpha_mods_anim.h +++ b/quantum/rgb_matrix/animations/alpha_mods_anim.h @@ -22,5 +22,5 @@ bool ALPHAS_MODS(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_ALPHAS_MODS +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_ALPHAS_MODS diff --git a/quantum/rgb_matrix/animations/breathing_anim.h b/quantum/rgb_matrix/animations/breathing_anim.h index 29187e1543..e9a3c96e1b 100644 --- a/quantum/rgb_matrix/animations/breathing_anim.h +++ b/quantum/rgb_matrix/animations/breathing_anim.h @@ -16,5 +16,5 @@ bool BREATHING(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BREATHING +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BREATHING diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h index 0375d4937d..06aa8b5ed5 100644 --- a/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h @@ -7,7 +7,9 @@ static HSV BAND_PINWHEEL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) return hsv; } -bool BAND_PINWHEEL_SAT(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); } +bool BAND_PINWHEEL_SAT(effect_params_t* params) { + return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h index e40bf4cd1f..bcbc319498 100644 --- a/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h @@ -7,7 +7,9 @@ static HSV BAND_PINWHEEL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) return hsv; } -bool BAND_PINWHEEL_VAL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); } +bool BAND_PINWHEEL_VAL(effect_params_t* params) { + return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_sat_anim.h b/quantum/rgb_matrix/animations/colorband_sat_anim.h index 1c4f7de575..cb0897ad3e 100644 --- a/quantum/rgb_matrix/animations/colorband_sat_anim.h +++ b/quantum/rgb_matrix/animations/colorband_sat_anim.h @@ -8,7 +8,9 @@ static HSV BAND_SAT_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool BAND_SAT(effect_params_t* params) { return effect_runner_i(params, &BAND_SAT_math); } +bool BAND_SAT(effect_params_t* params) { + return effect_runner_i(params, &BAND_SAT_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_SAT +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h index cdd02b3797..d26eb37855 100644 --- a/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h +++ b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h @@ -7,7 +7,9 @@ static HSV BAND_SPIRAL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, u return hsv; } -bool BAND_SPIRAL_SAT(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); } +bool BAND_SPIRAL_SAT(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h index e1331eaebe..3ae34bb6f0 100644 --- a/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h +++ b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h @@ -7,7 +7,9 @@ static HSV BAND_SPIRAL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, u return hsv; } -bool BAND_SPIRAL_VAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); } +bool BAND_SPIRAL_VAL(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_val_anim.h b/quantum/rgb_matrix/animations/colorband_val_anim.h index 02ee4add67..69c29f53a3 100644 --- a/quantum/rgb_matrix/animations/colorband_val_anim.h +++ b/quantum/rgb_matrix/animations/colorband_val_anim.h @@ -8,7 +8,9 @@ static HSV BAND_VAL_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool BAND_VAL(effect_params_t* params) { return effect_runner_i(params, &BAND_VAL_math); } +bool BAND_VAL(effect_params_t* params) { + return effect_runner_i(params, &BAND_VAL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_BAND_VAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_BAND_VAL diff --git a/quantum/rgb_matrix/animations/cycle_all_anim.h b/quantum/rgb_matrix/animations/cycle_all_anim.h index 3b73b9d385..d8c7220d95 100644 --- a/quantum/rgb_matrix/animations/cycle_all_anim.h +++ b/quantum/rgb_matrix/animations/cycle_all_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_ALL_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool CYCLE_ALL(effect_params_t* params) { return effect_runner_i(params, &CYCLE_ALL_math); } +bool CYCLE_ALL(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_ALL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_ALL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_ALL diff --git a/quantum/rgb_matrix/animations/cycle_left_right_anim.h b/quantum/rgb_matrix/animations/cycle_left_right_anim.h index bf6a574069..84c2127aff 100644 --- a/quantum/rgb_matrix/animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix/animations/cycle_left_right_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_LEFT_RIGHT_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/cycle_out_in_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_anim.h index 2bdb9d9375..9513fe9593 100644 --- a/quantum/rgb_matrix/animations/cycle_out_in_anim.h +++ b/quantum/rgb_matrix/animations/cycle_out_in_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_OUT_IN_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint return hsv; } -bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } +bool CYCLE_OUT_IN(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_OUT_IN +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_OUT_IN diff --git a/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h index 51979c44fe..3cca45f27a 100644 --- a/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h +++ b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h @@ -9,7 +9,9 @@ static HSV CYCLE_OUT_IN_DUAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) return hsv; } -bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); } +bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { + return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL diff --git a/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h index 10ba2b7c2c..de5993992c 100644 --- a/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h +++ b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_PINWHEEL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { return hsv; } -bool CYCLE_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); } +bool CYCLE_PINWHEEL(effect_params_t* params) { + return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_PINWHEEL diff --git a/quantum/rgb_matrix/animations/cycle_spiral_anim.h b/quantum/rgb_matrix/animations/cycle_spiral_anim.h index 482c7e7da6..904450179e 100644 --- a/quantum/rgb_matrix/animations/cycle_spiral_anim.h +++ b/quantum/rgb_matrix/animations/cycle_spiral_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_SPIRAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint return hsv; } -bool CYCLE_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); } +bool CYCLE_SPIRAL(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_SPIRAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_SPIRAL diff --git a/quantum/rgb_matrix/animations/cycle_up_down_anim.h b/quantum/rgb_matrix/animations/cycle_up_down_anim.h index 277edccb2f..dce05fecff 100644 --- a/quantum/rgb_matrix/animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix/animations/cycle_up_down_anim.h @@ -7,7 +7,9 @@ static HSV CYCLE_UP_DOWN_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } +bool CYCLE_UP_DOWN(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_UP_DOWN_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h index 8ce8fd7039..4633145ff6 100644 --- a/quantum/rgb_matrix/animations/digital_rain_anim.h +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -71,5 +71,5 @@ bool DIGITAL_RAIN(effect_params_t* params) { return false; } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(ENABLE_RGB_MATRIX_DIGITAL_RAIN) diff --git a/quantum/rgb_matrix/animations/dual_beacon_anim.h b/quantum/rgb_matrix/animations/dual_beacon_anim.h index dbe9b3ecf1..5585015b86 100644 --- a/quantum/rgb_matrix/animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix/animations/dual_beacon_anim.h @@ -7,7 +7,9 @@ static HSV DUAL_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t return hsv; } -bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } +bool DUAL_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_DUAL_BEACON +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_DUAL_BEACON diff --git a/quantum/rgb_matrix/animations/gradient_left_right_anim.h b/quantum/rgb_matrix/animations/gradient_left_right_anim.h index 8bb5e570bd..ebb06f59f2 100644 --- a/quantum/rgb_matrix/animations/gradient_left_right_anim.h +++ b/quantum/rgb_matrix/animations/gradient_left_right_anim.h @@ -18,5 +18,5 @@ bool GRADIENT_LEFT_RIGHT(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/gradient_up_down_anim.h b/quantum/rgb_matrix/animations/gradient_up_down_anim.h index a5674583e3..febc3919a8 100644 --- a/quantum/rgb_matrix/animations/gradient_up_down_anim.h +++ b/quantum/rgb_matrix/animations/gradient_up_down_anim.h @@ -18,5 +18,5 @@ bool GRADIENT_UP_DOWN(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN diff --git a/quantum/rgb_matrix/animations/hue_breathing_anim.h b/quantum/rgb_matrix/animations/hue_breathing_anim.h index 82be1a4424..8537762832 100644 --- a/quantum/rgb_matrix/animations/hue_breathing_anim.h +++ b/quantum/rgb_matrix/animations/hue_breathing_anim.h @@ -18,5 +18,5 @@ bool HUE_BREATHING(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_BREATHING +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_BREATHING diff --git a/quantum/rgb_matrix/animations/hue_pendulum_anim.h b/quantum/rgb_matrix/animations/hue_pendulum_anim.h index a6e1c1074d..7d8cbcdfb2 100644 --- a/quantum/rgb_matrix/animations/hue_pendulum_anim.h +++ b/quantum/rgb_matrix/animations/hue_pendulum_anim.h @@ -11,7 +11,9 @@ static HSV HUE_PENDULUM_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool HUE_PENDULUM(effect_params_t* params) { return effect_runner_i(params, &HUE_PENDULUM_math); } +bool HUE_PENDULUM(effect_params_t* params) { + return effect_runner_i(params, &HUE_PENDULUM_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_PENDULUM +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_PENDULUM diff --git a/quantum/rgb_matrix/animations/hue_wave_anim.h b/quantum/rgb_matrix/animations/hue_wave_anim.h index b1c72b7336..81aa7e139e 100644 --- a/quantum/rgb_matrix/animations/hue_wave_anim.h +++ b/quantum/rgb_matrix/animations/hue_wave_anim.h @@ -11,7 +11,9 @@ static HSV HUE_WAVE_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool HUE_WAVE(effect_params_t* params) { return effect_runner_i(params, &HUE_WAVE_math); } +bool HUE_WAVE(effect_params_t* params) { + return effect_runner_i(params, &HUE_WAVE_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_WAVE +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_WAVE diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h index 3ffb57eb35..31dffcbc5a 100644 --- a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -25,5 +25,5 @@ bool JELLYBEAN_RAINDROPS(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS diff --git a/quantum/rgb_matrix/animations/pixel_flow_anim.h b/quantum/rgb_matrix/animations/pixel_flow_anim.h new file mode 100644 index 0000000000..714f5d174e --- /dev/null +++ b/quantum/rgb_matrix/animations/pixel_flow_anim.h @@ -0,0 +1,51 @@ +// Copyright 2022 @filterpaper +// SPDX-License-Identifier: GPL-2.0+ + +#ifdef ENABLE_RGB_MATRIX_PIXEL_FLOW +RGB_MATRIX_EFFECT(PIXEL_FLOW) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static bool PIXEL_FLOW(effect_params_t* params) { + // LED state array + static RGB led[DRIVER_LED_TOTAL]; + + static uint32_t wait_timer = 0; + if (wait_timer > g_rgb_timer) { + return false; + } + + inline uint32_t interval(void) { + return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); + } + + if (params->init) { + // Clear LEDs and fill the state array + rgb_matrix_set_color_all(0, 0, 0); + for (uint8_t j = 0; j < DRIVER_LED_TOTAL; ++j) { + led[j] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), qadd8(random8() >> 1, 127), rgb_matrix_config.hsv.v}); + } + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + // Light LEDs based on state array + for (uint8_t i = led_min; i < led_max; ++i) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, led[i].r, led[i].g, led[i].b); + } + + if (!rgb_matrix_check_finished_leds(led_max)) { + // Shift LED state forward + for (uint8_t j = 0; j < led_max - 1; ++j) { + led[j] = led[j + 1]; + } + // Fill last LED + led[led_max - 1] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), qadd8(random8() >> 1, 127), rgb_matrix_config.hsv.v}); + // Set pulse timer + wait_timer = g_rgb_timer + interval(); + } + + return rgb_matrix_check_finished_leds(led_max); +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_PIXEL_FLOW diff --git a/quantum/rgb_matrix/animations/pixel_fractal_anim.h b/quantum/rgb_matrix/animations/pixel_fractal_anim.h index 8e25ec402c..906da1a48e 100644 --- a/quantum/rgb_matrix/animations/pixel_fractal_anim.h +++ b/quantum/rgb_matrix/animations/pixel_fractal_anim.h @@ -29,11 +29,17 @@ static bool PIXEL_FRACTAL(effect_params_t* params) { return false; } - inline uint32_t interval(void) { return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); } + inline uint32_t interval(void) { + return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); + } + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + } RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv); for (uint8_t h = 0; h < MATRIX_ROWS; ++h) { - for (uint8_t l = 0; l < MID_COL - 1; ++l) { // Light and move left columns outwards + for (uint8_t l = 0; l < MID_COL - 1; ++l) { // Light and move left columns outwards if (led[h][l]) { rgb_matrix_set_color(g_led_config.matrix_co[h][l], rgb.r, rgb.g, rgb.b); } else { @@ -42,7 +48,7 @@ static bool PIXEL_FRACTAL(effect_params_t* params) { led[h][l] = led[h][l + 1]; } - for (uint8_t r = MATRIX_COLS - 1; r > MID_COL; --r) { // Light and move right columns outwards + for (uint8_t r = MATRIX_COLS - 1; r > MID_COL; --r) { // Light and move right columns outwards if (led[h][r]) { rgb_matrix_set_color(g_led_config.matrix_co[h][r], rgb.r, rgb.g, rgb.b); } else { @@ -70,5 +76,5 @@ static bool PIXEL_FRACTAL(effect_params_t* params) { wait_timer = g_rgb_timer + interval(); return false; } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_PIXEL_FRACTAL +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_PIXEL_FRACTAL diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h index 001649aa6e..03488b43df 100644 --- a/quantum/rgb_matrix/animations/pixel_rain_anim.h +++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h @@ -24,7 +24,9 @@ static bool PIXEL_RAIN(effect_params_t* params) { return false; } - inline uint32_t interval(void) { return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); } + inline uint32_t interval(void) { + return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); + } bool rain_pixel(uint8_t i, effect_params_t * params, bool off) { if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) { @@ -44,5 +46,5 @@ static bool PIXEL_RAIN(effect_params_t* params) { return rain_pixel(mod8(random8(), DRIVER_LED_TOTAL), params, random8() & 2); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_PIXEL_RAIN +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_PIXEL_RAIN diff --git a/quantum/rgb_matrix/animations/rainbow_beacon_anim.h b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h index cd529958db..bdcca5530f 100644 --- a/quantum/rgb_matrix/animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h @@ -7,7 +7,9 @@ static HSV RAINBOW_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8 return hsv; } -bool RAINBOW_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } +bool RAINBOW_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_RAINBOW_BEACON +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_RAINBOW_BEACON diff --git a/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h index 2f3de64e9d..f7b8f6c2f3 100644 --- a/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h @@ -7,7 +7,9 @@ static HSV RAINBOW_MOVING_CHEVRON_math(HSV hsv, uint8_t i, uint8_t time) { return hsv; } -bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } +bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { + return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON diff --git a/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h index dae2b5d190..91e31ea8cc 100644 --- a/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h @@ -7,7 +7,9 @@ static HSV RAINBOW_PINWHEELS_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, ui return hsv; } -bool RAINBOW_PINWHEELS(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_PINWHEELS_math); } +bool RAINBOW_PINWHEELS(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &RAINBOW_PINWHEELS_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h index 4b1b9dd9ec..2d4b53b7b0 100644 --- a/quantum/rgb_matrix/animations/raindrops_anim.h +++ b/quantum/rgb_matrix/animations/raindrops_anim.h @@ -35,5 +35,5 @@ bool RAINDROPS(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // ENABLE_RGB_MATRIX_RAINDROPS +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // ENABLE_RGB_MATRIX_RAINDROPS diff --git a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc index 27ce347235..ac7bac428d 100644 --- a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc +++ b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc @@ -27,6 +27,7 @@ #include "hue_pendulum_anim.h" #include "hue_wave_anim.h" #include "pixel_rain_anim.h" +#include "pixel_flow_anim.h" #include "pixel_fractal_anim.h" #include "typing_heatmap_anim.h" #include "digital_rain_anim.h" diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h index d5c1a26cef..f9584d7071 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h @@ -26,4 +26,4 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { return rgb_matrix_check_finished_leds(led_max); } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h index d3a6e4e72f..41020eb47f 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h @@ -26,4 +26,4 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react return rgb_matrix_check_finished_leds(led_max); } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_color_anim.h b/quantum/rgb_matrix/animations/solid_color_anim.h index 4209959468..c8762dcbc2 100644 --- a/quantum/rgb_matrix/animations/solid_color_anim.h +++ b/quantum/rgb_matrix/animations/solid_color_anim.h @@ -12,4 +12,4 @@ bool SOLID_COLOR(effect_params_t* params) { return rgb_matrix_check_finished_leds(led_max); } -#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix/animations/solid_reactive_anim.h b/quantum/rgb_matrix/animations/solid_reactive_anim.h index 360d05a67a..d3a7ebbdf7 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix/animations/solid_reactive_anim.h @@ -8,8 +8,10 @@ static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) { return hsv; } -bool SOLID_REACTIVE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_math); } +bool SOLID_REACTIVE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // ENABLE_RGB_MATRIX_SOLID_REACTIVE -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // ENABLE_RGB_MATRIX_SOLID_REACTIVE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_cross.h b/quantum/rgb_matrix/animations/solid_reactive_cross.h index 496651f8a5..043a369b73 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix/animations/solid_reactive_cross.h @@ -24,13 +24,17 @@ static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di } # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); +} # endif # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } +bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); +} # endif -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_nexus.h b/quantum/rgb_matrix/animations/solid_reactive_nexus.h index 3562e74a72..8d62a49fea 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix/animations/solid_reactive_nexus.h @@ -22,13 +22,17 @@ static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di } # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); +} # endif # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } +bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); +} # endif -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h index 69189f636b..0d0a424cf3 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h @@ -8,8 +8,10 @@ static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) { return hsv; } -bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); +} -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_wide.h b/quantum/rgb_matrix/animations/solid_reactive_wide.h index a613c7ff5f..7598796316 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix/animations/solid_reactive_wide.h @@ -19,13 +19,17 @@ static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dis } # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); +} # endif # ifdef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } +bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); +} # endif -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_splash_anim.h b/quantum/rgb_matrix/animations/solid_splash_anim.h index bd9c1cfe2b..77d6f8c5eb 100644 --- a/quantum/rgb_matrix/animations/solid_splash_anim.h +++ b/quantum/rgb_matrix/animations/solid_splash_anim.h @@ -19,13 +19,17 @@ HSV SOLID_SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t ti } # ifdef ENABLE_RGB_MATRIX_SOLID_SPLASH -bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } +bool SOLID_SPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); +} # endif # ifdef ENABLE_RGB_MATRIX_SOLID_MULTISPLASH -bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } +bool SOLID_MULTISPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); +} # endif -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(ENABLE_RGB_MATRIX_SPLASH) && !defined(ENABLE_RGB_MATRIX_MULTISPLASH) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(ENABLE_RGB_MATRIX_SPLASH) && !defined(ENABLE_RGB_MATRIX_MULTISPLASH) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/splash_anim.h b/quantum/rgb_matrix/animations/splash_anim.h index 382355e9ed..06459e1b0a 100644 --- a/quantum/rgb_matrix/animations/splash_anim.h +++ b/quantum/rgb_matrix/animations/splash_anim.h @@ -20,13 +20,17 @@ HSV SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { } # ifdef ENABLE_RGB_MATRIX_SPLASH -bool SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); } +bool SPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); +} # endif # ifdef ENABLE_RGB_MATRIX_MULTISPLASH -bool MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SPLASH_math); } +bool MULTISPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SPLASH_math); +} # endif -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(ENABLE_RGB_MATRIX_SPLASH) || !defined(ENABLE_RGB_MATRIX_MULTISPLASH) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(ENABLE_RGB_MATRIX_SPLASH) || !defined(ENABLE_RGB_MATRIX_MULTISPLASH) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h index b66667b9b8..f3a94280c0 100644 --- a/quantum/rgb_matrix/animations/typing_heatmap_anim.h +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -82,5 +82,5 @@ bool TYPING_HEATMAP(effect_params_t* params) { return led_max < sizeof(g_rgb_frame_buffer); } -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 51e9554e2d..f721dfc7f2 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -31,7 +31,9 @@ const led_point_t k_rgb_matrix_center = {112, 32}; const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; #endif -__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } +__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { + return hsv_to_rgb(hsv); +} // Generic effect runners #include "rgb_matrix_runners.inc" @@ -109,14 +111,14 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv #endif // globals -rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr +rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_rgb_timer; #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; -#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS +#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED last_hit_t g_last_hit_tracker; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED // internals static bool suspend_state = false; @@ -126,13 +128,13 @@ static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; static rgb_task_states rgb_task_state = SYNCING; #if RGB_DISABLE_TIMEOUT > 0 static uint32_t rgb_anykey_timer; -#endif // RGB_DISABLE_TIMEOUT > 0 +#endif // RGB_DISABLE_TIMEOUT > 0 // double buffers static uint32_t rgb_timer_buffer; #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED static last_hit_t last_hit_buffer; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED // split rgb matrix #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) @@ -141,7 +143,9 @@ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config); -void eeconfig_update_rgb_matrix(void) { eeconfig_flush_rgb_matrix(true); } +void eeconfig_update_rgb_matrix(void) { + eeconfig_flush_rgb_matrix(true); +} void eeconfig_update_rgb_matrix_default(void) { dprintf("eeconfig_update_rgb_matrix_default\n"); @@ -164,7 +168,19 @@ void eeconfig_debug_rgb_matrix(void) { dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags); } -__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } +void rgb_matrix_reload_from_eeprom(void) { + rgb_matrix_disable_noeeprom(); + /* Reset back to what we have in eeprom */ + eeconfig_init_rgb_matrix(); + eeconfig_debug_rgb_matrix(); // display current eeprom values + if (rgb_matrix_config.enable) { + rgb_matrix_mode_noeeprom(rgb_matrix_config.mode); + } +} + +__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { + return 0; +} uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); @@ -176,13 +192,18 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l return led_count; } -void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } +void rgb_matrix_update_pwm_buffers(void) { + rgb_matrix_driver.flush(); +} -void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); } +void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + rgb_matrix_driver.set_color(index, red, green, blue); +} void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) rgb_matrix_set_color(i, red, green, blue); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) + rgb_matrix_set_color(i, red, green, blue); #else rgb_matrix_driver.set_color_all(red, green, blue); #endif @@ -194,7 +215,7 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { #endif #if RGB_DISABLE_TIMEOUT > 0 rgb_anykey_timer = 0; -#endif // RGB_DISABLE_TIMEOUT > 0 +#endif // RGB_DISABLE_TIMEOUT > 0 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED uint8_t led[LED_HITS_TO_REMEMBER]; @@ -204,7 +225,7 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { if (!pressed) # elif defined(RGB_MATRIX_KEYPRESSES) if (pressed) -# endif // defined(RGB_MATRIX_KEYRELEASES) +# endif // defined(RGB_MATRIX_KEYRELEASES) { led_count = rgb_matrix_map_row_column_to_led(row, col, led); } @@ -212,7 +233,7 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit + memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); last_hit_buffer.count = LED_HITS_TO_REMEMBER - led_count; } @@ -225,13 +246,13 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { last_hit_buffer.tick[index] = 0; last_hit_buffer.count++; } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) { process_rgb_matrix_typing_heatmap(row, col); } -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP) } void rgb_matrix_test(void) { @@ -270,7 +291,7 @@ static bool rgb_matrix_none(effect_params_t *params) { static void rgb_task_timers(void) { #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer); -#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 +#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 rgb_timer_buffer = sync_timer_read32(); // Update double buffer timers @@ -278,7 +299,7 @@ static void rgb_task_timers(void) { if (rgb_anykey_timer + deltaTime <= UINT32_MAX) { rgb_anykey_timer += deltaTime; } -#endif // RGB_DISABLE_TIMEOUT > 0 +#endif // RGB_DISABLE_TIMEOUT > 0 // Update double buffer last hit timers #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED @@ -290,7 +311,7 @@ static void rgb_task_timers(void) { } last_hit_buffer.tick[i] += deltaTime; } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED } static void rgb_task_sync(void) { @@ -307,7 +328,7 @@ static void rgb_task_start(void) { g_rgb_timer = rgb_timer_buffer; #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED g_last_hit_tracker = last_hit_buffer; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED // next task rgb_task_state = RENDERING; @@ -393,7 +414,7 @@ void rgb_matrix_task(void) { bool suspend_backlight = suspend_state || #if RGB_DISABLE_TIMEOUT > 0 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || -#endif // RGB_DISABLE_TIMEOUT > 0 +#endif // RGB_DISABLE_TIMEOUT > 0 false; uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; @@ -462,7 +483,7 @@ void rgb_matrix_init(void) { for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { last_hit_buffer.tick[i] = UINT16_MAX; } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED if (!eeconfig_is_enabled()) { dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); @@ -475,20 +496,22 @@ void rgb_matrix_init(void) { dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_rgb_matrix_default(); } - eeconfig_debug_rgb_matrix(); // display current eeprom values + eeconfig_debug_rgb_matrix(); // display current eeprom values } void rgb_matrix_set_suspend_state(bool state) { #ifdef RGB_DISABLE_WHEN_USB_SUSPENDED - if (state && !suspend_state) { // only run if turning off, and only once - rgb_task_render(0); // turn off all LEDs when suspending - rgb_task_flush(0); // and actually flash led state to LEDs + if (state && !suspend_state) { // only run if turning off, and only once + rgb_task_render(0); // turn off all LEDs when suspending + rgb_task_flush(0); // and actually flash led state to LEDs } suspend_state = state; #endif } -bool rgb_matrix_get_suspend_state(void) { return suspend_state; } +bool rgb_matrix_get_suspend_state(void) { + return suspend_state; +} void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { rgb_matrix_config.enable ^= 1; @@ -496,8 +519,12 @@ void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { eeconfig_flag_rgb_matrix(write_to_eeprom); dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); } -void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } -void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } +void rgb_matrix_toggle_noeeprom(void) { + rgb_matrix_toggle_eeprom_helper(false); +} +void rgb_matrix_toggle(void) { + rgb_matrix_toggle_eeprom_helper(true); +} void rgb_matrix_enable(void) { rgb_matrix_enable_noeeprom(); @@ -519,7 +546,9 @@ void rgb_matrix_disable_noeeprom(void) { rgb_matrix_config.enable = 0; } -uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } +uint8_t rgb_matrix_is_enabled(void) { + return rgb_matrix_config.enable; +} void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!rgb_matrix_config.enable) { @@ -536,24 +565,38 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { eeconfig_flag_rgb_matrix(write_to_eeprom); dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); } -void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } -void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } +void rgb_matrix_mode_noeeprom(uint8_t mode) { + rgb_matrix_mode_eeprom_helper(mode, false); +} +void rgb_matrix_mode(uint8_t mode) { + rgb_matrix_mode_eeprom_helper(mode, true); +} -uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } +uint8_t rgb_matrix_get_mode(void) { + return rgb_matrix_config.mode; +} void rgb_matrix_step_helper(bool write_to_eeprom) { uint8_t mode = rgb_matrix_config.mode + 1; rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); } -void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } -void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } +void rgb_matrix_step_noeeprom(void) { + rgb_matrix_step_helper(false); +} +void rgb_matrix_step(void) { + rgb_matrix_step_helper(true); +} void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { uint8_t mode = rgb_matrix_config.mode - 1; rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); } -void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } -void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } +void rgb_matrix_step_reverse_noeeprom(void) { + rgb_matrix_step_reverse_helper(false); +} +void rgb_matrix_step_reverse(void) { + rgb_matrix_step_reverse_helper(true); +} void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { if (!rgb_matrix_config.enable) { @@ -565,56 +608,126 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo eeconfig_flag_rgb_matrix(write_to_eeprom); dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v); } -void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } -void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } +void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { + rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); +} +void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { + rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); +} -HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } -uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } -uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } -uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } +HSV rgb_matrix_get_hsv(void) { + return rgb_matrix_config.hsv; +} +uint8_t rgb_matrix_get_hue(void) { + return rgb_matrix_config.hsv.h; +} +uint8_t rgb_matrix_get_sat(void) { + return rgb_matrix_config.hsv.s; +} +uint8_t rgb_matrix_get_val(void) { + return rgb_matrix_config.hsv.v; +} -void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } -void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } +void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); +} +void rgb_matrix_increase_hue_noeeprom(void) { + rgb_matrix_increase_hue_helper(false); +} +void rgb_matrix_increase_hue(void) { + rgb_matrix_increase_hue_helper(true); +} -void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } -void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } +void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); +} +void rgb_matrix_decrease_hue_noeeprom(void) { + rgb_matrix_decrease_hue_helper(false); +} +void rgb_matrix_decrease_hue(void) { + rgb_matrix_decrease_hue_helper(true); +} -void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } -void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } +void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); +} +void rgb_matrix_increase_sat_noeeprom(void) { + rgb_matrix_increase_sat_helper(false); +} +void rgb_matrix_increase_sat(void) { + rgb_matrix_increase_sat_helper(true); +} -void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } -void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } +void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); +} +void rgb_matrix_decrease_sat_noeeprom(void) { + rgb_matrix_decrease_sat_helper(false); +} +void rgb_matrix_decrease_sat(void) { + rgb_matrix_decrease_sat_helper(true); +} -void rgb_matrix_increase_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } -void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } -void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } +void rgb_matrix_increase_val_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); +} +void rgb_matrix_increase_val_noeeprom(void) { + rgb_matrix_increase_val_helper(false); +} +void rgb_matrix_increase_val(void) { + rgb_matrix_increase_val_helper(true); +} -void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } -void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } -void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } +void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { + rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); +} +void rgb_matrix_decrease_val_noeeprom(void) { + rgb_matrix_decrease_val_helper(false); +} +void rgb_matrix_decrease_val(void) { + rgb_matrix_decrease_val_helper(true); +} void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { rgb_matrix_config.speed = speed; eeconfig_flag_rgb_matrix(write_to_eeprom); dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); } -void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } -void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } +void rgb_matrix_set_speed_noeeprom(uint8_t speed) { + rgb_matrix_set_speed_eeprom_helper(speed, false); +} +void rgb_matrix_set_speed(uint8_t speed) { + rgb_matrix_set_speed_eeprom_helper(speed, true); +} -uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } +uint8_t rgb_matrix_get_speed(void) { + return rgb_matrix_config.speed; +} -void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } -void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } -void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } +void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { + rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); +} +void rgb_matrix_increase_speed_noeeprom(void) { + rgb_matrix_increase_speed_helper(false); +} +void rgb_matrix_increase_speed(void) { + rgb_matrix_increase_speed_helper(true); +} -void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } -void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } -void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } +void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { + rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); +} +void rgb_matrix_decrease_speed_noeeprom(void) { + rgb_matrix_decrease_speed_helper(false); +} +void rgb_matrix_decrease_speed(void) { + rgb_matrix_decrease_speed_helper(true); +} -led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; } +led_flags_t rgb_matrix_get_flags(void) { + return rgb_matrix_config.flags; +} -void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } +void rgb_matrix_set_flags(led_flags_t flags) { + rgb_matrix_config.flags = flags; +} diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index a804d99abc..359d507a4d 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -32,6 +32,8 @@ # include "is31fl3737.h" #elif defined(IS31FL3741) # include "is31fl3741.h" +#elif defined(IS31FLCOMMON) +# include "is31flcommon.h" #elif defined(CKLED2001) # include "ckled2001.h" #elif defined(AW20216) @@ -136,6 +138,8 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); void rgb_matrix_init(void); +void rgb_matrix_reload_from_eeprom(void); + void rgb_matrix_set_suspend_state(bool state); bool rgb_matrix_get_suspend_state(void); void rgb_matrix_toggle(void); @@ -182,6 +186,7 @@ void rgb_matrix_set_flags(led_flags_t flags); #ifndef RGBLIGHT_ENABLE # define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix +# define rgblight_reload_from_eeprom rgb_matrix_reload_from_eeprom # define rgblight_toggle rgb_matrix_toggle # define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom # define rgblight_enable rgb_matrix_enable diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 130ca47a63..27fa7369bf 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -23,7 +23,7 @@ * be here if shared between boards. */ -#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741) || defined(CKLED2001) +#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741) || defined(IS31FLCOMMON) || defined(CKLED2001) # include "i2c_master.h" // TODO: Remove this at some later date @@ -81,6 +81,18 @@ static void init(void) { # elif defined(IS31FL3741) IS31FL3741_init(DRIVER_ADDR_1); +# elif defined(IS31FLCOMMON) + IS31FL_common_init(DRIVER_ADDR_1, ISSI_SSR_1); +# if defined(DRIVER_ADDR_2) + IS31FL_common_init(DRIVER_ADDR_2, ISSI_SSR_2); +# if defined(DRIVER_ADDR_3) + IS31FL_common_init(DRIVER_ADDR_3, ISSI_SSR_3); +# if defined(DRIVER_ADDR_4) + IS31FL_common_init(DRIVER_ADDR_4, ISSI_SSR_4); +# endif +# endif +# endif + # elif defined(CKLED2001) CKLED2001_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) @@ -106,6 +118,8 @@ static void init(void) { IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); # elif defined(IS31FL3741) IS31FL3741_set_led_control_register(index, enabled, enabled, enabled); +# elif defined(IS31FLCOMMON) + IS31FL_RGB_set_scaling_buffer(index, enabled, enabled, enabled); # elif defined(CKLED2001) CKLED2001_set_led_control_register(index, enabled, enabled, enabled); # endif @@ -145,6 +159,21 @@ static void init(void) { # elif defined(IS31FL3741) IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0); +# elif defined(IS31FLCOMMON) +# ifdef ISSI_MANUAL_SCALING + IS31FL_set_manual_scaling_buffer(); +# endif + IS31FL_common_update_scaling_register(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + IS31FL_common_update_scaling_register(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + IS31FL_common_update_scaling_register(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + IS31FL_common_update_scaling_register(DRIVER_ADDR_4, 3); +# endif +# endif +# endif + # elif defined(CKLED2001) CKLED2001_update_led_control_registers(DRIVER_ADDR_1, 0); # if defined(DRIVER_ADDR_2) @@ -231,6 +260,27 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .set_color_all = IS31FL3741_set_color_all, }; +# elif defined(IS31FLCOMMON) +static void flush(void) { + IS31FL_common_update_pwm_register(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + IS31FL_common_update_pwm_register(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + IS31FL_common_update_pwm_register(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + IS31FL_common_update_pwm_register(DRIVER_ADDR_4, 3); +# endif +# endif +# endif +} + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = IS31FL_RGB_set_color, + .set_color_all = IS31FL_RGB_set_color_all, +}; + # elif defined(CKLED2001) static void flush(void) { CKLED2001_update_pwm_buffers(DRIVER_ADDR_1, 0); @@ -299,10 +349,15 @@ static void flush(void) { static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; - if (!is_keyboard_left() && (i >= k_rgb_matrix_split[0])) { - i -= k_rgb_matrix_split[0]; - } else if (is_keyboard_left() && (i >= k_rgb_matrix_split[0])) + if (!is_keyboard_left()) { + if (i >= k_rgb_matrix_split[0]) { + i -= k_rgb_matrix_split[0]; + } else { + return; + } + } else if (i >= k_rgb_matrix_split[0]) { return; + } # endif rgb_matrix_ws2812_array[i].r = r; diff --git a/quantum/rgb_matrix/rgb_matrix_types.h b/quantum/rgb_matrix/rgb_matrix_types.h index df575d6577..d0ac4e4466 100644 --- a/quantum/rgb_matrix/rgb_matrix_types.h +++ b/quantum/rgb_matrix/rgb_matrix_types.h @@ -37,7 +37,7 @@ // Last led hit #ifndef LED_HITS_TO_REMEMBER # define LED_HITS_TO_REMEMBER 8 -#endif // LED_HITS_TO_REMEMBER +#endif // LED_HITS_TO_REMEMBER #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED typedef struct PACKED { @@ -47,7 +47,7 @@ typedef struct PACKED { uint8_t index[LED_HITS_TO_REMEMBER]; uint16_t tick[LED_HITS_TO_REMEMBER]; } last_hit_t; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED typedef enum rgb_task_states { STARTING, RENDERING, FLUSHING, SYNCING } rgb_task_states; @@ -88,7 +88,7 @@ typedef union { uint8_t enable : 2; uint8_t mode : 6; HSV hsv; - uint8_t speed; // EECONFIG needs to be increased to support this + uint8_t speed; // EECONFIG needs to be increased to support this led_flags_t flags; }; } rgb_config_t; diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 148dae78f4..8f933a6e51 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -72,7 +72,7 @@ static uint8_t static_effect_table[] = { #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##msym, #define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##msym, static uint8_t mode_base_table[] = { - 0, // RGBLIGHT_MODE_zero + 0, // RGBLIGHT_MODE_zero #include "rgblight_modes.h" }; @@ -96,7 +96,9 @@ static uint8_t mode_base_table[] = { # define RGBLIGHT_DEFAULT_SPD 0 #endif -static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; } +static inline int is_static_effect(uint8_t mode) { + return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; +} #ifdef RGBLIGHT_LED_MAP const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; @@ -143,7 +145,9 @@ void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { rgblight_ranges.effect_num_leds = num_leds; } -__attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } +__attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) { + return hsv_to_rgb(hsv); +} void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { HSV hsv = {hue, sat, val}; @@ -151,7 +155,9 @@ void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { setrgb(rgb.r, rgb.g, rgb.b, led1); } -void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); } +void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { + sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); +} void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { led1->r = r; @@ -191,7 +197,9 @@ void eeconfig_update_rgblight(uint32_t val) { #endif } -void eeconfig_update_rgblight_current(void) { eeconfig_update_rgblight(rgblight_config.raw); } +void eeconfig_update_rgblight_current(void) { + eeconfig_update_rgblight(rgblight_config.raw); +} void eeconfig_update_rgblight_default(void) { rgblight_config.enable = 1; @@ -238,9 +246,9 @@ void rgblight_init(void) { } rgblight_check_config(); - eeconfig_debug_rgblight(); // display current eeprom values + eeconfig_debug_rgblight(); // display current eeprom values - rgblight_timer_init(); // setup the timer + rgblight_timer_init(); // setup the timer if (rgblight_config.enable) { rgblight_mode_noeeprom(rgblight_config.mode); @@ -254,13 +262,15 @@ void rgblight_reload_from_eeprom(void) { rgblight_config.raw = eeconfig_read_rgblight(); RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; rgblight_check_config(); - eeconfig_debug_rgblight(); // display current eeprom values + eeconfig_debug_rgblight(); // display current eeprom values if (rgblight_config.enable) { rgblight_mode_noeeprom(rgblight_config.mode); } } -uint32_t rgblight_read_dword(void) { return rgblight_config.raw; } +uint32_t rgblight_read_dword(void) { + return rgblight_config.raw; +} void rgblight_update_dword(uint32_t dword) { RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; @@ -296,8 +306,12 @@ void rgblight_step_helper(bool write_to_eeprom) { } rgblight_mode_eeprom_helper(mode, write_to_eeprom); } -void rgblight_step_noeeprom(void) { rgblight_step_helper(false); } -void rgblight_step(void) { rgblight_step_helper(true); } +void rgblight_step_noeeprom(void) { + rgblight_step_helper(false); +} +void rgblight_step(void) { + rgblight_step_helper(true); +} void rgblight_step_reverse_helper(bool write_to_eeprom) { uint8_t mode = 0; mode = rgblight_config.mode - 1; @@ -306,8 +320,12 @@ void rgblight_step_reverse_helper(bool write_to_eeprom) { } rgblight_mode_eeprom_helper(mode, write_to_eeprom); } -void rgblight_step_reverse_noeeprom(void) { rgblight_step_reverse_helper(false); } -void rgblight_step_reverse(void) { rgblight_step_reverse_helper(true); } +void rgblight_step_reverse_noeeprom(void) { + rgblight_step_reverse_helper(false); +} +void rgblight_step_reverse(void) { + rgblight_step_reverse_helper(true); +} uint8_t rgblight_get_mode(void) { if (!rgblight_config.enable) { @@ -346,9 +364,13 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } -void rgblight_mode(uint8_t mode) { rgblight_mode_eeprom_helper(mode, true); } +void rgblight_mode(uint8_t mode) { + rgblight_mode_eeprom_helper(mode, true); +} -void rgblight_mode_noeeprom(uint8_t mode) { rgblight_mode_eeprom_helper(mode, false); } +void rgblight_mode_noeeprom(uint8_t mode) { + rgblight_mode_eeprom_helper(mode, false); +} void rgblight_toggle(void) { dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); @@ -401,64 +423,98 @@ void rgblight_disable_noeeprom(void) { rgblight_set(); } -bool rgblight_is_enabled(void) { return rgblight_config.enable; } +bool rgblight_is_enabled(void) { + return rgblight_config.enable; +} void rgblight_increase_hue_helper(bool write_to_eeprom) { uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } -void rgblight_increase_hue_noeeprom(void) { rgblight_increase_hue_helper(false); } -void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); } +void rgblight_increase_hue_noeeprom(void) { + rgblight_increase_hue_helper(false); +} +void rgblight_increase_hue(void) { + rgblight_increase_hue_helper(true); +} void rgblight_decrease_hue_helper(bool write_to_eeprom) { uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } -void rgblight_decrease_hue_noeeprom(void) { rgblight_decrease_hue_helper(false); } -void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); } +void rgblight_decrease_hue_noeeprom(void) { + rgblight_decrease_hue_helper(false); +} +void rgblight_decrease_hue(void) { + rgblight_decrease_hue_helper(true); +} void rgblight_increase_sat_helper(bool write_to_eeprom) { uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } -void rgblight_increase_sat_noeeprom(void) { rgblight_increase_sat_helper(false); } -void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); } +void rgblight_increase_sat_noeeprom(void) { + rgblight_increase_sat_helper(false); +} +void rgblight_increase_sat(void) { + rgblight_increase_sat_helper(true); +} void rgblight_decrease_sat_helper(bool write_to_eeprom) { uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } -void rgblight_decrease_sat_noeeprom(void) { rgblight_decrease_sat_helper(false); } -void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); } +void rgblight_decrease_sat_noeeprom(void) { + rgblight_decrease_sat_helper(false); +} +void rgblight_decrease_sat(void) { + rgblight_decrease_sat_helper(true); +} void rgblight_increase_val_helper(bool write_to_eeprom) { uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } -void rgblight_increase_val_noeeprom(void) { rgblight_increase_val_helper(false); } -void rgblight_increase_val(void) { rgblight_increase_val_helper(true); } +void rgblight_increase_val_noeeprom(void) { + rgblight_increase_val_helper(false); +} +void rgblight_increase_val(void) { + rgblight_increase_val_helper(true); +} void rgblight_decrease_val_helper(bool write_to_eeprom) { uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } -void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); } -void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } +void rgblight_decrease_val_noeeprom(void) { + rgblight_decrease_val_helper(false); +} +void rgblight_decrease_val(void) { + rgblight_decrease_val_helper(true); +} void rgblight_increase_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed < 3) rgblight_config.speed++; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this } } -void rgblight_increase_speed(void) { rgblight_increase_speed_helper(true); } -void rgblight_increase_speed_noeeprom(void) { rgblight_increase_speed_helper(false); } +void rgblight_increase_speed(void) { + rgblight_increase_speed_helper(true); +} +void rgblight_increase_speed_noeeprom(void) { + rgblight_increase_speed_helper(false); +} void rgblight_decrease_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed > 0) rgblight_config.speed--; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this } } -void rgblight_decrease_speed(void) { rgblight_decrease_speed_helper(true); } -void rgblight_decrease_speed_noeeprom(void) { rgblight_decrease_speed_helper(false); } +void rgblight_decrease_speed(void) { + rgblight_decrease_speed_helper(true); +} +void rgblight_decrease_speed_noeeprom(void) { + rgblight_decrease_speed_helper(false); +} void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { @@ -478,7 +534,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); } else { // all LEDs in same color - if (1 == 0) { // dummy + if (1 == 0) { // dummy } #ifdef RGBLIGHT_EFFECT_BREATHING else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { @@ -540,33 +596,51 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w } } -void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); } +void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_eeprom_helper(hue, sat, val, true); +} -void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); } +void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_eeprom_helper(hue, sat, val, false); +} -uint8_t rgblight_get_speed(void) { return rgblight_config.speed; } +uint8_t rgblight_get_speed(void) { + return rgblight_config.speed; +} void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { rgblight_config.speed = speed; if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed); } else { dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed); } } -void rgblight_set_speed(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, true); } +void rgblight_set_speed(uint8_t speed) { + rgblight_set_speed_eeprom_helper(speed, true); +} -void rgblight_set_speed_noeeprom(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, false); } +void rgblight_set_speed_noeeprom(uint8_t speed) { + rgblight_set_speed_eeprom_helper(speed, false); +} -uint8_t rgblight_get_hue(void) { return rgblight_config.hue; } +uint8_t rgblight_get_hue(void) { + return rgblight_config.hue; +} -uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } +uint8_t rgblight_get_sat(void) { + return rgblight_config.sat; +} -uint8_t rgblight_get_val(void) { return rgblight_config.val; } +uint8_t rgblight_get_val(void) { + return rgblight_config.val; +} -HSV rgblight_get_hsv(void) { return (HSV){rgblight_config.hue, rgblight_config.sat, rgblight_config.val}; } +HSV rgblight_get_hsv(void) { + return (HSV){rgblight_config.hue, rgblight_config.sat, rgblight_config.val}; +} void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { if (!rgblight_config.enable) { @@ -648,14 +722,22 @@ void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, } #ifndef RGBLIGHT_SPLIT -void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, 0, (uint8_t)RGBLED_NUM / 2); } +void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { + rgblight_setrgb_range(r, g, b, 0, (uint8_t)RGBLED_NUM / 2); +} -void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); } +void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { + rgblight_setrgb_range(r, g, b, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); +} -void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, 0, (uint8_t)RGBLED_NUM / 2); } +void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_range(hue, sat, val, 0, (uint8_t)RGBLED_NUM / 2); +} -void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); } -#endif // ifndef RGBLIGHT_SPLIT +void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_range(hue, sat, val, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); +} +#endif // ifndef RGBLIGHT_SPLIT #ifdef RGBLIGHT_LAYERS void rgblight_set_layer_state(uint8_t layer, bool enabled) { @@ -693,18 +775,18 @@ static void rgblight_layers_write(void) { // For each layer for (const rgblight_segment_t *const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { if (!rgblight_get_layer_state(i)) { - continue; // Layer is disabled + continue; // Layer is disabled } const rgblight_segment_t *segment_ptr = pgm_read_ptr(layer_ptr); if (segment_ptr == NULL) { - break; // No more layers + break; // No more layers } // For each segment while (1) { rgblight_segment_t segment; memcpy_P(&segment, segment_ptr, sizeof(rgblight_segment_t)); if (segment.index == RGBLIGHT_END_SEGMENT_INDEX) { - break; // No more segments + break; // No more segments } // Write segment.count LEDs LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; @@ -726,7 +808,9 @@ static uint16_t _repeat_timer; static uint8_t _times_remaining; static uint16_t _dur; -void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_blink_layer_repeat(layer, duration_ms, 1); } +void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { + rgblight_blink_layer_repeat(layer, duration_ms, 1); +} void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) { _times_remaining = times * 2; @@ -796,7 +880,9 @@ void rgblight_wakeup(void) { #endif -__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); } +__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { + ws2812_setleds(start_led, num_leds); +} #ifndef RGBLIGHT_CUSTOM_DRIVER @@ -848,9 +934,13 @@ void rgblight_set(void) { #ifdef RGBLIGHT_SPLIT /* for split keyboard master side */ -uint8_t rgblight_get_change_flags(void) { return rgblight_status.change_flags; } +uint8_t rgblight_get_change_flags(void) { + return rgblight_status.change_flags; +} -void rgblight_clear_change_flags(void) { rgblight_status.change_flags = 0; } +void rgblight_clear_change_flags(void) { + rgblight_status.change_flags = 0; +} void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { syncinfo->config = rgblight_config; @@ -866,7 +956,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { # endif if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { if (syncinfo->config.enable) { - rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); + rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom); } else { rgblight_disable_noeeprom(); @@ -945,12 +1035,12 @@ static void rgblight_effect_dummy(animation_status_t *anim) { void rgblight_task(void) { if (rgblight_status.timer_enabled) { effect_func_t effect_func = rgblight_effect_dummy; - uint16_t interval_time = 2000; // dummy interval + uint16_t interval_time = 2000; // dummy interval uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; animation_status.delta = delta; // static light mode, do nothing here - if (1 == 0) { // dummy + if (1 == 0) { // dummy } # ifdef RGBLIGHT_EFFECT_BREATHING else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { @@ -1016,7 +1106,7 @@ void rgblight_task(void) { if (animation_status.restart) { animation_status.restart = false; animation_status.last_timer = sync_timer_read(); - animation_status.pos16 = 0; // restart signal to local each effect + animation_status.pos16 = 0; // restart signal to local each effect } uint16_t now = sync_timer_read(); if (timer_expired(now, animation_status.last_timer)) { @@ -1055,7 +1145,7 @@ void rgblight_task(void) { # ifndef RGBLIGHT_EFFECT_BREATHE_CENTER # ifndef RGBLIGHT_BREATHE_TABLE_SIZE -# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 +# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 # endif # include <rgblight_breathe_table.h> # endif @@ -1131,7 +1221,7 @@ void rgblight_effect_snake(animation_status_t *anim) { } # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (anim->pos == 0) { // restart signal + if (anim->pos == 0) { // restart signal if (increment == 1) { pos = rgblight_ranges.effect_num_leds - 1; } else { @@ -1194,7 +1284,7 @@ void rgblight_effect_knight(animation_status_t *anim) { uint8_t i, cur; # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (anim->pos == 0) { // restart signal + if (anim->pos == 0) { // restart signal anim->pos = 1; low_bound = 0; high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; @@ -1347,8 +1437,12 @@ void rgblight_effect_twinkle(animation_status_t *anim) { const uint8_t bottom = breathe_calc(0); const uint8_t top = breathe_calc(127); - uint8_t frac(uint8_t n, uint8_t d) { return (uint16_t)255 * n / d; } - uint8_t scale(uint16_t v, uint8_t scale) { return (v * scale) >> 8; } + uint8_t frac(uint8_t n, uint8_t d) { + return (uint16_t)255 * n / d; + } + uint8_t scale(uint16_t v, uint8_t scale) { + return (v * scale) >> 8; + } for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { TwinkleState *t = &(led_twinkle_state[i]); diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h index 5b90b8f49e..7076dc41ac 100644 --- a/quantum/rgblight/rgblight.h +++ b/quantum/rgblight/rgblight.h @@ -119,7 +119,7 @@ enum RGBLIGHT_EFFECT_MODE { // sample: #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 #ifndef RGBLIGHT_EFFECT_BREATHE_MAX -# define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0-255 +# define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0-255 #endif #ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH @@ -177,8 +177,8 @@ enum RGBLIGHT_EFFECT_MODE { #ifdef RGBLIGHT_LAYERS typedef struct { - uint8_t index; // The first LED to light - uint8_t count; // The number of LEDs to light + uint8_t index; // The first LED to light + uint8_t count; // The number of LEDs to light uint8_t hue; uint8_t sat; uint8_t val; @@ -241,7 +241,7 @@ typedef union { uint8_t hue : 8; uint8_t sat : 8; uint8_t val : 8; - uint8_t speed : 8; // EECONFIG needs to be increased to support this + uint8_t speed : 8; // EECONFIG needs to be increased to support this }; } rgblight_config_t; @@ -271,7 +271,7 @@ extern rgblight_ranges_t rgblight_ranges; /* === Utility Functions ===*/ void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); -void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check +void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); /* === Low level Functions === */ diff --git a/quantum/ring_buffer.h b/quantum/ring_buffer.h index 284745ca8e..85419de11b 100644 --- a/quantum/ring_buffer.h +++ b/quantum/ring_buffer.h @@ -36,9 +36,13 @@ static inline uint8_t rbuf_dequeue(void) { } static inline bool rbuf_has_data(void) { bool has_data; - ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { has_data = (rbuf_head != rbuf_tail); } + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + has_data = (rbuf_head != rbuf_tail); + } return has_data; } static inline void rbuf_clear(void) { - ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { rbuf_head = rbuf_tail = 0; } + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + rbuf_head = rbuf_tail = 0; + } } diff --git a/quantum/send_string.c b/quantum/send_string.c index 1a7f7a1315..0de12ba12d 100644 --- a/quantum/send_string.c +++ b/quantum/send_string.c @@ -142,9 +142,13 @@ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // Note: we bit-pack in "reverse" order to optimize loading #define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> ((pos) % 8)) & 0x01) -void send_string(const char *str) { send_string_with_delay(str, 0); } +void send_string(const char *str) { + send_string_with_delay(str, 0); +} -void send_string_P(const char *str) { send_string_with_delay_P(str, 0); } +void send_string_P(const char *str) { + send_string_with_delay_P(str, 0); +} void send_string_with_delay(const char *str, uint8_t interval) { while (1) { @@ -173,7 +177,8 @@ void send_string_with_delay(const char *str, uint8_t interval) { ms += keycode - '0'; keycode = *(++str); } - while (ms--) wait_ms(1); + while (ms--) + wait_ms(1); } } else { send_char(ascii_code); @@ -182,7 +187,8 @@ void send_string_with_delay(const char *str, uint8_t interval) { // interval { uint8_t ms = interval; - while (ms--) wait_ms(1); + while (ms--) + wait_ms(1); } } } @@ -214,7 +220,8 @@ void send_string_with_delay_P(const char *str, uint8_t interval) { ms += keycode - '0'; keycode = pgm_read_byte(++str); } - while (ms--) wait_ms(1); + while (ms--) + wait_ms(1); } } else { send_char(ascii_code); @@ -223,14 +230,15 @@ void send_string_with_delay_P(const char *str, uint8_t interval) { // interval { uint8_t ms = interval; - while (ms--) wait_ms(1); + while (ms--) + wait_ms(1); } } } void send_char(char ascii_code) { #if defined(AUDIO_ENABLE) && defined(SENDSTRING_BELL) - if (ascii_code == '\a') { // BEL + if (ascii_code == '\a') { // BEL PLAY_SONG(bell_song); return; } diff --git a/quantum/sequencer/sequencer.c b/quantum/sequencer/sequencer.c index 18a83661ec..2e92f7b3eb 100644 --- a/quantum/sequencer/sequencer.c +++ b/quantum/sequencer/sequencer.c @@ -25,16 +25,18 @@ #endif sequencer_config_t sequencer_config = { - false, // enabled - {false}, // steps - {0}, // track notes - 60, // tempo - SQ_RES_4, // resolution + false, // enabled + {false}, // steps + {0}, // track notes + 60, // tempo + SQ_RES_4, // resolution }; sequencer_state_t sequencer_internal_state = {0, 0, 0, 0, SEQUENCER_PHASE_ATTACK}; -bool is_sequencer_on(void) { return sequencer_config.enabled; } +bool is_sequencer_on(void) { + return sequencer_config.enabled; +} void sequencer_on(void) { dprintln("sequencer on"); @@ -65,7 +67,9 @@ void sequencer_set_track_notes(const uint16_t track_notes[SEQUENCER_TRACKS]) { } } -bool is_sequencer_track_active(uint8_t track) { return (sequencer_internal_state.active_tracks >> track) & true; } +bool is_sequencer_track_active(uint8_t track) { + return (sequencer_internal_state.active_tracks >> track) & true; +} void sequencer_set_track_activation(uint8_t track, bool value) { if (value) { @@ -76,7 +80,9 @@ void sequencer_set_track_activation(uint8_t track, bool value) { dprintf("sequencer: track %d is %s\n", track, value ? "active" : "inactive"); } -void sequencer_toggle_track_activation(uint8_t track) { sequencer_set_track_activation(track, !is_sequencer_track_active(track)); } +void sequencer_toggle_track_activation(uint8_t track) { + sequencer_set_track_activation(track, !is_sequencer_track_active(track)); +} void sequencer_toggle_single_active_track(uint8_t track) { if (is_sequencer_track_active(track)) { @@ -86,9 +92,13 @@ void sequencer_toggle_single_active_track(uint8_t track) { } } -bool is_sequencer_step_on(uint8_t step) { return step < SEQUENCER_STEPS && (sequencer_config.steps[step] & sequencer_internal_state.active_tracks) > 0; } +bool is_sequencer_step_on(uint8_t step) { + return step < SEQUENCER_STEPS && (sequencer_config.steps[step] & sequencer_internal_state.active_tracks) > 0; +} -bool is_sequencer_step_on_for_track(uint8_t step, uint8_t track) { return step < SEQUENCER_STEPS && (sequencer_config.steps[step] >> track) & true; } +bool is_sequencer_step_on_for_track(uint8_t step, uint8_t track) { + return step < SEQUENCER_STEPS && (sequencer_config.steps[step] >> track) & true; +} void sequencer_set_step(uint8_t step, bool value) { if (step < SEQUENCER_STEPS) { @@ -122,7 +132,9 @@ void sequencer_set_all_steps(bool value) { dprintf("sequencer: all steps are %s\n", value ? "on" : "off"); } -uint8_t sequencer_get_tempo(void) { return sequencer_config.tempo; } +uint8_t sequencer_get_tempo(void) { + return sequencer_config.tempo; +} void sequencer_set_tempo(uint8_t tempo) { if (tempo > 0) { @@ -142,9 +154,13 @@ void sequencer_increase_tempo(void) { } } -void sequencer_decrease_tempo(void) { sequencer_set_tempo(sequencer_config.tempo - 1); } +void sequencer_decrease_tempo(void) { + sequencer_set_tempo(sequencer_config.tempo - 1); +} -sequencer_resolution_t sequencer_get_resolution(void) { return sequencer_config.resolution; } +sequencer_resolution_t sequencer_get_resolution(void) { + return sequencer_config.resolution; +} void sequencer_set_resolution(sequencer_resolution_t resolution) { if (resolution >= 0 && resolution < SEQUENCER_RESOLUTIONS) { @@ -155,11 +171,17 @@ void sequencer_set_resolution(sequencer_resolution_t resolution) { } } -void sequencer_increase_resolution(void) { sequencer_set_resolution(sequencer_config.resolution + 1); } +void sequencer_increase_resolution(void) { + sequencer_set_resolution(sequencer_config.resolution + 1); +} -void sequencer_decrease_resolution(void) { sequencer_set_resolution(sequencer_config.resolution - 1); } +void sequencer_decrease_resolution(void) { + sequencer_set_resolution(sequencer_config.resolution - 1); +} -uint8_t sequencer_get_current_step(void) { return sequencer_internal_state.current_step; } +uint8_t sequencer_get_current_step(void) { + return sequencer_internal_state.current_step; +} void sequencer_phase_attack(void) { dprintf("sequencer: step %d\n", sequencer_internal_state.current_step); @@ -229,9 +251,13 @@ void sequencer_task(void) { } } -uint16_t sequencer_get_beat_duration(void) { return get_beat_duration(sequencer_config.tempo); } +uint16_t sequencer_get_beat_duration(void) { + return get_beat_duration(sequencer_config.tempo); +} -uint16_t sequencer_get_step_duration(void) { return get_step_duration(sequencer_config.tempo, sequencer_config.resolution); } +uint16_t sequencer_get_step_duration(void) { + return get_step_duration(sequencer_config.tempo, sequencer_config.resolution); +} uint16_t get_beat_duration(uint8_t tempo) { // Don’t crash in the unlikely case where the given tempo is 0 diff --git a/quantum/sequencer/sequencer.h b/quantum/sequencer/sequencer.h index 4017ae764e..a8ea16eece 100644 --- a/quantum/sequencer/sequencer.h +++ b/quantum/sequencer/sequencer.h @@ -48,7 +48,7 @@ typedef struct { bool enabled; uint8_t steps[SEQUENCER_STEPS]; uint16_t track_notes[SEQUENCER_TRACKS]; - uint8_t tempo; // Is a maximum tempo of 255 reasonable? + uint8_t tempo; // Is a maximum tempo of 255 reasonable? sequencer_resolution_t resolution; } sequencer_config_t; @@ -57,9 +57,9 @@ typedef struct { * We use a "phase" state machine to delay some of the events. */ typedef enum sequencer_phase_t { - SEQUENCER_PHASE_ATTACK, // t=0ms, send the MIDI note on signal - SEQUENCER_PHASE_RELEASE, // t=SEQUENCER_PHASE_RELEASE_TIMEOUT ms, send the MIDI note off signal - SEQUENCER_PHASE_PAUSE // t=step duration ms, loop + SEQUENCER_PHASE_ATTACK, // t=0ms, send the MIDI note on signal + SEQUENCER_PHASE_RELEASE, // t=SEQUENCER_PHASE_RELEASE_TIMEOUT ms, send the MIDI note off signal + SEQUENCER_PHASE_PAUSE // t=step duration ms, loop } sequencer_phase_t; typedef struct { diff --git a/quantum/sequencer/tests/midi_mock.c b/quantum/sequencer/tests/midi_mock.c index 236e16f9d7..5bd945d615 100644 --- a/quantum/sequencer/tests/midi_mock.c +++ b/quantum/sequencer/tests/midi_mock.c @@ -19,8 +19,14 @@ uint16_t last_noteon = 0; uint16_t last_noteoff = 0; -uint16_t midi_compute_note(uint16_t keycode) { return keycode; } +uint16_t midi_compute_note(uint16_t keycode) { + return keycode; +} -void process_midi_basic_noteon(uint16_t note) { last_noteon = note; } +void process_midi_basic_noteon(uint16_t note) { + last_noteon = note; +} -void process_midi_basic_noteoff(uint16_t note) { last_noteoff = note; } +void process_midi_basic_noteoff(uint16_t note) { + last_noteoff = note; +} diff --git a/quantum/sequencer/tests/sequencer_tests.cpp b/quantum/sequencer/tests/sequencer_tests.cpp index 290605a52a..05e58e4111 100644 --- a/quantum/sequencer/tests/sequencer_tests.cpp +++ b/quantum/sequencer/tests/sequencer_tests.cpp @@ -78,7 +78,9 @@ class SequencerTest : public ::testing::Test { sequencer_state_t state_copy; }; -TEST_F(SequencerTest, TestOffByDefault) { EXPECT_EQ(is_sequencer_on(), false); } +TEST_F(SequencerTest, TestOffByDefault) { + EXPECT_EQ(is_sequencer_on(), false); +} TEST_F(SequencerTest, TestOn) { sequencer_config.enabled = false; diff --git a/quantum/split_common/post_config.h b/quantum/split_common/post_config.h index a4c0a1956b..8f79beb6ed 100644 --- a/quantum/split_common/post_config.h +++ b/quantum/split_common/post_config.h @@ -5,6 +5,6 @@ # endif # ifndef F_SCL -# define F_SCL 100000UL // SCL frequency +# define F_SCL 100000UL // SCL frequency # endif #endif diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 35f0a9d181..7d50adf758 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -43,14 +43,14 @@ // Set to 0 to disable the disconnection check altogether. #ifndef SPLIT_MAX_CONNECTION_ERRORS # define SPLIT_MAX_CONNECTION_ERRORS 10 -#endif // SPLIT_MAX_CONNECTION_ERRORS +#endif // SPLIT_MAX_CONNECTION_ERRORS // How long (in milliseconds) to block all connection attempts after the communication has been flagged as disconnected. // One communication attempt will be allowed everytime this amount of time has passed since the last attempt. If that attempt succeeds, the communication is seen as working again. // Set to 0 to disable communication throttling while disconnected #ifndef SPLIT_CONNECTION_CHECK_TIMEOUT # define SPLIT_CONNECTION_CHECK_TIMEOUT 500 -#endif // SPLIT_CONNECTION_CHECK_TIMEOUT +#endif // SPLIT_CONNECTION_CHECK_TIMEOUT static uint8_t connection_errors = 0; @@ -68,7 +68,9 @@ static bool usbIsActive(void) { return false; } #else -static inline bool usbIsActive(void) { return usb_vbus_state(); } +static inline bool usbIsActive(void) { + return usb_vbus_state(); +} #endif #ifdef SPLIT_HAND_MATRIX_GRID @@ -83,7 +85,7 @@ static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) { uint8_t pin_state = readPin(in_pin); // Set out_pin to a setting that is less susceptible to noise. setPinInputHigh(out_pin); - matrix_io_delay(); // Wait for the pull-up to go HIGH. + matrix_io_delay(); // Wait for the pull-up to go HIGH. return pin_state; } #endif @@ -158,7 +160,9 @@ void split_post_init(void) { } } -bool is_transport_connected(void) { return connection_errors < SPLIT_MAX_CONNECTION_ERRORS; } +bool is_transport_connected(void) { + return connection_errors < SPLIT_MAX_CONNECTION_ERRORS; +} bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { #if SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 @@ -169,7 +173,7 @@ bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t sl if (is_disconnected && timer_elapsed(connection_check_timer) < SPLIT_CONNECTION_CHECK_TIMEOUT) { return false; } -#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 +#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 && SPLIT_CONNECTION_CHECK_TIMEOUT > 0 __attribute__((unused)) bool okay = transport_master(master_matrix, slave_matrix); #if SPLIT_MAX_CONNECTION_ERRORS > 0 @@ -186,10 +190,10 @@ bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t sl return connected; } else if (is_disconnected) { dprintln("Target connected"); -# endif // SPLIT_CONNECTION_CHECK_TIMEOUT > 0 +# endif // SPLIT_CONNECTION_CHECK_TIMEOUT > 0 } connection_errors = 0; -#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 +#endif // SPLIT_MAX_CONNECTION_ERRORS > 0 return true; } diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h index ef72043bb7..c7eabea233 100644 --- a/quantum/split_common/split_util.h +++ b/quantum/split_common/split_util.h @@ -2,7 +2,6 @@ #include <stdbool.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include "matrix.h" diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 535bc21aea..761a8884f4 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -19,81 +19,87 @@ enum serial_transaction_id { #ifdef USE_I2C I2C_EXECUTE_CALLBACK, -#endif // USE_I2C +#endif // USE_I2C GET_SLAVE_MATRIX_CHECKSUM, GET_SLAVE_MATRIX_DATA, #ifdef SPLIT_TRANSPORT_MIRROR PUT_MASTER_MATRIX, -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE GET_ENCODERS_CHECKSUM, GET_ENCODERS_DATA, -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifndef DISABLE_SYNC_TIMER PUT_SYNC_TIMER, -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) PUT_LAYER_STATE, PUT_DEFAULT_LAYER_STATE, -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #ifdef SPLIT_LED_STATE_ENABLE PUT_LED_STATE, -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE #ifdef SPLIT_MODS_ENABLE PUT_MODS, -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE #ifdef BACKLIGHT_ENABLE PUT_BACKLIGHT, -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) PUT_RGBLIGHT, -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) PUT_LED_MATRIX, -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) PUT_RGB_MATRIX, -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) PUT_WPM, -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) PUT_OLED, -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) PUT_ST7565, -#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + GET_POINTING_CHECKSUM, + GET_POINTING_DATA, + PUT_POINTING_CPI, +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) PUT_RPC_INFO, PUT_RPC_REQ_DATA, EXECUTE_RPC, GET_RPC_RESP_DATA, -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) // keyboard-specific #ifdef SPLIT_TRANSACTION_IDS_KB SPLIT_TRANSACTION_IDS_KB, -#endif // SPLIT_TRANSACTION_IDS_KB +#endif // SPLIT_TRANSACTION_IDS_KB // user/keymap-specific #ifdef SPLIT_TRANSACTION_IDS_USER SPLIT_TRANSACTION_IDS_USER, -#endif // SPLIT_TRANSACTION_IDS_USER +#endif // SPLIT_TRANSACTION_IDS_USER NUM_TOTAL_TRANSACTIONS }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 3ff87710e7..cffbccaeee 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -30,16 +30,16 @@ #ifndef FORCED_SYNC_THROTTLE_MS # define FORCED_SYNC_THROTTLE_MS 100 -#endif // FORCED_SYNC_THROTTLE_MS +#endif // FORCED_SYNC_THROTTLE_MS #define sizeof_member(type, member) sizeof(((type *)NULL)->member) #define trans_initiator2target_initializer_cb(member, cb) \ - { &dummy, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), 0, 0, cb } + { sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), 0, 0, cb } #define trans_initiator2target_initializer(member) trans_initiator2target_initializer_cb(member, NULL) #define trans_target2initiator_initializer_cb(member, cb) \ - { &dummy, 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } + { 0, 0, sizeof_member(split_shared_memory_t, member), offsetof(split_shared_memory_t, member), cb } #define trans_target2initiator_initializer(member) trans_target2initiator_initializer_cb(member, NULL) #define transport_write(id, data, length) transport_execute_transaction(id, data, length, NULL, 0) @@ -49,7 +49,7 @@ // Forward-declare the RPC callback handlers void slave_rpc_info_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer); -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) //////////////////////////////////////////////////// // Helpers @@ -63,7 +63,9 @@ static bool transaction_handler_master(matrix_row_t master_matrix[], matrix_row_ } } bool this_okay = true; - ATOMIC_BLOCK_FORCEON { this_okay = handler(master_matrix, slave_matrix); }; + ATOMIC_BLOCK_FORCEON { + this_okay = handler(master_matrix, slave_matrix); + }; if (this_okay) return true; } dprintf("Failed to execute %s\n", prefix); @@ -75,9 +77,11 @@ static bool transaction_handler_master(matrix_row_t master_matrix[], matrix_row_ if (!transaction_handler_master(master_matrix, slave_matrix, #prefix, &prefix##_handlers_master)) return false; \ } while (0) -#define TRANSACTION_HANDLER_SLAVE(prefix) \ - do { \ - ATOMIC_BLOCK_FORCEON { prefix##_handlers_slave(master_matrix, slave_matrix); }; \ +#define TRANSACTION_HANDLER_SLAVE(prefix) \ + do { \ + ATOMIC_BLOCK_FORCEON { \ + prefix##_handlers_slave(master_matrix, slave_matrix); \ + }; \ } while (0) inline static bool read_if_checksum_mismatch(int8_t trans_id_checksum, int8_t trans_id_retrieve, uint32_t *last_update, void *destination, const void *equiv_shmem, size_t length) { @@ -116,8 +120,8 @@ inline static bool send_if_data_mismatch(int8_t trans_id, uint32_t *last_update, static bool slave_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_update = 0; - static matrix_row_t last_matrix[(MATRIX_ROWS) / 2] = {0}; // last successfully-read matrix, so we can replicate if there are checksum errors - matrix_row_t temp_matrix[(MATRIX_ROWS) / 2]; // holding area while we test whether or not checksum is correct + static matrix_row_t last_matrix[(MATRIX_ROWS) / 2] = {0}; // last successfully-read matrix, so we can replicate if there are checksum errors + matrix_row_t temp_matrix[(MATRIX_ROWS) / 2]; // holding area while we test whether or not checksum is correct bool okay = read_if_checksum_mismatch(GET_SLAVE_MATRIX_CHECKSUM, GET_SLAVE_MATRIX_DATA, &last_update, temp_matrix, split_shmem->smatrix.matrix, sizeof(split_shmem->smatrix.matrix)); if (okay) { @@ -161,13 +165,13 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro # define TRANSACTIONS_MASTER_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(master_matrix) # define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS [PUT_MASTER_MATRIX] = trans_initiator2target_initializer(mmatrix.matrix), -#else // SPLIT_TRANSPORT_MIRROR +#else // SPLIT_TRANSPORT_MIRROR # define TRANSACTIONS_MASTER_MATRIX_MASTER() # define TRANSACTIONS_MASTER_MATRIX_SLAVE() # define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR //////////////////////////////////////////////////// // Encoders @@ -200,13 +204,13 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl [GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.state), // clang-format on -#else // ENCODER_ENABLE +#else // ENCODER_ENABLE # define TRANSACTIONS_ENCODERS_MASTER() # define TRANSACTIONS_ENCODERS_SLAVE() # define TRANSACTIONS_ENCODERS_REGISTRATIONS -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE //////////////////////////////////////////////////// // Sync timer @@ -239,13 +243,13 @@ static void sync_timer_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_SYNC_TIMER_SLAVE() TRANSACTION_HANDLER_SLAVE(sync_timer) # define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS [PUT_SYNC_TIMER] = trans_initiator2target_initializer(sync_timer), -#else // DISABLE_SYNC_TIMER +#else // DISABLE_SYNC_TIMER # define TRANSACTIONS_SYNC_TIMER_MASTER() # define TRANSACTIONS_SYNC_TIMER_SLAVE() # define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER //////////////////////////////////////////////////// // Layer state @@ -276,13 +280,13 @@ static void layer_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_ [PUT_DEFAULT_LAYER_STATE] = trans_initiator2target_initializer(layers.default_layer_state), // clang-format on -#else // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#else // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) # define TRANSACTIONS_LAYER_STATE_MASTER() # define TRANSACTIONS_LAYER_STATE_SLAVE() # define TRANSACTIONS_LAYER_STATE_REGISTRATIONS -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) //////////////////////////////////////////////////// // LED state @@ -304,13 +308,13 @@ static void led_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_LED_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(led_state) # define TRANSACTIONS_LED_STATE_REGISTRATIONS [PUT_LED_STATE] = trans_initiator2target_initializer(led_state), -#else // SPLIT_LED_STATE_ENABLE +#else // SPLIT_LED_STATE_ENABLE # define TRANSACTIONS_LED_STATE_MASTER() # define TRANSACTIONS_LED_STATE_SLAVE() # define TRANSACTIONS_LED_STATE_REGISTRATIONS -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE //////////////////////////////////////////////////// // Mods @@ -336,7 +340,7 @@ static bool mods_handlers_master(matrix_row_t master_matrix[], matrix_row_t slav if (!mods_need_sync && new_mods.oneshot_mods != split_shmem->mods.oneshot_mods) { mods_need_sync = true; } -# endif // NO_ACTION_ONESHOT +# endif // NO_ACTION_ONESHOT bool okay = true; if (mods_need_sync) { @@ -361,13 +365,13 @@ static void mods_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave # define TRANSACTIONS_MODS_SLAVE() TRANSACTION_HANDLER_SLAVE(mods) # define TRANSACTIONS_MODS_REGISTRATIONS [PUT_MODS] = trans_initiator2target_initializer(mods), -#else // SPLIT_MODS_ENABLE +#else // SPLIT_MODS_ENABLE # define TRANSACTIONS_MODS_MASTER() # define TRANSACTIONS_MODS_SLAVE() # define TRANSACTIONS_MODS_REGISTRATIONS -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE //////////////////////////////////////////////////// // Backlight @@ -380,19 +384,21 @@ static bool backlight_handlers_master(matrix_row_t master_matrix[], matrix_row_t return send_if_condition(PUT_BACKLIGHT, &last_update, (level != split_shmem->backlight_level), &level, sizeof(level)); } -static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { backlight_set(split_shmem->backlight_level); } +static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + backlight_set(split_shmem->backlight_level); +} # define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight) # define TRANSACTIONS_BACKLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(backlight) # define TRANSACTIONS_BACKLIGHT_REGISTRATIONS [PUT_BACKLIGHT] = trans_initiator2target_initializer(backlight_level), -#else // BACKLIGHT_ENABLE +#else // BACKLIGHT_ENABLE # define TRANSACTIONS_BACKLIGHT_MASTER() # define TRANSACTIONS_BACKLIGHT_SLAVE() # define TRANSACTIONS_BACKLIGHT_REGISTRATIONS -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE //////////////////////////////////////////////////// // RGBLIGHT @@ -423,13 +429,13 @@ static void rgblight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s # define TRANSACTIONS_RGBLIGHT_SLAVE() TRANSACTION_HANDLER_SLAVE(rgblight) # define TRANSACTIONS_RGBLIGHT_REGISTRATIONS [PUT_RGBLIGHT] = trans_initiator2target_initializer(rgblight_sync), -#else // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#else // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) # define TRANSACTIONS_RGBLIGHT_MASTER() # define TRANSACTIONS_RGBLIGHT_SLAVE() # define TRANSACTIONS_RGBLIGHT_REGISTRATIONS -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) //////////////////////////////////////////////////// // LED Matrix @@ -453,13 +459,13 @@ static void led_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_LED_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(led_matrix) # define TRANSACTIONS_LED_MATRIX_REGISTRATIONS [PUT_LED_MATRIX] = trans_initiator2target_initializer(led_matrix_sync), -#else // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#else // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) # define TRANSACTIONS_LED_MATRIX_MASTER() # define TRANSACTIONS_LED_MATRIX_SLAVE() # define TRANSACTIONS_LED_MATRIX_REGISTRATIONS -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) //////////////////////////////////////////////////// // RGB Matrix @@ -483,13 +489,13 @@ static void rgb_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t # define TRANSACTIONS_RGB_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(rgb_matrix) # define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS [PUT_RGB_MATRIX] = trans_initiator2target_initializer(rgb_matrix_sync), -#else // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#else // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) # define TRANSACTIONS_RGB_MATRIX_MASTER() # define TRANSACTIONS_RGB_MATRIX_SLAVE() # define TRANSACTIONS_RGB_MATRIX_REGISTRATIONS -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) //////////////////////////////////////////////////// // WPM @@ -502,19 +508,21 @@ static bool wpm_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave return send_if_condition(PUT_WPM, &last_update, (current_wpm != split_shmem->current_wpm), ¤t_wpm, sizeof(current_wpm)); } -static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { set_current_wpm(split_shmem->current_wpm); } +static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + set_current_wpm(split_shmem->current_wpm); +} # define TRANSACTIONS_WPM_MASTER() TRANSACTION_HANDLER_MASTER(wpm) # define TRANSACTIONS_WPM_SLAVE() TRANSACTION_HANDLER_SLAVE(wpm) # define TRANSACTIONS_WPM_REGISTRATIONS [PUT_WPM] = trans_initiator2target_initializer(current_wpm), -#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) # define TRANSACTIONS_WPM_MASTER() # define TRANSACTIONS_WPM_SLAVE() # define TRANSACTIONS_WPM_REGISTRATIONS -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) //////////////////////////////////////////////////// // OLED @@ -539,13 +547,13 @@ static void oled_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave # define TRANSACTIONS_OLED_SLAVE() TRANSACTION_HANDLER_SLAVE(oled) # define TRANSACTIONS_OLED_REGISTRATIONS [PUT_OLED] = trans_initiator2target_initializer(current_oled_state), -#else // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#else // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) # define TRANSACTIONS_OLED_MASTER() # define TRANSACTIONS_OLED_SLAVE() # define TRANSACTIONS_OLED_REGISTRATIONS -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) //////////////////////////////////////////////////// // ST7565 @@ -570,24 +578,101 @@ static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla # define TRANSACTIONS_ST7565_SLAVE() TRANSACTION_HANDLER_SLAVE(st7565) # define TRANSACTIONS_ST7565_REGISTRATIONS [PUT_ST7565] = trans_initiator2target_initializer(current_st7565_state), -#else // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#else // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) # define TRANSACTIONS_ST7565_MASTER() # define TRANSACTIONS_ST7565_SLAVE() # define TRANSACTIONS_ST7565_REGISTRATIONS -#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +//////////////////////////////////////////////////// +// POINTING + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (is_keyboard_left()) { + return true; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (!is_keyboard_left()) { + return true; + } +# endif + static uint32_t last_update = 0; + static uint16_t last_cpi = 0; + report_mouse_t temp_state; + uint16_t temp_cpi; + bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state)); + if (okay) pointing_device_set_shared_report(temp_state); + temp_cpi = pointing_device_get_shared_cpi(); + if (temp_cpi && memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)); + okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi)); + if (okay) { + last_cpi = temp_cpi; + } + } + return okay; +} + +extern const pointing_device_driver_t pointing_device_driver; + +static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# if defined(POINTING_DEVICE_LEFT) + if (!is_keyboard_left()) { + return; + } +# elif defined(POINTING_DEVICE_RIGHT) + if (is_keyboard_left()) { + return; + } +# endif + report_mouse_t temp_report; + uint16_t temp_cpi; +# if (POINTING_DEVICE_TASK_THROTTLE_MS > 0) + static uint32_t last_exec = 0; + if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) { + return; + } + last_exec = timer_read32(); +# endif + temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL + if (split_shmem->pointing.cpi && memcmp(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)) != 0) { + if (pointing_device_driver.set_cpi) { + pointing_device_driver.set_cpi(split_shmem->pointing.cpi); + } + } + memset(&temp_report, 0, sizeof(temp_report)); + temp_report = pointing_device_driver.get_report(temp_report); + memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report)); + // Now update the checksum given that the pointing has been written to + split_shmem->pointing.checksum = crc8(&temp_report, sizeof(temp_report)); +} + +# define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing) +# define TRANSACTIONS_POINTING_SLAVE() TRANSACTION_HANDLER_SLAVE(pointing) +# define TRANSACTIONS_POINTING_REGISTRATIONS [GET_POINTING_CHECKSUM] = trans_target2initiator_initializer(pointing.checksum), [GET_POINTING_DATA] = trans_target2initiator_initializer(pointing.report), [PUT_POINTING_CPI] = trans_initiator2target_initializer(pointing.cpi), + +#else // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + +# define TRANSACTIONS_POINTING_MASTER() +# define TRANSACTIONS_POINTING_SLAVE() +# define TRANSACTIONS_POINTING_REGISTRATIONS + +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) //////////////////////////////////////////////////// -uint8_t dummy; split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { // Set defaults - [0 ...(NUM_TOTAL_TRANSACTIONS - 1)] = {NULL, 0, 0, 0, 0, 0}, + [0 ...(NUM_TOTAL_TRANSACTIONS - 1)] = {0, 0, 0, 0, 0}, #ifdef USE_I2C [I2C_EXECUTE_CALLBACK] = trans_initiator2target_initializer(transaction_id), -#endif // USE_I2C +#endif // USE_I2C // clang-format off TRANSACTIONS_SLAVE_MATRIX_REGISTRATIONS @@ -604,6 +689,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { TRANSACTIONS_WPM_REGISTRATIONS TRANSACTIONS_OLED_REGISTRATIONS TRANSACTIONS_ST7565_REGISTRATIONS + TRANSACTIONS_POINTING_REGISTRATIONS // clang-format on #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -611,7 +697,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { [PUT_RPC_REQ_DATA] = trans_initiator2target_initializer(rpc_m2s_buffer), [EXECUTE_RPC] = trans_initiator2target_initializer_cb(rpc_info.transaction_id, slave_rpc_exec_callback), [GET_RPC_RESP_DATA] = trans_target2initiator_initializer(rpc_s2m_buffer), -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) }; bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { @@ -629,6 +715,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix TRANSACTIONS_WPM_MASTER(); TRANSACTIONS_OLED_MASTER(); TRANSACTIONS_ST7565_MASTER(); + TRANSACTIONS_POINTING_MASTER(); return true; } @@ -647,6 +734,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ TRANSACTIONS_WPM_SLAVE(); TRANSACTIONS_OLED_SLAVE(); TRANSACTIONS_ST7565_SLAVE(); + TRANSACTIONS_POINTING_SLAVE(); } #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -720,4 +808,4 @@ void slave_rpc_exec_callback(uint8_t initiator2target_buffer_size, const void *i } } -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transactions.h b/quantum/split_common/transactions.h index 53610d6f8e..e38ec79ce9 100644 --- a/quantum/split_common/transactions.h +++ b/quantum/split_common/transactions.h @@ -27,7 +27,6 @@ typedef void (*slave_callback_t)(uint8_t initiator2target_buffer_size, const voi // Split transaction Descriptor typedef struct _split_transaction_desc_t { - uint8_t * status; uint8_t initiator2target_buffer_size; uint16_t initiator2target_offset; uint8_t target2initiator_buffer_size; diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index bcc0261417..aade3c98d7 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -26,7 +26,7 @@ # ifndef SLAVE_I2C_TIMEOUT # define SLAVE_I2C_TIMEOUT 100 -# endif // SLAVE_I2C_TIMEOUT +# endif // SLAVE_I2C_TIMEOUT # ifndef SLAVE_I2C_ADDRESS # define SLAVE_I2C_ADDRESS 0x32 @@ -40,8 +40,12 @@ _Static_assert(sizeof(split_shared_memory_t) <= I2C_SLAVE_REG_COUNT, "split_shar split_shared_memory_t *const split_shmem = (split_shared_memory_t *)i2c_slave_reg; -void transport_master_init(void) { i2c_init(); } -void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); } +void transport_master_init(void) { + i2c_init(); +} +void transport_slave_init(void) { + i2c_slave_init(SLAVE_I2C_ADDRESS); +} i2c_status_t transport_trigger_callback(int8_t id) { // If there's no callback, indicate that we were successful @@ -82,15 +86,19 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, return true; } -#else // USE_I2C +#else // USE_I2C # include "serial.h" static split_shared_memory_t shared_memory; split_shared_memory_t *const split_shmem = &shared_memory; -void transport_master_init(void) { soft_serial_initiator_init(); } -void transport_slave_init(void) { soft_serial_target_init(); } +void transport_master_init(void) { + soft_serial_initiator_init(); +} +void transport_slave_init(void) { + soft_serial_target_init(); +} bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) { split_transaction_desc_t *trans = &split_transaction_table[id]; @@ -99,7 +107,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len); } - if (soft_serial_transaction(id) != TRANSACTION_END) { + if (!soft_serial_transaction(id)) { return false; } @@ -111,8 +119,12 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, return true; } -#endif // USE_I2C +#endif // USE_I2C -bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { return transactions_master(master_matrix, slave_matrix); } +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + return transactions_master(master_matrix, slave_matrix); +} -void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { transactions_slave(master_matrix, slave_matrix); } +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + transactions_slave(master_matrix, slave_matrix); +} diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 1d4f6ed0cd..26bd136728 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -25,11 +25,11 @@ #ifndef RPC_M2S_BUFFER_SIZE # define RPC_M2S_BUFFER_SIZE 32 -#endif // RPC_M2S_BUFFER_SIZE +#endif // RPC_M2S_BUFFER_SIZE #ifndef RPC_S2M_BUFFER_SIZE # define RPC_S2M_BUFFER_SIZE 32 -#endif // RPC_S2M_BUFFER_SIZE +#endif // RPC_S2M_BUFFER_SIZE void transport_master_init(void); void transport_slave_init(void); @@ -43,15 +43,15 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, #ifdef ENCODER_ENABLE # include "encoder.h" # define NUMBER_OF_ENCODERS (sizeof((pin_t[])ENCODERS_PAD_A) / sizeof(pin_t)) -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifdef BACKLIGHT_ENABLE # include "backlight.h" -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE # include "rgblight.h" -#endif // RGBLIGHT_ENABLE +#endif // RGBLIGHT_ENABLE typedef struct _split_slave_matrix_sync_t { uint8_t checksum; @@ -62,21 +62,21 @@ typedef struct _split_slave_matrix_sync_t { typedef struct _split_master_matrix_sync_t { matrix_row_t matrix[(MATRIX_ROWS) / 2]; } split_master_matrix_sync_t; -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE typedef struct _split_slave_encoder_sync_t { uint8_t checksum; uint8_t state[NUMBER_OF_ENCODERS]; } split_slave_encoder_sync_t; -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) typedef struct _split_layers_sync_t { layer_state_t layer_state; layer_state_t default_layer_state; } split_layers_sync_t; -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) # include "led_matrix.h" @@ -85,7 +85,7 @@ typedef struct _led_matrix_sync_t { led_eeconfig_t led_matrix; bool led_suspend_state; } led_matrix_sync_t; -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) # include "rgb_matrix.h" @@ -94,7 +94,7 @@ typedef struct _rgb_matrix_sync_t { rgb_config_t rgb_matrix; bool rgb_suspend_state; } rgb_matrix_sync_t; -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) #ifdef SPLIT_MODS_ENABLE typedef struct _split_mods_sync_t { @@ -102,9 +102,18 @@ typedef struct _split_mods_sync_t { uint8_t weak_mods; # ifndef NO_ACTION_ONESHOT uint8_t oneshot_mods; -# endif // NO_ACTION_ONESHOT +# endif // NO_ACTION_ONESHOT } split_mods_sync_t; -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) +# include "pointing_device.h" +typedef struct _split_slave_pointing_sync_t { + uint8_t checksum; + report_mouse_t report; + uint16_t cpi; +} split_slave_pointing_sync_t; +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _rpc_sync_info_t { @@ -112,72 +121,76 @@ typedef struct _rpc_sync_info_t { uint8_t m2s_length; uint8_t s2m_length; } rpc_sync_info_t; -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) typedef struct _split_shared_memory_t { #ifdef USE_I2C int8_t transaction_id; -#endif // USE_I2C +#endif // USE_I2C split_slave_matrix_sync_t smatrix; #ifdef SPLIT_TRANSPORT_MIRROR split_master_matrix_sync_t mmatrix; -#endif // SPLIT_TRANSPORT_MIRROR +#endif // SPLIT_TRANSPORT_MIRROR #ifdef ENCODER_ENABLE split_slave_encoder_sync_t encoders; -#endif // ENCODER_ENABLE +#endif // ENCODER_ENABLE #ifndef DISABLE_SYNC_TIMER uint32_t sync_timer; -#endif // DISABLE_SYNC_TIMER +#endif // DISABLE_SYNC_TIMER #if !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) split_layers_sync_t layers; -#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) +#endif // !defined(NO_ACTION_LAYER) && defined(SPLIT_LAYER_STATE_ENABLE) #ifdef SPLIT_LED_STATE_ENABLE uint8_t led_state; -#endif // SPLIT_LED_STATE_ENABLE +#endif // SPLIT_LED_STATE_ENABLE #ifdef SPLIT_MODS_ENABLE split_mods_sync_t mods; -#endif // SPLIT_MODS_ENABLE +#endif // SPLIT_MODS_ENABLE #ifdef BACKLIGHT_ENABLE uint8_t backlight_level; -#endif // BACKLIGHT_ENABLE +#endif // BACKLIGHT_ENABLE #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) rgblight_syncinfo_t rgblight_sync; -#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +#endif // defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) led_matrix_sync_t led_matrix_sync; -#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +#endif // defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) rgb_matrix_sync_t rgb_matrix_sync; -#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +#endif // defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) #if defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) uint8_t current_wpm; -#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) +#endif // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE) #if defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) uint8_t current_oled_state; -#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) +#endif // defined(OLED_ENABLE) && defined(SPLIT_OLED_ENABLE) #if defined(ST7565_ENABLE) && defined(SPLIT_ST7565_ENABLE) uint8_t current_st7565_state; -#endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) +#endif // ST7565_ENABLE(OLED_ENABLE) && defined(SPLIT_ST7565_ENABLE) + +#if defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) + split_slave_pointing_sync_t pointing; +#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE) #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) rpc_sync_info_t rpc_info; uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; -#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) } split_shared_memory_t; extern split_shared_memory_t *const split_shmem; diff --git a/quantum/sync_timer.c b/quantum/sync_timer.c index de24b463b6..217891233f 100644 --- a/quantum/sync_timer.c +++ b/quantum/sync_timer.c @@ -29,7 +29,9 @@ SOFTWARE. #if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) volatile int32_t sync_timer_ms; -void sync_timer_init(void) { sync_timer_ms = 0; } +void sync_timer_init(void) { + sync_timer_ms = 0; +} void sync_timer_update(uint32_t time) { if (is_keyboard_master()) return; diff --git a/quantum/velocikey.c b/quantum/velocikey.c index 6b7f82d950..58e14215bb 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -13,7 +13,9 @@ #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; -bool velocikey_enabled(void) { return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; } +bool velocikey_enabled(void) { + return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; +} void velocikey_toggle(void) { if (velocikey_enabled()) @@ -39,4 +41,6 @@ void velocikey_decelerate(void) { } } -uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); } +uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { + return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); +} diff --git a/quantum/via.c b/quantum/via.c index 7c8aa753e7..05ab799cbb 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -45,7 +45,7 @@ #include "raw_hid.h" #include "dynamic_keymap.h" #include "eeprom.h" -#include "version.h" // for QMK_BUILDDATE used in EEPROM magic +#include "version.h" // for QMK_BUILDDATE used in EEPROM magic #include "via_ensure_keycode.h" // Forward declare some helpers. @@ -62,7 +62,7 @@ void via_qmk_rgblight_get_value(uint8_t *data); // Can be called in an overriding via_init_kb() to test if keyboard level code usage of // EEPROM is invalid and use/save defaults. bool via_eeprom_is_valid(void) { - char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" + char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F); uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F); uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F); @@ -73,7 +73,7 @@ bool via_eeprom_is_valid(void) { // Sets VIA/keyboard level usage of EEPROM to valid/invalid // Keyboard level code (eg. via_init_kb()) should not call this void via_eeprom_set_valid(bool valid) { - char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" + char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F); uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F); uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F); @@ -96,6 +96,7 @@ void via_init(void) { // Let keyboard level test EEPROM valid state, // but not set it valid, it is done here. via_init_kb(); + via_set_layout_options_kb(via_get_layout_options()); // If the EEPROM has the magic, the data is good. // OK to load from EEPROM. @@ -131,7 +132,10 @@ uint32_t via_get_layout_options(void) { return value; } +__attribute__((weak)) void via_set_layout_options_kb(uint32_t value) {} + void via_set_layout_options(uint32_t value) { + via_set_layout_options_kb(value); // Start at the least significant byte void *target = (void *)(VIA_EEPROM_LAYOUT_OPTIONS_ADDR + VIA_EEPROM_LAYOUT_OPTIONS_SIZE - 1); for (uint8_t i = 0; i < VIA_EEPROM_LAYOUT_OPTIONS_SIZE; i++) { @@ -343,13 +347,13 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { } case id_dynamic_keymap_macro_get_buffer: { uint16_t offset = (command_data[0] << 8) | command_data[1]; - uint16_t size = command_data[2]; // size <= 28 + uint16_t size = command_data[2]; // size <= 28 dynamic_keymap_macro_get_buffer(offset, size, &command_data[3]); break; } case id_dynamic_keymap_macro_set_buffer: { uint16_t offset = (command_data[0] << 8) | command_data[1]; - uint16_t size = command_data[2]; // size <= 28 + uint16_t size = command_data[2]; // size <= 28 dynamic_keymap_macro_set_buffer(offset, size, &command_data[3]); break; } @@ -363,13 +367,13 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { } case id_dynamic_keymap_get_buffer: { uint16_t offset = (command_data[0] << 8) | command_data[1]; - uint16_t size = command_data[2]; // size <= 28 + uint16_t size = command_data[2]; // size <= 28 dynamic_keymap_get_buffer(offset, size, &command_data[3]); break; } case id_dynamic_keymap_set_buffer: { uint16_t offset = (command_data[0] << 8) | command_data[1]; - uint16_t size = command_data[2]; // size <= 28 + uint16_t size = command_data[2]; // size <= 28 dynamic_keymap_set_buffer(offset, size, &command_data[3]); break; } @@ -434,7 +438,7 @@ void via_qmk_backlight_set_value(uint8_t *data) { } } -#endif // #if defined(VIA_QMK_BACKLIGHT_ENABLE) +#endif // #if defined(VIA_QMK_BACKLIGHT_ENABLE) #if defined(VIA_QMK_RGBLIGHT_ENABLE) @@ -490,4 +494,4 @@ void via_qmk_rgblight_set_value(uint8_t *data) { } } -#endif // #if defined(VIA_QMK_RGBLIGHT_ENABLE) +#endif // #if defined(VIA_QMK_RGBLIGHT_ENABLE) diff --git a/quantum/via.h b/quantum/via.h index 3db318a454..ac29a58902 100644 --- a/quantum/via.h +++ b/quantum/via.h @@ -16,7 +16,7 @@ #pragma once -#include "eeconfig.h" // for EECONFIG_SIZE +#include "eeconfig.h" // for EECONFIG_SIZE // Keyboard level code can change where VIA stores the magic. // The magic is the build date YYMMDD encoded as BCD in 3 bytes, @@ -59,7 +59,7 @@ #define VIA_PROTOCOL_VERSION 0x0009 enum via_command_id { - id_get_protocol_version = 0x01, // always 0x01 + id_get_protocol_version = 0x01, // always 0x01 id_get_keyboard_value = 0x02, id_set_keyboard_value = 0x03, id_dynamic_keymap_get_keycode = 0x04, @@ -82,7 +82,7 @@ enum via_command_id { }; enum via_keyboard_value_id { - id_uptime = 0x01, // + id_uptime = 0x01, // id_layout_options = 0x02, id_switch_matrix_state = 0x03 }; @@ -159,6 +159,7 @@ void via_init(void); // Used by VIA to store and retrieve the layout options. uint32_t via_get_layout_options(void); void via_set_layout_options(uint32_t value); +void via_set_layout_options_kb(uint32_t value); // Called by QMK core to process VIA-specific keycodes. bool process_record_via(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/via_ensure_keycode.h b/quantum/via_ensure_keycode.h index 1aba0cdd2a..75f816b560 100644 --- a/quantum/via_ensure_keycode.h +++ b/quantum/via_ensure_keycode.h @@ -244,12 +244,12 @@ _Static_assert(KC_LT == 0x0236, ""); _Static_assert(KC_GT == 0x0237, ""); _Static_assert(KC_QUES == 0x0238, ""); -_Static_assert(RESET == 0x5C00, ""); -_Static_assert(DEBUG == 0x5C01, ""); +_Static_assert(QK_BOOTLOADER == 0x5C00, ""); +_Static_assert(QK_DEBUG_TOGGLE == 0x5C01, ""); _Static_assert(MAGIC_TOGGLE_NKRO == 0x5C14, ""); -_Static_assert(KC_GESC == 0x5C16, ""); +_Static_assert(QK_GRAVE_ESCAPE == 0x5C16, ""); _Static_assert(AU_ON == 0x5C1D, ""); _Static_assert(AU_OFF == 0x5C1E, ""); diff --git a/quantum/wpm.c b/quantum/wpm.c index 925e2c416e..b2e6fe0430 100644 --- a/quantum/wpm.c +++ b/quantum/wpm.c @@ -22,41 +22,53 @@ // WPM Stuff static uint8_t current_wpm = 0; static uint32_t wpm_timer = 0; -#ifndef WPM_UNFILTERED -static uint32_t smoothing_timer = 0; -#endif /* The WPM calculation works by specifying a certain number of 'periods' inside * a ring buffer, and we count the number of keypresses which occur in each of * those periods. Then to calculate WPM, we add up all of the keypresses in * the whole ring buffer, divide by the number of keypresses in a 'word', and - * then adjust for how much time is captured by our ring buffer. Right now - * the ring buffer is hardcoded below to be six half-second periods, accounting - * for a total WPM sampling period of up to three seconds of typing. + * then adjust for how much time is captured by our ring buffer. The size + * of the ring buffer can be configured using the keymap configuration + * value `WPM_SAMPLE_PERIODS`. * - * Whenever our WPM drops to absolute zero due to no typing occurring within - * any contiguous three seconds, we reset and start measuring fresh, - * which lets our WPM immediately reach the correct value even before a full - * three second sampling buffer has been filled. */ #define MAX_PERIODS (WPM_SAMPLE_PERIODS) #define PERIOD_DURATION (1000 * WPM_SAMPLE_SECONDS / MAX_PERIODS) -#define LATENCY (100) -static int8_t period_presses[MAX_PERIODS] = {0}; + +static int16_t period_presses[MAX_PERIODS] = {0}; static uint8_t current_period = 0; static uint8_t periods = 1; #if !defined(WPM_UNFILTERED) -static uint8_t prev_wpm = 0; -static uint8_t next_wpm = 0; +/* LATENCY is used as part of filtering, and controls how quickly the reported + * WPM trails behind our actual instantaneous measured WPM value, and is + * defined in milliseconds. So for LATENCY == 100, the displayed WPM is + * smoothed out over periods of 0.1 seconds. This results in a nice, + * smoothly-moving reported WPM value which nevertheless is never more than + * 0.1 seconds behind the typist's actual current WPM. + * + * LATENCY is not used if WPM_UNFILTERED is defined. + */ +# define LATENCY (100) +static uint32_t smoothing_timer = 0; +static uint8_t prev_wpm = 0; +static uint8_t next_wpm = 0; #endif -void set_current_wpm(uint8_t new_wpm) { current_wpm = new_wpm; } -uint8_t get_current_wpm(void) { return current_wpm; } +void set_current_wpm(uint8_t new_wpm) { + current_wpm = new_wpm; +} +uint8_t get_current_wpm(void) { + return current_wpm; +} -bool wpm_keycode(uint16_t keycode) { return wpm_keycode_kb(keycode); } +bool wpm_keycode(uint16_t keycode) { + return wpm_keycode_kb(keycode); +} -__attribute__((weak)) bool wpm_keycode_kb(uint16_t keycode) { return wpm_keycode_user(keycode); } +__attribute__((weak)) bool wpm_keycode_kb(uint16_t keycode) { + return wpm_keycode_user(keycode); +} __attribute__((weak)) bool wpm_keycode_user(uint16_t keycode) { if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) || (keycode >= QK_MODS && keycode <= QK_MODS_MAX)) { @@ -71,7 +83,7 @@ __attribute__((weak)) bool wpm_keycode_user(uint16_t keycode) { return false; } -#ifdef WPM_ALLOW_COUNT_REGRESSION +#if defined(WPM_ALLOW_COUNT_REGRESSION) __attribute__((weak)) uint8_t wpm_regress_count(uint16_t keycode) { bool weak_modded = (keycode >= QK_LCTL && keycode < QK_LSFT) || (keycode >= QK_RCTL && keycode < QK_RSFT); @@ -95,12 +107,12 @@ __attribute__((weak)) uint8_t wpm_regress_count(uint16_t keycode) { // Outside 'raw' mode we smooth results over time. void update_wpm(uint16_t keycode) { - if (wpm_keycode(keycode)) { + if (wpm_keycode(keycode) && period_presses[current_period] < INT16_MAX) { period_presses[current_period]++; } -#ifdef WPM_ALLOW_COUNT_REGRESSION +#if defined(WPM_ALLOW_COUNT_REGRESSION) uint8_t regress = wpm_regress_count(keycode); - if (regress) { + if (regress && period_presses[current_period] > INT16_MIN) { period_presses[current_period]--; } #endif @@ -116,32 +128,41 @@ void decay_wpm(void) { } int32_t elapsed = timer_elapsed32(wpm_timer); uint32_t duration = (((periods)*PERIOD_DURATION) + elapsed); - uint32_t wpm_now = (60000 * presses) / (duration * WPM_ESTIMATED_WORD_SIZE); - wpm_now = (wpm_now > 240) ? 240 : wpm_now; + int32_t wpm_now = (60000 * presses) / (duration * WPM_ESTIMATED_WORD_SIZE); + + if (wpm_now < 0) // set some reasonable WPM measurement limits + wpm_now = 0; + if (wpm_now > 240) wpm_now = 240; if (elapsed > PERIOD_DURATION) { current_period = (current_period + 1) % MAX_PERIODS; period_presses[current_period] = 0; periods = (periods < MAX_PERIODS - 1) ? periods + 1 : MAX_PERIODS - 1; elapsed = 0; - /* if (wpm_timer == 0) { */ - wpm_timer = timer_read32(); - /* } else { */ - /* wpm_timer += PERIOD_DURATION; */ - /* } */ + wpm_timer = timer_read32(); } - if (presses < 2) // don't guess high WPM based on a single keypress. + if (presses < 2) // don't guess high WPM based on a single keypress. wpm_now = 0; -#if defined WPM_LAUNCH_CONTROL +#if defined(WPM_LAUNCH_CONTROL) + /* + * If the `WPM_LAUNCH_CONTROL` option is enabled, then whenever our WPM + * drops to absolute zero due to no typing occurring within our sample + * ring buffer, we reset and start measuring fresh, which lets our WPM + * immediately reach the correct value even before a full sampling buffer + * has been filled. + */ if (presses == 0) { - current_period = 0; - periods = 0; - wpm_now = 0; + current_period = 0; + periods = 0; + wpm_now = 0; + period_presses[0] = 0; } -#endif // WPM_LAUNCH_CONTROL +#endif // WPM_LAUNCH_CONTROL -#ifndef WPM_UNFILTERED +#if defined(WPM_UNFILTERED) + current_wpm = wpm_now; +#else int32_t latency = timer_elapsed32(smoothing_timer); if (latency > LATENCY) { smoothing_timer = timer_read32(); @@ -150,7 +171,5 @@ void decay_wpm(void) { } current_wpm = prev_wpm + (latency * ((int)next_wpm - (int)prev_wpm) / LATENCY); -#else - current_wpm = wpm_now; #endif } diff --git a/quantum/wpm.h b/quantum/wpm.h index c8e7d26684..305d75b450 100644 --- a/quantum/wpm.h +++ b/quantum/wpm.h @@ -26,7 +26,7 @@ # define WPM_SAMPLE_SECONDS 5 #endif #ifndef WPM_SAMPLE_PERIODS -# define WPM_SAMPLE_PERIODS 50 +# define WPM_SAMPLE_PERIODS 25 #endif bool wpm_keycode(uint16_t keycode); |