]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboard/cluepad/backlight.c
a9caed1df89be596a3dfc37989c428743a9b2ecb
[qmk_firmware.git] / keyboard / cluepad / backlight.c
1 #include <avr/io.h>
2 #include "backlight.h"
3 #include "led.h"
4
5 #include "print.h"
6
7 int pwm_level;
8
9 void led_set_kb(uint8_t usb_led)
10 {
11     print("led_set\n");
12 }
13
14 void init_backlight_pin(void)
15 {
16     // Set C7 to output
17     DDRC |= (1<<7);
18
19     // Initialize the timer
20     TC4H = 0x03;
21     OCR4C = 0xFF;
22     TCCR4A = 0b10000010;
23     TCCR4B = 0b00000001;
24 }
25
26 void backlight_set(uint8_t level)
27 {
28     // Determine the PWM level
29     switch (level)
30     {
31         case 0:
32             // 33%
33             pwm_level = 0x54;
34             break;
35         case 1:
36             // 66%
37             pwm_level = 0xA8;
38             break;
39         case 2:
40             // 100%
41             pwm_level = 0xFF;
42             break;
43         case 3:
44             // 0%
45             pwm_level = 0x00;
46             break;
47         default:
48             xprintf("Unknown level: %d\n", level);
49     }
50
51     // Write the PWM level to the timer
52     TC4H = pwm_level >> 8;
53     OCR4A = 0xFF & pwm_level;
54 }