diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/bootmagic/bootmagic.h | 24 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_full.c | 147 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_full.h | 115 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_lite.c | 66 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_lite.h | 25 | ||||
-rw-r--r-- | quantum/bootmagic/magic.c | 54 | ||||
-rw-r--r-- | quantum/bootmagic/magic.h | 18 | ||||
-rw-r--r-- | quantum/keycode_config.h | 1 | ||||
-rw-r--r-- | quantum/led_matrix.c | 8 | ||||
-rw-r--r-- | quantum/led_matrix.h | 4 | ||||
-rw-r--r-- | quantum/process_keycode/process_backlight.c | 29 | ||||
-rw-r--r-- | quantum/quantum.c | 28 | ||||
-rw-r--r-- | quantum/quantum.h | 55 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 14 | ||||
-rw-r--r-- | quantum/rgb_matrix.c | 34 | ||||
-rw-r--r-- | quantum/rgb_matrix_types.h | 9 | ||||
-rw-r--r-- | quantum/split_common/split_util.c | 70 | ||||
-rw-r--r-- | quantum/split_common/transport.c | 45 |
18 files changed, 610 insertions, 136 deletions
diff --git a/quantum/bootmagic/bootmagic.h b/quantum/bootmagic/bootmagic.h new file mode 100644 index 0000000000..959750178d --- /dev/null +++ b/quantum/bootmagic/bootmagic.h @@ -0,0 +1,24 @@ +/* Copyright 2021 QMK + * + * 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 3 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 + +#if defined(BOOTMAGIC_ENABLE) +# include "bootmagic_full.h" +#elif defined(BOOTMAGIC_LITE) +# include "bootmagic_lite.h" +#endif + +void bootmagic(void); diff --git a/quantum/bootmagic/bootmagic_full.c b/quantum/bootmagic/bootmagic_full.c new file mode 100644 index 0000000000..a7a0dcfcb2 --- /dev/null +++ b/quantum/bootmagic/bootmagic_full.c @@ -0,0 +1,147 @@ +/* Copyright 2021 QMK + * + * 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 3 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 <stdint.h> +#include <stdbool.h> +#include "wait.h" +#include "matrix.h" +#include "bootloader.h" +#include "debug.h" +#include "keymap.h" +#include "host.h" +#include "action_layer.h" +#include "eeconfig.h" +#include "bootmagic.h" + +/** \brief Scan Keycode + * + * FIXME: needs doc + */ +static bool scan_keycode(uint8_t keycode) { + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + matrix_row_t matrix_row = matrix_get_row(r); + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + if (matrix_row & ((matrix_row_t)1 << c)) { + if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) { + return true; + } + } + } + } + return false; +} + +/** \brief Bootmagic Scan Keycode + * + * FIXME: needs doc + */ +static bool bootmagic_scan_keycode(uint8_t keycode) { + if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false; + + return scan_keycode(keycode); +} + +void bootmagic(void) { + /* do scans in case of bounce */ + print("bootmagic scan: ... "); + uint8_t scan = 100; + while (scan--) { + matrix_scan(); + wait_ms(10); + } + print("done.\n"); + + /* bootmagic skip */ + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) { + return; + } + + /* eeconfig clear */ + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { + eeconfig_init(); + } + + /* bootloader */ + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) { + bootloader_jump(); + } + + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) { + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) { + debug_config.matrix = !debug_config.matrix; + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) { + debug_config.keyboard = !debug_config.keyboard; + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) { + debug_config.mouse = !debug_config.mouse; + } else { + debug_config.enable = !debug_config.enable; + } + } + eeconfig_update_debug(debug_config.raw); + + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) { + keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) { + keymap_config.capslock_to_control = !keymap_config.capslock_to_control; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) { + keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) { + keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) { + keymap_config.no_gui = !keymap_config.no_gui; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) { + keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc; + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) { + keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace; + } + if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) { + keymap_config.nkro = !keymap_config.nkro; + } + eeconfig_update_keymap(keymap_config.raw); + + /* default layer */ + uint8_t default_layer = 0; + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { + default_layer |= (1 << 0); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { + default_layer |= (1 << 1); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { + default_layer |= (1 << 2); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { + default_layer |= (1 << 3); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { + default_layer |= (1 << 4); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { + default_layer |= (1 << 5); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { + default_layer |= (1 << 6); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { + default_layer |= (1 << 7); + } + eeconfig_update_default_layer(default_layer); + + /* EE_HANDS handedness */ + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { + eeconfig_update_handedness(true); + } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) { + eeconfig_update_handedness(false); + } +} diff --git a/quantum/bootmagic/bootmagic_full.h b/quantum/bootmagic/bootmagic_full.h new file mode 100644 index 0000000000..28f914c1b6 --- /dev/null +++ b/quantum/bootmagic/bootmagic_full.h @@ -0,0 +1,115 @@ +/* Copyright 2021 QMK + * + * 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 3 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 + +/* FIXME: Add special doxygen comments for defines here. */ + +/* bootmagic salt key */ +#ifndef BOOTMAGIC_KEY_SALT +# define BOOTMAGIC_KEY_SALT KC_SPACE +#endif + +/* skip bootmagic and eeconfig */ +#ifndef BOOTMAGIC_KEY_SKIP +# define BOOTMAGIC_KEY_SKIP KC_ESC +#endif + +/* eeprom clear */ +#ifndef BOOTMAGIC_KEY_EEPROM_CLEAR +# define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE +#endif + +/* kick up bootloader */ +#ifndef BOOTMAGIC_KEY_BOOTLOADER +# define BOOTMAGIC_KEY_BOOTLOADER KC_B +#endif + +/* debug enable */ +#ifndef BOOTMAGIC_KEY_DEBUG_ENABLE +# define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D +#endif +#ifndef BOOTMAGIC_KEY_DEBUG_MATRIX +# define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X +#endif +#ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD +# define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K +#endif +#ifndef BOOTMAGIC_KEY_DEBUG_MOUSE +# define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M +#endif +#ifndef BOOTMAGIC_KEY_EE_HANDS_LEFT +# define BOOTMAGIC_KEY_EE_HANDS_LEFT KC_L +#endif +#ifndef BOOTMAGIC_KEY_EE_HANDS_RIGHT +# define BOOTMAGIC_KEY_EE_HANDS_RIGHT KC_R +#endif + +/* + * keymap config + */ +#ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK +# define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL +#endif +#ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL +# define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK +#endif +#ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI +# define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT +#endif +#ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI +# define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT +#endif +#ifndef BOOTMAGIC_KEY_NO_GUI +# define BOOTMAGIC_KEY_NO_GUI KC_LGUI +#endif +#ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC +# define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE +#endif +#ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE +# define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH +#endif +#ifndef BOOTMAGIC_HOST_NKRO +# define BOOTMAGIC_HOST_NKRO KC_N +#endif + +/* + * change default layer + */ +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6 +#endif +#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 +# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 +#endif
\ No newline at end of file diff --git a/quantum/bootmagic/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c new file mode 100644 index 0000000000..9cbdcb0bbd --- /dev/null +++ b/quantum/bootmagic/bootmagic_lite.c @@ -0,0 +1,66 @@ +/* Copyright 2021 QMK + * + * 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 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "quantum.h" + +/** \brief Reset eeprom + * + * ...just incase someone wants to only change the eeprom behaviour + */ +__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { +#if defined(VIA_ENABLE) + via_eeprom_reset(); +#else + eeconfig_disable(); +#endif +} + +/** \brief The lite version of TMK's bootmagic based on Wilba. + * + * 100% less potential for accidentally making the keyboard do stupid things. + */ +__attribute__((weak)) void bootmagic_lite(void) { + // We need multiple scans because debouncing can't be turned off. + matrix_scan(); +#if defined(DEBOUNCE) && DEBOUNCE > 0 + wait_ms(DEBOUNCE * 2); +#else + wait_ms(30); +#endif + matrix_scan(); + + // If the configured key (commonly Esc) is held down on power up, + // reset the EEPROM valid state and jump to bootloader. + // This isn't very generalized, but we need something that doesn't + // rely on user's keymaps in firmware or EEPROM. + uint8_t row = BOOTMAGIC_LITE_ROW; + uint8_t col = BOOTMAGIC_LITE_COLUMN; + +#if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) + if (!is_keyboard_left()) { + row = BOOTMAGIC_LITE_ROW_RIGHT; + col = BOOTMAGIC_LITE_COLUMN_RIGHT; + } +#endif + + if (matrix_get_row(row) & (1 << col)) { + bootmagic_lite_reset_eeprom(); + + // Jump to bootloader. + bootloader_jump(); + } +} + +void bootmagic(void) { bootmagic_lite(); } diff --git a/quantum/bootmagic/bootmagic_lite.h b/quantum/bootmagic/bootmagic_lite.h new file mode 100644 index 0000000000..17777e6b4a --- /dev/null +++ b/quantum/bootmagic/bootmagic_lite.h @@ -0,0 +1,25 @@ +/* Copyright 2021 QMK + * + * 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 3 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 + +#ifndef BOOTMAGIC_LITE_COLUMN +# define BOOTMAGIC_LITE_COLUMN 0 +#endif +#ifndef BOOTMAGIC_LITE_ROW +# define BOOTMAGIC_LITE_ROW 0 +#endif + +void bootmagic_lite(void); diff --git a/quantum/bootmagic/magic.c b/quantum/bootmagic/magic.c new file mode 100644 index 0000000000..f1cb11c395 --- /dev/null +++ b/quantum/bootmagic/magic.c @@ -0,0 +1,54 @@ +/* Copyright 2021 QMK + * + * 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 3 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 <stdint.h> +#include <stdbool.h> +#include "wait.h" +#include "matrix.h" +#include "bootloader.h" +#include "debug.h" +#include "keymap.h" +#include "host.h" +#include "action_layer.h" +#include "eeconfig.h" +#include "bootmagic.h" + +keymap_config_t keymap_config; + +__attribute__((weak)) void bootmagic(void) {} + +/** \brief Magic + * + * FIXME: Needs doc + */ +void magic(void) { + /* check signature */ + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + + /* init globals */ + debug_config.raw = eeconfig_read_debug(); + keymap_config.raw = eeconfig_read_keymap(); + + bootmagic(); + + /* read here just incase bootmagic process changed its value */ + layer_state_t default_layer = (layer_state_t)eeconfig_read_default_layer(); + default_layer_set(default_layer); + + /* Also initialize layer state to trigger callback functions for layer_state */ + layer_state_set_kb((layer_state_t)layer_state); +} diff --git a/quantum/bootmagic/magic.h b/quantum/bootmagic/magic.h new file mode 100644 index 0000000000..2c3969b85c --- /dev/null +++ b/quantum/bootmagic/magic.h @@ -0,0 +1,18 @@ +/* Copyright 2021 QMK + * + * 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 3 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 + +void magic(void); diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index f878168c5f..d7e334fdc8 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -37,6 +37,7 @@ typedef union { bool nkro : 1; bool swap_lctl_lgui : 1; bool swap_rctl_rgui : 1; + bool oneshot_disable : 1; }; } keymap_config_t; diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 4f1f06c7ac..39bccdd580 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c @@ -45,10 +45,6 @@ led_eeconfig_t led_matrix_eeconfig; # define LED_DISABLE_WHEN_USB_SUSPENDED false #endif -#ifndef EECONFIG_LED_MATRIX -# define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT -#endif - #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255 # define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 #endif @@ -135,7 +131,7 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; } void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } // Uniform brightness -void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); } +void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); } void led_matrix_custom(void) {} @@ -344,5 +340,3 @@ void led_matrix_set_value(uint8_t val) { led_matrix_set_value_noeeprom(val); eeconfig_update_led_matrix(led_matrix_eeconfig.raw); } - -void backlight_set(uint8_t val) { led_matrix_set_value(val); } diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index 85bae43c15..0817d13573 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h @@ -21,10 +21,6 @@ #include "led_matrix_types.h" -#ifndef BACKLIGHT_ENABLE -# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE -#endif - enum led_matrix_effects { LED_MATRIX_UNIFORM_BRIGHTNESS = 1, // All new effects go above this line diff --git a/quantum/process_keycode/process_backlight.c b/quantum/process_keycode/process_backlight.c index 4d12f6813a..8b70339a55 100644 --- a/quantum/process_keycode/process_backlight.c +++ b/quantum/process_keycode/process_backlight.c @@ -16,11 +16,35 @@ #include "process_backlight.h" -#include "backlight.h" +#ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" +#else +# include "backlight.h" +#endif bool process_backlight(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { +#ifdef LED_MATRIX_ENABLE + case BL_ON: + led_matrix_enable(); + return false; + case BL_OFF: + led_matrix_disable(); + return false; + case BL_DEC: + led_matrix_decrease_val(); + return false; + case BL_INC: + led_matrix_increase_val(); + return false; + case BL_TOGG: + led_matrix_toggle(); + return false; + case BL_STEP: + led_matrix_step(); + return false; +#else case BL_ON: backlight_level(BACKLIGHT_LEVELS); return false; @@ -39,10 +63,11 @@ bool process_backlight(uint16_t keycode, keyrecord_t *record) { case BL_STEP: backlight_step(); return false; -#ifdef BACKLIGHT_BREATHING +# ifdef BACKLIGHT_BREATHING case BL_BRTG: backlight_toggle_breathing(); return false; +# endif #endif } } diff --git a/quantum/quantum.c b/quantum/quantum.c index b40b40544a..8ccdb774bd 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -15,6 +15,7 @@ */ #include "quantum.h" +#include "magic.h" #ifdef BLUETOOTH_ENABLE # include "outputselect.h" @@ -233,7 +234,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif -#ifdef BACKLIGHT_ENABLE +#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) process_backlight(keycode, record) && #endif #ifdef STENO_ENABLE @@ -318,6 +319,17 @@ bool process_record_quantum(keyrecord_t *record) { set_output(OUTPUT_BLUETOOTH); return false; #endif +#ifndef NO_ACTION_ONESHOT + case ONESHOT_TOGGLE: + oneshot_toggle(); + break; + case ONESHOT_ENABLE: + oneshot_enable(); + break; + case ONESHOT_DISABLE: + oneshot_disable(); + break; +#endif } } @@ -341,26 +353,20 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_ 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 matrix_init_quantum() { -#ifdef BOOTMAGIC_LITE - bootmagic_lite(); -#endif - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } + magic(); #if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) // TODO: remove calls to led_init_ports from keyboards and remove ifdef led_init_ports(); #endif #ifdef BACKLIGHT_ENABLE -# ifdef LED_MATRIX_ENABLE - led_matrix_init(); -# else backlight_init_ports(); -# endif #endif #ifdef AUDIO_ENABLE audio_init(); #endif +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif #ifdef RGB_MATRIX_ENABLE rgb_matrix_init(); #endif diff --git a/quantum/quantum.h b/quantum/quantum.h index e24a4c43a3..fe6bf310aa 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -30,11 +30,11 @@ #include "keymap.h" #ifdef BACKLIGHT_ENABLE -# ifdef LED_MATRIX_ENABLE -# include "led_matrix.h" -# else -# include "backlight.h" -# endif +# include "backlight.h" +#endif + +#ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" #endif #if defined(RGBLIGHT_ENABLE) @@ -52,6 +52,7 @@ #include "action_layer.h" #include "eeconfig.h" #include "bootloader.h" +#include "bootmagic.h" #include "timer.h" #include "sync_timer.h" #include "config_common.h" @@ -97,7 +98,7 @@ extern layer_state_t layer_state; # include "process_music.h" #endif -#ifdef BACKLIGHT_ENABLE +#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) # include "process_backlight.h" #endif @@ -199,39 +200,6 @@ extern layer_state_t layer_state; # include "usbpd.h" #endif -// Function substitutions to ease GPIO manipulation -#if defined(__AVR__) - -/* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. - * But here's more margin to make it two clocks. */ -# if !defined(GPIO_INPUT_PIN_DELAY) -# define GPIO_INPUT_PIN_DELAY 2 -# endif -# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) - -#elif defined(__ARMEL__) || defined(__ARMEB__) - -/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus - * to which the GPIO is connected. - * The connected buses differ depending on the various series of MCUs. - * And since the instruction execution clock of the CPU and the bus clock of GPIO are different, - * there is a delay of several clocks to read the change of the input signal. - * - * Define this delay with the GPIO_INPUT_PIN_DELAY macro. - * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used. - * (A fairly large value of 0.25 microseconds is set.) - */ -# if !defined(GPIO_INPUT_PIN_DELAY) -# if defined(STM32_SYSCLK) -# define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4) -# elif defined(KINETIS_SYSCLK_FREQUENCY) -# define GPIO_INPUT_PIN_DELAY (KINETIS_SYSCLK_FREQUENCY / 1000000L / 4) -# endif -# endif -# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) - -#endif - // For tri-layer void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); @@ -256,15 +224,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record); void post_process_record_kb(uint16_t keycode, keyrecord_t *record); void post_process_record_user(uint16_t keycode, keyrecord_t *record); -#ifndef BOOTMAGIC_LITE_COLUMN -# define BOOTMAGIC_LITE_COLUMN 0 -#endif -#ifndef BOOTMAGIC_LITE_ROW -# define BOOTMAGIC_LITE_ROW 0 -#endif - -void bootmagic_lite(void); - void reset_keyboard(void); void startup_user(void); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 1863a79434..dab9ba3d71 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -569,6 +569,10 @@ enum quantum_keycodes { #endif + ONESHOT_ENABLE, + ONESHOT_DISABLE, + ONESHOT_TOGGLE, + // always leave at the end SAFE_RANGE }; @@ -676,16 +680,13 @@ enum quantum_keycodes { #define KC_DELT KC_DELETE // Del key (four letter code) -// Alias for function layers than expand past FN31 -#define FUNC(kc) (QK_FUNCTION | (kc)) - // Aliases #define C(kc) LCTL(kc) #define S(kc) LSFT(kc) #define A(kc) LALT(kc) #define G(kc) LGUI(kc) -#define F(kc) FUNC(kc) +#define F(kc) (QK_FUNCTION | (kc)) #define M(kc) (QK_MACRO | (kc)) #define MACROTAP(kc) (QK_MACRO | (FUNC_TAP << 8) | (kc)) @@ -870,3 +871,8 @@ enum quantum_keycodes { #define DM_RSTP DYN_REC_STOP #define DM_PLY1 DYN_MACRO_PLAY1 #define DM_PLY2 DYN_MACRO_PLAY2 + +// One Shot toggle +#define OS_TOGG ONESHOT_TOGGLE +#define OS_ON ONESHOT_ENABLE +#define OS_OFF ONESHOT_DISABLE diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index ec17b4d72c..8aae486034 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -131,7 +131,7 @@ last_hit_t g_last_hit_tracker; // internals static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX; -static effect_params_t rgb_effect_params = {0, 0xFF}; +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; @@ -143,6 +143,11 @@ static uint32_t rgb_timer_buffer; static last_hit_t last_hit_buffer; #endif // RGB_MATRIX_KEYREACTIVE_ENABLED +// split rgb matrix +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; +#endif + void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } @@ -153,6 +158,7 @@ void eeconfig_update_rgb_matrix_default(void) { rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; + rgb_matrix_config.flags = LED_FLAG_ALL; eeconfig_update_rgb_matrix(); } @@ -164,6 +170,7 @@ void eeconfig_debug_rgb_matrix(void) { dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); + 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; } @@ -180,9 +187,22 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l 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) { +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + if (!is_keyboard_left() && index >= k_rgb_matrix_split[0]) + rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue); + else if (is_keyboard_left() && index < k_rgb_matrix_split[0]) +#endif + rgb_matrix_driver.set_color(index, red, green, blue); +} -void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(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); +#else + rgb_matrix_driver.set_color_all(red, green, blue); +#endif +} void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { #ifndef RGB_MATRIX_SPLIT @@ -315,6 +335,10 @@ static void rgb_task_start(void) { static void rgb_task_render(uint8_t effect) { bool rendering = false; rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); + if (rgb_effect_params.flags != rgb_matrix_config.flags) { + rgb_effect_params.flags = rgb_matrix_config.flags; + rgb_matrix_set_color_all(0, 0, 0); + } // each effect can opt to do calculations // and/or request PWM buffer updates. @@ -618,6 +642,6 @@ void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_spe 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_effect_params.flags; } +led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; } -void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } +void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h index 7b8171fb23..1a37922af9 100644 --- a/quantum/rgb_matrix_types.h +++ b/quantum/rgb_matrix_types.h @@ -85,10 +85,11 @@ typedef struct PACKED { typedef union { uint32_t raw; struct PACKED { - uint8_t enable : 2; - uint8_t mode : 6; - HSV hsv; - uint8_t speed; // EECONFIG needs to be increased to support this + uint8_t enable : 2; + uint8_t mode : 6; + HSV hsv; + uint8_t speed; // EECONFIG needs to be increased to support this + led_flags_t flags; }; } rgb_config_t; diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 2ae44e6e15..9e75e19ce0 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -1,3 +1,18 @@ +/* Copyright 2021 QMK + * + * 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 3 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 "split_util.h" #include "matrix.h" #include "keyboard.h" @@ -6,14 +21,7 @@ #include "transport.h" #include "quantum.h" #include "wait.h" - -#ifdef PROTOCOL_LUFA -# include <LUFA/Drivers/USB/USB.h> -#endif - -#ifdef PROTOCOL_VUSB -# include <usbdrv/usbdrv.h> -#endif +#include "usb_util.h" #ifdef EE_HANDS # include "eeconfig.h" @@ -31,56 +39,21 @@ # define SPLIT_USB_TIMEOUT_POLL 10 #endif -#ifdef PROTOCOL_CHIBIOS -# define SPLIT_USB_DETECT // Force this on for now -#endif - volatile bool isLeftHand = true; #if defined(SPLIT_USB_DETECT) -# if defined(PROTOCOL_LUFA) -static inline bool usbHasActiveConnection(void) { return USB_Device_IsAddressSet(); } -static inline void usbDisable(void) { - USB_Disable(); - USB_DeviceState = DEVICE_STATE_Unattached; -} -# elif defined(PROTOCOL_CHIBIOS) -static inline bool usbHasActiveConnection(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; } -static inline void usbDisable(void) { usbStop(&USBD1); } -# elif defined(PROTOCOL_VUSB) -static inline bool usbHasActiveConnection(void) { - usbPoll(); - return usbConfiguration; -} -static inline void usbDisable(void) { usbDeviceDisconnect(); } -# else -static inline bool usbHasActiveConnection(void) { return true; } -static inline void usbDisable(void) {} -# endif - -bool usbIsActive(void) { +static bool usbIsActive(void) { for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { // This will return true if a USB connection has been established - if (usbHasActiveConnection()) { + if (usb_connected_state()) { return true; } wait_ms(SPLIT_USB_TIMEOUT_POLL); } - - // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow - usbDisable(); - return false; } -#elif defined(PROTOCOL_LUFA) && defined(OTGPADE) -static inline bool usbIsActive(void) { - USB_OTGPAD_On(); // enables VBUS pad - wait_us(5); - - return USB_VBUS_GetStatus(); // checks state of VBUS -} #else -static inline bool usbIsActive(void) { return true; } +static inline bool usbIsActive(void) { return usb_vbus_state(); } #endif #ifdef SPLIT_HAND_MATRIX_GRID @@ -126,6 +99,11 @@ __attribute__((weak)) bool is_keyboard_master(void) { // only check once, as this is called often if (usbstate == UNKNOWN) { usbstate = usbIsActive() ? MASTER : SLAVE; + + // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow + if (usbstate == SLAVE) { + usb_disable(); + } } return (usbstate == MASTER); diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 61b61ea08c..27a1c0d3a4 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -22,6 +22,10 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; # define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) #endif +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +# include "rgb_matrix.h" +#endif + #if defined(USE_I2C) # include "i2c_master.h" @@ -54,6 +58,10 @@ typedef struct _I2C_slave_buffer_t { # ifdef WPM_ENABLE uint8_t current_wpm; # endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + rgb_config_t rgb_matrix; + bool rgb_suspend_state; +# endif } I2C_slave_buffer_t; static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; @@ -68,6 +76,8 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) +# define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix) +# define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state) # define TIMEOUT 100 @@ -141,6 +151,11 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) # endif # endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT); + i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT); +# endif + # ifndef DISABLE_SYNC_TIMER i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); @@ -186,6 +201,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) set_oneshot_mods(i2c_buffer->oneshot_mods); # endif # endif + +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix)); + memcpy((void *)i2c_buffer->rgb_suspend_state, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state)); +# endif } void transport_master_init(void) { i2c_init(); } @@ -226,6 +246,10 @@ typedef struct _Serial_m2s_buffer_t { # ifdef WPM_ENABLE uint8_t current_wpm; # endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + rgb_config_t rgb_matrix; + bool rgb_suspend_state; +# endif } Serial_m2s_buffer_t; # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) @@ -333,18 +357,24 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) # ifdef WPM_ENABLE // Write wpm to slave - serial_m2s_buffer.current_wpm = get_current_wpm(); + serial_m2s_buffer.current_wpm = get_current_wpm(); # endif # ifdef SPLIT_MODS_ENABLE - serial_m2s_buffer.real_mods = get_mods(); - serial_m2s_buffer.weak_mods = get_weak_mods(); + serial_m2s_buffer.real_mods = get_mods(); + serial_m2s_buffer.weak_mods = get_weak_mods(); # ifndef NO_ACTION_ONESHOT - serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); + serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); # endif # endif + +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + serial_m2s_buffer.rgb_matrix = rgb_matrix_config; + serial_m2s_buffer.rgb_suspend_state = g_suspend_state; +# endif + # ifndef DISABLE_SYNC_TIMER - serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; + serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; # endif return true; } @@ -381,6 +411,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) set_oneshot_mods(serial_m2s_buffer.oneshot_mods); # endif # endif + +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + rgb_matrix_config = serial_m2s_buffer.rgb_matrix; + g_suspend_state = serial_m2s_buffer.rgb_suspend_state; +# endif } #endif |