bootmagic_lite.c 2.1 KB

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