Added basic led+backlight support

master
Ralf Schmitt 2014-03-19 23:58:08 +01:00
parent 160678a7b8
commit 526d988a0c
5 changed files with 94 additions and 3 deletions

View 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

View File

@ -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);
}
}

View 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

View 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()
};

View 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);
}
}