You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1102 lines
38 KiB

Merge ChibiOS and LUFA descriptor support (#2362) * Move lufa descriptor to protocol/usb_descriptor * Try to compile usb_descriptor on ChibiOS * Add lufa_utils for ChibiOS Lufa USB descriptors for ChibiOS * More lufa_util compatibility fixes * First compiling version of shared USB descriptor * Send the usb descriptors * Fix the CONSOLE output on ChibiOS * Add errors for unsupported interfaces * Enable support for vitual serial port USB descriptors * Implement virtual serial port for ChibiOS * Cleanup the lufa_utils Use the default lufa header files * Add raw hid support for ChibiOS This is completely untested * Enable midi compilation on ChibiOS * Move midi functionality out of lufa.c * Don't register sysex callback when not needed * ChibiOS compilation fixes * Update ChibiOS submodule * Fix the Midi USB descriptor It didn't work properly when both Midi and Virtual serial port was enabled. * Add MIDI support for ChibiOS * Fix USB descriptor strings on ChibiOS * Use serial usb driver for raw hid * Generalize the ChibiOS stream like drivers This makes the initialization much more simple and eliminates a lot of the code duplication. * Convert console output to chibios stream driver * Fixes for ChibiOS update * Update the ChibiOS contrib submodule To include the usb data toggle synchronization fixes * Fix duplicate reset enumeration on ChibiOS * Add missing include * Add number of endpoints check for ChibiOS * Enable serial USB driver on all keyboards * Add missing includes when API is enabled withot midi * Add another missing inlcude
6 years ago
Merge ChibiOS and LUFA descriptor support (#2362) * Move lufa descriptor to protocol/usb_descriptor * Try to compile usb_descriptor on ChibiOS * Add lufa_utils for ChibiOS Lufa USB descriptors for ChibiOS * More lufa_util compatibility fixes * First compiling version of shared USB descriptor * Send the usb descriptors * Fix the CONSOLE output on ChibiOS * Add errors for unsupported interfaces * Enable support for vitual serial port USB descriptors * Implement virtual serial port for ChibiOS * Cleanup the lufa_utils Use the default lufa header files * Add raw hid support for ChibiOS This is completely untested * Enable midi compilation on ChibiOS * Move midi functionality out of lufa.c * Don't register sysex callback when not needed * ChibiOS compilation fixes * Update ChibiOS submodule * Fix the Midi USB descriptor It didn't work properly when both Midi and Virtual serial port was enabled. * Add MIDI support for ChibiOS * Fix USB descriptor strings on ChibiOS * Use serial usb driver for raw hid * Generalize the ChibiOS stream like drivers This makes the initialization much more simple and eliminates a lot of the code duplication. * Convert console output to chibios stream driver * Fixes for ChibiOS update * Update the ChibiOS contrib submodule To include the usb data toggle synchronization fixes * Fix duplicate reset enumeration on ChibiOS * Add missing include * Add number of endpoints check for ChibiOS * Enable serial USB driver on all keyboards * Add missing includes when API is enabled withot midi * Add another missing inlcude
6 years ago
Merge ChibiOS and LUFA descriptor support (#2362) * Move lufa descriptor to protocol/usb_descriptor * Try to compile usb_descriptor on ChibiOS * Add lufa_utils for ChibiOS Lufa USB descriptors for ChibiOS * More lufa_util compatibility fixes * First compiling version of shared USB descriptor * Send the usb descriptors * Fix the CONSOLE output on ChibiOS * Add errors for unsupported interfaces * Enable support for vitual serial port USB descriptors * Implement virtual serial port for ChibiOS * Cleanup the lufa_utils Use the default lufa header files * Add raw hid support for ChibiOS This is completely untested * Enable midi compilation on ChibiOS * Move midi functionality out of lufa.c * Don't register sysex callback when not needed * ChibiOS compilation fixes * Update ChibiOS submodule * Fix the Midi USB descriptor It didn't work properly when both Midi and Virtual serial port was enabled. * Add MIDI support for ChibiOS * Fix USB descriptor strings on ChibiOS * Use serial usb driver for raw hid * Generalize the ChibiOS stream like drivers This makes the initialization much more simple and eliminates a lot of the code duplication. * Convert console output to chibios stream driver * Fixes for ChibiOS update * Update the ChibiOS contrib submodule To include the usb data toggle synchronization fixes * Fix duplicate reset enumeration on ChibiOS * Add missing include * Add number of endpoints check for ChibiOS * Enable serial USB driver on all keyboards * Add missing includes when API is enabled withot midi * Add another missing inlcude
6 years ago
Velocikey: Match RGB animation speed to typing speed (#3754) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Experimental LED support (untested) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Added documentation * Renamed feature to velocikey * Reverted readme to original state * Correct the readme title * Updated feature name in the docs * Update EECONFIG name * Add compile-time toggles for velocikey * Update feature documentation * Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. * Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE * Rename decay_task function to decelerate * Apply suggestions from code review Co-Authored-By: chrislewisdev <chris@chrislewisdev.com> * Re-order eeconfig definitions * Apply coding conventions * Apply #ifdef check in lufa.c * Refactored interval time checks into one functionc * Small rename * Fix unused function error for layouts not using all rgb effects * Only update EEPROM if Velocikey is enabled * Incorporate code review feedback * Small adjustment to top-end decay rate * Add Velocikey documentation to table of contents * Bring tetris:default keymap size down by disabling audio
5 years ago
Velocikey: Match RGB animation speed to typing speed (#3754) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Experimental LED support (untested) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Added documentation * Renamed feature to velocikey * Reverted readme to original state * Correct the readme title * Updated feature name in the docs * Update EECONFIG name * Add compile-time toggles for velocikey * Update feature documentation * Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. * Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE * Rename decay_task function to decelerate * Apply suggestions from code review Co-Authored-By: chrislewisdev <chris@chrislewisdev.com> * Re-order eeconfig definitions * Apply coding conventions * Apply #ifdef check in lufa.c * Refactored interval time checks into one functionc * Small rename * Fix unused function error for layouts not using all rgb effects * Only update EEPROM if Velocikey is enabled * Incorporate code review feedback * Small adjustment to top-end decay rate * Add Velocikey documentation to table of contents * Bring tetris:default keymap size down by disabling audio
5 years ago
Backlighting for JJ40 and underglow initialisation code (#2260) * Cleanup Mechmini keymap. Once the custom RGB function is defined, there is no need to manually handle RGB code. * Change default to KEYMAP_MIT, not KEYMAP_OFFSET * Add custom RGB code for JJ40 * Reset Mechmini advertised power draw to 500. Will have to test actual maximum power draw later. * RGB working on JJ40. * Fix: saturation increase/decrease flipped * Add new directory for my custom keymap with RGB keycodes * Swap LAlt and LGUI * Update JJ40 max power draw with measured value * Update: fun40 rules.mk to enable underglow; earlier failed Travis CI * Fix: init RGB LEDs on boot. Also added HHKB-like keymap for XD60. * Super rudimentary backlight test, init RGB LEDs on boot * Backlighting works - stays on for now * Toggling working * Now can override backlight.c functions. Problem was functions in backlight.c weren't called before due to a lack of matrix_scan_quantum() in matrix.c * Timers not working * Delete global.h * Cleanup * Compiles * Good sign: LEDs stop working again * Handle timer1 overflow * Progress: fix: forgot to init * Backlighting fully working now except breathing. * Revert keymap to original keycodes * Update XD60 keymap README * Update JJ40 keymap with backlight toggles * Breathing working just fine. * Update references * Add backlight_set() call * Cleanup code to disable backlight * Fix: does not compile * Fix: missing call to rgblight_task. * Testing with BACKLIGHT_BREATHING * Cleanup * Cleanup comments * More commenting cleanup. * Do not enable BACKLIGHT_BREATHING by default
6 years ago
Velocikey: Match RGB animation speed to typing speed (#3754) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Experimental LED support (untested) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Added documentation * Renamed feature to velocikey * Reverted readme to original state * Correct the readme title * Updated feature name in the docs * Update EECONFIG name * Add compile-time toggles for velocikey * Update feature documentation * Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. * Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE * Rename decay_task function to decelerate * Apply suggestions from code review Co-Authored-By: chrislewisdev <chris@chrislewisdev.com> * Re-order eeconfig definitions * Apply coding conventions * Apply #ifdef check in lufa.c * Refactored interval time checks into one functionc * Small rename * Fix unused function error for layouts not using all rgb effects * Only update EEPROM if Velocikey is enabled * Incorporate code review feedback * Small adjustment to top-end decay rate * Add Velocikey documentation to table of contents * Bring tetris:default keymap size down by disabling audio
5 years ago
Overhaul Unicode Common functionality (#4325) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * remove merge artifacts * Unicode common cleanup (#17) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * Rearrange process_unicode_common functions * Make Unicode input mode constants (UC_*) an enum * Simplify unicode_input_start/finish code * Make the key used for WinCompose configurable * Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY * Update Unicode input mode doc * Add descriptions and rearrange definitions in process_unicode_common.h * Add registry command to Unicode docs + misc updates * Reword an explanation in Unicode docs * Add TODO comment * Remove trailing whitespace * Improve Cycling documentation * Add Unicode Input method Cycling support (#19) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * Rearrange process_unicode_common functions * Make Unicode input mode constants (UC_*) an enum * Simplify unicode_input_start/finish code * Make the key used for WinCompose configurable * Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY * Update Unicode input mode doc * Add descriptions and rearrange definitions in process_unicode_common.h * Add registry command to Unicode docs + misc updates * Reword an explanation in Unicode docs * Add TODO comment * Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro * Add an option for making cycle changes persistent * Add debug prints to functions that change input_mode * Use cycle_unicode_input_mode in whitefox/konstantin * Add persist_unicode_input_mode function * Add offset to cycle to allow stepping in reverse * Add keycodes: UNICODE_MODE_FORWARD, UNICODE_MODE_REVERSE Aliases: UC_MOD, UC_RMOD (respectively) * REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts * Fix wrong constant name * Revert "REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts" This reverts commit 42676bf251fc8e3823f5e614dad6e510ba47a2f3. * Change dprintf text * Give selected modes priority over EEPROM when !UNICODE_CYCLE_PERSIST * Remove trailing whitespace * Cleanup of RALT code and unicode compilation stuff * Remove else for unicode handling
5 years ago
Moves features to their own files (process_*), adds tap dance feature (#460) * non-working commit * working * subprojects implemented for planck * pass a subproject variable through to c * consolidates clueboard revisions * thanks for letting me know about conflicts.. * turn off audio for yang's * corrects starting paths for subprojects * messing around with travis * semicolon * travis script * travis script * script for travis * correct directory (probably), amend files to commit * remove origin before adding * git pull, correct syntax * git checkout * git pull origin branch * where are we? * where are we? * merging * force things to happen * adds commit message, adds add * rebase, no commit message * rebase branch * idk! * try just pull * fetch - merge * specify repo branch * checkout * goddammit * merge? idk * pls * after all * don't split up keyboards * syntax * adds quick for all-keyboards * trying out new script * script update * lowercase * all keyboards * stop replacing compiled.hex automatically * adds if statement * skip automated build branches * forces push to automated build branch * throw an add in there * upstream? * adds AUTOGEN * ignore all .hex files again * testing out new repo * global ident * generate script, keyboard_keymap.hex * skip generation for now, print pandoc info, submodule update * try trusty * and sudo * try generate * updates subprojects to keyboards * no idea * updates to keyboards * cleans up clueboard stuff * setup to use local readme * updates cluepad, planck experimental * remove extra led.c [ci skip] * audio and midi moved over to separate files * chording, leader, unicode separated * consolidate each [skip ci] * correct include * quantum: Add a tap dance feature (#451) * quantum: Add a tap dance feature With this feature one can specify keys that behave differently, based on the amount of times they have been tapped, and when interrupted, they get handled before the interrupter. To make it clear how this is different from `ACTION_FUNCTION_TAP`, lets explore a certain setup! We want one key to send `Space` on single tap, but `Enter` on double-tap. With `ACTION_FUNCTION_TAP`, it is quite a rain-dance to set this up, and has the problem that when the sequence is interrupted, the interrupting key will be send first. Thus, `SPC a` will result in `a SPC` being sent, if they are typed within `TAPPING_TERM`. With the tap dance feature, that'll come out as `SPC a`, correctly. The implementation hooks into two parts of the system, to achieve this: into `process_record_quantum()`, and the matrix scan. We need the latter to be able to time out a tap sequence even when a key is not being pressed, so `SPC` alone will time out and register after `TAPPING_TERM` time. But lets start with how to use it, first! First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array. This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are two possible options: * `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. * `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the current state of the tap-dance action. The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise. And that's the bulk of it! Do note, however, that this implementation does have some consequences: keys do not register until either they reach the tapping ceiling, or they time out. This means that if you hold the key, nothing happens, no repeat, no nothing. It is possible to detect held state, and register an action then too, but that's not implemented yet. Keys also unregister immediately after being registered, so you can't even hold the second tap. This is intentional, to be consistent. And now, on to the explanation of how it works! The main entry point is `process_tap_dance()`, called from `process_record_quantum()`, which is run for every keypress, and our handler gets to run early. This function checks whether the key pressed is a tap-dance key. If it is not, and a tap-dance was in action, we handle that first, and enqueue the newly pressed key. If it is a tap-dance key, then we check if it is the same as the already active one (if there's one active, that is). If it is not, we fire off the old one first, then register the new one. If it was the same, we increment the counter and the timer. This means that you have `TAPPING_TERM` time to tap the key again, you do not have to input all the taps within that timeframe. This allows for longer tap counts, with minimal impact on responsiveness. Our next stop is `matrix_scan_tap_dance()`. This handles the timeout of tap-dance keys. For the sake of flexibility, tap-dance actions can be either a pair of keycodes, or a user function. The latter allows one to handle higher tap counts, or do extra things, like blink the LEDs, fiddle with the backlighting, and so on. This is accomplished by using an union, and some clever macros. In the end, lets see a full example! ```c enum { CT_SE = 0, CT_CLN, CT_EGG }; /* Have the above three on the keymap, TD(CT_SE), etc... */ void dance_cln (qk_tap_dance_state_t *state) { if (state->count == 1) { register_code (KC_RSFT); register_code (KC_SCLN); unregister_code (KC_SCLN); unregister_code (KC_RSFT); } else { register_code (KC_SCLN); unregister_code (KC_SCLN); reset_tap_dance (state); } } void dance_egg (qk_tap_dance_state_t *state) { if (state->count >= 100) { SEND_STRING ("Safety dance!"); reset_tap_dance (state); } } const qk_tap_dance_action_t tap_dance_actions[] = { [CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT) ,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln) ,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg) }; ``` This addresses #426. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * hhkb: Fix the build with the new tap-dance feature Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Move process_tap_dance further down Process the tap dance stuff after midi and audio, because those don't process keycodes, but row/col positions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Use conditionals instead of dummy functions To be consistent with how the rest of the quantum features are implemented, use ifdefs instead of dummy functions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * Merge branch 'master' into quantum-keypress-process # Conflicts: # Makefile # keyboards/planck/rev3/config.h # keyboards/planck/rev4/config.h * update build script
7 years ago
Moves features to their own files (process_*), adds tap dance feature (#460) * non-working commit * working * subprojects implemented for planck * pass a subproject variable through to c * consolidates clueboard revisions * thanks for letting me know about conflicts.. * turn off audio for yang's * corrects starting paths for subprojects * messing around with travis * semicolon * travis script * travis script * script for travis * correct directory (probably), amend files to commit * remove origin before adding * git pull, correct syntax * git checkout * git pull origin branch * where are we? * where are we? * merging * force things to happen * adds commit message, adds add * rebase, no commit message * rebase branch * idk! * try just pull * fetch - merge * specify repo branch * checkout * goddammit * merge? idk * pls * after all * don't split up keyboards * syntax * adds quick for all-keyboards * trying out new script * script update * lowercase * all keyboards * stop replacing compiled.hex automatically * adds if statement * skip automated build branches * forces push to automated build branch * throw an add in there * upstream? * adds AUTOGEN * ignore all .hex files again * testing out new repo * global ident * generate script, keyboard_keymap.hex * skip generation for now, print pandoc info, submodule update * try trusty * and sudo * try generate * updates subprojects to keyboards * no idea * updates to keyboards * cleans up clueboard stuff * setup to use local readme * updates cluepad, planck experimental * remove extra led.c [ci skip] * audio and midi moved over to separate files * chording, leader, unicode separated * consolidate each [skip ci] * correct include * quantum: Add a tap dance feature (#451) * quantum: Add a tap dance feature With this feature one can specify keys that behave differently, based on the amount of times they have been tapped, and when interrupted, they get handled before the interrupter. To make it clear how this is different from `ACTION_FUNCTION_TAP`, lets explore a certain setup! We want one key to send `Space` on single tap, but `Enter` on double-tap. With `ACTION_FUNCTION_TAP`, it is quite a rain-dance to set this up, and has the problem that when the sequence is interrupted, the interrupting key will be send first. Thus, `SPC a` will result in `a SPC` being sent, if they are typed within `TAPPING_TERM`. With the tap dance feature, that'll come out as `SPC a`, correctly. The implementation hooks into two parts of the system, to achieve this: into `process_record_quantum()`, and the matrix scan. We need the latter to be able to time out a tap sequence even when a key is not being pressed, so `SPC` alone will time out and register after `TAPPING_TERM` time. But lets start with how to use it, first! First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array. This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are two possible options: * `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. * `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the current state of the tap-dance action. The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise. And that's the bulk of it! Do note, however, that this implementation does have some consequences: keys do not register until either they reach the tapping ceiling, or they time out. This means that if you hold the key, nothing happens, no repeat, no nothing. It is possible to detect held state, and register an action then too, but that's not implemented yet. Keys also unregister immediately after being registered, so you can't even hold the second tap. This is intentional, to be consistent. And now, on to the explanation of how it works! The main entry point is `process_tap_dance()`, called from `process_record_quantum()`, which is run for every keypress, and our handler gets to run early. This function checks whether the key pressed is a tap-dance key. If it is not, and a tap-dance was in action, we handle that first, and enqueue the newly pressed key. If it is a tap-dance key, then we check if it is the same as the already active one (if there's one active, that is). If it is not, we fire off the old one first, then register the new one. If it was the same, we increment the counter and the timer. This means that you have `TAPPING_TERM` time to tap the key again, you do not have to input all the taps within that timeframe. This allows for longer tap counts, with minimal impact on responsiveness. Our next stop is `matrix_scan_tap_dance()`. This handles the timeout of tap-dance keys. For the sake of flexibility, tap-dance actions can be either a pair of keycodes, or a user function. The latter allows one to handle higher tap counts, or do extra things, like blink the LEDs, fiddle with the backlighting, and so on. This is accomplished by using an union, and some clever macros. In the end, lets see a full example! ```c enum { CT_SE = 0, CT_CLN, CT_EGG }; /* Have the above three on the keymap, TD(CT_SE), etc... */ void dance_cln (qk_tap_dance_state_t *state) { if (state->count == 1) { register_code (KC_RSFT); register_code (KC_SCLN); unregister_code (KC_SCLN); unregister_code (KC_RSFT); } else { register_code (KC_SCLN); unregister_code (KC_SCLN); reset_tap_dance (state); } } void dance_egg (qk_tap_dance_state_t *state) { if (state->count >= 100) { SEND_STRING ("Safety dance!"); reset_tap_dance (state); } } const qk_tap_dance_action_t tap_dance_actions[] = { [CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT) ,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln) ,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg) }; ``` This addresses #426. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * hhkb: Fix the build with the new tap-dance feature Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Move process_tap_dance further down Process the tap dance stuff after midi and audio, because those don't process keycodes, but row/col positions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * tap_dance: Use conditionals instead of dummy functions To be consistent with how the rest of the quantum features are implemented, use ifdefs instead of dummy functions. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> * Merge branch 'master' into quantum-keypress-process # Conflicts: # Makefile # keyboards/planck/rev3/config.h # keyboards/planck/rev4/config.h * update build script
7 years ago
7 years ago
7 years ago
  1. /* Copyright 2016-2017 Jack Humbert
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "quantum.h"
  17. #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE)
  18. # include "rgb.h"
  19. #endif
  20. #ifdef PROTOCOL_LUFA
  21. # include "outputselect.h"
  22. #endif
  23. #ifdef BACKLIGHT_ENABLE
  24. # include "backlight.h"
  25. extern backlight_config_t backlight_config;
  26. #endif
  27. #ifdef FAUXCLICKY_ENABLE
  28. # include "fauxclicky.h"
  29. #endif
  30. #ifdef API_ENABLE
  31. # include "api.h"
  32. #endif
  33. #ifdef MIDI_ENABLE
  34. # include "process_midi.h"
  35. #endif
  36. #ifdef VELOCIKEY_ENABLE
  37. # include "velocikey.h"
  38. #endif
  39. #ifdef HAPTIC_ENABLE
  40. # include "haptic.h"
  41. #endif
  42. #ifdef ENCODER_ENABLE
  43. # include "encoder.h"
  44. #endif
  45. #ifdef AUDIO_ENABLE
  46. # ifndef GOODBYE_SONG
  47. # define GOODBYE_SONG SONG(GOODBYE_SOUND)
  48. # endif
  49. # ifndef AG_NORM_SONG
  50. # define AG_NORM_SONG SONG(AG_NORM_SOUND)
  51. # endif
  52. # ifndef AG_SWAP_SONG
  53. # define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
  54. # endif
  55. # ifndef CG_NORM_SONG
  56. # define CG_NORM_SONG SONG(AG_NORM_SOUND)
  57. # endif
  58. # ifndef CG_SWAP_SONG
  59. # define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
  60. # endif
  61. float goodbye_song[][2] = GOODBYE_SONG;
  62. float ag_norm_song[][2] = AG_NORM_SONG;
  63. float ag_swap_song[][2] = AG_SWAP_SONG;
  64. float cg_norm_song[][2] = CG_NORM_SONG;
  65. float cg_swap_song[][2] = CG_SWAP_SONG;
  66. # ifdef DEFAULT_LAYER_SONGS
  67. float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
  68. # endif
  69. #endif
  70. static void do_code16(uint16_t code, void (*f)(uint8_t)) {
  71. switch (code) {
  72. case QK_MODS ... QK_MODS_MAX:
  73. break;
  74. default:
  75. return;
  76. }
  77. uint8_t mods_to_send = 0;
  78. if (code & QK_RMODS_MIN) { // Right mod flag is set
  79. if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
  80. if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
  81. if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
  82. if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
  83. } else {
  84. if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
  85. if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
  86. if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
  87. if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
  88. }
  89. f(mods_to_send);
  90. }
  91. void register_code16(uint16_t code) {
  92. if (IS_MOD(code) || code == KC_NO) {
  93. do_code16(code, register_mods);
  94. } else {
  95. do_code16(code, register_weak_mods);
  96. }
  97. register_code(code);
  98. }
  99. void unregister_code16(uint16_t code) {
  100. unregister_code(code);
  101. if (IS_MOD(code) || code == KC_NO) {
  102. do_code16(code, unregister_mods);
  103. } else {
  104. do_code16(code, unregister_weak_mods);
  105. }
  106. }
  107. void tap_code16(uint16_t code) {
  108. register_code16(code);
  109. #if TAP_CODE_DELAY > 0
  110. wait_ms(TAP_CODE_DELAY);
  111. #endif
  112. unregister_code16(code);
  113. }
  114. __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
  115. __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
  116. __attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; }
  117. void reset_keyboard(void) {
  118. clear_keyboard();
  119. #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
  120. process_midi_all_notes_off();
  121. #endif
  122. #ifdef AUDIO_ENABLE
  123. # ifndef NO_MUSIC_MODE
  124. music_all_notes_off();
  125. # endif
  126. uint16_t timer_start = timer_read();
  127. PLAY_SONG(goodbye_song);
  128. shutdown_user();
  129. while (timer_elapsed(timer_start) < 250) wait_ms(1);
  130. stop_all_notes();
  131. #else
  132. shutdown_user();
  133. wait_ms(250);
  134. #endif
  135. #ifdef HAPTIC_ENABLE
  136. haptic_shutdown();
  137. #endif
  138. // this is also done later in bootloader.c - not sure if it's neccesary here
  139. #ifdef BOOTLOADER_CATERINA
  140. *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
  141. #endif
  142. bootloader_jump();
  143. }
  144. /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
  145. * Used to ensure that the correct keycode is released if the key is released.
  146. */
  147. static bool grave_esc_was_shifted = false;
  148. /* Convert record into usable keycode via the contained event. */
  149. uint16_t get_record_keycode(keyrecord_t *record) { return get_event_keycode(record->event); }
  150. /* Convert event into usable keycode. Checks the layer cache to ensure that it
  151. * retains the correct keycode after a layer change, if the key is still pressed.
  152. */
  153. uint16_t get_event_keycode(keyevent_t event) {
  154. #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
  155. /* TODO: Use store_or_get_action() or a similar function. */
  156. if (!disable_action_cache) {
  157. uint8_t layer;
  158. if (event.pressed) {
  159. layer = layer_switch_get_layer(event.key);
  160. update_source_layers_cache(event.key, layer);
  161. } else {
  162. layer = read_source_layers_cache(event.key);
  163. }
  164. return keymap_key_to_keycode(layer, event.key);
  165. } else
  166. #endif
  167. return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
  168. }
  169. /* Main keycode processing function. Hands off handling to other functions,
  170. * then processes internal Quantum keycodes, then processes ACTIONs.
  171. */
  172. bool process_record_quantum(keyrecord_t *record) {
  173. uint16_t keycode = get_record_keycode(record);
  174. // This is how you use actions here
  175. // if (keycode == KC_LEAD) {
  176. // action_t action;
  177. // action.code = ACTION_DEFAULT_LAYER_SET(0);
  178. // process_action(record, action);
  179. // return false;
  180. // }
  181. #ifdef VELOCIKEY_ENABLE
  182. if (velocikey_enabled() && record->event.pressed) {
  183. velocikey_accelerate();
  184. }
  185. #endif
  186. #ifdef TAP_DANCE_ENABLE
  187. preprocess_tap_dance(keycode, record);
  188. #endif
  189. if (!(
  190. #if defined(KEY_LOCK_ENABLE)
  191. // Must run first to be able to mask key_up events.
  192. process_key_lock(&keycode, record) &&
  193. #endif
  194. #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
  195. process_clicky(keycode, record) &&
  196. #endif // AUDIO_CLICKY
  197. #ifdef HAPTIC_ENABLE
  198. process_haptic(keycode, record) &&
  199. #endif // HAPTIC_ENABLE
  200. #if defined(RGB_MATRIX_ENABLE)
  201. process_rgb_matrix(keycode, record) &&
  202. #endif
  203. process_record_kb(keycode, record) &&
  204. #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
  205. process_midi(keycode, record) &&
  206. #endif
  207. #ifdef AUDIO_ENABLE
  208. process_audio(keycode, record) &&
  209. #endif
  210. #ifdef STENO_ENABLE
  211. process_steno(keycode, record) &&
  212. #endif
  213. #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
  214. process_music(keycode, record) &&
  215. #endif
  216. #ifdef TAP_DANCE_ENABLE
  217. process_tap_dance(keycode, record) &&
  218. #endif
  219. #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
  220. process_unicode_common(keycode, record) &&
  221. #endif
  222. #ifdef LEADER_ENABLE
  223. process_leader(keycode, record) &&
  224. #endif
  225. #ifdef COMBO_ENABLE
  226. process_combo(keycode, record) &&
  227. #endif
  228. #ifdef PRINTING_ENABLE
  229. process_printer(keycode, record) &&
  230. #endif
  231. #ifdef AUTO_SHIFT_ENABLE
  232. process_auto_shift(keycode, record) &&
  233. #endif
  234. #ifdef TERMINAL_ENABLE
  235. process_terminal(keycode, record) &&
  236. #endif
  237. #ifdef SPACE_CADET_ENABLE
  238. process_space_cadet(keycode, record) &&
  239. #endif
  240. true)) {
  241. return false;
  242. }
  243. // Shift / paren setup
  244. switch (keycode) {
  245. case RESET:
  246. if (record->event.pressed) {
  247. reset_keyboard();
  248. }
  249. return false;
  250. case DEBUG:
  251. if (record->event.pressed) {
  252. debug_enable ^= 1;
  253. if (debug_enable) {
  254. print("DEBUG: enabled.\n");
  255. } else {
  256. print("DEBUG: disabled.\n");
  257. }
  258. }
  259. return false;
  260. case EEPROM_RESET:
  261. if (record->event.pressed) {
  262. eeconfig_init();
  263. }
  264. return false;
  265. #ifdef FAUXCLICKY_ENABLE
  266. case FC_TOG:
  267. if (record->event.pressed) {
  268. FAUXCLICKY_TOGGLE;
  269. }
  270. return false;
  271. case FC_ON:
  272. if (record->event.pressed) {
  273. FAUXCLICKY_ON;
  274. }
  275. return false;
  276. case FC_OFF:
  277. if (record->event.pressed) {
  278. FAUXCLICKY_OFF;
  279. }
  280. return false;
  281. #endif
  282. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  283. case RGB_TOG:
  284. // Split keyboards need to trigger on key-up for edge-case issue
  285. # ifndef SPLIT_KEYBOARD
  286. if (record->event.pressed) {
  287. # else
  288. if (!record->event.pressed) {
  289. # endif
  290. rgblight_toggle();
  291. }
  292. return false;
  293. case RGB_MODE_FORWARD:
  294. if (record->event.pressed) {
  295. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
  296. if (shifted) {
  297. rgblight_step_reverse();
  298. } else {
  299. rgblight_step();
  300. }
  301. }
  302. return false;
  303. case RGB_MODE_REVERSE:
  304. if (record->event.pressed) {
  305. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
  306. if (shifted) {
  307. rgblight_step();
  308. } else {
  309. rgblight_step_reverse();
  310. }
  311. }
  312. return false;
  313. case RGB_HUI:
  314. // Split keyboards need to trigger on key-up for edge-case issue
  315. # ifndef SPLIT_KEYBOARD
  316. if (record->event.pressed) {
  317. # else
  318. if (!record->event.pressed) {
  319. # endif
  320. rgblight_increase_hue();
  321. }
  322. return false;
  323. case RGB_HUD:
  324. // Split keyboards need to trigger on key-up for edge-case issue
  325. # ifndef SPLIT_KEYBOARD
  326. if (record->event.pressed) {
  327. # else
  328. if (!record->event.pressed) {
  329. # endif
  330. rgblight_decrease_hue();
  331. }
  332. return false;
  333. case RGB_SAI:
  334. // Split keyboards need to trigger on key-up for edge-case issue
  335. # ifndef SPLIT_KEYBOARD
  336. if (record->event.pressed) {
  337. # else
  338. if (!record->event.pressed) {
  339. # endif
  340. rgblight_increase_sat();
  341. }
  342. return false;
  343. case RGB_SAD:
  344. // Split keyboards need to trigger on key-up for edge-case issue
  345. # ifndef SPLIT_KEYBOARD
  346. if (record->event.pressed) {
  347. # else
  348. if (!record->event.pressed) {
  349. # endif
  350. rgblight_decrease_sat();
  351. }
  352. return false;
  353. case RGB_VAI:
  354. // Split keyboards need to trigger on key-up for edge-case issue
  355. # ifndef SPLIT_KEYBOARD
  356. if (record->event.pressed) {
  357. # else
  358. if (!record->event.pressed) {
  359. # endif
  360. rgblight_increase_val();
  361. }
  362. return false;
  363. case RGB_VAD:
  364. // Split keyboards need to trigger on key-up for edge-case issue
  365. # ifndef SPLIT_KEYBOARD
  366. if (record->event.pressed) {
  367. # else
  368. if (!record->event.pressed) {
  369. # endif
  370. rgblight_decrease_val();
  371. }
  372. return false;
  373. case RGB_SPI:
  374. if (record->event.pressed) {
  375. rgblight_increase_speed();
  376. }
  377. return false;
  378. case RGB_SPD:
  379. if (record->event.pressed) {
  380. rgblight_decrease_speed();
  381. }
  382. return false;
  383. case RGB_MODE_PLAIN:
  384. if (record->event.pressed) {
  385. rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
  386. }
  387. return false;
  388. case RGB_MODE_BREATHE:
  389. # ifdef RGBLIGHT_EFFECT_BREATHING
  390. if (record->event.pressed) {
  391. if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) {
  392. rgblight_step();
  393. } else {
  394. rgblight_mode(RGBLIGHT_MODE_BREATHING);
  395. }
  396. }
  397. # endif
  398. return false;
  399. case RGB_MODE_RAINBOW:
  400. # ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
  401. if (record->event.pressed) {
  402. if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) {
  403. rgblight_step();
  404. } else {
  405. rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD);
  406. }
  407. }
  408. # endif
  409. return false;
  410. case RGB_MODE_SWIRL:
  411. # ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
  412. if (record->event.pressed) {
  413. if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) {
  414. rgblight_step();
  415. } else {
  416. rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
  417. }
  418. }
  419. # endif
  420. return false;
  421. case RGB_MODE_SNAKE:
  422. # ifdef RGBLIGHT_EFFECT_SNAKE
  423. if (record->event.pressed) {
  424. if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) {
  425. rgblight_step();
  426. } else {
  427. rgblight_mode(RGBLIGHT_MODE_SNAKE);
  428. }
  429. }
  430. # endif
  431. return false;
  432. case RGB_MODE_KNIGHT:
  433. # ifdef RGBLIGHT_EFFECT_KNIGHT
  434. if (record->event.pressed) {
  435. if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) {
  436. rgblight_step();
  437. } else {
  438. rgblight_mode(RGBLIGHT_MODE_KNIGHT);
  439. }
  440. }
  441. # endif
  442. return false;
  443. case RGB_MODE_XMAS:
  444. # ifdef RGBLIGHT_EFFECT_CHRISTMAS
  445. if (record->event.pressed) {
  446. rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
  447. }
  448. # endif
  449. return false;
  450. case RGB_MODE_GRADIENT:
  451. # ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
  452. if (record->event.pressed) {
  453. if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) {
  454. rgblight_step();
  455. } else {
  456. rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT);
  457. }
  458. }
  459. # endif
  460. return false;
  461. case RGB_MODE_RGBTEST:
  462. # ifdef RGBLIGHT_EFFECT_RGB_TEST
  463. if (record->event.pressed) {
  464. rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
  465. }
  466. # endif
  467. return false;
  468. #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  469. #ifdef VELOCIKEY_ENABLE
  470. case VLK_TOG:
  471. if (record->event.pressed) {
  472. velocikey_toggle();
  473. }
  474. return false;
  475. #endif
  476. #ifdef PROTOCOL_LUFA
  477. case OUT_AUTO:
  478. if (record->event.pressed) {
  479. set_output(OUTPUT_AUTO);
  480. }
  481. return false;
  482. case OUT_USB:
  483. if (record->event.pressed) {
  484. set_output(OUTPUT_USB);
  485. }
  486. return false;
  487. # ifdef BLUETOOTH_ENABLE
  488. case OUT_BT:
  489. if (record->event.pressed) {
  490. set_output(OUTPUT_BLUETOOTH);
  491. }
  492. return false;
  493. # endif
  494. #endif
  495. case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI:
  496. case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT:
  497. if (record->event.pressed) {
  498. // MAGIC actions (BOOTMAGIC without the boot)
  499. if (!eeconfig_is_enabled()) {
  500. eeconfig_init();
  501. }
  502. /* keymap config */
  503. keymap_config.raw = eeconfig_read_keymap();
  504. switch (keycode) {
  505. case MAGIC_SWAP_CONTROL_CAPSLOCK:
  506. keymap_config.swap_control_capslock = true;
  507. break;
  508. case MAGIC_CAPSLOCK_TO_CONTROL:
  509. keymap_config.capslock_to_control = true;
  510. break;
  511. case MAGIC_SWAP_LALT_LGUI:
  512. keymap_config.swap_lalt_lgui = true;
  513. break;
  514. case MAGIC_SWAP_RALT_RGUI:
  515. keymap_config.swap_ralt_rgui = true;
  516. break;
  517. case MAGIC_SWAP_LCTL_LGUI:
  518. keymap_config.swap_lctl_lgui = true;
  519. break;
  520. case MAGIC_SWAP_RCTL_RGUI:
  521. keymap_config.swap_rctl_rgui = true;
  522. break;
  523. case MAGIC_NO_GUI:
  524. keymap_config.no_gui = true;
  525. break;
  526. case MAGIC_SWAP_GRAVE_ESC:
  527. keymap_config.swap_grave_esc = true;
  528. break;
  529. case MAGIC_SWAP_BACKSLASH_BACKSPACE:
  530. keymap_config.swap_backslash_backspace = true;
  531. break;
  532. case MAGIC_HOST_NKRO:
  533. keymap_config.nkro = true;
  534. break;
  535. case MAGIC_SWAP_ALT_GUI:
  536. keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
  537. #ifdef AUDIO_ENABLE
  538. PLAY_SONG(ag_swap_song);
  539. #endif
  540. break;
  541. case MAGIC_SWAP_CTL_GUI:
  542. keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
  543. #ifdef AUDIO_ENABLE
  544. PLAY_SONG(cg_swap_song);
  545. #endif
  546. break;
  547. case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
  548. keymap_config.swap_control_capslock = false;
  549. break;
  550. case MAGIC_UNCAPSLOCK_TO_CONTROL:
  551. keymap_config.capslock_to_control = false;
  552. break;
  553. case MAGIC_UNSWAP_LALT_LGUI:
  554. keymap_config.swap_lalt_lgui = false;
  555. break;
  556. case MAGIC_UNSWAP_RALT_RGUI:
  557. keymap_config.swap_ralt_rgui = false;
  558. break;
  559. case MAGIC_UNSWAP_LCTL_LGUI:
  560. keymap_config.swap_lctl_lgui = false;
  561. break;
  562. case MAGIC_UNSWAP_RCTL_RGUI:
  563. keymap_config.swap_rctl_rgui = false;
  564. break;
  565. case MAGIC_UNNO_GUI:
  566. keymap_config.no_gui = false;
  567. break;
  568. case MAGIC_UNSWAP_GRAVE_ESC:
  569. keymap_config.swap_grave_esc = false;
  570. break;
  571. case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
  572. keymap_config.swap_backslash_backspace = false;
  573. break;
  574. case MAGIC_UNHOST_NKRO:
  575. keymap_config.nkro = false;
  576. break;
  577. case MAGIC_UNSWAP_ALT_GUI:
  578. keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
  579. #ifdef AUDIO_ENABLE
  580. PLAY_SONG(ag_norm_song);
  581. #endif
  582. break;
  583. case MAGIC_UNSWAP_CTL_GUI:
  584. keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
  585. #ifdef AUDIO_ENABLE
  586. PLAY_SONG(cg_norm_song);
  587. #endif
  588. break;
  589. case MAGIC_TOGGLE_ALT_GUI:
  590. keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
  591. keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
  592. #ifdef AUDIO_ENABLE
  593. if (keymap_config.swap_ralt_rgui) {
  594. PLAY_SONG(ag_swap_song);
  595. } else {
  596. PLAY_SONG(ag_norm_song);
  597. }
  598. #endif
  599. break;
  600. case MAGIC_TOGGLE_CTL_GUI:
  601. keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
  602. keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
  603. #ifdef AUDIO_ENABLE
  604. if (keymap_config.swap_rctl_rgui) {
  605. PLAY_SONG(cg_swap_song);
  606. } else {
  607. PLAY_SONG(cg_norm_song);
  608. }
  609. #endif
  610. break;
  611. case MAGIC_TOGGLE_NKRO:
  612. keymap_config.nkro = !keymap_config.nkro;
  613. break;
  614. case MAGIC_EE_HANDS_LEFT:
  615. eeconfig_update_handedness(true);
  616. break;
  617. case MAGIC_EE_HANDS_RIGHT:
  618. eeconfig_update_handedness(false);
  619. break;
  620. default:
  621. break;
  622. }
  623. eeconfig_update_keymap(keymap_config.raw);
  624. clear_keyboard(); // clear to prevent stuck keys
  625. return false;
  626. }
  627. break;
  628. case GRAVE_ESC: {
  629. uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)));
  630. #ifdef GRAVE_ESC_ALT_OVERRIDE
  631. // if ALT is pressed, ESC is always sent
  632. // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
  633. if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) {
  634. shifted = 0;
  635. }
  636. #endif
  637. #ifdef GRAVE_ESC_CTRL_OVERRIDE
  638. // if CTRL is pressed, ESC is always sent
  639. // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
  640. if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) {
  641. shifted = 0;
  642. }
  643. #endif
  644. #ifdef GRAVE_ESC_GUI_OVERRIDE
  645. // if GUI is pressed, ESC is always sent
  646. if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) {
  647. shifted = 0;
  648. }
  649. #endif
  650. #ifdef GRAVE_ESC_SHIFT_OVERRIDE
  651. // if SHIFT is pressed, ESC is always sent
  652. if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
  653. shifted = 0;
  654. }
  655. #endif
  656. if (record->event.pressed) {
  657. grave_esc_was_shifted = shifted;
  658. add_key(shifted ? KC_GRAVE : KC_ESCAPE);
  659. } else {
  660. del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
  661. }
  662. send_keyboard_report();
  663. return false;
  664. }
  665. #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
  666. case BL_BRTG: {
  667. if (record->event.pressed) {
  668. backlight_toggle_breathing();
  669. }
  670. return false;
  671. }
  672. #endif
  673. }
  674. return process_action_kb(record);
  675. }
  676. __attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  677. 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0};
  678. __attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  680. __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL SOH STX ETX EOT ENQ ACK BEL
  681. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  682. // BS TAB LF VT FF CR SO SI
  683. KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  684. // DLE DC1 DC2 DC3 DC4 NAK SYN ETB
  685. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  686. // CAN EM SUB ESC FS GS RS US
  687. XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  688. // ! " # $ % & '
  689. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  690. // ( ) * + , - . /
  691. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  692. // 0 1 2 3 4 5 6 7
  693. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  694. // 8 9 : ; < = > ?
  695. KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  696. // @ A B C D E F G
  697. KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  698. // H I J K L M N O
  699. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  700. // P Q R S T U V W
  701. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  702. // X Y Z [ \ ] ^ _
  703. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  704. // ` a b c d e f g
  705. KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  706. // h i j k l m n o
  707. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  708. // p q r s t u v w
  709. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  710. // x y z { | } ~ DEL
  711. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
  712. void send_string(const char *str) { send_string_with_delay(str, 0); }
  713. void send_string_P(const char *str) { send_string_with_delay_P(str, 0); }
  714. void send_string_with_delay(const char *str, uint8_t interval) {
  715. while (1) {
  716. char ascii_code = *str;
  717. if (!ascii_code) break;
  718. if (ascii_code == SS_TAP_CODE) {
  719. // tap
  720. uint8_t keycode = *(++str);
  721. register_code(keycode);
  722. unregister_code(keycode);
  723. } else if (ascii_code == SS_DOWN_CODE) {
  724. // down
  725. uint8_t keycode = *(++str);
  726. register_code(keycode);
  727. } else if (ascii_code == SS_UP_CODE) {
  728. // up
  729. uint8_t keycode = *(++str);
  730. unregister_code(keycode);
  731. } else {
  732. send_char(ascii_code);
  733. }
  734. ++str;
  735. // interval
  736. {
  737. uint8_t ms = interval;
  738. while (ms--) wait_ms(1);
  739. }
  740. }
  741. }
  742. void send_string_with_delay_P(const char *str, uint8_t interval) {
  743. while (1) {
  744. char ascii_code = pgm_read_byte(str);
  745. if (!ascii_code) break;
  746. if (ascii_code == SS_TAP_CODE) {
  747. // tap
  748. uint8_t keycode = pgm_read_byte(++str);
  749. register_code(keycode);
  750. unregister_code(keycode);
  751. } else if (ascii_code == SS_DOWN_CODE) {
  752. // down
  753. uint8_t keycode = pgm_read_byte(++str);
  754. register_code(keycode);
  755. } else if (ascii_code == SS_UP_CODE) {
  756. // up
  757. uint8_t keycode = pgm_read_byte(++str);
  758. unregister_code(keycode);
  759. } else {
  760. send_char(ascii_code);
  761. }
  762. ++str;
  763. // interval
  764. {
  765. uint8_t ms = interval;
  766. while (ms--) wait_ms(1);
  767. }
  768. }
  769. }
  770. void send_char(char ascii_code) {
  771. uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
  772. bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]);
  773. bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]);
  774. if (is_shifted) {
  775. register_code(KC_LSFT);
  776. }
  777. if (is_altgred) {
  778. register_code(KC_RALT);
  779. }
  780. tap_code(keycode);
  781. if (is_altgred) {
  782. unregister_code(KC_RALT);
  783. }
  784. if (is_shifted) {
  785. unregister_code(KC_LSFT);
  786. }
  787. }
  788. void set_single_persistent_default_layer(uint8_t default_layer) {
  789. #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
  790. PLAY_SONG(default_layer_songs[default_layer]);
  791. #endif
  792. eeconfig_update_default_layer(1U << default_layer);
  793. default_layer_set(1U << default_layer);
  794. }
  795. layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  796. layer_state_t mask12 = (1UL << layer1) | (1UL << layer2);
  797. layer_state_t mask3 = 1UL << layer3;
  798. return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
  799. }
  800. 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)); }
  801. void tap_random_base64(void) {
  802. #if defined(__AVR_ATmega32U4__)
  803. uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
  804. #else
  805. uint8_t key = rand() % 64;
  806. #endif
  807. switch (key) {
  808. case 0 ... 25:
  809. register_code(KC_LSFT);
  810. register_code(key + KC_A);
  811. unregister_code(key + KC_A);
  812. unregister_code(KC_LSFT);
  813. break;
  814. case 26 ... 51:
  815. register_code(key - 26 + KC_A);
  816. unregister_code(key - 26 + KC_A);
  817. break;
  818. case 52:
  819. register_code(KC_0);
  820. unregister_code(KC_0);
  821. break;
  822. case 53 ... 61:
  823. register_code(key - 53 + KC_1);
  824. unregister_code(key - 53 + KC_1);
  825. break;
  826. case 62:
  827. register_code(KC_LSFT);
  828. register_code(KC_EQL);
  829. unregister_code(KC_EQL);
  830. unregister_code(KC_LSFT);
  831. break;
  832. case 63:
  833. register_code(KC_SLSH);
  834. unregister_code(KC_SLSH);
  835. break;
  836. }
  837. }
  838. __attribute__((weak)) void bootmagic_lite(void) {
  839. // The lite version of TMK's bootmagic based on Wilba.
  840. // 100% less potential for accidentally making the
  841. // keyboard do stupid things.
  842. // We need multiple scans because debouncing can't be turned off.
  843. matrix_scan();
  844. #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
  845. wait_ms(DEBOUNCING_DELAY * 2);
  846. #elif defined(DEBOUNCE) && DEBOUNCE > 0
  847. wait_ms(DEBOUNCE * 2);
  848. #else
  849. wait_ms(30);
  850. #endif
  851. matrix_scan();
  852. // If the Esc and space bar are held down on power up,
  853. // reset the EEPROM valid state and jump to bootloader.
  854. // Assumes Esc is at [0,0].
  855. // This isn't very generalized, but we need something that doesn't
  856. // rely on user's keymaps in firmware or EEPROM.
  857. if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
  858. eeconfig_disable();
  859. // Jump to bootloader.
  860. bootloader_jump();
  861. }
  862. }
  863. void matrix_init_quantum() {
  864. #ifdef BOOTMAGIC_LITE
  865. bootmagic_lite();
  866. #endif
  867. if (!eeconfig_is_enabled()) {
  868. eeconfig_init();
  869. }
  870. #ifdef BACKLIGHT_ENABLE
  871. # ifdef LED_MATRIX_ENABLE
  872. led_matrix_init();
  873. # else
  874. backlight_init_ports();
  875. # endif
  876. #endif
  877. #ifdef AUDIO_ENABLE
  878. audio_init();
  879. #endif
  880. #ifdef RGB_MATRIX_ENABLE
  881. rgb_matrix_init();
  882. #endif
  883. #ifdef ENCODER_ENABLE
  884. encoder_init();
  885. #endif
  886. #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
  887. unicode_input_mode_init();
  888. #endif
  889. #ifdef HAPTIC_ENABLE
  890. haptic_init();
  891. #endif
  892. #ifdef OUTPUT_AUTO_ENABLE
  893. set_output(OUTPUT_AUTO);
  894. #endif
  895. #ifdef DIP_SWITCH_ENABLE
  896. dip_switch_init();
  897. #endif
  898. matrix_init_kb();
  899. }
  900. void matrix_scan_quantum() {
  901. #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
  902. matrix_scan_music();
  903. #endif
  904. #ifdef TAP_DANCE_ENABLE
  905. matrix_scan_tap_dance();
  906. #endif
  907. #ifdef COMBO_ENABLE
  908. matrix_scan_combo();
  909. #endif
  910. #if defined(BACKLIGHT_ENABLE)
  911. # if defined(LED_MATRIX_ENABLE)
  912. led_matrix_task();
  913. # elif defined(BACKLIGHT_PIN)
  914. backlight_task();
  915. # endif
  916. #endif
  917. #ifdef RGB_MATRIX_ENABLE
  918. rgb_matrix_task();
  919. #endif
  920. #ifdef ENCODER_ENABLE
  921. encoder_read();
  922. #endif
  923. #ifdef HAPTIC_ENABLE
  924. haptic_task();
  925. #endif
  926. #ifdef DIP_SWITCH_ENABLE
  927. dip_switch_read(false);
  928. #endif
  929. matrix_scan_kb();
  930. }
  931. #ifdef HD44780_ENABLED
  932. # include "hd44780.h"
  933. #endif
  934. // Functions for spitting out values
  935. //
  936. void send_dword(uint32_t number) { // this might not actually work
  937. uint16_t word = (number >> 16);
  938. send_word(word);
  939. send_word(number & 0xFFFFUL);
  940. }
  941. void send_word(uint16_t number) {
  942. uint8_t byte = number >> 8;
  943. send_byte(byte);
  944. send_byte(number & 0xFF);
  945. }
  946. void send_byte(uint8_t number) {
  947. uint8_t nibble = number >> 4;
  948. send_nibble(nibble);
  949. send_nibble(number & 0xF);
  950. }
  951. void send_nibble(uint8_t number) {
  952. switch (number) {
  953. case 0:
  954. register_code(KC_0);
  955. unregister_code(KC_0);
  956. break;
  957. case 1 ... 9:
  958. register_code(KC_1 + (number - 1));
  959. unregister_code(KC_1 + (number - 1));
  960. break;
  961. case 0xA ... 0xF:
  962. register_code(KC_A + (number - 0xA));
  963. unregister_code(KC_A + (number - 0xA));
  964. break;
  965. }
  966. }
  967. __attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) {
  968. hex = hex & 0xF;
  969. if (hex == 0x0) {
  970. return KC_0;
  971. } else if (hex < 0xA) {
  972. return KC_1 + (hex - 0x1);
  973. } else {
  974. return KC_A + (hex - 0xA);
  975. }
  976. }
  977. void api_send_unicode(uint32_t unicode) {
  978. #ifdef API_ENABLE
  979. uint8_t chunk[4];
  980. dword_to_bytes(unicode, chunk);
  981. MT_SEND_DATA(DT_UNICODE, chunk, 5);
  982. #endif
  983. }
  984. __attribute__((weak)) void led_set_user(uint8_t usb_led) {}
  985. __attribute__((weak)) void led_set_kb(uint8_t usb_led) { led_set_user(usb_led); }
  986. __attribute__((weak)) void led_init_ports(void) {}
  987. __attribute__((weak)) void led_set(uint8_t usb_led) {
  988. #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
  989. // Use backlight as Caps Lock indicator
  990. uint8_t bl_toggle_lvl = 0;
  991. if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) && !backlight_config.enable) {
  992. // Turning Caps Lock ON and backlight is disabled in config
  993. // Toggling backlight to the brightest level
  994. bl_toggle_lvl = BACKLIGHT_LEVELS;
  995. } else if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK) && backlight_config.enable) {
  996. // Turning Caps Lock OFF and backlight is enabled in config
  997. // Toggling backlight and restoring config level
  998. bl_toggle_lvl = backlight_config.level;
  999. }
  1000. // Set level without modify backlight_config to keep ability to restore state
  1001. backlight_set(bl_toggle_lvl);
  1002. #endif
  1003. led_set_kb(usb_led);
  1004. }
  1005. //------------------------------------------------------------------------------
  1006. // Override these functions in your keymap file to play different tunes on
  1007. // different events such as startup and bootloader jump
  1008. __attribute__((weak)) void startup_user() {}
  1009. __attribute__((weak)) void shutdown_user() {}
  1010. //------------------------------------------------------------------------------