diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-04-29 22:19:40 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-29 22:19:40 -0400 |
| commit | 0656f2fa10e25e160617c3e5d14cfbae35dd9c8d (patch) | |
| tree | d93e122e84313a89b84ea2a1011093398cf75ab3 | |
| parent | 9ab7098c834ffe601ad5c39759acfddabbd6373f (diff) | |
| download | qmk_firmware-0656f2fa10e25e160617c3e5d14cfbae35dd9c8d.tar.gz qmk_firmware-0656f2fa10e25e160617c3e5d14cfbae35dd9c8d.zip | |
moves backlight functionality to keyboard files and updates template makefile
previously there were two backlight.c files (bad)
| -rw-r--r-- | keyboard/atomic/Makefile | 4 | ||||
| -rw-r--r-- | keyboard/atomic/atomic.c | 61 | ||||
| -rw-r--r-- | keyboard/atomic/atomic.h | 5 | ||||
| -rw-r--r-- | keyboard/atomic/backlight.c | 63 | ||||
| -rw-r--r-- | keyboard/planck/Makefile | 4 | ||||
| -rw-r--r-- | keyboard/planck/backlight.c | 61 | ||||
| -rw-r--r-- | keyboard/planck/planck.c | 61 | ||||
| -rw-r--r-- | keyboard/planck/planck.h | 1 | ||||
| -rw-r--r-- | keyboard/preonic/Makefile | 5 | ||||
| -rw-r--r-- | keyboard/preonic/backlight.c | 61 | ||||
| -rw-r--r-- | keyboard/preonic/preonic.c | 63 | ||||
| -rw-r--r-- | keyboard/preonic/preonic.h | 1 | ||||
| -rw-r--r-- | quantum/template/Makefile | 46 | ||||
| -rw-r--r-- | quantum/template/template.c | 61 | ||||
| -rw-r--r-- | quantum/template/template.h | 5 |
15 files changed, 287 insertions, 215 deletions
diff --git a/keyboard/atomic/Makefile b/keyboard/atomic/Makefile index 1d91c34b7..c1a0a6db4 100644 --- a/keyboard/atomic/Makefile +++ b/keyboard/atomic/Makefile | |||
| @@ -171,10 +171,6 @@ endif | |||
| 171 | 171 | ||
| 172 | endif | 172 | endif |
| 173 | 173 | ||
| 174 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | ||
| 175 | SRC := backlight.c $(SRC) | ||
| 176 | endif | ||
| 177 | |||
| 178 | # Optimize size but this may cause error "relocation truncated to fit" | 174 | # Optimize size but this may cause error "relocation truncated to fit" |
| 179 | #EXTRALDFLAGS = -Wl,--relax | 175 | #EXTRALDFLAGS = -Wl,--relax |
| 180 | 176 | ||
diff --git a/keyboard/atomic/atomic.c b/keyboard/atomic/atomic.c index 5e31264e6..399649716 100644 --- a/keyboard/atomic/atomic.c +++ b/keyboard/atomic/atomic.c | |||
| @@ -57,3 +57,64 @@ void led_set_kb(uint8_t usb_led) { | |||
| 57 | 57 | ||
| 58 | led_set_user(usb_led); | 58 | led_set_user(usb_led); |
| 59 | } | 59 | } |
| 60 | |||
| 61 | #ifdef BACKLIGHT_ENABLE | ||
| 62 | #define CHANNEL OCR1C | ||
| 63 | |||
| 64 | void backlight_init_ports() | ||
| 65 | { | ||
| 66 | |||
| 67 | // Setup PB7 as output and output low. | ||
| 68 | DDRB |= (1<<7); | ||
| 69 | PORTB &= ~(1<<7); | ||
| 70 | |||
| 71 | // Use full 16-bit resolution. | ||
| 72 | ICR1 = 0xFFFF; | ||
| 73 | |||
| 74 | // I could write a wall of text here to explain... but TL;DW | ||
| 75 | // Go read the ATmega32u4 datasheet. | ||
| 76 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 77 | |||
| 78 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 79 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 80 | // (i.e. start high, go low when counter matches.) | ||
| 81 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 82 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 83 | |||
| 84 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 85 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 86 | |||
| 87 | backlight_init(); | ||
| 88 | } | ||
| 89 | |||
| 90 | void backlight_set(uint8_t level) | ||
| 91 | { | ||
| 92 | if ( level == 0 ) | ||
| 93 | { | ||
| 94 | // Turn off PWM control on PB7, revert to output low. | ||
| 95 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 96 | CHANNEL = 0x0; | ||
| 97 | // Prevent backlight blink on lowest level | ||
| 98 | PORTB &= ~(_BV(PORTB7)); | ||
| 99 | } | ||
| 100 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 101 | { | ||
| 102 | // Prevent backlight blink on lowest level | ||
| 103 | PORTB &= ~(_BV(PORTB7)); | ||
| 104 | // Turn on PWM control of PB7 | ||
| 105 | TCCR1A |= _BV(COM1C1); | ||
| 106 | // Set the brightness | ||
| 107 | CHANNEL = 0xFFFF; | ||
| 108 | } | ||
| 109 | else | ||
| 110 | { | ||
| 111 | // Prevent backlight blink on lowest level | ||
| 112 | PORTB &= ~(_BV(PORTB7)); | ||
| 113 | // Turn on PWM control of PB7 | ||
| 114 | TCCR1A |= _BV(COM1C1); | ||
| 115 | // Set the brightness | ||
| 116 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | #endif \ No newline at end of file | ||
diff --git a/keyboard/atomic/atomic.h b/keyboard/atomic/atomic.h index d5461e424..0c7aeb1cc 100644 --- a/keyboard/atomic/atomic.h +++ b/keyboard/atomic/atomic.h | |||
| @@ -3,8 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | #include "matrix.h" | 4 | #include "matrix.h" |
| 5 | #include "keymap_common.h" | 5 | #include "keymap_common.h" |
| 6 | #include "backlight.h" | 6 | #ifdef BACKLIGHT_ENABLE |
| 7 | #include "backlight.h" | ||
| 8 | #endif | ||
| 7 | #include <stddef.h> | 9 | #include <stddef.h> |
| 10 | #include <avr/io.h> | ||
| 8 | 11 | ||
| 9 | // This a shortcut to help you visually see your layout. | 12 | // This a shortcut to help you visually see your layout. |
| 10 | // The following is an example using the Planck MIT layout | 13 | // The following is an example using the Planck MIT layout |
diff --git a/keyboard/atomic/backlight.c b/keyboard/atomic/backlight.c deleted file mode 100644 index 647b57e71..000000000 --- a/keyboard/atomic/backlight.c +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | |||
| 2 | #include <avr/io.h> | ||
| 3 | #include "backlight.h" | ||
| 4 | #include "atomic.h" | ||
| 5 | |||
| 6 | |||
| 7 | #define CHANNEL OCR1C | ||
| 8 | |||
| 9 | void backlight_init_ports() | ||
| 10 | { | ||
| 11 | |||
| 12 | // Setup PB7 as output and output low. | ||
| 13 | DDRB |= (1<<7); | ||
| 14 | PORTB &= ~(1<<7); | ||
| 15 | |||
| 16 | // Use full 16-bit resolution. | ||
| 17 | ICR1 = 0xFFFF; | ||
| 18 | |||
| 19 | // I could write a wall of text here to explain... but TL;DW | ||
| 20 | // Go read the ATmega32u4 datasheet. | ||
| 21 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 22 | |||
| 23 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 24 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 25 | // (i.e. start high, go low when counter matches.) | ||
| 26 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 27 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 28 | |||
| 29 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 30 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 31 | |||
| 32 | backlight_init(); | ||
| 33 | } | ||
| 34 | |||
| 35 | void backlight_set(uint8_t level) | ||
| 36 | { | ||
| 37 | if ( level == 0 ) | ||
| 38 | { | ||
| 39 | // Turn off PWM control on PB7, revert to output low. | ||
| 40 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 41 | CHANNEL = 0x0; | ||
| 42 | // Prevent backlight blink on lowest level | ||
| 43 | PORTB &= ~(_BV(PORTB7)); | ||
| 44 | } | ||
| 45 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 46 | { | ||
| 47 | // Prevent backlight blink on lowest level | ||
| 48 | PORTB &= ~(_BV(PORTB7)); | ||
| 49 | // Turn on PWM control of PB7 | ||
| 50 | TCCR1A |= _BV(COM1C1); | ||
| 51 | // Set the brightness | ||
| 52 | CHANNEL = 0xFFFF; | ||
| 53 | } | ||
| 54 | else | ||
| 55 | { | ||
| 56 | // Prevent backlight blink on lowest level | ||
| 57 | PORTB &= ~(_BV(PORTB7)); | ||
| 58 | // Turn on PWM control of PB7 | ||
| 59 | TCCR1A |= _BV(COM1C1); | ||
| 60 | // Set the brightness | ||
| 61 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 62 | } | ||
| 63 | } \ No newline at end of file | ||
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index 01d9e3ce9..c0c6201cb 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile | |||
| @@ -171,10 +171,6 @@ endif | |||
| 171 | 171 | ||
| 172 | endif | 172 | endif |
| 173 | 173 | ||
| 174 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | ||
| 175 | SRC := backlight.c $(SRC) | ||
| 176 | endif | ||
| 177 | |||
| 178 | # Optimize size but this may cause error "relocation truncated to fit" | 174 | # Optimize size but this may cause error "relocation truncated to fit" |
| 179 | #EXTRALDFLAGS = -Wl,--relax | 175 | #EXTRALDFLAGS = -Wl,--relax |
| 180 | 176 | ||
diff --git a/keyboard/planck/backlight.c b/keyboard/planck/backlight.c deleted file mode 100644 index f69364b2a..000000000 --- a/keyboard/planck/backlight.c +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | |||
| 2 | #include <avr/io.h> | ||
| 3 | #include "backlight.h" | ||
| 4 | |||
| 5 | #define CHANNEL OCR1C | ||
| 6 | |||
| 7 | void backlight_init_ports() | ||
| 8 | { | ||
| 9 | |||
| 10 | // Setup PB7 as output and output low. | ||
| 11 | DDRB |= (1<<7); | ||
| 12 | PORTB &= ~(1<<7); | ||
| 13 | |||
| 14 | // Use full 16-bit resolution. | ||
| 15 | ICR1 = 0xFFFF; | ||
| 16 | |||
| 17 | // I could write a wall of text here to explain... but TL;DW | ||
| 18 | // Go read the ATmega32u4 datasheet. | ||
| 19 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 20 | |||
| 21 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 22 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 23 | // (i.e. start high, go low when counter matches.) | ||
| 24 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 25 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 26 | |||
| 27 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 28 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 29 | |||
| 30 | backlight_init(); | ||
| 31 | } | ||
| 32 | |||
| 33 | void backlight_set(uint8_t level) | ||
| 34 | { | ||
| 35 | if ( level == 0 ) | ||
| 36 | { | ||
| 37 | // Turn off PWM control on PB7, revert to output low. | ||
| 38 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 39 | CHANNEL = 0x0; | ||
| 40 | // Prevent backlight blink on lowest level | ||
| 41 | PORTB &= ~(_BV(PORTB7)); | ||
| 42 | } | ||
| 43 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 44 | { | ||
| 45 | // Prevent backlight blink on lowest level | ||
| 46 | PORTB &= ~(_BV(PORTB7)); | ||
| 47 | // Turn on PWM control of PB7 | ||
| 48 | TCCR1A |= _BV(COM1C1); | ||
| 49 | // Set the brightness | ||
| 50 | CHANNEL = 0xFFFF; | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | // Prevent backlight blink on lowest level | ||
| 55 | PORTB &= ~(_BV(PORTB7)); | ||
| 56 | // Turn on PWM control of PB7 | ||
| 57 | TCCR1A |= _BV(COM1C1); | ||
| 58 | // Set the brightness | ||
| 59 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 60 | } | ||
| 61 | } \ No newline at end of file | ||
diff --git a/keyboard/planck/planck.c b/keyboard/planck/planck.c index 4b39cf1e8..655850150 100644 --- a/keyboard/planck/planck.c +++ b/keyboard/planck/planck.c | |||
| @@ -32,3 +32,64 @@ void matrix_scan_kb(void) { | |||
| 32 | void process_action_kb(keyrecord_t *record) { | 32 | void process_action_kb(keyrecord_t *record) { |
| 33 | process_action_user(record); | 33 | process_action_user(record); |
| 34 | } | 34 | } |
| 35 | |||
| 36 | #ifdef BACKLIGHT_ENABLE | ||
| 37 | #define CHANNEL OCR1C | ||
| 38 | |||
| 39 | void backlight_init_ports() | ||
| 40 | { | ||
| 41 | |||
| 42 | // Setup PB7 as output and output low. | ||
| 43 | DDRB |= (1<<7); | ||
| 44 | PORTB &= ~(1<<7); | ||
| 45 | |||
| 46 | // Use full 16-bit resolution. | ||
| 47 | ICR1 = 0xFFFF; | ||
| 48 | |||
| 49 | // I could write a wall of text here to explain... but TL;DW | ||
| 50 | // Go read the ATmega32u4 datasheet. | ||
| 51 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 52 | |||
| 53 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 54 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 55 | // (i.e. start high, go low when counter matches.) | ||
| 56 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 57 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 58 | |||
| 59 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 60 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 61 | |||
| 62 | backlight_init(); | ||
| 63 | } | ||
| 64 | |||
| 65 | void backlight_set(uint8_t level) | ||
| 66 | { | ||
| 67 | if ( level == 0 ) | ||
| 68 | { | ||
| 69 | // Turn off PWM control on PB7, revert to output low. | ||
| 70 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 71 | CHANNEL = 0x0; | ||
| 72 | // Prevent backlight blink on lowest level | ||
| 73 | PORTB &= ~(_BV(PORTB7)); | ||
| 74 | } | ||
| 75 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 76 | { | ||
| 77 | // Prevent backlight blink on lowest level | ||
| 78 | PORTB &= ~(_BV(PORTB7)); | ||
| 79 | // Turn on PWM control of PB7 | ||
| 80 | TCCR1A |= _BV(COM1C1); | ||
| 81 | // Set the brightness | ||
| 82 | CHANNEL = 0xFFFF; | ||
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | // Prevent backlight blink on lowest level | ||
| 87 | PORTB &= ~(_BV(PORTB7)); | ||
| 88 | // Turn on PWM control of PB7 | ||
| 89 | TCCR1A |= _BV(COM1C1); | ||
| 90 | // Set the brightness | ||
| 91 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | #endif \ No newline at end of file | ||
diff --git a/keyboard/planck/planck.h b/keyboard/planck/planck.h index edcb5fbff..c5b59d999 100644 --- a/keyboard/planck/planck.h +++ b/keyboard/planck/planck.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "rgblight.h" | 10 | #include "rgblight.h" |
| 11 | #endif | 11 | #endif |
| 12 | #include <stddef.h> | 12 | #include <stddef.h> |
| 13 | #include <avr/io.h> | ||
| 13 | #ifdef MIDI_ENABLE | 14 | #ifdef MIDI_ENABLE |
| 14 | #include <keymap_midi.h> | 15 | #include <keymap_midi.h> |
| 15 | #endif | 16 | #endif |
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile index 3504e2720..259dd6686 100644 --- a/keyboard/preonic/Makefile +++ b/keyboard/preonic/Makefile | |||
| @@ -162,11 +162,6 @@ endif | |||
| 162 | 162 | ||
| 163 | endif | 163 | endif |
| 164 | 164 | ||
| 165 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | ||
| 166 | SRC := backlight.c $(SRC) | ||
| 167 | endif | ||
| 168 | |||
| 169 | |||
| 170 | # Optimize size but this may cause error "relocation truncated to fit" | 165 | # Optimize size but this may cause error "relocation truncated to fit" |
| 171 | #EXTRALDFLAGS = -Wl,--relax | 166 | #EXTRALDFLAGS = -Wl,--relax |
| 172 | 167 | ||
diff --git a/keyboard/preonic/backlight.c b/keyboard/preonic/backlight.c deleted file mode 100644 index f69364b2a..000000000 --- a/keyboard/preonic/backlight.c +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | |||
| 2 | #include <avr/io.h> | ||
| 3 | #include "backlight.h" | ||
| 4 | |||
| 5 | #define CHANNEL OCR1C | ||
| 6 | |||
| 7 | void backlight_init_ports() | ||
| 8 | { | ||
| 9 | |||
| 10 | // Setup PB7 as output and output low. | ||
| 11 | DDRB |= (1<<7); | ||
| 12 | PORTB &= ~(1<<7); | ||
| 13 | |||
| 14 | // Use full 16-bit resolution. | ||
| 15 | ICR1 = 0xFFFF; | ||
| 16 | |||
| 17 | // I could write a wall of text here to explain... but TL;DW | ||
| 18 | // Go read the ATmega32u4 datasheet. | ||
| 19 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 20 | |||
| 21 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 22 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 23 | // (i.e. start high, go low when counter matches.) | ||
| 24 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 25 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 26 | |||
| 27 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 28 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 29 | |||
| 30 | backlight_init(); | ||
| 31 | } | ||
| 32 | |||
| 33 | void backlight_set(uint8_t level) | ||
| 34 | { | ||
| 35 | if ( level == 0 ) | ||
| 36 | { | ||
| 37 | // Turn off PWM control on PB7, revert to output low. | ||
| 38 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 39 | CHANNEL = 0x0; | ||
| 40 | // Prevent backlight blink on lowest level | ||
| 41 | PORTB &= ~(_BV(PORTB7)); | ||
| 42 | } | ||
| 43 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 44 | { | ||
| 45 | // Prevent backlight blink on lowest level | ||
| 46 | PORTB &= ~(_BV(PORTB7)); | ||
| 47 | // Turn on PWM control of PB7 | ||
| 48 | TCCR1A |= _BV(COM1C1); | ||
| 49 | // Set the brightness | ||
| 50 | CHANNEL = 0xFFFF; | ||
| 51 | } | ||
| 52 | else | ||
| 53 | { | ||
| 54 | // Prevent backlight blink on lowest level | ||
| 55 | PORTB &= ~(_BV(PORTB7)); | ||
| 56 | // Turn on PWM control of PB7 | ||
| 57 | TCCR1A |= _BV(COM1C1); | ||
| 58 | // Set the brightness | ||
| 59 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 60 | } | ||
| 61 | } \ No newline at end of file | ||
diff --git a/keyboard/preonic/preonic.c b/keyboard/preonic/preonic.c index f639f247a..211f8d029 100644 --- a/keyboard/preonic/preonic.c +++ b/keyboard/preonic/preonic.c | |||
| @@ -38,4 +38,65 @@ void matrix_scan_kb(void) { | |||
| 38 | 38 | ||
| 39 | void process_action_kb(keyrecord_t *record) { | 39 | void process_action_kb(keyrecord_t *record) { |
| 40 | process_action_user(record); | 40 | process_action_user(record); |
| 41 | } \ No newline at end of file | 41 | } |
| 42 | |||
| 43 | #ifdef BACKLIGHT_ENABLE | ||
| 44 | #define CHANNEL OCR1C | ||
| 45 | |||
| 46 | void backlight_init_ports() | ||
| 47 | { | ||
| 48 | |||
| 49 | // Setup PB7 as output and output low. | ||
| 50 | DDRB |= (1<<7); | ||
| 51 | PORTB &= ~(1<<7); | ||
| 52 | |||
| 53 | // Use full 16-bit resolution. | ||
| 54 | ICR1 = 0xFFFF; | ||
| 55 | |||
| 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 | ||
| 59 | |||
| 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 | ||
| 65 | |||
| 66 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 67 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 68 | |||
| 69 | backlight_init(); | ||
| 70 | } | ||
| 71 | |||
| 72 | void backlight_set(uint8_t level) | ||
| 73 | { | ||
| 74 | if ( level == 0 ) | ||
| 75 | { | ||
| 76 | // Turn off PWM control on PB7, revert to output low. | ||
| 77 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 78 | CHANNEL = 0x0; | ||
| 79 | // Prevent backlight blink on lowest level | ||
| 80 | PORTB &= ~(_BV(PORTB7)); | ||
| 81 | } | ||
| 82 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 83 | { | ||
| 84 | // Prevent backlight blink on lowest level | ||
| 85 | PORTB &= ~(_BV(PORTB7)); | ||
| 86 | // Turn on PWM control of PB7 | ||
| 87 | TCCR1A |= _BV(COM1C1); | ||
| 88 | // Set the brightness | ||
| 89 | CHANNEL = 0xFFFF; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | // Prevent backlight blink on lowest level | ||
| 94 | PORTB &= ~(_BV(PORTB7)); | ||
| 95 | // Turn on PWM control of PB7 | ||
| 96 | TCCR1A |= _BV(COM1C1); | ||
| 97 | // Set the brightness | ||
| 98 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | #endif \ No newline at end of file | ||
diff --git a/keyboard/preonic/preonic.h b/keyboard/preonic/preonic.h index 51ed9ba39..030acdadb 100644 --- a/keyboard/preonic/preonic.h +++ b/keyboard/preonic/preonic.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "rgblight.h" | 10 | #include "rgblight.h" |
| 11 | #endif | 11 | #endif |
| 12 | #include <stddef.h> | 12 | #include <stddef.h> |
| 13 | #include <avr/io.h> | ||
| 13 | #ifdef MIDI_ENABLE | 14 | #ifdef MIDI_ENABLE |
| 14 | #include <keymap_midi.h> | 15 | #include <keymap_midi.h> |
| 15 | #endif | 16 | #endif |
diff --git a/quantum/template/Makefile b/quantum/template/Makefile index 4fa195468..1a535ef2c 100644 --- a/quantum/template/Makefile +++ b/quantum/template/Makefile | |||
| @@ -111,23 +111,41 @@ OPT_DEFS += -DBOOTLOADER_SIZE=512 | |||
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | # Build Options | 113 | # Build Options |
| 114 | # comment out to disable the options. | 114 | # change yes to no to disable |
| 115 | # | 115 | # |
| 116 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | 116 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) |
| 117 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 117 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
| 118 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 118 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
| 119 | CONSOLE_ENABLE = yes # Console for debug(+400) | 119 | CONSOLE_ENABLE = yes # Console for debug(+400) |
| 120 | COMMAND_ENABLE = yes # Commands for debug and configuration | 120 | COMMAND_ENABLE = yes # Commands for debug and configuration |
| 121 | KEYBOARD_LOCK_ENABLE = yes # Allow locking of keyboard via magic key | 121 | KEYBOARD_LOCK_ENABLE = yes # Allow locking of keyboard via magic key |
| 122 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 122 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 123 | # SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | 123 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
| 124 | #NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 124 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
| 125 | # BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | 125 | NKRO_ENABLE = no # USB Nkey Rollover |
| 126 | # MIDI_ENABLE = YES # MIDI controls | 126 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality |
| 127 | # UNICODE_ENABLE = YES # Unicode | 127 | MIDI_ENABLE = no # MIDI controls |
| 128 | # BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID | 128 | UNICODE_ENABLE = no # Unicode |
| 129 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | ||
| 130 | AUDIO_ENABLE = no # Audio output on port C6 | ||
| 129 | 131 | ||
| 130 | 132 | ||
| 133 | ifdef KEYMAP | ||
| 134 | |||
| 135 | ifeq ("$(wildcard keymaps/$(KEYMAP).c)","") | ||
| 136 | ifneq ("$(wildcard keymaps/$(KEYMAP)/makefile.mk)","") | ||
| 137 | include keymaps/$(KEYMAP)/makefile.mk | ||
| 138 | endif | ||
| 139 | endif | ||
| 140 | |||
| 141 | else | ||
| 142 | |||
| 143 | ifneq ("$(wildcard keymaps/default/makefile.mk)","") | ||
| 144 | include keymaps/default/makefile.mk | ||
| 145 | endif | ||
| 146 | |||
| 147 | endif | ||
| 148 | |||
| 131 | # Optimize size but this may cause error "relocation truncated to fit" | 149 | # Optimize size but this may cause error "relocation truncated to fit" |
| 132 | #EXTRALDFLAGS = -Wl,--relax | 150 | #EXTRALDFLAGS = -Wl,--relax |
| 133 | 151 | ||
diff --git a/quantum/template/template.c b/quantum/template/template.c index cc52e496f..6050a2d20 100644 --- a/quantum/template/template.c +++ b/quantum/template/template.c | |||
| @@ -46,3 +46,64 @@ void led_set_kb(uint8_t usb_led) { | |||
| 46 | 46 | ||
| 47 | led_set_user(usb_led); | 47 | led_set_user(usb_led); |
| 48 | } | 48 | } |
| 49 | |||
| 50 | #ifdef BACKLIGHT_ENABLE | ||
| 51 | #define CHANNEL OCR1C | ||
| 52 | |||
| 53 | void backlight_init_ports() | ||
| 54 | { | ||
| 55 | |||
| 56 | // Setup PB7 as output and output low. | ||
| 57 | DDRB |= (1<<7); | ||
| 58 | PORTB &= ~(1<<7); | ||
| 59 | |||
| 60 | // Use full 16-bit resolution. | ||
| 61 | ICR1 = 0xFFFF; | ||
| 62 | |||
| 63 | // I could write a wall of text here to explain... but TL;DW | ||
| 64 | // Go read the ATmega32u4 datasheet. | ||
| 65 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 66 | |||
| 67 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 68 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 69 | // (i.e. start high, go low when counter matches.) | ||
| 70 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 71 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 72 | |||
| 73 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 74 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 75 | |||
| 76 | backlight_init(); | ||
| 77 | } | ||
| 78 | |||
| 79 | void backlight_set(uint8_t level) | ||
| 80 | { | ||
| 81 | if ( level == 0 ) | ||
| 82 | { | ||
| 83 | // Turn off PWM control on PB7, revert to output low. | ||
| 84 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 85 | CHANNEL = 0x0; | ||
| 86 | // Prevent backlight blink on lowest level | ||
| 87 | PORTB &= ~(_BV(PORTB7)); | ||
| 88 | } | ||
| 89 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 90 | { | ||
| 91 | // Prevent backlight blink on lowest level | ||
| 92 | PORTB &= ~(_BV(PORTB7)); | ||
| 93 | // Turn on PWM control of PB7 | ||
| 94 | TCCR1A |= _BV(COM1C1); | ||
| 95 | // Set the brightness | ||
| 96 | CHANNEL = 0xFFFF; | ||
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | // Prevent backlight blink on lowest level | ||
| 101 | PORTB &= ~(_BV(PORTB7)); | ||
| 102 | // Turn on PWM control of PB7 | ||
| 103 | TCCR1A |= _BV(COM1C1); | ||
| 104 | // Set the brightness | ||
| 105 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | #endif \ No newline at end of file | ||
diff --git a/quantum/template/template.h b/quantum/template/template.h index b1c34d3cb..22742105a 100644 --- a/quantum/template/template.h +++ b/quantum/template/template.h | |||
| @@ -3,7 +3,10 @@ | |||
| 3 | 3 | ||
| 4 | #include "matrix.h" | 4 | #include "matrix.h" |
| 5 | #include "keymap_common.h" | 5 | #include "keymap_common.h" |
| 6 | #include "backlight.h" | 6 | #ifdef BACKLIGHT_ENABLE |
| 7 | #include "backlight.h" | ||
| 8 | #endif | ||
| 9 | #include <avr/io.h> | ||
| 7 | #include <stddef.h> | 10 | #include <stddef.h> |
| 8 | 11 | ||
| 9 | // This a shortcut to help you visually see your layout. | 12 | // This a shortcut to help you visually see your layout. |
