]> git.donarmstrong.com Git - tmk_firmware.git/blob - keyboard/lightsaber/backlight.c
Added basic led+backlight support
[tmk_firmware.git] / keyboard / lightsaber / backlight.c
1 /*
2 Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <avr/io.h>
19 #include "backlight.h"
20
21 /* Backlight pin configuration
22  *
23  * Alphas    PB1 (high)
24  * Numeric   PB2 (high)
25  * Mod+Num   PB3 (high)
26  * Backside  PD6 (high)
27  * TopRight  PD7 (low)
28  * F-Row     PE6 (high)
29  *
30  */
31 void backlight_set(uint8_t level)
32 {
33     // Set as output.
34     DDRB |= (1<<1) | (1<<2) | (1<<3);
35     DDRD |= (1<<6) | (1<<7);
36     DDRE |= (1<<6);
37
38     if(level & (1<<0))
39     {
40         PORTB &= ~(1<<1);
41         PORTB &= ~(1<<2);
42         PORTB &= ~(1<<3);
43         PORTD &= ~(1<<6);
44         PORTD |= (1<<7);
45         PORTE &= ~(1<<6);
46     }
47     else
48     {
49         PORTB |= (1<<1);
50         PORTB |= (1<<2);
51         PORTB |= (1<<3);
52         PORTD |= (1<<6);
53         PORTD &= ~(1<<7);
54         PORTE |= (1<<6);
55     }
56 }