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.

98 lines
1.7 KiB

  1. #include "cluecard.h"
  2. #define BL_RED OCR1B
  3. #define BL_GREEN OCR1A
  4. #define BL_BLUE OCR1C
  5. void matrix_init_kb(void) {
  6. // put your keyboard start-up code here
  7. // runs once when the firmware starts up
  8. matrix_init_user();
  9. }
  10. void matrix_scan_kb(void) {
  11. // put your looping keyboard code here
  12. // runs every cycle (a lot)
  13. matrix_scan_user();
  14. }
  15. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  16. // put your per-action keyboard code here
  17. // runs for every action, just before processing by the firmware
  18. return process_record_user(keycode, record);
  19. }
  20. void led_set_kb(uint8_t usb_led) {
  21. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  22. led_set_user(usb_led);
  23. }
  24. void backlight_init_ports(void)
  25. {
  26. // Set B5, B6, and B7 as output
  27. DDRB |= (1<<7)|(1<<6)|(1<<5);
  28. // Setup PWM
  29. ICR1 = 0xFFFF;
  30. TCCR1A = 0b10101010;
  31. TCCR1B = 0b00011001;
  32. BL_RED = 0xFFFF;
  33. BL_GREEN = 0xFFFF;
  34. BL_BLUE = 0xFFFF;
  35. }
  36. void backlight_set(uint8_t level)
  37. {
  38. // Set the RGB color
  39. switch (level)
  40. {
  41. case 0:
  42. // Off
  43. BL_RED = 0xFFFF;
  44. BL_GREEN = 0xFFFF;
  45. BL_BLUE = 0xFFFF;
  46. break;
  47. case 1:
  48. // Red
  49. BL_RED = 0x0000;
  50. BL_GREEN = 0xFFFF;
  51. BL_BLUE = 0xFFFF;
  52. break;
  53. case 2:
  54. // Green
  55. BL_RED = 0xFFFF;
  56. BL_GREEN = 0x0000;
  57. BL_BLUE = 0xFFFF;
  58. break;
  59. case 3:
  60. // Blue
  61. BL_RED = 0xFFFF;
  62. BL_GREEN = 0xFFFF;
  63. BL_BLUE = 0x0000;
  64. break;
  65. case 4:
  66. // Magenta
  67. BL_RED = 0x4000;
  68. BL_GREEN = 0x4000;
  69. BL_BLUE = 0x4000;
  70. break;
  71. case 5:
  72. // Purple
  73. BL_RED = 0x0000;
  74. BL_GREEN = 0xFFFF;
  75. BL_BLUE = 0x0000;
  76. break;
  77. case 6:
  78. // Yellow
  79. BL_RED = 0x0000;
  80. BL_GREEN = 0x0000;
  81. BL_BLUE = 0xFFFF;
  82. break;
  83. default:
  84. xprintf("Unknown level: %d\n", level);
  85. }
  86. }