From d03bc3a9c185f97d3813758e7f6df7c879f42ad0 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Fri, 5 Jun 2020 05:01:47 -0400 Subject: [PATCH] Major enhancements to spidey3 keymaps and userspace (#9261) * Add Chrome OS specific keys to 75_ansi/spidey3 * Clean up duplicative settings in rules.mk * Refactor spidey3 userspace to use rgb layer blink * Blink green on wakeup * Improve _FN layer indicator * Glyph transformation modes: wide, script, fraktur, and enclosed characters * Add spider unicode glyph * Fix compile error when NO_ACTION_ONESHOT * Add a few more emoji * Further refinement of lighting layer usage * Fix reversed yes/no ack * Lighting layers override RGB off * Fix missing wide and incorrect script numbers * Add LOL and surprise emoji * Add missing break in switch statement * Trim firmware size * Use usage ID definitions in report.h * Some minor whitespace cleanup * Disable some unused features to reduce firmware size * Print version on startup * Seed rand() on first keystroke * Add a key to immediately sleep CrOS * Switch to Bootmagic Lite * Trim down firmware size a little bit more * Make RGBLIGHT_MODE_TWINKLE+4 my default * Scan rate debug / fix version printing Delay printing version on startup (console may not be ready) Better scan rate reporting * Disable locking caps, etc. to save more space * Enable LTO * Better seed for rand() * Set MAX_LAYER for some performance improvement * Another scan rate improvement * Set manufacturer * New startup animation * Add GUI lock for F-keys (for CrOS) * Add visual indication for glyph replacement and F-keys GUI lock * Some cleanup; run cformat on spidey3 userspace * Cycle between debug verbosity options * Fix disable RGB Lighting after wakeup on Mac --- layouts/community/75_ansi/spidey3/config.h | 9 + layouts/community/75_ansi/spidey3/keymap.c | 9 +- layouts/community/75_ansi/spidey3/rules.mk | 8 +- users/spidey3/config.h | 18 ++ users/spidey3/init.c | 20 +- users/spidey3/layer_rgb.c | 301 ++++++++++++++++----- users/spidey3/rules.mk | 2 + users/spidey3/spidey3.c | 289 ++++++++++++++++---- users/spidey3/spidey3.h | 72 +++-- users/spidey3/unicode.c | 30 +- users/spidey3/unicode.h | 13 +- 11 files changed, 588 insertions(+), 183 deletions(-) create mode 100644 layouts/community/75_ansi/spidey3/config.h diff --git a/layouts/community/75_ansi/spidey3/config.h b/layouts/community/75_ansi/spidey3/config.h new file mode 100644 index 00000000000..7fe098f0e8a --- /dev/null +++ b/layouts/community/75_ansi/spidey3/config.h @@ -0,0 +1,9 @@ +#pragma once + +#define NO_ACTION_ONESHOT +#define NO_ACTION_MACRO +#define NO_ACTION_FUNCTION +#undef LOCKING_SUPPORT_ENABLE + +#define LAYER_STATE_8BIT +#define MAX_LAYER 4 diff --git a/layouts/community/75_ansi/spidey3/keymap.c b/layouts/community/75_ansi/spidey3/keymap.c index fbb6a980621..aaa93ee2d02 100644 --- a/layouts/community/75_ansi/spidey3/keymap.c +++ b/layouts/community/75_ansi/spidey3/keymap.c @@ -1,6 +1,5 @@ #include "spidey3.h" -#define CH_MENU A(S(KC_S)) #define OSX_PSC G(S(KC_4)) #define FN_MENU LT(_FN,KC_APP) @@ -34,11 +33,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // FN [_FN] = LAYOUT_75_ansi( - RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_SLEP, KC_WAKE, KC_PWR, - EEP_RST, _______, _______, _______, _______, _______, _______, _______, X_BUL, KC_MPRV, KC_MNXT, X_DASH, _______, KC_PAUS, KC_SLCK, + RESET, SPI_NORMAL, SPI_WIDE, SPI_SCRIPT, SPI_BLOCKS, SPI_CIRCLE, SPI_SQUARE, SPI_PARENS, SPI_FRAKTR, _______, _______, _______, SPI_GFLOCK, KC_SLEP, KC_WAKE, KC_PWR, + EEP_RST, X(SAD), X(MEH), X(HAPPY), X(ANGRY), X(THUMBDN), X(THUMBUP), X(SPIDER), X_BUL, X(LOL), X(SURPRISE),X_DASH, _______, KC_PAUS, KC_SLCK, _______, RGB_TOG, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, RGB_SPD, RGB_SPI, VLK_TOG, _______, _______, KC_BRIU, _______, RGB_M_P, RGB_M_B, RGB_M_R, RGB_M_SW, RGB_M_SN, RGB_M_K, RGB_M_G, RGB_M_T, SPI_LNX, _______, _______, _______, KC_BRID, - _______, SPI_GLO, _______, SPI_WIN, _______, NK_TOGG, TG(_NUMPAD),SPI_OSX, X(LARR), X(RARR), DEBUG, _______, KC_VOLU, KC_MUTE, - _______, _______, _______, KC_MPLY, KC_APP, _______, CH_MENU, KC_MPRV, KC_VOLD, KC_MNXT + _______, SPI_GLO, CH_SUSP, SPI_WIN, _______, NK_TOGG, TG(_NUMPAD),SPI_OSX, X(LARR), X(RARR), DEBUG, _______, KC_VOLU, KC_MUTE, + _______, _______, _______, KC_MPLY, CH_ASST, _______, CH_CPNL, KC_MPRV, KC_VOLD, KC_MNXT ) }; diff --git a/layouts/community/75_ansi/spidey3/rules.mk b/layouts/community/75_ansi/spidey3/rules.mk index fdb44b3ea55..7d5c56841e0 100644 --- a/layouts/community/75_ansi/spidey3/rules.mk +++ b/layouts/community/75_ansi/spidey3/rules.mk @@ -1,18 +1,12 @@ # Build Options # comment out to disable the options. # -BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration MOUSEKEY_ENABLE = no # Mouse keys -EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = yes # Console for debug -COMMAND_ENABLE = no # Commands for debug and configuration -SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend -NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -AUDIO_ENABLE = no -RGBLIGHT_ENABLE = yes UNICODEMAP_ENABLE = yes VELOCIKEY_ENABLE = yes +GRAVE_ESC_ENABLE = no # The following disabled to save space SPACE_CADET_ENABLE = no diff --git a/users/spidey3/config.h b/users/spidey3/config.h index 9da7f553025..053240718e6 100644 --- a/users/spidey3/config.h +++ b/users/spidey3/config.h @@ -3,3 +3,21 @@ #define LED_DISABLE_WHEN_USB_SUSPENDED true #define RGB_DISABLE_WHEN_USB_SUSPENDED true #define RGBLIGHT_LAYERS +#define RGBLIGHT_MAX_LAYERS 16 +#define RGBLIGHT_LAYER_BLINK +#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF + +#undef RGBLIGHT_ANIMATIONS +#define RGBLIGHT_EFFECT_BREATHING +#define RGBLIGHT_EFFECT_RAINBOW_MOOD +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL +#define RGBLIGHT_EFFECT_SNAKE +#define RGBLIGHT_EFFECT_KNIGHT +#define RGBLIGHT_EFFECT_STATIC_GRADIENT +#define RGBLIGHT_EFFECT_ALTERNATING +#define RGBLIGHT_EFFECT_TWINKLE + +#define SPI_DEBUG_SCAN_RATE + +#undef MANUFACTURER +#define MANUFACTURER Window of Fire diff --git a/users/spidey3/init.c b/users/spidey3/init.c index b9239460934..273c2b28992 100644 --- a/users/spidey3/init.c +++ b/users/spidey3/init.c @@ -1,30 +1,28 @@ #include "spidey3.h" void keyboard_post_init_user(void) { - print("keyboard_post_init_user\n"); - uprintf("\tdebug_enable=%u\n", debug_enable); #ifdef RGBLIGHT_ENABLE - keyboard_post_init_user_rgb(); + keyboard_post_init_user_rgb(); #endif } void eeconfig_init_user(void) { - print("eeconfig_init_user\n"); - set_single_persistent_default_layer(_BASE); + print("eeconfig_init_user\n"); + set_single_persistent_default_layer(_BASE); #ifdef UNICODEMAP_ENABLE - eeconfig_init_user_unicode(); + eeconfig_init_user_unicode(); #endif #ifdef RGBLIGHT_ENABLE - eeconfig_init_user_rgb(); + eeconfig_init_user_rgb(); #endif } void shutdown_user() { #ifdef RGBLIGHT_ENABLE - clear_rgb_layers(); - rgblight_enable(); - rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); - rgblight_sethsv_noeeprom(HSV_RED); + clear_rgb_layers(); + rgblight_enable(); + rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); + rgblight_sethsv_noeeprom(HSV_RED); #endif } diff --git a/users/spidey3/layer_rgb.c b/users/spidey3/layer_rgb.c index 75e66384e27..160cc43174d 100644 --- a/users/spidey3/layer_rgb.c +++ b/users/spidey3/layer_rgb.c @@ -5,127 +5,280 @@ uint32_t rgb_mode; uint16_t rgb_hue; -uint8_t rgb_sat; -uint8_t rgb_val; -bool rgb_saved = 0; +uint8_t rgb_sat; +uint8_t rgb_val; +bool rgb_saved = 0; -void spidey_swirl(void) { - dprint("Setting Spidey Swirl!\n"); - rgblight_enable(); - rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL); - rgblight_sethsv(213, 255, 128); +void spidey_glow(void) { + rgblight_enable(); + rgblight_mode(RGBLIGHT_MODE_TWINKLE + 4); + rgblight_sethsv(213, 255, 128); #ifdef VELOCIKEY_ENABLE - if (!velocikey_enabled()) - velocikey_toggle(); + if (velocikey_enabled()) velocikey_toggle(); #endif } -void eeconfig_init_user_rgb(void) -{ - spidey_swirl(); -} +void eeconfig_init_user_rgb(void) { spidey_glow(); } -const rgblight_segment_t PROGMEM _capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( {0, 2, HSV_AZURE}, {14, 2, HSV_AZURE} ); -const rgblight_segment_t PROGMEM _layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( {7, 1, HSV_PURPLE} ); -const rgblight_segment_t PROGMEM _layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 3, HSV_MAGENTA} ); -const rgblight_segment_t PROGMEM _layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 1, HSV_GREEN} ); -const rgblight_segment_t PROGMEM _yes_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_GREEN} ); -const rgblight_segment_t PROGMEM _no_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_RED} ); +// clang-format off + +// Convenience macros +#define CORNER_BL(color) { 0, 1, color } +#define CORNER_BR(color) { RGBLED_NUM / 2 - 1, 1, color } +#define CORNER_FR(color) { RGBLED_NUM / 2, 1, color } +#define CORNER_FL(color) { RGBLED_NUM - 1, 1, color } +#define CORNERS(color) {0, 1, color}, {RGBLED_NUM / 2 - 1, 2, color}, { RGBLED_NUM - 1, 1, color } +#define FRONT(inset, color) { RGBLED_NUM / 2 + inset, RGBLED_NUM / 2 - 2 * inset, color } +#define BACK(inset, color) { inset, RGBLED_NUM / 2 - 2 * inset, color } + +#define LAYER_OFFSET 0 +const rgblight_segment_t PROGMEM _layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(CORNER_BR(HSV_PURPLE)); +const rgblight_segment_t PROGMEM _layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(CORNERS(HSV_MAGENTA)); +const rgblight_segment_t PROGMEM _layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(CORNERS(HSV_GREEN)); + +#define LOCK_OFFSET 3 +const rgblight_segment_t PROGMEM _numlock_layer[] = RGBLIGHT_LAYER_SEGMENTS(FRONT(3, HSV_YELLOW)); +const rgblight_segment_t PROGMEM _capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(CORNER_FL(HSV_AZURE)); +const rgblight_segment_t PROGMEM _scrolllock_layer[] = RGBLIGHT_LAYER_SEGMENTS(CORNER_FR(HSV_ORANGE)); + +#define MISC_OFFSET 6 +const rgblight_segment_t PROGMEM _gflock_layer[] = RGBLIGHT_LAYER_SEGMENTS(BACK(1, HSV_ORANGE)); +const rgblight_segment_t PROGMEM _glyphreplace_layer[] = RGBLIGHT_LAYER_SEGMENTS(FRONT(1, HSV_ORANGE)); + +#define ACK_OFFSET 8 +const rgblight_segment_t PROGMEM _no_layer[] = RGBLIGHT_LAYER_SEGMENTS(FRONT(1, HSV_RED)); +const rgblight_segment_t PROGMEM _yes_layer[] = RGBLIGHT_LAYER_SEGMENTS(FRONT(1, HSV_GREEN)); +const rgblight_segment_t PROGMEM _meh_layer[] = RGBLIGHT_LAYER_SEGMENTS(FRONT(1, HSV_YELLOW)); + +// Now define the array of layers. Higher numbered layers take precedence. +const rgblight_segment_t *const PROGMEM _rgb_layers[] = { + [LAYER_OFFSET + 0] = _layer1_layer, + [LAYER_OFFSET + 1] = _layer2_layer, + [LAYER_OFFSET + 2] = _layer3_layer, + + [LOCK_OFFSET + USB_LED_NUM_LOCK] = _numlock_layer, + [LOCK_OFFSET + USB_LED_CAPS_LOCK] = _capslock_layer, + [LOCK_OFFSET + USB_LED_SCROLL_LOCK] = _scrolllock_layer, + + [MISC_OFFSET + 0] = _gflock_layer, + [MISC_OFFSET + 1] = _glyphreplace_layer, + + [ACK_OFFSET + ACK_NO] = _no_layer, + [ACK_OFFSET + ACK_YES] = _yes_layer, + [ACK_OFFSET + ACK_MEH] = _meh_layer, + + [ACK_OFFSET + ACK_MEH + 1] = NULL +}; + +// clang-format on -// Now define the array of layers. Later layers take precedence -const rgblight_segment_t* const PROGMEM _rgb_layers[] = - RGBLIGHT_LAYERS_LIST( _capslock_layer, _layer1_layer, _layer2_layer, _layer3_layer, _yes_layer, _no_layer ); const uint8_t PROGMEM _n_rgb_layers = sizeof(_rgb_layers) / sizeof(_rgb_layers[0]) - 1; void clear_rgb_layers() { - for (uint8_t i=0; i<_n_rgb_layers; i++) { + dprint("clear_rgb_layers()\n"); + for (uint8_t i = 0; i < _n_rgb_layers; i++) { rgblight_set_layer_state(i, false); } } void do_rgb_layers(layer_state_t state, uint8_t start, uint8_t end) { - dprint("do_rgb_layers()\n"); - for (uint8_t i=start; i 0; i -= STARTUP_ANIMATION_STEP) { + rgblight_sethsv_noeeprom((i + old_hue) % 255, STARTUP_ANIMATION_SATURATION, STARTUP_ANIMATION_VALUE); + matrix_scan(); + wait_ms(10); + } + + if (ramp_down) { + dprintln("ramp_down"); + for (uint8_t i = STARTUP_ANIMATION_VALUE; i > 0; i -= STARTUP_ANIMATION_STEP) { + rgblight_sethsv_noeeprom(old_hue, STARTUP_ANIMATION_SATURATION, i); + matrix_scan(); + wait_ms(10); + } + } else if (ramp_to) { + dprintf("ramp_to s=%u, v=%u\n", old_sat, old_val); + uint8_t steps = 50; + for (uint8_t i = 0; i < steps; i++) { + uint8_t s = STARTUP_ANIMATION_SATURATION + i * (((float)old_sat - STARTUP_ANIMATION_SATURATION) / (float)steps); + uint8_t v = STARTUP_ANIMATION_VALUE + i * (((float)old_val - STARTUP_ANIMATION_VALUE) / (float)steps); + rgblight_sethsv_noeeprom(old_hue, s, v); + matrix_scan(); + wait_ms(10); + } + } + rgblight_mode_noeeprom(old_mode); + } + if (is_enabled) { + rgblight_sethsv_noeeprom(old_hue, old_sat, old_val); + } else { + rgblight_disable_noeeprom(); + // Hack! + // rgblight_sethsv_noeeprom() doesn't update these if rgblight is disabled, + // but if do it before disabling we get an ugly flash. + rgblight_config.hue = old_hue; + rgblight_config.sat = old_sat; + rgblight_config.val = old_val; + } + dprint("done\n"); + startup_animation_done = true; + } } layer_state_t default_layer_state_set_user_rgb(layer_state_t state) { - dprint("default_layer_state_set_user_rgb()\n"); - do_rgb_layers(state, 1u, RGB_LAYER_BASE_REGULAR); + do_rgb_layers(state, 1u, LAYER_BASE_REGULAR); return state; } layer_state_t layer_state_set_user_rgb(layer_state_t state) { - dprint("layer_state_set_user_rgb()\n"); - do_rgb_layers(state, RGB_LAYER_BASE_REGULAR, RGB_LAYER_BASE_ACKS); + do_rgb_layers(state, LAYER_BASE_REGULAR, LAYER_BASE_END); return state; } bool led_update_user_rgb(led_t led_state) { - dprintf("caps_lock=%u\n", led_state.caps_lock); - rgblight_set_layer_state(0, led_state.caps_lock); + dprintf("num=%u, cap=%u, scl=%u, cmp=%u, kan=%u\n", led_state.num_lock, led_state.caps_lock, led_state.scroll_lock, led_state.compose, led_state.kana); + + rgblight_set_layer_state(LOCK_OFFSET + USB_LED_NUM_LOCK, led_state.num_lock); + rgblight_set_layer_state(LOCK_OFFSET + USB_LED_CAPS_LOCK, led_state.caps_lock); + rgblight_set_layer_state(LOCK_OFFSET + USB_LED_SCROLL_LOCK, led_state.scroll_lock); + return true; } -void rgb_layer_ack(bool yn, bool pressed) { - uint8_t layer = RGB_LAYER_BASE_ACKS + (yn ? 0 : 1); - rgblight_set_layer_state(layer, pressed); +void rgb_layer_ack_yn(bool yn) { rgb_layer_ack(yn ? ACK_YES : ACK_NO); } + +void rgb_layer_ack(layer_ack_t n) { + uint8_t layer = ACK_OFFSET + n; + dprintf("rgb_layer_ack(%u) ==> %u\n", n, layer); + rgblight_blink_layer(layer, RGB_LAYER_ACK_DURATION); } -extern keymap_config_t keymap_config; +extern keymap_config_t keymap_config; +extern rgblight_config_t rgblight_config; + +extern bool spi_gflock; +extern uint16_t spi_replace_mode; bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { - bool pressed = record->event.pressed; + if (record->event.pressed) { + switch (keycode) { + case SPI_GLO: + spidey_glow(); + return false; + } + } - switch (keycode) { - case SPI_GLO: - if (pressed) { - spidey_swirl(); - } - return false; + return true; +} - // Acks follow... - case DEBUG: - rgb_layer_ack(debug_enable, pressed); - return false; +void post_process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + // Acks follow... + case DEBUG: + rgb_layer_ack_yn(debug_enable); + break; - case SPI_LNX: - case SPI_OSX: - case SPI_WIN: - rgb_layer_ack(true, pressed); - return false; + case SPI_LNX: + case SPI_OSX: + case SPI_WIN: + rgb_layer_ack(ACK_MEH); + break; - // Tricky! - // For these, on press the toggle hasn't happened yet, - // so we need a little logic to invert, assuming that - // on key press the flag WILL be toggled, and on key - // release the flag has already been toggled. + case SPI_GFLOCK: + rgb_layer_ack_yn(spi_gflock); + rgblight_set_layer_state(MISC_OFFSET + 0, spi_gflock); + break; + + case SPI_NORMAL ... SPI_FRAKTR: + rgb_layer_ack_yn(spi_replace_mode != SPI_NORMAL); + rgblight_set_layer_state(MISC_OFFSET + 1, spi_replace_mode != SPI_NORMAL); + break; + + case RGB_TOG: + rgb_layer_ack_yn(rgblight_config.enable); + break; #ifdef VELOCIKEY_ENABLE - case VLK_TOG: - rgb_layer_ack(pressed != velocikey_enabled(), pressed); - return true; + case VLK_TOG: + rgb_layer_ack_yn(velocikey_enabled()); + break; #endif #ifdef NKRO_ENABLE - case NK_TOGG: - case NK_ON: - case NK_OFF: - rgb_layer_ack(pressed != keymap_config.nkro, pressed); - return true; + case NK_TOGG: + case NK_ON: + case NK_OFF: + rgb_layer_ack_yn(keymap_config.nkro); + break; #endif - } - - return true; + } } diff --git a/users/spidey3/rules.mk b/users/spidey3/rules.mk index 0a77d2bfc76..2d4da22946c 100644 --- a/users/spidey3/rules.mk +++ b/users/spidey3/rules.mk @@ -1,3 +1,5 @@ +BOOTMAGIC_ENABLE = lite +LTO_ENABLE = yes SRC += init.c SRC += spidey3.c diff --git a/users/spidey3/spidey3.c b/users/spidey3/spidey3.c index 8be99dea046..9d696494f74 100644 --- a/users/spidey3/spidey3.c +++ b/users/spidey3/spidey3.c @@ -1,80 +1,267 @@ #include QMK_KEYBOARD_H #include "spidey3.h" +#include "version.h" +#include + +static bool rand_seeded = false; + +uint16_t spi_replace_mode = SPI_NORMAL; +bool spi_gflock = false; + +#if defined(CONSOLE_ENABLE) && !defined(NO_DEBUG) +static uint32_t matrix_scan_count = 0; +static bool reported_version = false; + +# if defined(SPI_DEBUG_SCAN_RATE) +static uint32_t matrix_timer = 0; +static uint32_t last_matrix_scan_count = 0; +# endif + +void matrix_scan_user(void) { +# if defined(SPI_DEBUG_SCAN_RATE) + matrix_scan_count++; + if (debug_enable) { + uint32_t timer_now = timer_read32(); + if (matrix_timer == 0) { + matrix_timer = timer_now; + last_matrix_scan_count = matrix_scan_count; + matrix_scan_count = 0; + } else if (TIMER_DIFF_32(timer_now, matrix_timer) > SPI_SCAN_RATE_INTERVAL * 1000) { + matrix_timer = timer_now; + last_matrix_scan_count = matrix_scan_count; + matrix_scan_count = 0; + if (!reported_version) { + uprintln(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE); + reported_version = true; + } + uprintf("scan rate: %lu/s\n", last_matrix_scan_count / SPI_SCAN_RATE_INTERVAL); + } + } +# else + if (!reported_version) { + matrix_scan_count++; + if (matrix_scan_count > 300) { + uprintln(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE); + reported_version = true; + } + } +# endif +} +#endif + +bool process_record_glyph_replacement(uint16_t keycode, keyrecord_t *record, uint32_t baseAlphaLower, uint32_t baseAlphaUpper, uint32_t zeroGlyph, uint32_t baseNumberOne, uint32_t spaceGlyph) { + uint8_t temp_mod = get_mods(); +#ifndef NO_ACTION_ONESHOT + uint8_t temp_osm = get_oneshot_mods(); +#else + uint8_t temp_osm = 0; +#endif + if ((((temp_mod | temp_osm) & (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI))) == 0) { + switch (keycode) { + case KC_A ... KC_Z: + if (record->event.pressed) { + clear_mods(); +#ifndef NO_ACTION_ONESHOT + clear_oneshot_mods(); +#endif + + unicode_input_start(); + uint32_t base = ((temp_mod | temp_osm) & MOD_MASK_SHIFT) ? baseAlphaUpper : baseAlphaLower; + register_hex32(base + (keycode - KC_A)); + unicode_input_finish(); + + set_mods(temp_mod); + } + return false; + case KC_0: + if ((temp_mod | temp_osm) & MOD_MASK_SHIFT) { // skip shifted numbers, so that we can still use symbols etc. + return true; + } + if (record->event.pressed) { + unicode_input_start(); + register_hex32(zeroGlyph); + unicode_input_finish(); + } + return false; + case KC_1 ... KC_9: + if ((temp_mod | temp_osm) & MOD_MASK_SHIFT) { // skip shifted numbers, so that we can still use symbols etc. + return true; + } + if (record->event.pressed) { + unicode_input_start(); + register_hex32(baseNumberOne + (keycode - KC_1)); + unicode_input_finish(); + } + return false; + case KC_SPACE: + if (record->event.pressed) { + unicode_input_start(); + register_hex32(spaceGlyph); // em space + unicode_input_finish(); + } + return false; + } + } + + return true; +} + +bool process_gflock(uint16_t keycode, keyrecord_t *record) { + if (!spi_gflock) { + return true; + } + + if (record->event.pressed) { + register_code16(G(keycode)); + } else { + unregister_code16(G(keycode)); + } + return false; +} bool process_record_user(uint16_t keycode, keyrecord_t *record) { - -// If console is enabled, it will print the matrix position and status of each key pressed -// dprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); - - if (record->event.pressed) { - switch (keycode) { -#ifndef NO_DEBUG - // Re-implement this here, but fix the persistence! - case DEBUG: - debug_enable ^= 1; - if (debug_enable) { - print("DEBUG: enabled.\n"); - } else { - print("DEBUG: disabled.\n"); - } - eeconfig_update_debug(debug_config.raw); -#endif - break; - case SPI_LNX: - dprint("SPI_LNX\n"); - set_single_persistent_default_layer(_BASE); - layer_off(_OSX); -#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) - set_unicode_input_mode(UC_LNX); -#endif - break; - case SPI_OSX: - dprint("SPI_OSX\n"); - set_single_persistent_default_layer(_OSX); -#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) - set_unicode_input_mode(UC_OSX); -#endif - break; - case SPI_WIN: - dprint("SPI_WIN\n"); - set_single_persistent_default_layer(_BASE); - layer_off(_OSX); -#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) - set_unicode_input_mode(UC_WINC); -#endif - break; + if (!rand_seeded) { + srand(record->event.time % keycode); + rand_seeded = true; + } + + if (record->event.pressed) { + switch (keycode) { +#ifndef NO_DEBUG + // Re-implement this here, but fix the persistence! + case DEBUG: + if (!debug_enable) { + debug_enable = 1; +# if defined(SPI_DEBUG_SCAN_RATE) + matrix_timer = 0; + reported_version = false; +# endif + } else if (!debug_keyboard) { + debug_keyboard = 1; + } else if (!debug_matrix) { + debug_matrix = 1; + } else { + debug_enable = 0; + debug_keyboard = 0; + debug_matrix = 0; + } + uprintf("DEBUG: enable=%u, keyboard=%u, matrix=%u\n", debug_enable, debug_keyboard, debug_matrix); + eeconfig_update_debug(debug_config.raw); + return false; +#endif + + // clang-format off + + case CH_CPNL: host_consumer_send(AL_CONTROL_PANEL); return false; + case CH_ASST: host_consumer_send(AL_ASSISTANT); return false; + case CH_SUSP: tap_code16(LGUI(LSFT(KC_L))); return true; + + // clang-format on + + case SPI_LNX: + dprint("SPI_LNX\n"); + set_single_persistent_default_layer(_BASE); + layer_off(_OSX); +#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) + set_unicode_input_mode(UC_LNX); +#endif + break; + case SPI_OSX: + dprint("SPI_OSX\n"); + set_single_persistent_default_layer(_OSX); +#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) + set_unicode_input_mode(UC_OSX); +#endif + break; + case SPI_WIN: + dprint("SPI_WIN\n"); + set_single_persistent_default_layer(_BASE); + layer_off(_OSX); +#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) + set_unicode_input_mode(UC_WINC); +#endif + break; + + case SPI_NORMAL ... SPI_FRAKTR: + spi_replace_mode = (spi_replace_mode == keycode) ? SPI_NORMAL : keycode; + dprintf("spi_replace_mode = %u\n", spi_replace_mode); + break; + + case SPI_GFLOCK: + spi_gflock = !spi_gflock; + dprintf("spi_gflock = %u\n", spi_gflock); + break; + } + } else { + switch (keycode) { + case CH_CPNL: + case CH_ASST: + host_consumer_send(0); + return false; + } + } + + switch (keycode) { + case KC_A ... KC_0: + case KC_SPACE: + switch (spi_replace_mode) { + case SPI_WIDE: + return process_record_glyph_replacement(keycode, record, 0xFF41, 0xFF21, 0xFF10, 0xFF11, 0x2003); + case SPI_SCRIPT: + return process_record_glyph_replacement(keycode, record, 0x1D4EA, 0x1D4D0, 0x1D7CE, 0x1D7CF, 0x2002); + case SPI_BLOCKS: + return process_record_glyph_replacement(keycode, record, 0x1F170, 0x1F170, '0', '1', 0x2002); + case SPI_CIRCLE: + return process_record_glyph_replacement(keycode, record, 0x1F150, 0x1F150, '0', '1', 0x2002); + case SPI_SQUARE: + return process_record_glyph_replacement(keycode, record, 0x1F130, 0x1F130, '0', '1', 0x2002); + case SPI_PARENS: + return process_record_glyph_replacement(keycode, record, 0x1F110, 0x1F110, '0', '1', 0x2002); + case SPI_FRAKTR: + return process_record_glyph_replacement(keycode, record, 0x1D586, 0x1D56C, '0', '1', 0x2002); + } + break; + + case KC_F1 ... KC_F24: + return process_gflock(keycode, record); } - } #ifdef RGBLIGHT_ENABLE - bool res = process_record_user_rgb(keycode, record); - if (res) return true; + bool res = process_record_user_rgb(keycode, record); + if (!res) return false; #endif - return false; + return true; +} + +void post_process_record_user(uint16_t keycode, keyrecord_t *record) { +#ifdef RGBLIGHT_ENABLE + post_process_record_user_rgb(keycode, record); +#endif + return; } layer_state_t default_layer_state_set_user(layer_state_t state) { #ifdef RGBLIGHT_ENABLE - return default_layer_state_set_user_rgb(state); + return default_layer_state_set_user_rgb(state); #else - return state; + return state; #endif } layer_state_t layer_state_set_user(layer_state_t state) { #ifdef RGBLIGHT_ENABLE - return layer_state_set_user_rgb(state); + return layer_state_set_user_rgb(state); #else - return state; + return state; #endif } bool led_update_user(led_t led_state) { #ifdef RGBLIGHT_ENABLE - return led_update_user_rgb(led_state); + return led_update_user_rgb(led_state); #else - return true; + return true; #endif } diff --git a/users/spidey3/spidey3.h b/users/spidey3/spidey3.h index 224858391dc..5bfba4e5928 100644 --- a/users/spidey3/spidey3.h +++ b/users/spidey3/spidey3.h @@ -3,41 +3,71 @@ #include QMK_KEYBOARD_H #ifdef UNICODEMAP_ENABLE -#include "unicode.h" +# include "unicode.h" #endif enum userspace_layers { - _BASE = 0, - _OSX, - _NUMPAD, - _FN, -}; - -enum rgb_base_layer { - RGB_LAYER_BASE_DEFAULT = _BASE, - RGB_LAYER_BASE_REGULAR = _NUMPAD, - RGB_LAYER_BASE_ACKS = _FN+1, + _BASE = 0, + _OSX, + _NUMPAD, + _FN, }; enum custom_keycodes { - SPI_GLO = SAFE_RANGE, - SPI_LNX, - SPI_OSX, - SPI_WIN, + SPI_GLO = SAFE_RANGE, + SPI_LNX, // Mode: Linux + SPI_OSX, // Mode: Mac + SPI_WIN, // Mode: Windows + CH_CPNL, // AL Control Panel + CH_ASST, // AL Context-aware Desktop Assistant + CH_SUSP, // Suspend + + SPI_NORMAL, + SPI_WIDE, + SPI_SCRIPT, + SPI_BLOCKS, + SPI_CIRCLE, + SPI_SQUARE, + SPI_PARENS, + SPI_FRAKTR, + SPI_GFLOCK, }; #ifdef RGBLIGHT_ENABLE -void eeconfig_init_user_rgb(void); -void matrix_init_user_rgb(void); -void keyboard_post_init_user_rgb(void); -bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record); + +enum layer_base { + LAYER_BASE_DEFAULT = _BASE, + LAYER_BASE_REGULAR = _NUMPAD, + LAYER_BASE_END = _FN + 1, +}; + +typedef enum layer_ack { + ACK_NO = 0, + ACK_YES, + ACK_MEH, +} layer_ack_t; + +# define RGB_LAYER_ACK_DURATION 500 + +void eeconfig_init_user_rgb(void); +void matrix_init_user_rgb(void); +void keyboard_post_init_user_rgb(void); +bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record); +void post_process_record_user_rgb(uint16_t keycode, keyrecord_t *record); layer_state_t layer_state_set_user_rgb(layer_state_t state); layer_state_t default_layer_state_set_user_rgb(layer_state_t state); -bool led_update_user_rgb(led_t led_state); -void clear_rgb_layers(void); +bool led_update_user_rgb(led_t led_state); +void rgb_layer_ack(layer_ack_t n); +void rgb_layer_ack_yn(bool yn); +void clear_rgb_layers(void); #endif #ifdef UNICODEMAP_ENABLE void eeconfig_init_user_unicode(void); #endif +#ifdef SPI_DEBUG_SCAN_RATE +# ifndef SPI_SCAN_RATE_INTERVAL +# define SPI_SCAN_RATE_INTERVAL 10 +# endif +#endif diff --git a/users/spidey3/unicode.c b/users/spidey3/unicode.c index 41ceef83756..39a990674c5 100644 --- a/users/spidey3/unicode.c +++ b/users/spidey3/unicode.c @@ -2,18 +2,24 @@ #include "unicode.h" const uint32_t PROGMEM unicode_map[] = { - [BUL1] = 0x2022, // • - [BUL2] = 0x25E6, // ◦ - [LARR] = 0x2190, // ← - [RARR] = 0x2192, // → - [ENDASH] = 0x2013, // – - [EMDASH] = 0x2014, // — + [BUL1] = 0x2022, // • + [BUL2] = 0x25E6, // ◦ + [LARR] = 0x2190, // ← + [RARR] = 0x2192, // → + [ENDASH] = 0x2013, // – + [EMDASH] = 0x2014, // — + [SPIDER] = 0x1F577, // 🕷 + [SAD] = 0x2639, // ☹ + [MEH] = 0x1F611, // 😑 + [HAPPY] = 0x1F600, // 😀 + [ANGRY] = 0x1F620, // 😠 + [THUMBUP] = 0x1F44D, // 👍 + [THUMBDN] = 0x1F44E, // 👎 + [LOL] = 0x1F602, // 😂 + [SURPRISE] = 0x1F62E, // 😮 }; -void eeconfig_init_user_unicode(void) -{ - // Default to Linux style - set_unicode_input_mode(UC_LNX); +void eeconfig_init_user_unicode(void) { + // Default to Linux style + set_unicode_input_mode(UC_LNX); } - - diff --git a/users/spidey3/unicode.h b/users/spidey3/unicode.h index 72a91e8a806..db7824983b1 100644 --- a/users/spidey3/unicode.h +++ b/users/spidey3/unicode.h @@ -11,9 +11,18 @@ enum unicode_names { RARR, ENDASH, EMDASH, + SPIDER, + SAD, + MEH, + HAPPY, + ANGRY, + THUMBUP, + THUMBDN, + LOL, + SURPRISE, }; -#define X_BUL (XP(BUL1, BUL2)) -#define X_DASH (XP(ENDASH, EMDASH)) +# define X_BUL (XP(BUL1, BUL2)) +# define X_DASH (XP(ENDASH, EMDASH)) #endif