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.

125 lines
3.2 KiB

Backlighting for JJ40 and underglow initialisation code (#2260) * Cleanup Mechmini keymap. Once the custom RGB function is defined, there is no need to manually handle RGB code. * Change default to KEYMAP_MIT, not KEYMAP_OFFSET * Add custom RGB code for JJ40 * Reset Mechmini advertised power draw to 500. Will have to test actual maximum power draw later. * RGB working on JJ40. * Fix: saturation increase/decrease flipped * Add new directory for my custom keymap with RGB keycodes * Swap LAlt and LGUI * Update JJ40 max power draw with measured value * Update: fun40 rules.mk to enable underglow; earlier failed Travis CI * Fix: init RGB LEDs on boot. Also added HHKB-like keymap for XD60. * Super rudimentary backlight test, init RGB LEDs on boot * Backlighting works - stays on for now * Toggling working * Now can override backlight.c functions. Problem was functions in backlight.c weren't called before due to a lack of matrix_scan_quantum() in matrix.c * Timers not working * Delete global.h * Cleanup * Compiles * Good sign: LEDs stop working again * Handle timer1 overflow * Progress: fix: forgot to init * Backlighting fully working now except breathing. * Revert keymap to original keycodes * Update XD60 keymap README * Update JJ40 keymap with backlight toggles * Breathing working just fine. * Update references * Add backlight_set() call * Cleanup code to disable backlight * Fix: does not compile * Fix: missing call to rgblight_task. * Testing with BACKLIGHT_BREATHING * Cleanup * Cleanup comments * More commenting cleanup. * Do not enable BACKLIGHT_BREATHING by default
6 years ago
  1. /*
  2. Copyright 2013 Mathias Andersson <wraul@dbox.se>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "backlight.h"
  15. #include "eeconfig.h"
  16. #include "debug.h"
  17. backlight_config_t backlight_config;
  18. /** \brief Backlight initialization
  19. *
  20. * FIXME: needs doc
  21. */
  22. void backlight_init(void)
  23. {
  24. /* check signature */
  25. if (!eeconfig_is_enabled()) {
  26. eeconfig_init();
  27. }
  28. backlight_config.raw = eeconfig_read_backlight();
  29. if (backlight_config.level > BACKLIGHT_LEVELS) {
  30. backlight_config.level = BACKLIGHT_LEVELS;
  31. }
  32. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  33. }
  34. /** \brief Backlight increase
  35. *
  36. * FIXME: needs doc
  37. */
  38. void backlight_increase(void)
  39. {
  40. if(backlight_config.level < BACKLIGHT_LEVELS)
  41. {
  42. backlight_config.level++;
  43. }
  44. backlight_config.enable = 1;
  45. eeconfig_update_backlight(backlight_config.raw);
  46. dprintf("backlight increase: %u\n", backlight_config.level);
  47. backlight_set(backlight_config.level);
  48. }
  49. /** \brief Backlight decrease
  50. *
  51. * FIXME: needs doc
  52. */
  53. void backlight_decrease(void)
  54. {
  55. if(backlight_config.level > 0)
  56. {
  57. backlight_config.level--;
  58. backlight_config.enable = !!backlight_config.level;
  59. eeconfig_update_backlight(backlight_config.raw);
  60. }
  61. dprintf("backlight decrease: %u\n", backlight_config.level);
  62. backlight_set(backlight_config.level);
  63. }
  64. /** \brief Backlight toggle
  65. *
  66. * FIXME: needs doc
  67. */
  68. void backlight_toggle(void)
  69. {
  70. backlight_config.enable ^= 1;
  71. if (backlight_config.raw == 1) // enabled but level = 0
  72. backlight_config.level = 1;
  73. eeconfig_update_backlight(backlight_config.raw);
  74. dprintf("backlight toggle: %u\n", backlight_config.enable);
  75. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  76. }
  77. /** \brief Backlight step through levels
  78. *
  79. * FIXME: needs doc
  80. */
  81. void backlight_step(void)
  82. {
  83. backlight_config.level++;
  84. if(backlight_config.level > BACKLIGHT_LEVELS)
  85. {
  86. backlight_config.level = 0;
  87. }
  88. backlight_config.enable = !!backlight_config.level;
  89. eeconfig_update_backlight(backlight_config.raw);
  90. dprintf("backlight step: %u\n", backlight_config.level);
  91. backlight_set(backlight_config.level);
  92. }
  93. /** \brief Backlight set level
  94. *
  95. * FIXME: needs doc
  96. */
  97. void backlight_level(uint8_t level)
  98. {
  99. if (level > BACKLIGHT_LEVELS)
  100. level = BACKLIGHT_LEVELS;
  101. backlight_config.level = level;
  102. backlight_config.enable = !!backlight_config.level;
  103. eeconfig_update_backlight(backlight_config.raw);
  104. backlight_set(backlight_config.level);
  105. }
  106. /** \brief Get backlight level
  107. *
  108. * FIXME: needs doc
  109. */
  110. uint8_t get_backlight_level(void)
  111. {
  112. return backlight_config.level;
  113. }