logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

wt_main.c (5066B)


  1. /* Copyright 2018 Jason Williams (Wilba)
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "quantum.h"
  17. // Check that no backlight functions are called
  18. #if RGB_BACKLIGHT_ENABLED
  19. #include "keyboards/wilba_tech/wt_rgb_backlight.h"
  20. #endif // RGB_BACKLIGHT_ENABLED
  21. #if MONO_BACKLIGHT_ENABLED
  22. #include "keyboards/wilba_tech/wt_mono_backlight.h"
  23. #endif // MONO_BACKLIGHT_ENABLED
  24. #include "via.h"
  25. #ifndef VIA_ENABLE
  26. #include "eeprom.h"
  27. #include "version.h" // for QMK_BUILDDATE used in EEPROM magic
  28. #endif
  29. // Called from via_init() if VIA_ENABLE
  30. // Called from matrix_init_kb() if not VIA_ENABLE
  31. void wt_main_init(void)
  32. {
  33. // This checks both an EEPROM reset (from bootmagic lite, keycodes)
  34. // and also firmware build date (from via_eeprom_is_valid())
  35. if (eeconfig_is_enabled()) {
  36. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  37. backlight_config_load();
  38. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  39. } else {
  40. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  41. // If the EEPROM has not been saved before, or is out of date,
  42. // save the default values to the EEPROM. Default values
  43. // come from construction of the backlight_config instance.
  44. backlight_config_save();
  45. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  46. // DO NOT set EEPROM valid here, let caller do this
  47. }
  48. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  49. // Initialize LED drivers for backlight.
  50. backlight_init_drivers();
  51. backlight_timer_init();
  52. backlight_timer_enable();
  53. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  54. }
  55. void matrix_init_kb(void)
  56. {
  57. // If VIA is disabled, we still need to load backlight settings.
  58. // Call via_init_kb() the same way as via_init_kb() does.
  59. #ifndef VIA_ENABLE
  60. wt_main_init();
  61. #endif // VIA_ENABLE
  62. matrix_init_user();
  63. }
  64. void matrix_scan_kb(void)
  65. {
  66. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  67. // This only updates the LED driver buffers if something has changed.
  68. backlight_update_pwm_buffers();
  69. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  70. matrix_scan_user();
  71. }
  72. bool process_record_kb(uint16_t keycode, keyrecord_t *record)
  73. {
  74. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  75. process_record_backlight(keycode, record);
  76. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  77. return process_record_user(keycode, record);
  78. }
  79. void suspend_power_down_kb(void)
  80. {
  81. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  82. backlight_set_suspend_state(true);
  83. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  84. }
  85. void suspend_wakeup_init_kb(void)
  86. {
  87. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  88. backlight_set_suspend_state(false);
  89. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  90. }
  91. // Moving this to the bottom of this source file is a workaround
  92. // for an intermittent compiler error for Atmel compiler.
  93. #ifdef VIA_ENABLE
  94. void via_init_kb(void) {
  95. wt_main_init();
  96. }
  97. void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
  98. uint8_t *command_id = &(data[0]);
  99. uint8_t *channel_id = &(data[1]);
  100. uint8_t *value_id_and_data = &(data[2]);
  101. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  102. if ( *channel_id == id_custom_channel ) {
  103. switch ( *command_id )
  104. {
  105. case id_custom_set_value:
  106. {
  107. backlight_config_set_value(value_id_and_data);
  108. break;
  109. }
  110. case id_custom_get_value:
  111. {
  112. backlight_config_get_value(value_id_and_data);
  113. break;
  114. }
  115. case id_custom_save:
  116. {
  117. backlight_config_save();
  118. break;
  119. }
  120. default:
  121. {
  122. // Unhandled message.
  123. *command_id = id_unhandled;
  124. break;
  125. }
  126. }
  127. return;
  128. }
  129. #else
  130. *command_id = id_unhandled;
  131. *channel_id = *channel_id; // force use of variable
  132. *value_id_and_data = *value_id_and_data; // force use of variable
  133. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  134. // DO NOT call raw_hid_send(data,length) here, let caller do this
  135. }
  136. void via_set_device_indication(uint8_t value)
  137. {
  138. #if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  139. backlight_device_indication(value);
  140. #endif // RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
  141. }
  142. #endif // VIA_ENABLE