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.

bootmagic.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if (!BOOTMAGIC_IS_ENABLED()) { return; }
  12. /* do scans in case of bounce */
  13. uint8_t scan = 100;
  14. while (scan--) { matrix_scan(); _delay_ms(1); }
  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. if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) {
  25. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK);
  26. }
  27. if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) {
  28. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL);
  29. }
  30. if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) {
  31. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI);
  32. }
  33. if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) {
  34. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI);
  35. }
  36. if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) {
  37. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI);
  38. }
  39. if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) {
  40. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC);
  41. }
  42. if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) {
  43. eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE);
  44. }
  45. }
  46. bool bootmagic_scan_keycode(uint8_t keycode)
  47. {
  48. for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
  49. matrix_row_t matrix_row = matrix_get_row(r);
  50. for (uint8_t c = 0; c < MATRIX_COLS; c++) {
  51. if (matrix_row & ((matrix_row_t)1<<c)) {
  52. if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) {
  53. return true;
  54. }
  55. }
  56. }
  57. }
  58. return false;
  59. }