summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Schmitt <ralf@bunkertor.net>2014-03-19 23:58:08 +0100
committerRalf Schmitt <ralf@bunkertor.net>2014-03-19 23:58:08 +0100
commit526d988a0caadc1a48bea862f605c9cee90c3dd3 (patch)
tree8c47584c7ab21ffa9f7b6b46937a33c85cb4dc43
parent160678a7b825af634a6fe02ea6a191b5c67cf75b (diff)
downloadqmk_firmware-526d988a0caadc1a48bea862f605c9cee90c3dd3.tar.gz
qmk_firmware-526d988a0caadc1a48bea862f605c9cee90c3dd3.tar.xz
Added basic led+backlight support
-rw-r--r--keyboard/lightsaber/Makefile.lufa3
-rw-r--r--keyboard/lightsaber/backlight.c56
-rw-r--r--keyboard/lightsaber/config.h3
-rw-r--r--keyboard/lightsaber/keymap_winkey.h3
-rw-r--r--keyboard/lightsaber/led.c32
5 files changed, 94 insertions, 3 deletions
diff --git a/keyboard/lightsaber/Makefile.lufa b/keyboard/lightsaber/Makefile.lufa
index 6982b51f7..25816ac03 100644
--- a/keyboard/lightsaber/Makefile.lufa
+++ b/keyboard/lightsaber/Makefile.lufa
@@ -51,6 +51,7 @@ TARGET_DIR = .
# List C source files here. (C dependencies are automatically generated.)
SRC += keymap.c \
led.c \
+ backlight.c \
matrix.c
CONFIG_H = config.h
@@ -103,7 +104,7 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
-#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
+BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
# Boot Section Size in bytes
diff --git a/keyboard/lightsaber/backlight.c b/keyboard/lightsaber/backlight.c
new file mode 100644
index 000000000..b28200807
--- /dev/null
+++ b/keyboard/lightsaber/backlight.c
@@ -0,0 +1,56 @@
+/*
+Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <avr/io.h>
+#include "backlight.h"
+
+/* Backlight pin configuration
+ *
+ * Alphas PB1 (high)
+ * Numeric PB2 (high)
+ * Mod+Num PB3 (high)
+ * Backside PD6 (high)
+ * TopRight PD7 (low)
+ * F-Row PE6 (high)
+ *
+ */
+void backlight_set(uint8_t level)
+{
+ // Set as output.
+ DDRB |= (1<<1) | (1<<2) | (1<<3);
+ DDRD |= (1<<6) | (1<<7);
+ DDRE |= (1<<6);
+
+ if(level & (1<<0))
+ {
+ PORTB &= ~(1<<1);
+ PORTB &= ~(1<<2);
+ PORTB &= ~(1<<3);
+ PORTD &= ~(1<<6);
+ PORTD |= (1<<7);
+ PORTE &= ~(1<<6);
+ }
+ else
+ {
+ PORTB |= (1<<1);
+ PORTB |= (1<<2);
+ PORTB |= (1<<3);
+ PORTD |= (1<<6);
+ PORTD &= ~(1<<7);
+ PORTE |= (1<<6);
+ }
+}
diff --git a/keyboard/lightsaber/config.h b/keyboard/lightsaber/config.h
index b8de6adbf..d971d038e 100644
--- a/keyboard/lightsaber/config.h
+++ b/keyboard/lightsaber/config.h
@@ -32,6 +32,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROWS 6
#define MATRIX_COLS 18
+/* number of backlight levels */
+#define BACKLIGHT_LEVELS 1
+
/* Set 0 if need no debouncing */
#define DEBOUNCE 5
diff --git a/keyboard/lightsaber/keymap_winkey.h b/keyboard/lightsaber/keymap_winkey.h
index 510fa7f72..9d558ae73 100644
--- a/keyboard/lightsaber/keymap_winkey.h
+++ b/keyboard/lightsaber/keymap_winkey.h
@@ -3,10 +3,11 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, PSCR, SLCK, BRK, \
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, NUMLOCK,KP_SLASH,KP_ASTERISK,KP_MINUS, \
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, KP_7, KP_8, KP_9, KP_PLUS, \
- CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, KP_4, KP_5, KP_6, NO, \
+ CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,FN0, ENT, KP_4, KP_5, KP_6, NO, \
LSFT, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, KP_1, KP_2, KP_3, KP_ENTER, \
LCTL,LGUI,LALT, SPC, NO, RALT,RGUI,RCTL, KP_0, NO, KP_DOT, NO)
};
static const uint16_t PROGMEM fn_actions[] = {
+ [0] = ACTION_BACKLIGHT_STEP()
};
diff --git a/keyboard/lightsaber/led.c b/keyboard/lightsaber/led.c
index 9c98f9db2..c3f85427f 100644
--- a/keyboard/lightsaber/led.c
+++ b/keyboard/lightsaber/led.c
@@ -1,5 +1,5 @@
/*
-Copyright 2012 Jun Wako <wakojun@gmail.com>
+Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdint.h"
#include "led.h"
+/* LED pin configuration
+ *
+ * Caps PB0 (low)
+ * NumLock PB4 (low)
+ *
+ */
void led_set(uint8_t usb_led)
{
+ // Set as output.
+ DDRB |= (1<<0) | (1<<4);
+
+ if (usb_led & (1<<USB_LED_CAPS_LOCK))
+ {
+ // Output low.
+ PORTB &= ~(1<<0);
+ }
+ else
+ {
+ // Output high.
+ PORTB |= (1<<0);
+ }
+
+ if (usb_led & (1<<USB_LED_NUM_LOCK))
+ {
+ // Output low.
+ PORTB &= ~(1<<4);
+ }
+ else
+ {
+ // Output high.
+ PORTB |= (1<<4);
+ }
}