retro_refit.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "retro_refit.h"
  2. __attribute__ ((weak))
  3. void * matrix_init_user(void) {
  4. // leave this function blank - it can be defined in a keymap file
  5. return NULL;
  6. };
  7. __attribute__ ((weak))
  8. void * matrix_scan_user(void) {
  9. // leave this function blank - it can be defined in a keymap file
  10. return NULL;
  11. };
  12. __attribute__ ((weak))
  13. void * led_set_user(uint8_t usb_led) {
  14. // leave this function blank - it can be defined in a keymap file
  15. return NULL;
  16. };
  17. void * matrix_init_kb(void) {
  18. // put your keyboard start-up code here
  19. // runs once when the firmware starts up
  20. // Disable status LED on KB, enable status LED on Teensy (KB_STATUS = !TEENSY_STATUS)
  21. DDRD |= (1<<6);
  22. PORTD |= (1<<6);
  23. if (matrix_init_user) {
  24. (*matrix_init_user)();
  25. }
  26. return NULL;
  27. };
  28. void * matrix_scan_kb(void) {
  29. // put your looping keyboard code here
  30. // runs every cycle (a lot)
  31. if (matrix_scan_user) {
  32. (*matrix_scan_user)();
  33. }
  34. return NULL;
  35. };
  36. void * led_set_kb(uint8_t usb_led) {
  37. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  38. if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
  39. // output low
  40. DDRD |= (1<<0);
  41. PORTD &= ~(1<<0);
  42. } else {
  43. // Hi-Z
  44. DDRD &= ~(1<<0);
  45. PORTD &= ~(1<<0);
  46. }
  47. if (usb_led & (1<<USB_LED_NUM_LOCK)) {
  48. // output low
  49. DDRD |= (1<<1);
  50. PORTD &= ~(1<<1);
  51. } else {
  52. // Hi-Z
  53. DDRD &= ~(1<<1);
  54. PORTD &= ~(1<<1);
  55. }
  56. if (usb_led & (1<<USB_LED_SCROLL_LOCK)) {
  57. // output low
  58. DDRC |= (1<<6);
  59. PORTC &= ~(1<<6);
  60. } else {
  61. // Hi-Z
  62. DDRC &= ~(1<<6);
  63. PORTC &= ~(1<<6);
  64. }
  65. if (led_set_user) {
  66. (*led_set_user)(usb_led);
  67. }
  68. return NULL;
  69. };