17.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "17.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. print("led_set\n");
  13. }
  14. void backlight_init_ports(void) {
  15. // Set C7 to output
  16. DDRC |= (1<<7);
  17. // Initialize the timer
  18. TC4H = 0x03;
  19. OCR4C = 0xFF;
  20. TCCR4A = 0b10000010;
  21. TCCR4B = 0b00000001;
  22. }
  23. void backlight_set(uint8_t level) {
  24. // Determine the PWM level
  25. switch (level)
  26. {
  27. case 0:
  28. // 33%
  29. pwm_level = 0x54;
  30. break;
  31. case 1:
  32. // 66%
  33. pwm_level = 0xA8;
  34. break;
  35. case 2:
  36. // 100%
  37. pwm_level = 0xFF;
  38. break;
  39. case 3:
  40. // 0%
  41. pwm_level = 0x00;
  42. break;
  43. default:
  44. xprintf("Unknown level: %d\n", level);
  45. }
  46. // Write the PWM level to the timer
  47. TC4H = pwm_level >> 8;
  48. OCR4A = 0xFF & pwm_level;
  49. }