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.

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