]> git.donarmstrong.com Git - tmk_firmware.git/commitdiff
Added basic led+backlight support
authorRalf Schmitt <ralf@bunkertor.net>
Wed, 19 Mar 2014 22:58:08 +0000 (23:58 +0100)
committerRalf Schmitt <ralf@bunkertor.net>
Wed, 19 Mar 2014 22:58:08 +0000 (23:58 +0100)
keyboard/lightsaber/Makefile.lufa
keyboard/lightsaber/backlight.c [new file with mode: 0644]
keyboard/lightsaber/config.h
keyboard/lightsaber/keymap_winkey.h
keyboard/lightsaber/led.c

index 6982b51f70541d3090aaf4625051f2df4a3a7519..25816ac03eea87118df5167840c9beef911e8ca1 100644 (file)
@@ -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 (file)
index 0000000..b282008
--- /dev/null
@@ -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);
+    }
+}
index b8de6adbffbc7c37ff3173886d3f0378aa5575f0..d971d038e34c464a7fc4cc8bcee953126dff5b67 100644 (file)
@@ -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
 
index 510fa7f72eeae01609fe087f7e90c61345a7c9d1..9d558ae734f0fc25044f004d39f619b8ea20c2a6 100644 (file)
@@ -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()
 };
index 9c98f9db2cc3b7f4033b6163f7abfe48f8e1190d..c3f85427f51dbd1b376edd8bc31a69d41fdd409d 100644 (file)
@@ -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);
+    }
 }