4 void matrix_init_user(void) {
9 void matrix_scan_user(void) {
13 __attribute__ ((weak))
14 bool process_action_user(keyrecord_t *record) {
18 void matrix_init_kb(void) {
19 #ifdef BACKLIGHT_ENABLE
20 backlight_init_ports();
23 #ifdef RGBLIGHT_ENABLE
35 void matrix_scan_kb(void) {
39 bool process_action_kb(keyrecord_t *record) {
40 return process_action_user(record);
43 #ifdef BACKLIGHT_ENABLE
46 void backlight_init_ports()
49 // Setup PB7 as output and output low.
53 // Use full 16-bit resolution.
56 // I could write a wall of text here to explain... but TL;DW
57 // Go read the ATmega32u4 datasheet.
58 // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
60 // Pin PB7 = OCR1C (Timer 1, Channel C)
61 // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
62 // (i.e. start high, go low when counter matches.)
63 // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
64 // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
66 TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
67 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
72 void backlight_set(uint8_t level)
76 // Turn off PWM control on PB7, revert to output low.
77 TCCR1A &= ~(_BV(COM1C1));
79 // Prevent backlight blink on lowest level
80 PORTB &= ~(_BV(PORTB7));
82 else if ( level == BACKLIGHT_LEVELS )
84 // Prevent backlight blink on lowest level
85 PORTB &= ~(_BV(PORTB7));
86 // Turn on PWM control of PB7
87 TCCR1A |= _BV(COM1C1);
93 // Prevent backlight blink on lowest level
94 PORTB &= ~(_BV(PORTB7));
95 // Turn on PWM control of PB7
96 TCCR1A |= _BV(COM1C1);
98 CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));