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.

1066 lines
30 KiB

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
7 years ago
7 years ago
7 years ago
7 years ago
Lets split eh (#3120) * Line ending stuff again * Added Let's Split Eh? Files and updated #USE_IC2 checks to also include th EH revision (can only be used in I2C) * Added personal keymap, updated some of the EH files * Created new keyboard file for testing "lets_split_eh" will merge into lets_split once fully functional * Added split code from lets_split, removed pro micro imports and LED code THIS IS WORKING CODE, WITHOUT RGB AND BACKLIGHT * Took back original Lets Slit files for the lets_split keyboard, working in the lets_split_eh folder for now * Updated eh.c * More rework of the I2C code, added global flags for split boards. * Introduced RGB over I2C, having weird edge case issues at the moment though * Fixed weird I2C edgecase with RGB, although still would like to track down route cause.. * Changed RGB keycodes (static ones) to activate on key-up instead of key-down to elimate weird ghosting issue over I2C * Lots of changes, mainly externalized the Split keyboard code and added logic for only including when needed. - Added makefile option "SPLIT_KEYBOARD" that when = yes will include the split keyboard files and custom matrix - Split keyboard files placed into quantum/split_common/ - Added define option for config files "SPLIT_HAND_PIN" FOr using high/low pin to determine handedness, low = right hand, high = left hand - Cleaned up split logic for RGB and Backlight so it is only exectuted / included when needed * Updated documentation for the new makefile options and #defines specific to split keyboards * Added a bit more info to docs, so people aren't confused * Modifed Let's Split to use externalized code, also added left and right hand eeprom files to the split_common folder * Removed some debugging from eh.c * Small changes to keyboard configs. Also added a default keymap (just a copy of my that_canadian keymap). * Added a README file to the Let's Split Eh? * Changed it so RGB static updates are done on key-up ONLY for split boards rather than all boards. Also fixed leftover un-used variable in rgblight.c * Updated default keymap and my keymap for Let's Split Eh? Updated the comments so it reflects RGB control, and removed audio functions. * Fixed lets_split_eh not having a default version * Removed "eh" references from lets_split folder for now * Took lets_split folder from master to fix travis build errors, weird my local was overriding. * Changed LAYOUT_ortho_4x12_kc -> LAYOUT_kc_ortho_4x12 to match bakingpy and others * Removed rules.mk from my lets_split keymap, not needed * Updated the config_options doc to better explain the usage of "#define SPLIT_HAND_PIN"
5 years ago
7 years ago
7 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
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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
7 years ago
7 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
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
7 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
7 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
  1. /* Copyright 2016-2017 Yang Liu
  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 <math.h>
  17. #include <string.h>
  18. #ifdef __AVR__
  19. #include <avr/eeprom.h>
  20. #include <avr/interrupt.h>
  21. #endif
  22. #ifdef STM32_EEPROM_ENABLE
  23. #include "hal.h"
  24. #include "eeprom.h"
  25. #include "eeprom_stm32.h"
  26. #endif
  27. #include "wait.h"
  28. #include "progmem.h"
  29. #include "timer.h"
  30. #include "rgblight.h"
  31. #include "debug.h"
  32. #include "led_tables.h"
  33. #ifdef VELOCIKEY_ENABLE
  34. #include "velocikey.h"
  35. #endif
  36. #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
  37. #define _RGBM_SINGLE_DYNAMIC(sym)
  38. #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym,
  39. #define _RGBM_MULTI_DYNAMIC(sym)
  40. #define _RGBM_TMP_STATIC(sym) RGBLIGHT_MODE_ ## sym,
  41. #define _RGBM_TMP_DYNAMIC(sym)
  42. static uint8_t static_effect_table [] = {
  43. #include "rgblight.h"
  44. };
  45. static inline int is_static_effect(uint8_t mode) {
  46. return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL;
  47. }
  48. #define MIN(a,b) (((a)<(b))?(a):(b))
  49. #define MAX(a,b) (((a)>(b))?(a):(b))
  50. #ifdef RGBLIGHT_LED_MAP
  51. const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP;
  52. #endif
  53. #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
  54. __attribute__ ((weak))
  55. const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
  56. #endif
  57. rgblight_config_t rgblight_config;
  58. bool is_rgblight_initialized = false;
  59. #ifndef LED_ARRAY
  60. LED_TYPE led[RGBLED_NUM];
  61. #define LED_ARRAY led
  62. #endif
  63. bool rgblight_timer_enabled = false;
  64. static uint8_t clipping_start_pos = 0;
  65. static uint8_t clipping_num_leds = RGBLED_NUM;
  66. void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) {
  67. clipping_start_pos = start_pos;
  68. clipping_num_leds = num_leds;
  69. }
  70. void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
  71. uint8_t r = 0, g = 0, b = 0, base, color;
  72. if (val > RGBLIGHT_LIMIT_VAL) {
  73. val=RGBLIGHT_LIMIT_VAL; // limit the val
  74. }
  75. if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
  76. r = val;
  77. g = val;
  78. b = val;
  79. } else {
  80. base = ((255 - sat) * val) >> 8;
  81. color = (val - base) * (hue % 60) / 60;
  82. switch (hue / 60) {
  83. case 0:
  84. r = val;
  85. g = base + color;
  86. b = base;
  87. break;
  88. case 1:
  89. r = val - color;
  90. g = val;
  91. b = base;
  92. break;
  93. case 2:
  94. r = base;
  95. g = val;
  96. b = base + color;
  97. break;
  98. case 3:
  99. r = base;
  100. g = val - color;
  101. b = val;
  102. break;
  103. case 4:
  104. r = base + color;
  105. g = base;
  106. b = val;
  107. break;
  108. case 5:
  109. r = val;
  110. g = base;
  111. b = val - color;
  112. break;
  113. }
  114. }
  115. r = pgm_read_byte(&CIE1931_CURVE[r]);
  116. g = pgm_read_byte(&CIE1931_CURVE[g]);
  117. b = pgm_read_byte(&CIE1931_CURVE[b]);
  118. setrgb(r, g, b, led1);
  119. }
  120. void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
  121. (*led1).r = r;
  122. (*led1).g = g;
  123. (*led1).b = b;
  124. }
  125. void rgblight_check_config(void) {
  126. /* Add some out of bound checks for RGB light config */
  127. if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) {
  128. rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
  129. }
  130. else if (rgblight_config.mode > RGBLIGHT_MODES) {
  131. rgblight_config.mode = RGBLIGHT_MODES;
  132. }
  133. if (rgblight_config.hue < 0) {
  134. rgblight_config.hue = 0;
  135. } else if (rgblight_config.hue > 360) {
  136. rgblight_config.hue %= 360;
  137. }
  138. if (rgblight_config.sat < 0) {
  139. rgblight_config.sat = 0;
  140. } else if (rgblight_config.sat > 255) {
  141. rgblight_config.sat = 255;
  142. }
  143. if (rgblight_config.val < 0) {
  144. rgblight_config.val = 0;
  145. } else if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) {
  146. rgblight_config.val = RGBLIGHT_LIMIT_VAL;
  147. }
  148. }
  149. uint32_t eeconfig_read_rgblight(void) {
  150. #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
  151. return eeprom_read_dword(EECONFIG_RGBLIGHT);
  152. #else
  153. return 0;
  154. #endif
  155. }
  156. void eeconfig_update_rgblight(uint32_t val) {
  157. #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
  158. rgblight_check_config();
  159. eeprom_update_dword(EECONFIG_RGBLIGHT, val);
  160. #endif
  161. }
  162. void eeconfig_update_rgblight_default(void) {
  163. //dprintf("eeconfig_update_rgblight_default\n");
  164. rgblight_config.enable = 1;
  165. rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
  166. rgblight_config.hue = 0;
  167. rgblight_config.sat = 255;
  168. rgblight_config.val = RGBLIGHT_LIMIT_VAL;
  169. rgblight_config.speed = 0;
  170. eeconfig_update_rgblight(rgblight_config.raw);
  171. }
  172. void eeconfig_debug_rgblight(void) {
  173. dprintf("rgblight_config eprom\n");
  174. dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
  175. dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
  176. dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
  177. dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
  178. dprintf("rgblight_config.val = %d\n", rgblight_config.val);
  179. dprintf("rgblight_config.speed = %d\n", rgblight_config.speed);
  180. }
  181. void rgblight_init(void) {
  182. /* if already initialized, don't do it again.
  183. If you must do it again, extern this and set to false, first.
  184. This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */
  185. if (is_rgblight_initialized) { return; }
  186. debug_enable = 1; // Debug ON!
  187. dprintf("rgblight_init called.\n");
  188. dprintf("rgblight_init start!\n");
  189. if (!eeconfig_is_enabled()) {
  190. dprintf("rgblight_init eeconfig is not enabled.\n");
  191. eeconfig_init();
  192. eeconfig_update_rgblight_default();
  193. }
  194. rgblight_config.raw = eeconfig_read_rgblight();
  195. if (!rgblight_config.mode) {
  196. dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
  197. eeconfig_update_rgblight_default();
  198. rgblight_config.raw = eeconfig_read_rgblight();
  199. }
  200. rgblight_check_config();
  201. eeconfig_debug_rgblight(); // display current eeprom values
  202. #ifdef RGBLIGHT_USE_TIMER
  203. rgblight_timer_init(); // setup the timer
  204. #endif
  205. if (rgblight_config.enable) {
  206. rgblight_mode_noeeprom(rgblight_config.mode);
  207. }
  208. is_rgblight_initialized = true;
  209. }
  210. uint32_t rgblight_read_dword(void) {
  211. return rgblight_config.raw;
  212. }
  213. void rgblight_update_dword(uint32_t dword) {
  214. rgblight_config.raw = dword;
  215. if (rgblight_config.enable)
  216. rgblight_mode_noeeprom(rgblight_config.mode);
  217. else {
  218. #ifdef RGBLIGHT_USE_TIMER
  219. rgblight_timer_disable();
  220. #endif
  221. rgblight_set();
  222. }
  223. }
  224. void rgblight_increase(void) {
  225. uint8_t mode = 0;
  226. if (rgblight_config.mode < RGBLIGHT_MODES) {
  227. mode = rgblight_config.mode + 1;
  228. }
  229. rgblight_mode(mode);
  230. }
  231. void rgblight_decrease(void) {
  232. uint8_t mode = 0;
  233. // Mode will never be < 1. If it ever is, eeprom needs to be initialized.
  234. if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) {
  235. mode = rgblight_config.mode - 1;
  236. }
  237. rgblight_mode(mode);
  238. }
  239. void rgblight_step_helper(bool write_to_eeprom) {
  240. uint8_t mode = 0;
  241. mode = rgblight_config.mode + 1;
  242. if (mode > RGBLIGHT_MODES) {
  243. mode = 1;
  244. }
  245. rgblight_mode_eeprom_helper(mode, write_to_eeprom);
  246. }
  247. void rgblight_step_noeeprom(void) {
  248. rgblight_step_helper(false);
  249. }
  250. void rgblight_step(void) {
  251. rgblight_step_helper(true);
  252. }
  253. void rgblight_step_reverse_helper(bool write_to_eeprom) {
  254. uint8_t mode = 0;
  255. mode = rgblight_config.mode - 1;
  256. if (mode < 1) {
  257. mode = RGBLIGHT_MODES;
  258. }
  259. rgblight_mode_eeprom_helper(mode, write_to_eeprom);
  260. }
  261. void rgblight_step_reverse_noeeprom(void) {
  262. rgblight_step_reverse_helper(false);
  263. }
  264. void rgblight_step_reverse(void) {
  265. rgblight_step_reverse_helper(true);
  266. }
  267. uint8_t rgblight_get_mode(void) {
  268. if (!rgblight_config.enable) {
  269. return false;
  270. }
  271. return rgblight_config.mode;
  272. }
  273. void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
  274. if (!rgblight_config.enable) {
  275. return;
  276. }
  277. if (mode < RGBLIGHT_MODE_STATIC_LIGHT) {
  278. rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
  279. } else if (mode > RGBLIGHT_MODES) {
  280. rgblight_config.mode = RGBLIGHT_MODES;
  281. } else {
  282. rgblight_config.mode = mode;
  283. }
  284. if (write_to_eeprom) {
  285. eeconfig_update_rgblight(rgblight_config.raw);
  286. xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
  287. } else {
  288. xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
  289. }
  290. if( is_static_effect(rgblight_config.mode) ) {
  291. #ifdef RGBLIGHT_USE_TIMER
  292. rgblight_timer_disable();
  293. #endif
  294. } else {
  295. #ifdef RGBLIGHT_USE_TIMER
  296. rgblight_timer_enable();
  297. #endif
  298. }
  299. rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
  300. }
  301. void rgblight_mode(uint8_t mode) {
  302. rgblight_mode_eeprom_helper(mode, true);
  303. }
  304. void rgblight_mode_noeeprom(uint8_t mode) {
  305. rgblight_mode_eeprom_helper(mode, false);
  306. }
  307. void rgblight_toggle(void) {
  308. xprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
  309. if (rgblight_config.enable) {
  310. rgblight_disable();
  311. }
  312. else {
  313. rgblight_enable();
  314. }
  315. }
  316. void rgblight_toggle_noeeprom(void) {
  317. xprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
  318. if (rgblight_config.enable) {
  319. rgblight_disable_noeeprom();
  320. }
  321. else {
  322. rgblight_enable_noeeprom();
  323. }
  324. }
  325. void rgblight_enable(void) {
  326. rgblight_config.enable = 1;
  327. // No need to update EEPROM here. rgblight_mode() will do that, actually
  328. //eeconfig_update_rgblight(rgblight_config.raw);
  329. xprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
  330. rgblight_mode(rgblight_config.mode);
  331. }
  332. void rgblight_enable_noeeprom(void) {
  333. rgblight_config.enable = 1;
  334. xprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
  335. rgblight_mode_noeeprom(rgblight_config.mode);
  336. }
  337. void rgblight_disable(void) {
  338. rgblight_config.enable = 0;
  339. eeconfig_update_rgblight(rgblight_config.raw);
  340. xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
  341. #ifdef RGBLIGHT_USE_TIMER
  342. rgblight_timer_disable();
  343. #endif
  344. wait_ms(50);
  345. rgblight_set();
  346. }
  347. void rgblight_disable_noeeprom(void) {
  348. rgblight_config.enable = 0;
  349. xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
  350. #ifdef RGBLIGHT_USE_TIMER
  351. rgblight_timer_disable();
  352. #endif
  353. wait_ms(50);
  354. rgblight_set();
  355. }
  356. // Deals with the messy details of incrementing an integer
  357. static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
  358. int16_t new_value = value;
  359. new_value += step;
  360. return MIN( MAX( new_value, min ), max );
  361. }
  362. static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
  363. int16_t new_value = value;
  364. new_value -= step;
  365. return MIN( MAX( new_value, min ), max );
  366. }
  367. void rgblight_increase_hue_helper(bool write_to_eeprom) {
  368. uint16_t hue;
  369. hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360;
  370. rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
  371. }
  372. void rgblight_increase_hue_noeeprom(void) {
  373. rgblight_increase_hue_helper(false);
  374. }
  375. void rgblight_increase_hue(void) {
  376. rgblight_increase_hue_helper(true);
  377. }
  378. void rgblight_decrease_hue_helper(bool write_to_eeprom) {
  379. uint16_t hue;
  380. if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) {
  381. hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360;
  382. } else {
  383. hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360;
  384. }
  385. rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
  386. }
  387. void rgblight_decrease_hue_noeeprom(void) {
  388. rgblight_decrease_hue_helper(false);
  389. }
  390. void rgblight_decrease_hue(void) {
  391. rgblight_decrease_hue_helper(true);
  392. }
  393. void rgblight_increase_sat_helper(bool write_to_eeprom) {
  394. uint8_t sat;
  395. if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) {
  396. sat = 255;
  397. } else {
  398. sat = rgblight_config.sat + RGBLIGHT_SAT_STEP;
  399. }
  400. rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
  401. }
  402. void rgblight_increase_sat_noeeprom(void) {
  403. rgblight_increase_sat_helper(false);
  404. }
  405. void rgblight_increase_sat(void) {
  406. rgblight_increase_sat_helper(true);
  407. }
  408. void rgblight_decrease_sat_helper(bool write_to_eeprom) {
  409. uint8_t sat;
  410. if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) {
  411. sat = 0;
  412. } else {
  413. sat = rgblight_config.sat - RGBLIGHT_SAT_STEP;
  414. }
  415. rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
  416. }
  417. void rgblight_decrease_sat_noeeprom(void) {
  418. rgblight_decrease_sat_helper(false);
  419. }
  420. void rgblight_decrease_sat(void) {
  421. rgblight_decrease_sat_helper(true);
  422. }
  423. void rgblight_increase_val_helper(bool write_to_eeprom) {
  424. uint8_t val;
  425. if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) {
  426. val = RGBLIGHT_LIMIT_VAL;
  427. } else {
  428. val = rgblight_config.val + RGBLIGHT_VAL_STEP;
  429. }
  430. rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
  431. }
  432. void rgblight_increase_val_noeeprom(void) {
  433. rgblight_increase_val_helper(false);
  434. }
  435. void rgblight_increase_val(void) {
  436. rgblight_increase_val_helper(true);
  437. }
  438. void rgblight_decrease_val_helper(bool write_to_eeprom) {
  439. uint8_t val;
  440. if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) {
  441. val = 0;
  442. } else {
  443. val = rgblight_config.val - RGBLIGHT_VAL_STEP;
  444. }
  445. rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
  446. }
  447. void rgblight_decrease_val_noeeprom(void) {
  448. rgblight_decrease_val_helper(false);
  449. }
  450. void rgblight_decrease_val(void) {
  451. rgblight_decrease_val_helper(true);
  452. }
  453. void rgblight_increase_speed(void) {
  454. rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 );
  455. eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
  456. }
  457. void rgblight_decrease_speed(void) {
  458. rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 );
  459. eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
  460. }
  461. void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) {
  462. if (rgblight_config.enable) {
  463. LED_TYPE tmp_led;
  464. sethsv(hue, sat, val, &tmp_led);
  465. // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val);
  466. rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
  467. }
  468. }
  469. void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
  470. if (rgblight_config.enable) {
  471. if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
  472. // same static color
  473. LED_TYPE tmp_led;
  474. sethsv(hue, sat, val, &tmp_led);
  475. rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
  476. } else {
  477. // all LEDs in same color
  478. if ( 1 == 0 ) { //dummy
  479. }
  480. #ifdef RGBLIGHT_EFFECT_BREATHING
  481. else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING &&
  482. rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) {
  483. // breathing mode, ignore the change of val, use in memory value instead
  484. val = rgblight_config.val;
  485. }
  486. #endif
  487. #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
  488. else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD &&
  489. rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) {
  490. // rainbow mood, ignore the change of hue
  491. hue = rgblight_config.hue;
  492. }
  493. #endif
  494. #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
  495. else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL &&
  496. rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) {
  497. // rainbow swirl, ignore the change of hue
  498. hue = rgblight_config.hue;
  499. }
  500. #endif
  501. #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
  502. else if (rgblight_config.mode >= RGBLIGHT_MODE_STATIC_GRADIENT &&
  503. rgblight_config.mode <= RGBLIGHT_MODE_STATIC_GRADIENT_end) {
  504. // static gradient
  505. uint16_t _hue;
  506. int8_t direction = ((rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) % 2) ? -1 : 1;
  507. uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) / 2]);
  508. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  509. _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360;
  510. dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range);
  511. sethsv(_hue, sat, val, (LED_TYPE *)&led[i]);
  512. }
  513. rgblight_set();
  514. }
  515. #endif
  516. }
  517. rgblight_config.hue = hue;
  518. rgblight_config.sat = sat;
  519. rgblight_config.val = val;
  520. if (write_to_eeprom) {
  521. eeconfig_update_rgblight(rgblight_config.raw);
  522. xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
  523. } else {
  524. xprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
  525. }
  526. }
  527. }
  528. void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
  529. rgblight_sethsv_eeprom_helper(hue, sat, val, true);
  530. }
  531. void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
  532. rgblight_sethsv_eeprom_helper(hue, sat, val, false);
  533. }
  534. uint16_t rgblight_get_hue(void) {
  535. return rgblight_config.hue;
  536. }
  537. uint8_t rgblight_get_sat(void) {
  538. return rgblight_config.sat;
  539. }
  540. uint8_t rgblight_get_val(void) {
  541. return rgblight_config.val;
  542. }
  543. void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
  544. if (!rgblight_config.enable) { return; }
  545. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  546. led[i].r = r;
  547. led[i].g = g;
  548. led[i].b = b;
  549. }
  550. rgblight_set();
  551. }
  552. void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) {
  553. if (!rgblight_config.enable || index >= RGBLED_NUM) { return; }
  554. led[index].r = r;
  555. led[index].g = g;
  556. led[index].b = b;
  557. rgblight_set();
  558. }
  559. void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) {
  560. if (!rgblight_config.enable) { return; }
  561. LED_TYPE tmp_led;
  562. sethsv(hue, sat, val, &tmp_led);
  563. rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
  564. }
  565. #if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \
  566. || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
  567. static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
  568. return
  569. #ifdef VELOCIKEY_ENABLE
  570. velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
  571. #endif
  572. pgm_read_byte(default_interval_address);
  573. }
  574. #endif
  575. void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
  576. if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
  577. for (uint8_t i = start; i < end; i++) {
  578. led[i].r = r;
  579. led[i].g = g;
  580. led[i].b = b;
  581. }
  582. rgblight_set();
  583. wait_ms(1);
  584. }
  585. void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
  586. if (!rgblight_config.enable) { return; }
  587. LED_TYPE tmp_led;
  588. sethsv(hue, sat, val, &tmp_led);
  589. rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
  590. }
  591. void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) {
  592. rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2);
  593. }
  594. void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) {
  595. rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
  596. }
  597. void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) {
  598. rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2);
  599. }
  600. void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) {
  601. rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
  602. }
  603. #ifndef RGBLIGHT_CUSTOM_DRIVER
  604. void rgblight_set(void) {
  605. LED_TYPE *start_led = led + clipping_start_pos;
  606. uint16_t num_leds = clipping_num_leds;
  607. if (rgblight_config.enable) {
  608. #ifdef RGBLIGHT_LED_MAP
  609. LED_TYPE led0[RGBLED_NUM];
  610. for(uint8_t i = 0; i < RGBLED_NUM; i++) {
  611. led0[i] = led[pgm_read_byte(&led_map[i])];
  612. }
  613. start_led = led0 + clipping_start_pos;
  614. #endif
  615. #ifdef RGBW
  616. ws2812_setleds_rgbw(start_led, num_leds);
  617. #else
  618. ws2812_setleds(start_led, num_leds);
  619. #endif
  620. } else {
  621. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  622. led[i].r = 0;
  623. led[i].g = 0;
  624. led[i].b = 0;
  625. }
  626. #ifdef RGBW
  627. ws2812_setleds_rgbw(start_led, num_leds);
  628. #else
  629. ws2812_setleds(start_led, num_leds);
  630. #endif
  631. }
  632. }
  633. #endif
  634. #ifdef RGBLIGHT_USE_TIMER
  635. // Animation timer -- AVR Timer3
  636. void rgblight_timer_init(void) {
  637. // static uint8_t rgblight_timer_is_init = 0;
  638. // if (rgblight_timer_is_init) {
  639. // return;
  640. // }
  641. // rgblight_timer_is_init = 1;
  642. // /* Timer 3 setup */
  643. // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP
  644. // | _BV(CS30); // Clock selelct: clk/1
  645. // /* Set TOP value */
  646. // uint8_t sreg = SREG;
  647. // cli();
  648. // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
  649. // OCR3AL = RGBLED_TIMER_TOP & 0xff;
  650. // SREG = sreg;
  651. rgblight_timer_enabled = true;
  652. }
  653. void rgblight_timer_enable(void) {
  654. rgblight_timer_enabled = true;
  655. dprintf("TIMER3 enabled.\n");
  656. }
  657. void rgblight_timer_disable(void) {
  658. rgblight_timer_enabled = false;
  659. dprintf("TIMER3 disabled.\n");
  660. }
  661. void rgblight_timer_toggle(void) {
  662. rgblight_timer_enabled ^= rgblight_timer_enabled;
  663. dprintf("TIMER3 toggled.\n");
  664. }
  665. void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
  666. rgblight_enable();
  667. rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
  668. rgblight_setrgb(r, g, b);
  669. }
  670. void rgblight_task(void) {
  671. if (rgblight_timer_enabled) {
  672. // static light mode, do nothing here
  673. if ( 1 == 0 ) { //dummy
  674. }
  675. #ifdef RGBLIGHT_EFFECT_BREATHING
  676. else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING &&
  677. rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) {
  678. // breathing mode
  679. rgblight_effect_breathing(rgblight_config.mode - RGBLIGHT_MODE_BREATHING );
  680. }
  681. #endif
  682. #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
  683. else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD &&
  684. rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) {
  685. // rainbow mood mode
  686. rgblight_effect_rainbow_mood(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_MOOD);
  687. }
  688. #endif
  689. #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
  690. else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL &&
  691. rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) {
  692. // rainbow swirl mode
  693. rgblight_effect_rainbow_swirl(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_SWIRL);
  694. }
  695. #endif
  696. #ifdef RGBLIGHT_EFFECT_SNAKE
  697. else if (rgblight_config.mode >= RGBLIGHT_MODE_SNAKE &&
  698. rgblight_config.mode <= RGBLIGHT_MODE_SNAKE_end) {
  699. // snake mode
  700. rgblight_effect_snake(rgblight_config.mode - RGBLIGHT_MODE_SNAKE);
  701. }
  702. #endif
  703. #ifdef RGBLIGHT_EFFECT_KNIGHT
  704. else if (rgblight_config.mode >= RGBLIGHT_MODE_KNIGHT &&
  705. rgblight_config.mode <= RGBLIGHT_MODE_KNIGHT_end) {
  706. // knight mode
  707. rgblight_effect_knight(rgblight_config.mode - RGBLIGHT_MODE_KNIGHT);
  708. }
  709. #endif
  710. #ifdef RGBLIGHT_EFFECT_CHRISTMAS
  711. else if (rgblight_config.mode == RGBLIGHT_MODE_CHRISTMAS) {
  712. // christmas mode
  713. rgblight_effect_christmas();
  714. }
  715. #endif
  716. #ifdef RGBLIGHT_EFFECT_RGB_TEST
  717. else if (rgblight_config.mode == RGBLIGHT_MODE_RGB_TEST) {
  718. // RGB test mode
  719. rgblight_effect_rgbtest();
  720. }
  721. #endif
  722. #ifdef RGBLIGHT_EFFECT_ALTERNATING
  723. else if (rgblight_config.mode == RGBLIGHT_MODE_ALTERNATING){
  724. rgblight_effect_alternating();
  725. }
  726. #endif
  727. }
  728. }
  729. #endif /* RGBLIGHT_USE_TIMER */
  730. // Effects
  731. #ifdef RGBLIGHT_EFFECT_BREATHING
  732. __attribute__ ((weak))
  733. const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
  734. void rgblight_effect_breathing(uint8_t interval) {
  735. static uint8_t pos = 0;
  736. static uint16_t last_timer = 0;
  737. float val;
  738. uint8_t interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[interval], 1, 100);
  739. if (timer_elapsed(last_timer) < interval_time) {
  740. return;
  741. }
  742. last_timer = timer_read();
  743. // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
  744. val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
  745. rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
  746. pos = (pos + 1) % 256;
  747. }
  748. #endif
  749. #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
  750. __attribute__ ((weak))
  751. const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
  752. void rgblight_effect_rainbow_mood(uint8_t interval) {
  753. static uint16_t current_hue = 0;
  754. static uint16_t last_timer = 0;
  755. uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100);
  756. if (timer_elapsed(last_timer) < interval_time) {
  757. return;
  758. }
  759. last_timer = timer_read();
  760. rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val);
  761. current_hue = (current_hue + 1) % 360;
  762. }
  763. #endif
  764. #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
  765. #ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE
  766. #define RGBLIGHT_RAINBOW_SWIRL_RANGE 360
  767. #endif
  768. __attribute__ ((weak))
  769. const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
  770. void rgblight_effect_rainbow_swirl(uint8_t interval) {
  771. static uint16_t current_hue = 0;
  772. static uint16_t last_timer = 0;
  773. uint16_t hue;
  774. uint8_t i;
  775. uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
  776. if (timer_elapsed(last_timer) < interval_time) {
  777. return;
  778. }
  779. last_timer = timer_read();
  780. for (i = 0; i < RGBLED_NUM; i++) {
  781. hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + current_hue) % 360;
  782. sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
  783. }
  784. rgblight_set();
  785. if (interval % 2) {
  786. current_hue = (current_hue + 1) % 360;
  787. } else {
  788. if (current_hue - 1 < 0) {
  789. current_hue = 359;
  790. } else {
  791. current_hue = current_hue - 1;
  792. }
  793. }
  794. }
  795. #endif
  796. #ifdef RGBLIGHT_EFFECT_SNAKE
  797. __attribute__ ((weak))
  798. const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
  799. void rgblight_effect_snake(uint8_t interval) {
  800. static uint8_t pos = 0;
  801. static uint16_t last_timer = 0;
  802. uint8_t i, j;
  803. int8_t k;
  804. int8_t increment = 1;
  805. if (interval % 2) {
  806. increment = -1;
  807. }
  808. uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200);
  809. if (timer_elapsed(last_timer) < interval_time) {
  810. return;
  811. }
  812. last_timer = timer_read();
  813. for (i = 0; i < RGBLED_NUM; i++) {
  814. led[i].r = 0;
  815. led[i].g = 0;
  816. led[i].b = 0;
  817. for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
  818. k = pos + j * increment;
  819. if (k < 0) {
  820. k = k + RGBLED_NUM;
  821. }
  822. if (i == k) {
  823. sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), (LED_TYPE *)&led[i]);
  824. }
  825. }
  826. }
  827. rgblight_set();
  828. if (increment == 1) {
  829. if (pos - 1 < 0) {
  830. pos = RGBLED_NUM - 1;
  831. } else {
  832. pos -= 1;
  833. }
  834. } else {
  835. pos = (pos + 1) % RGBLED_NUM;
  836. }
  837. }
  838. #endif
  839. #ifdef RGBLIGHT_EFFECT_KNIGHT
  840. __attribute__ ((weak))
  841. const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
  842. void rgblight_effect_knight(uint8_t interval) {
  843. static uint16_t last_timer = 0;
  844. uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100);
  845. if (timer_elapsed(last_timer) < interval_time) {
  846. return;
  847. }
  848. last_timer = timer_read();
  849. static int8_t low_bound = 0;
  850. static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
  851. static int8_t increment = 1;
  852. uint8_t i, cur;
  853. // Set all the LEDs to 0
  854. for (i = 0; i < RGBLED_NUM; i++) {
  855. led[i].r = 0;
  856. led[i].g = 0;
  857. led[i].b = 0;
  858. }
  859. // Determine which LEDs should be lit up
  860. for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) {
  861. cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM;
  862. if (i >= low_bound && i <= high_bound) {
  863. sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
  864. } else {
  865. led[cur].r = 0;
  866. led[cur].g = 0;
  867. led[cur].b = 0;
  868. }
  869. }
  870. rgblight_set();
  871. // Move from low_bound to high_bound changing the direction we increment each
  872. // time a boundary is hit.
  873. low_bound += increment;
  874. high_bound += increment;
  875. if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) {
  876. increment = -increment;
  877. }
  878. }
  879. #endif
  880. #ifdef RGBLIGHT_EFFECT_CHRISTMAS
  881. void rgblight_effect_christmas(void) {
  882. static uint16_t current_offset = 0;
  883. static uint16_t last_timer = 0;
  884. uint16_t hue;
  885. uint8_t i;
  886. if (timer_elapsed(last_timer) < RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL) {
  887. return;
  888. }
  889. last_timer = timer_read();
  890. current_offset = (current_offset + 1) % 2;
  891. for (i = 0; i < RGBLED_NUM; i++) {
  892. hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + current_offset) % 2) * 120;
  893. sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
  894. }
  895. rgblight_set();
  896. }
  897. #endif
  898. #ifdef RGBLIGHT_EFFECT_RGB_TEST
  899. __attribute__ ((weak))
  900. const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024};
  901. void rgblight_effect_rgbtest(void) {
  902. static uint8_t pos = 0;
  903. static uint16_t last_timer = 0;
  904. static uint8_t maxval = 0;
  905. uint8_t g; uint8_t r; uint8_t b;
  906. if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0])) {
  907. return;
  908. }
  909. if( maxval == 0 ) {
  910. LED_TYPE tmp_led;
  911. sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
  912. maxval = tmp_led.r;
  913. }
  914. last_timer = timer_read();
  915. g = r = b = 0;
  916. switch( pos ) {
  917. case 0: r = maxval; break;
  918. case 1: g = maxval; break;
  919. case 2: b = maxval; break;
  920. }
  921. rgblight_setrgb(r, g, b);
  922. pos = (pos + 1) % 3;
  923. }
  924. #endif
  925. #ifdef RGBLIGHT_EFFECT_ALTERNATING
  926. void rgblight_effect_alternating(void){
  927. static uint16_t last_timer = 0;
  928. static uint16_t pos = 0;
  929. if (timer_elapsed(last_timer) < 500) {
  930. return;
  931. }
  932. last_timer = timer_read();
  933. for(int i = 0; i<RGBLED_NUM; i++){
  934. if(i<RGBLED_NUM/2 && pos){
  935. sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
  936. }else if (i>=RGBLED_NUM/2 && !pos){
  937. sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
  938. }else{
  939. sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]);
  940. }
  941. }
  942. rgblight_set();
  943. pos = (pos + 1) % 2;
  944. }
  945. #endif