bootmagic_lite.c 2.0 KB

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