logo

qmk_firmware

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

ec_980c.c (6711B)


  1. /* Copyright 2023 Cipulot
  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 3 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 "ec_switch_matrix.h"
  17. #include "quantum.h"
  18. void eeconfig_init_kb(void) {
  19. // Default values
  20. eeprom_ec_config.num.h = 0;
  21. eeprom_ec_config.num.s = 0;
  22. eeprom_ec_config.num.v = 60;
  23. eeprom_ec_config.num.enabled = true;
  24. eeprom_ec_config.caps.h = 0;
  25. eeprom_ec_config.caps.s = 0;
  26. eeprom_ec_config.caps.v = 60;
  27. eeprom_ec_config.caps.enabled = true;
  28. eeprom_ec_config.scroll.h = 0;
  29. eeprom_ec_config.scroll.s = 0;
  30. eeprom_ec_config.scroll.v = 60;
  31. eeprom_ec_config.scroll.enabled = true;
  32. eeprom_ec_config.actuation_mode = DEFAULT_ACTUATION_MODE;
  33. eeprom_ec_config.mode_0_actuation_threshold = DEFAULT_MODE_0_ACTUATION_LEVEL;
  34. eeprom_ec_config.mode_0_release_threshold = DEFAULT_MODE_0_RELEASE_LEVEL;
  35. eeprom_ec_config.mode_1_initial_deadzone_offset = DEFAULT_MODE_1_INITIAL_DEADZONE_OFFSET;
  36. eeprom_ec_config.mode_1_actuation_offset = DEFAULT_MODE_1_ACTUATION_OFFSET;
  37. eeprom_ec_config.mode_1_release_offset = DEFAULT_MODE_1_RELEASE_OFFSET;
  38. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  39. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  40. eeprom_ec_config.bottoming_reading[row][col] = DEFAULT_BOTTOMING_READING;
  41. }
  42. }
  43. // Write default value to EEPROM now
  44. eeconfig_update_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
  45. eeconfig_init_user();
  46. }
  47. // On Keyboard startup
  48. void keyboard_post_init_kb(void) {
  49. // Read custom menu variables from memory
  50. eeconfig_read_kb_datablock(&eeprom_ec_config, 0, EECONFIG_KB_DATA_SIZE);
  51. // Set runtime values to EEPROM values
  52. ec_config.actuation_mode = eeprom_ec_config.actuation_mode;
  53. ec_config.mode_0_actuation_threshold = eeprom_ec_config.mode_0_actuation_threshold;
  54. ec_config.mode_0_release_threshold = eeprom_ec_config.mode_0_release_threshold;
  55. ec_config.mode_1_initial_deadzone_offset = eeprom_ec_config.mode_1_initial_deadzone_offset;
  56. ec_config.mode_1_actuation_offset = eeprom_ec_config.mode_1_actuation_offset;
  57. ec_config.mode_1_release_offset = eeprom_ec_config.mode_1_release_offset;
  58. ec_config.bottoming_calibration = false;
  59. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  60. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  61. ec_config.bottoming_calibration_starter[row][col] = true;
  62. ec_config.bottoming_reading[row][col] = eeprom_ec_config.bottoming_reading[row][col];
  63. ec_config.rescaled_mode_0_actuation_threshold[row][col] = rescale(ec_config.mode_0_actuation_threshold, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  64. ec_config.rescaled_mode_0_release_threshold[row][col] = rescale(ec_config.mode_0_release_threshold, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  65. ec_config.rescaled_mode_1_initial_deadzone_offset[row][col] = rescale(ec_config.mode_1_initial_deadzone_offset, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  66. ec_config.rescaled_mode_1_actuation_offset[row][col] = rescale(ec_config.mode_1_actuation_offset, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  67. ec_config.rescaled_mode_1_release_offset[row][col] = rescale(ec_config.mode_1_release_offset, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  68. }
  69. }
  70. // Call the indicator callback to set the indicator color
  71. rgb_matrix_indicators_kb();
  72. keyboard_post_init_user();
  73. }
  74. // INDICATOR CALLBACK ------------------------------------------------------------------------------
  75. /* LED index to physical position
  76. *
  77. * LED0 | LED1 | LED2
  78. * -----+------+--------
  79. * Num | Caps | Scroll |
  80. */
  81. bool rgb_matrix_indicators_kb(void) {
  82. if (!rgb_matrix_indicators_user()) {
  83. return false;
  84. }
  85. if (eeprom_ec_config.num.enabled) {
  86. // The rgb_matrix_set_color function needs an RGB code to work, so first the indicator color is cast to an HSV value and then translated to RGB
  87. hsv_t hsv_num_indicator_color = {eeprom_ec_config.num.h, eeprom_ec_config.num.s, eeprom_ec_config.num.v};
  88. rgb_t rgb_num_indicator_color = hsv_to_rgb(hsv_num_indicator_color);
  89. if (host_keyboard_led_state().num_lock)
  90. rgb_matrix_set_color(NUM_INDICATOR_INDEX, rgb_num_indicator_color.r, rgb_num_indicator_color.g, rgb_num_indicator_color.b);
  91. else
  92. rgb_matrix_set_color(NUM_INDICATOR_INDEX, 0, 0, 0);
  93. }
  94. if (eeprom_ec_config.caps.enabled) {
  95. hsv_t hsv_caps_indicator_color = {eeprom_ec_config.caps.h, eeprom_ec_config.caps.s, eeprom_ec_config.caps.v};
  96. rgb_t rgb_caps_indicator_color = hsv_to_rgb(hsv_caps_indicator_color);
  97. if (host_keyboard_led_state().caps_lock)
  98. rgb_matrix_set_color(CAPS_INDICATOR_INDEX, rgb_caps_indicator_color.r, rgb_caps_indicator_color.g, rgb_caps_indicator_color.b);
  99. else
  100. rgb_matrix_set_color(CAPS_INDICATOR_INDEX, 0, 0, 0);
  101. }
  102. if (eeprom_ec_config.scroll.enabled) {
  103. hsv_t hsv_scroll_indicator_color = {eeprom_ec_config.scroll.h, eeprom_ec_config.scroll.s, eeprom_ec_config.scroll.v};
  104. rgb_t rgb_scroll_indicator_color = hsv_to_rgb(hsv_scroll_indicator_color);
  105. if (host_keyboard_led_state().scroll_lock)
  106. rgb_matrix_set_color(SCROLL_INDICATOR_INDEX, rgb_scroll_indicator_color.r, rgb_scroll_indicator_color.g, rgb_scroll_indicator_color.b);
  107. else
  108. rgb_matrix_set_color(SCROLL_INDICATOR_INDEX, 0, 0, 0);
  109. }
  110. return true;
  111. }