aboutsummaryrefslogtreecommitdiff
path: root/quantum/template/template.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/template/template.c')
-rw-r--r--quantum/template/template.c84
1 files changed, 1 insertions, 83 deletions
diff --git a/quantum/template/template.c b/quantum/template/template.c
index 649072eb2..dcc4b0a22 100644
--- a/quantum/template/template.c
+++ b/quantum/template/template.c
@@ -1,26 +1,5 @@
1#include "%KEYBOARD%.h" 1#include "%KEYBOARD%.h"
2 2
3__attribute__ ((weak))
4void matrix_init_user(void) {
5 // leave this function blank - it can be defined in a keymap file
6};
7
8__attribute__ ((weak))
9void matrix_scan_user(void) {
10 // leave this function blank - it can be defined in a keymap file
11}
12
13__attribute__ ((weak))
14bool process_action_user(keyrecord_t *record) {
15 // leave this function blank - it can be defined in a keymap file
16 return true;
17}
18
19__attribute__ ((weak))
20void led_set_user(uint8_t usb_led) {
21 // leave this function blank - it can be defined in a keymap file
22}
23
24void matrix_init_kb(void) { 3void matrix_init_kb(void) {
25 // put your keyboard start-up code here 4 // put your keyboard start-up code here
26 // runs once when the firmware starts up 5 // runs once when the firmware starts up
@@ -35,7 +14,7 @@ void matrix_scan_kb(void) {
35 matrix_scan_user(); 14 matrix_scan_user();
36} 15}
37 16
38bool process_action_kb(keyrecord_t *record) { 17bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
39 // put your per-action keyboard code here 18 // put your per-action keyboard code here
40 // runs for every action, just before processing by the firmware 19 // runs for every action, just before processing by the firmware
41 20
@@ -47,64 +26,3 @@ void led_set_kb(uint8_t usb_led) {
47 26
48 led_set_user(usb_led); 27 led_set_user(usb_led);
49} 28}
50
51#ifdef BACKLIGHT_ENABLE
52#define CHANNEL OCR1C
53
54void backlight_init_ports()
55{
56
57 // Setup PB7 as output and output low.
58 DDRB |= (1<<7);
59 PORTB &= ~(1<<7);
60
61 // Use full 16-bit resolution.
62 ICR1 = 0xFFFF;
63
64 // I could write a wall of text here to explain... but TL;DW
65 // Go read the ATmega32u4 datasheet.
66 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
67
68 // Pin PB7 = OCR1C (Timer 1, Channel C)
69 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
70 // (i.e. start high, go low when counter matches.)
71 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
72 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
73
74 TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
75 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
76
77 backlight_init();
78}
79
80void backlight_set(uint8_t level)
81{
82 if ( level == 0 )
83 {
84 // Turn off PWM control on PB7, revert to output low.
85 TCCR1A &= ~(_BV(COM1C1));
86 CHANNEL = 0x0;
87 // Prevent backlight blink on lowest level
88 PORTB &= ~(_BV(PORTB7));
89 }
90 else if ( level == BACKLIGHT_LEVELS )
91 {
92 // Prevent backlight blink on lowest level
93 PORTB &= ~(_BV(PORTB7));
94 // Turn on PWM control of PB7
95 TCCR1A |= _BV(COM1C1);
96 // Set the brightness
97 CHANNEL = 0xFFFF;
98 }
99 else
100 {
101 // Prevent backlight blink on lowest level
102 PORTB &= ~(_BV(PORTB7));
103 // Turn on PWM control of PB7
104 TCCR1A |= _BV(COM1C1);
105 // Set the brightness
106 CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
107 }
108}
109
110#endif \ No newline at end of file