aboutsummaryrefslogtreecommitdiff
path: root/keyboard/cluepad/backlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/cluepad/backlight.c')
-rw-r--r--keyboard/cluepad/backlight.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/keyboard/cluepad/backlight.c b/keyboard/cluepad/backlight.c
new file mode 100644
index 000000000..c0f853949
--- /dev/null
+++ b/keyboard/cluepad/backlight.c
@@ -0,0 +1,54 @@
1#include <avr/io.h>
2#include "backlight.h"
3#include "led.h"
4
5#include "print.h"
6
7int pwm_level;
8
9void led_set(uint8_t usb_led)
10{
11 print("led_set\n");
12}
13
14void 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
26void 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}