3 #ifdef BACKLIGHT_ENABLE
8 void matrix_init_user(void) {
12 __attribute__ ((weak))
13 void matrix_scan_user(void) {
18 #ifdef BACKLIGHT_ENABLE
20 void backlight_init_ports()
23 // Setup PB6 as output and output low.
27 // Use full 16-bit resolution.
30 // I could write a wall of text here to explain... but TL;DW
31 // Go read the ATmega32u4 datasheet.
32 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
34 // Pin PB6 = OCR1B (Timer 1, Channel C)
35 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
36 // (i.e. start high, go low when counter matches.)
37 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
38 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
40 TCCR1A = _BV(COM1B1) | _BV(WGM11); // = 0b00001010;
41 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
46 void backlight_set(uint8_t level)
48 // Prevent backlight blink on lowest level
49 PORTB &= ~(_BV(PORTB6));
53 // Turn off PWM control on PB6, revert to output low.
54 TCCR1A &= ~(_BV(COM1B1));
57 else if ( level == BACKLIGHT_LEVELS )
59 // Turn on PWM control of PB6
60 TCCR1A |= _BV(COM1B1);
66 // Turn on PWM control of PB6
67 TCCR1A |= _BV(COM1B1);
69 OCR1B = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
75 void matrix_init_kb(void) {
76 // put your keyboard start-up code here
77 // runs once when the firmware starts up
78 if (matrix_init_user) {
79 (*matrix_init_user)();
83 #ifdef BACKLIGHT_ENABLE
84 backlight_init_ports();
88 void matrix_scan_kb(void) {
89 // put your looping keyboard code here
90 // runs every cycle (a lot)
91 if (matrix_scan_user) {
92 (*matrix_scan_user)();