Keyboard firmwares for Atmel AVR and Cortex-M
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include <util/delay.h>
  4. #include "matrix.h"
  5. #include "keymap.h"
  6. #include "eeconfig.h"
  7. #include "bootloader.h"
  8. #include "bootmagic.h"
  9. void bootmagic(void)
  10. {
  11. /* do scans in case of bounce */
  12. uint8_t scan = 100;
  13. while (scan--) { matrix_scan(); _delay_ms(1); }
  14. if (!BOOTMAGIC_IS_ENABLE()) { return; }
  15. if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) {
  16. bootloader_jump();
  17. }
  18. if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) {
  19. eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE);
  20. }
  21. if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) {
  22. eeconfig_init();
  23. }
  24. }
  25. bool bootmagic_scan_keycode(uint8_t keycode)
  26. {
  27. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  28. matrix_row_t matrix_row = matrix_get_row(r);
  29. for (uint8_t c = 0; c < MATRIX_COLS; c++) {
  30. if (matrix_row & ((matrix_row_t)1<<c)) {
  31. if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) {
  32. return true;
  33. }
  34. }
  35. }
  36. }
  37. return false;
  38. }