cluepad.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "cluepad.h"
  2. int pwm_level;
  3. void matrix_init_kb(void) {
  4. // put your keyboard start-up code here
  5. // runs once when the firmware starts up
  6. matrix_init_user();
  7. // JTAG disable for PORT F. write JTD bit twice within four cycles.
  8. MCUCR |= (1<<JTD);
  9. MCUCR |= (1<<JTD);
  10. };
  11. void led_set_kb(uint8_t usb_led)
  12. {
  13. print("led_set\n");
  14. }
  15. void backlight_init_ports(void)
  16. {
  17. // Set C7 to output
  18. DDRC |= (1<<7);
  19. // Initialize the timer
  20. TC4H = 0x03;
  21. OCR4C = 0xFF;
  22. TCCR4A = 0b10000010;
  23. TCCR4B = 0b00000001;
  24. }
  25. void backlight_set(uint8_t level)
  26. {
  27. // Determine the PWM level
  28. switch (level)
  29. {
  30. case 0:
  31. // 33%
  32. pwm_level = 0x54;
  33. break;
  34. case 1:
  35. // 66%
  36. pwm_level = 0xA8;
  37. break;
  38. case 2:
  39. // 100%
  40. pwm_level = 0xFF;
  41. break;
  42. case 3:
  43. // 0%
  44. pwm_level = 0x00;
  45. break;
  46. default:
  47. xprintf("Unknown level: %d\n", level);
  48. }
  49. // Write the PWM level to the timer
  50. TC4H = pwm_level >> 8;
  51. OCR4A = 0xFF & pwm_level;
  52. }