mxss.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2020 Jumail Mundekkat / MxBlue
  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. * EEPROM management code from ../cannonkeys/stm32f072/keyboard.c
  17. */
  18. #include "quantum.h"
  19. #include "eeprom.h"
  20. #include "mxss_frontled.h"
  21. #include "version.h" // for QMK_BUILDDATE used in EEPROM magic
  22. void via_init_kb(void) {
  23. fled_init();
  24. }
  25. void matrix_init_kb(void) {
  26. // If VIA is disabled, we still need to load settings
  27. // Call via_init_kb() the same way as via_init(), with setting
  28. // EEPROM valid afterwards.
  29. #ifndef VIA_ENABLE
  30. fled_init();
  31. via_eeprom_set_valid(true);
  32. #endif // VIA_ENABLE
  33. matrix_init_user();
  34. }
  35. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  36. // Handle custom keycodes for front LED operation
  37. process_record_fled(keycode, record);
  38. return process_record_user(keycode, record);
  39. }
  40. bool led_update_kb(led_t led_state) {
  41. fled_lock_update(led_state);
  42. return led_update_user(led_state);
  43. }
  44. layer_state_t layer_state_set_kb(layer_state_t state) {
  45. fled_layer_update(state);
  46. return layer_state_set_user(state);
  47. }
  48. // Fallback eeprom functions if VIA is not enabled
  49. #ifndef VIA_ENABLE
  50. // Sets VIA/keyboard level usage of EEPROM to valid/invalid
  51. // Keyboard level code (eg. via_init_kb()) should not call this
  52. void via_eeprom_set_valid(bool valid)
  53. {
  54. char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
  55. uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
  56. uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
  57. uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
  58. eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF);
  59. eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF);
  60. eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF);
  61. }
  62. #endif