aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-29 22:19:40 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-29 22:19:40 -0400
commit0656f2fa10e25e160617c3e5d14cfbae35dd9c8d (patch)
treed93e122e84313a89b84ea2a1011093398cf75ab3 /quantum
parent9ab7098c834ffe601ad5c39759acfddabbd6373f (diff)
downloadqmk_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)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/template/Makefile46
-rw-r--r--quantum/template/template.c61
-rw-r--r--quantum/template/template.h5
3 files changed, 97 insertions, 15 deletions
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#
116BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) 116BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
117MOUSEKEY_ENABLE = yes # Mouse keys(+4700) 117MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
118EXTRAKEY_ENABLE = yes # Audio control and System control(+450) 118EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
119CONSOLE_ENABLE = yes # Console for debug(+400) 119CONSOLE_ENABLE = yes # Console for debug(+400)
120COMMAND_ENABLE = yes # Commands for debug and configuration 120COMMAND_ENABLE = yes # Commands for debug and configuration
121KEYBOARD_LOCK_ENABLE = yes # Allow locking of keyboard via magic key 121KEYBOARD_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 123SLEEP_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 125NKRO_ENABLE = no # USB Nkey Rollover
126# MIDI_ENABLE = YES # MIDI controls 126BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
127# UNICODE_ENABLE = YES # Unicode 127MIDI_ENABLE = no # MIDI controls
128# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID 128UNICODE_ENABLE = no # Unicode
129BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
130AUDIO_ENABLE = no # Audio output on port C6
129 131
130 132
133ifdef KEYMAP
134
135ifeq ("$(wildcard keymaps/$(KEYMAP).c)","")
136ifneq ("$(wildcard keymaps/$(KEYMAP)/makefile.mk)","")
137 include keymaps/$(KEYMAP)/makefile.mk
138endif
139endif
140
141else
142
143ifneq ("$(wildcard keymaps/default/makefile.mk)","")
144 include keymaps/default/makefile.mk
145endif
146
147endif
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
53void 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
79void 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.