diff options
author | Nicholas Keene <git@nicholaskeene.com> | 2016-05-02 21:35:58 -0500 |
---|---|---|
committer | Nicholas Keene <git@nicholaskeene.com> | 2016-05-02 21:35:58 -0500 |
commit | 8b0274f60a47eae523e28b5a7c6c7f581b6d605a (patch) | |
tree | b8c6194d89712ddaf5e22aef85274c12c53cb2f1 /keyboard/cluepad/backlight.c | |
parent | 1076c2b1226ed049a364971bf8e1edcd9ed45f6d (diff) | |
parent | 2c070163ffffffde546fb00acaa2fbb96b93da64 (diff) |
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
Diffstat (limited to 'keyboard/cluepad/backlight.c')
-rw-r--r-- | keyboard/cluepad/backlight.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/keyboard/cluepad/backlight.c b/keyboard/cluepad/backlight.c new file mode 100644 index 0000000000..a9caed1df8 --- /dev/null +++ b/keyboard/cluepad/backlight.c @@ -0,0 +1,54 @@ +#include <avr/io.h> +#include "backlight.h" +#include "led.h" + +#include "print.h" + +int pwm_level; + +void led_set_kb(uint8_t usb_led) +{ + print("led_set\n"); +} + +void init_backlight_pin(void) +{ + // Set C7 to output + DDRC |= (1<<7); + + // Initialize the timer + TC4H = 0x03; + OCR4C = 0xFF; + TCCR4A = 0b10000010; + TCCR4B = 0b00000001; +} + +void backlight_set(uint8_t level) +{ + // Determine the PWM level + switch (level) + { + case 0: + // 33% + pwm_level = 0x54; + break; + case 1: + // 66% + pwm_level = 0xA8; + break; + case 2: + // 100% + pwm_level = 0xFF; + break; + case 3: + // 0% + pwm_level = 0x00; + break; + default: + xprintf("Unknown level: %d\n", level); + } + + // Write the PWM level to the timer + TC4H = pwm_level >> 8; + OCR4A = 0xFF & pwm_level; +} |