backlight.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Backlighting code for PS2AVRGB boards (ATMEGA32A)
  3. * Kenneth A. (github.com/krusli | krusli.me)
  4. */
  5. #include "quantum.h"
  6. #include <avr/pgmspace.h>
  7. #include <avr/interrupt.h>
  8. // Port D: digital pins of the AVR chipset
  9. #define NUMLOCK_PORT (1 << 0) // D0
  10. #define CAPSLOCK_PORT (1 << 1) // D1
  11. #define BACKLIGHT_PORT (1 << 4) // D4
  12. #define SCROLLLOCK_PORT (1 << 6) // D6
  13. /**
  14. * References
  15. * Port Registers: https://www.arduino.cc/en/Reference/PortManipulation
  16. * TCCR1A: https://electronics.stackexchange.com/questions/92350/what-is-the-difference-between-tccr1a-and-tccr1b
  17. * Timers: http://www.avrbeginners.net/architecture/timers/timers.html
  18. * 16-bit timer setup: http://sculland.com/ATmega168/Interrupts-And-Timers/16-Bit-Timer-Setup/
  19. * PS2AVRGB firmware: https://github.com/showjean/ps2avrU/tree/master/firmware
  20. */
  21. // @Override
  22. // turn LEDs on and off depending on USB caps/num/scroll lock states.
  23. __attribute__ ((weak))
  24. void led_set_user(uint8_t usb_led) {
  25. /* It appears that these cause the v1 JJ40 PCB to hang.
  26. * I haven't looked into why, but I don't have any LEDs on my board anyway. */
  27. #if 0
  28. if (usb_led & (1 << USB_LED_NUM_LOCK)) {
  29. // turn on
  30. DDRD |= NUMLOCK_PORT;
  31. PORTD |= NUMLOCK_PORT;
  32. } else {
  33. // turn off
  34. DDRD &= ~NUMLOCK_PORT;
  35. PORTD &= ~NUMLOCK_PORT;
  36. }
  37. if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
  38. DDRD |= CAPSLOCK_PORT;
  39. PORTD |= CAPSLOCK_PORT;
  40. } else {
  41. DDRD &= ~CAPSLOCK_PORT;
  42. PORTD &= ~CAPSLOCK_PORT;
  43. }
  44. if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
  45. DDRD |= SCROLLLOCK_PORT;
  46. PORTD |= SCROLLLOCK_PORT;
  47. } else {
  48. DDRD &= ~SCROLLLOCK_PORT;
  49. PORTD &= ~SCROLLLOCK_PORT;
  50. }
  51. #endif
  52. }