17.c 1.0 KB

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