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.

82 lines
2.6 KiB

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