diff options
Diffstat (limited to 'users/spidey3/spidey3.c')
| -rw-r--r-- | users/spidey3/spidey3.c | 168 |
1 files changed, 99 insertions, 69 deletions
diff --git a/users/spidey3/spidey3.c b/users/spidey3/spidey3.c index a8dafcb7b..df73c903d 100644 --- a/users/spidey3/spidey3.c +++ b/users/spidey3/spidey3.c | |||
| @@ -14,49 +14,44 @@ static uint32_t matrix_scan_count = 0; | |||
| 14 | static bool reported_version = false; | 14 | static bool reported_version = false; |
| 15 | 15 | ||
| 16 | # if defined(SPI_DEBUG_SCAN_RATE) | 16 | # if defined(SPI_DEBUG_SCAN_RATE) |
| 17 | static uint32_t matrix_timer = 0; | 17 | static uint32_t matrix_timer = 0; |
| 18 | static uint32_t last_matrix_scan_count = 0; | ||
| 19 | # endif | 18 | # endif |
| 20 | 19 | ||
| 20 | void report_version(void) { | ||
| 21 | uprintln(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE); | ||
| 22 | reported_version = true; | ||
| 23 | } | ||
| 24 | #endif | ||
| 25 | |||
| 21 | void matrix_scan_user(void) { | 26 | void matrix_scan_user(void) { |
| 27 | #if defined(CONSOLE_ENABLE) && !defined(NO_DEBUG) | ||
| 22 | # if defined(SPI_DEBUG_SCAN_RATE) | 28 | # if defined(SPI_DEBUG_SCAN_RATE) |
| 23 | matrix_scan_count++; | 29 | matrix_scan_count++; |
| 24 | if (debug_enable) { | 30 | if (debug_enable) { |
| 25 | uint32_t timer_now = timer_read32(); | 31 | uint32_t timer_now = timer_read32(); |
| 26 | if (matrix_timer == 0) { | 32 | if (matrix_timer == 0) { |
| 27 | matrix_timer = timer_now; | 33 | matrix_timer = timer_now; |
| 28 | last_matrix_scan_count = matrix_scan_count; | 34 | matrix_scan_count = 0; |
| 29 | matrix_scan_count = 0; | ||
| 30 | } else if (TIMER_DIFF_32(timer_now, matrix_timer) > SPI_SCAN_RATE_INTERVAL * 1000) { | 35 | } else if (TIMER_DIFF_32(timer_now, matrix_timer) > SPI_SCAN_RATE_INTERVAL * 1000) { |
| 31 | matrix_timer = timer_now; | 36 | matrix_timer = timer_now; |
| 32 | last_matrix_scan_count = matrix_scan_count; | 37 | uprintf("scan rate: %lu/s\n", matrix_scan_count / SPI_SCAN_RATE_INTERVAL); |
| 33 | matrix_scan_count = 0; | 38 | matrix_scan_count = 0; |
| 34 | if (!reported_version) { | 39 | if (!reported_version) report_version(); |
| 35 | uprintln(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE); | ||
| 36 | reported_version = true; | ||
| 37 | } | ||
| 38 | uprintf("scan rate: %lu/s\n", last_matrix_scan_count / SPI_SCAN_RATE_INTERVAL); | ||
| 39 | } | 40 | } |
| 40 | } | 41 | } |
| 41 | # else | 42 | # else |
| 42 | if (!reported_version) { | 43 | if (!reported_version) { |
| 43 | matrix_scan_count++; | 44 | matrix_scan_count++; |
| 44 | if (matrix_scan_count > 300) { | 45 | if (matrix_scan_count > 300) report_version(); |
| 45 | uprintln(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE); | ||
| 46 | reported_version = true; | ||
| 47 | } | ||
| 48 | } | 46 | } |
| 49 | # endif | 47 | # endif |
| 50 | } | ||
| 51 | #endif | 48 | #endif |
| 52 | 49 | #ifdef RGBLIGHT_ENABLE | |
| 53 | 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) { | 50 | matrix_scan_user_rgb(); |
| 54 | uint8_t temp_mod = get_mods(); | ||
| 55 | #ifndef NO_ACTION_ONESHOT | ||
| 56 | uint8_t temp_osm = get_oneshot_mods(); | ||
| 57 | #else | ||
| 58 | uint8_t temp_osm = 0; | ||
| 59 | #endif | 51 | #endif |
| 52 | } | ||
| 53 | |||
| 54 | 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, uint8_t temp_osm) { | ||
| 60 | if ((((temp_mod | temp_osm) & (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI))) == 0) { | 55 | if ((((temp_mod | temp_osm) & (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI))) == 0) { |
| 61 | switch (keycode) { | 56 | switch (keycode) { |
| 62 | case KC_A ... KC_Z: | 57 | case KC_A ... KC_Z: |
| @@ -121,21 +116,43 @@ bool process_gflock(uint16_t keycode, keyrecord_t *record) { | |||
| 121 | } | 116 | } |
| 122 | 117 | ||
| 123 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | 118 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { |
| 119 | dprintf("key event: kc: %02X, col: %02u, row: %02u, pressed: %u mods: %08b " | ||
| 120 | #if !defined(NO_ACTION_ONESHOT) | ||
| 121 | "os: %08b " | ||
| 122 | #endif | ||
| 123 | "weak: %08b\n", | ||
| 124 | keycode, record->event.key.col, record->event.key.row, record->event.pressed, bitrev(get_mods()), | ||
| 125 | #if !defined(NO_ACTION_ONESHOT) | ||
| 126 | bitrev(get_oneshot_mods()), | ||
| 127 | #endif | ||
| 128 | bitrev(get_weak_mods())); | ||
| 129 | |||
| 124 | if (!rand_seeded) { | 130 | if (!rand_seeded) { |
| 125 | srand(record->event.time % keycode); | 131 | srand(record->event.time % keycode); |
| 126 | rand_seeded = true; | 132 | rand_seeded = true; |
| 127 | } | 133 | } |
| 128 | 134 | ||
| 135 | uint8_t mods = get_mods(); | ||
| 136 | #ifndef NO_ACTION_ONESHOT | ||
| 137 | uint8_t osm = get_oneshot_mods(); | ||
| 138 | #else | ||
| 139 | uint8_t osm = 0; | ||
| 140 | #endif | ||
| 141 | |||
| 129 | if (record->event.pressed) { | 142 | if (record->event.pressed) { |
| 130 | switch (keycode) { | 143 | switch (keycode) { |
| 131 | #ifndef NO_DEBUG | 144 | #ifndef NO_DEBUG |
| 132 | // Re-implement this here, but fix the persistence! | 145 | // Re-implement this here, but fix the persistence! |
| 133 | case DEBUG: | 146 | case DEBUG: |
| 134 | if (!debug_enable) { | 147 | if (get_mods() & MOD_MASK_SHIFT) { |
| 148 | debug_enable = 0; | ||
| 149 | debug_keyboard = 0; | ||
| 150 | debug_matrix = 0; | ||
| 151 | } else if (!debug_enable) { | ||
| 135 | debug_enable = 1; | 152 | debug_enable = 1; |
| 136 | # if defined(SPI_DEBUG_SCAN_RATE) | 153 | # if defined(SPI_DEBUG_SCAN_RATE) |
| 137 | matrix_timer = 0; | 154 | matrix_timer = 0; |
| 138 | reported_version = false; | 155 | report_version(); |
| 139 | # endif | 156 | # endif |
| 140 | } else if (!debug_keyboard) { | 157 | } else if (!debug_keyboard) { |
| 141 | debug_keyboard = 1; | 158 | debug_keyboard = 1; |
| @@ -157,31 +174,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 157 | case CH_ASST: host_consumer_send(AL_ASSISTANT); return false; | 174 | case CH_ASST: host_consumer_send(AL_ASSISTANT); return false; |
| 158 | case CH_SUSP: tap_code16(LGUI(LSFT(KC_L))); return true; | 175 | case CH_SUSP: tap_code16(LGUI(LSFT(KC_L))); return true; |
| 159 | 176 | ||
| 160 | // clang-format on | 177 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) |
| 161 | 178 | case SPI_LNX: set_unicode_input_mode(UC_LNX); break; | |
| 162 | case SPI_LNX: | 179 | case SPI_OSX: set_unicode_input_mode(UC_OSX); break; |
| 163 | dprint("SPI_LNX\n"); | 180 | case SPI_WIN: set_unicode_input_mode(UC_WINC); break; |
| 164 | set_single_persistent_default_layer(_BASE); | ||
| 165 | layer_off(_OSX); | ||
| 166 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) | ||
| 167 | set_unicode_input_mode(UC_LNX); | ||
| 168 | #endif | 181 | #endif |
| 169 | break; | 182 | // clang-format on |
| 170 | case SPI_OSX: | ||
| 171 | dprint("SPI_OSX\n"); | ||
| 172 | set_single_persistent_default_layer(_OSX); | ||
| 173 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) | ||
| 174 | set_unicode_input_mode(UC_OSX); | ||
| 175 | #endif | ||
| 176 | break; | ||
| 177 | case SPI_WIN: | ||
| 178 | dprint("SPI_WIN\n"); | ||
| 179 | set_single_persistent_default_layer(_BASE); | ||
| 180 | layer_off(_OSX); | ||
| 181 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) | ||
| 182 | set_unicode_input_mode(UC_WINC); | ||
| 183 | #endif | ||
| 184 | break; | ||
| 185 | 183 | ||
| 186 | case SPI_NORMAL ... SPI_FRAKTR: | 184 | case SPI_NORMAL ... SPI_FRAKTR: |
| 187 | spi_replace_mode = (spi_replace_mode == keycode) ? SPI_NORMAL : keycode; | 185 | spi_replace_mode = (spi_replace_mode == keycode) ? SPI_NORMAL : keycode; |
| @@ -193,14 +191,18 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 193 | dprintf("spi_gflock = %u\n", spi_gflock); | 191 | dprintf("spi_gflock = %u\n", spi_gflock); |
| 194 | break; | 192 | break; |
| 195 | 193 | ||
| 196 | case KC_PSCR: { | 194 | case SPI_KP_00: |
| 197 | uint8_t mods = get_mods(); | 195 | tap_code(KC_KP_0); |
| 198 | #ifndef NO_ACTION_ONESHOT | 196 | #if TAP_CODE_DELAY > 0 |
| 199 | uint8_t osm = get_oneshot_mods(); | 197 | wait_ms(TAP_CODE_DELAY); |
| 200 | #else | ||
| 201 | uint8_t osm = 0; | ||
| 202 | #endif | 198 | #endif |
| 199 | register_code(KC_KP_0); | ||
| 200 | return false; | ||
| 203 | 201 | ||
| 202 | case KC_PSCR: { | ||
| 203 | // It's kind of a hack, but we use unicode input mode | ||
| 204 | // to determine what Print Screen key should do. The | ||
| 205 | // idea here is to make it consistent across hosts. | ||
| 204 | switch (get_unicode_input_mode()) { | 206 | switch (get_unicode_input_mode()) { |
| 205 | case UC_MAC: | 207 | case UC_MAC: |
| 206 | if ((mods | osm) & MOD_MASK_ALT) { | 208 | if ((mods | osm) & MOD_MASK_ALT) { |
| @@ -265,6 +267,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 265 | case CH_ASST: | 267 | case CH_ASST: |
| 266 | host_consumer_send(0); | 268 | host_consumer_send(0); |
| 267 | return false; | 269 | return false; |
| 270 | |||
| 271 | case SPI_KP_00: | ||
| 272 | unregister_code(KC_KP_0); | ||
| 273 | return false; | ||
| 268 | } | 274 | } |
| 269 | } | 275 | } |
| 270 | 276 | ||
| @@ -273,32 +279,56 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
| 273 | case KC_SPACE: | 279 | case KC_SPACE: |
| 274 | switch (spi_replace_mode) { | 280 | switch (spi_replace_mode) { |
| 275 | case SPI_WIDE: | 281 | case SPI_WIDE: |
| 276 | return process_record_glyph_replacement(keycode, record, 0xFF41, 0xFF21, 0xFF10, 0xFF11, 0x2003); | 282 | return process_record_glyph_replacement(keycode, record, 0xFF41, 0xFF21, 0xFF10, 0xFF11, 0x2003, mods, osm); |
| 277 | case SPI_SCRIPT: | 283 | case SPI_SCRIPT: |
| 278 | return process_record_glyph_replacement(keycode, record, 0x1D4EA, 0x1D4D0, 0x1D7CE, 0x1D7CF, 0x2002); | 284 | return process_record_glyph_replacement(keycode, record, 0x1D4EA, 0x1D4D0, 0x1D7CE, 0x1D7CF, 0x2002, mods, osm); |
| 279 | case SPI_BLOCKS: | 285 | case SPI_BLOCKS: |
| 280 | return process_record_glyph_replacement(keycode, record, 0x1F170, 0x1F170, '0', '1', 0x2002); | 286 | return process_record_glyph_replacement(keycode, record, 0x1F170, 0x1F170, '0', '1', 0x2002, mods, osm); |
| 281 | case SPI_CIRCLE: | 287 | case SPI_CIRCLE: |
| 282 | return process_record_glyph_replacement(keycode, record, 0x1F150, 0x1F150, '0', '1', 0x2002); | 288 | return process_record_glyph_replacement(keycode, record, 0x1F150, 0x1F150, '0', '1', 0x2002, mods, osm); |
| 283 | case SPI_SQUARE: | 289 | case SPI_SQUARE: |
| 284 | return process_record_glyph_replacement(keycode, record, 0x1F130, 0x1F130, '0', '1', 0x2002); | 290 | return process_record_glyph_replacement(keycode, record, 0x1F130, 0x1F130, '0', '1', 0x2002, mods, osm); |
| 285 | case SPI_PARENS: | 291 | case SPI_PARENS: |
| 286 | return process_record_glyph_replacement(keycode, record, 0x1F110, 0x1F110, '0', '1', 0x2002); | 292 | return process_record_glyph_replacement(keycode, record, 0x1F110, 0x1F110, '0', '1', 0x2002, mods, osm); |
| 287 | case SPI_FRAKTR: | 293 | case SPI_FRAKTR: |
| 288 | return process_record_glyph_replacement(keycode, record, 0x1D586, 0x1D56C, '0', '1', 0x2002); | 294 | return process_record_glyph_replacement(keycode, record, 0x1D586, 0x1D56C, '0', '1', 0x2002, mods, osm); |
| 289 | } | 295 | } |
| 290 | break; | 296 | break; |
| 291 | 297 | ||
| 292 | case KC_F1 ... KC_F12: | 298 | case KC_F1 ... KC_F12: |
| 293 | return process_gflock(keycode, record); | 299 | return process_gflock(keycode, record); |
| 294 | } | ||
| 295 | 300 | ||
| 296 | #ifdef RGBLIGHT_ENABLE | 301 | #ifdef SHIFT_BACKSPACE_DELETE |
| 297 | bool res = process_record_user_rgb(keycode, record); | 302 | case KC_BSPC: { |
| 298 | if (!res) return false; | 303 | static bool delkey_registered; |
| 304 | if (record->event.pressed) { | ||
| 305 | if ((mods | osm) & MOD_MASK_SHIFT) { | ||
| 306 | del_mods(MOD_MASK_SHIFT); | ||
| 307 | #ifndef NO_ACTION_ONESHOT | ||
| 308 | clear_oneshot_mods(); | ||
| 309 | #endif | ||
| 310 | register_code(KC_DEL); | ||
| 311 | delkey_registered = true; | ||
| 312 | set_mods(mods); | ||
| 313 | return false; | ||
| 314 | } | ||
| 315 | } else { // on release of KC_BSPC | ||
| 316 | // In case KC_DEL is still being sent even after the release of KC_BSPC | ||
| 317 | if (delkey_registered) { | ||
| 318 | unregister_code(KC_DEL); | ||
| 319 | delkey_registered = false; | ||
| 320 | return false; | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 299 | #endif | 324 | #endif |
| 325 | } | ||
| 300 | 326 | ||
| 327 | #ifdef RGBLIGHT_ENABLE | ||
| 328 | return process_record_user_rgb(keycode, record); | ||
| 329 | #else | ||
| 301 | return true; | 330 | return true; |
| 331 | #endif | ||
| 302 | } | 332 | } |
| 303 | 333 | ||
| 304 | void post_process_record_user(uint16_t keycode, keyrecord_t *record) { | 334 | void post_process_record_user(uint16_t keycode, keyrecord_t *record) { |
