logo

qmk_firmware

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

ec_typek.c (6255B)


  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. // Set the RGB LEDs range that will be used for the effects
  71. rgblight_set_effect_range(3, 66);
  72. // Call the indicator callback to set the indicator color
  73. indicators_callback();
  74. keyboard_post_init_user();
  75. }
  76. // This function gets called when caps, num, scroll change
  77. bool led_update_kb(led_t led_state) {
  78. if (led_update_user(led_state)) {
  79. indicators_callback();
  80. }
  81. return true;
  82. }
  83. // This function is called when layers change
  84. __attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) {
  85. indicators_callback();
  86. return state;
  87. }
  88. // INDICATOR CALLBACK ------------------------------------------------------------------------------
  89. /* LED index to physical position
  90. *
  91. * LED2 | LED1 | LED0
  92. * -----+------+--------
  93. * Num | Caps | Scroll |
  94. */
  95. bool indicators_callback(void) {
  96. if ((eeprom_ec_config.num.enabled) && (host_keyboard_led_state().num_lock))
  97. rgblight_sethsv_at(eeprom_ec_config.num.h, eeprom_ec_config.num.s, eeprom_ec_config.num.v, NUM_INDICATOR_INDEX);
  98. else
  99. rgblight_sethsv_at(0, 0, 0, NUM_INDICATOR_INDEX);
  100. if ((eeprom_ec_config.caps.enabled) && (host_keyboard_led_state().caps_lock))
  101. rgblight_sethsv_at(eeprom_ec_config.caps.h, eeprom_ec_config.caps.s, eeprom_ec_config.caps.v, CAPS_INDICATOR_INDEX);
  102. else
  103. rgblight_sethsv_at(0, 0, 0, CAPS_INDICATOR_INDEX);
  104. if ((eeprom_ec_config.scroll.enabled) && (host_keyboard_led_state().scroll_lock))
  105. rgblight_sethsv_at(eeprom_ec_config.scroll.h, eeprom_ec_config.scroll.s, eeprom_ec_config.scroll.v, SCROLL_INDICATOR_INDEX);
  106. else
  107. rgblight_sethsv_at(0, 0, 0, SCROLL_INDICATOR_INDEX);
  108. rgblight_set();
  109. return true;
  110. }