bootmagic_lite.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright 2021 QMK
  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 "quantum.h"
  17. /** \brief Reset eeprom
  18. *
  19. * ...just incase someone wants to only change the eeprom behaviour
  20. */
  21. __attribute__((weak)) void bootmagic_lite_reset_eeprom(void) {
  22. #if defined(VIA_ENABLE)
  23. via_eeprom_reset();
  24. #else
  25. eeconfig_disable();
  26. #endif
  27. }
  28. /** \brief The lite version of TMK's bootmagic based on Wilba.
  29. *
  30. * 100% less potential for accidentally making the keyboard do stupid things.
  31. */
  32. __attribute__((weak)) void bootmagic_lite(void) {
  33. // We need multiple scans because debouncing can't be turned off.
  34. matrix_scan();
  35. #if defined(DEBOUNCE) && DEBOUNCE > 0
  36. wait_ms(DEBOUNCE * 2);
  37. #else
  38. wait_ms(30);
  39. #endif
  40. matrix_scan();
  41. // If the configured key (commonly Esc) is held down on power up,
  42. // reset the EEPROM valid state and jump to bootloader.
  43. // This isn't very generalized, but we need something that doesn't
  44. // rely on user's keymaps in firmware or EEPROM.
  45. uint8_t row = BOOTMAGIC_LITE_ROW;
  46. uint8_t col = BOOTMAGIC_LITE_COLUMN;
  47. #if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT)
  48. if (!is_keyboard_left()) {
  49. row = BOOTMAGIC_LITE_ROW_RIGHT;
  50. col = BOOTMAGIC_LITE_COLUMN_RIGHT;
  51. }
  52. #endif
  53. if (matrix_get_row(row) & (1 << col)) {
  54. bootmagic_lite_reset_eeprom();
  55. // Jump to bootloader.
  56. bootloader_jump();
  57. }
  58. }
  59. void bootmagic(void) { bootmagic_lite(); }