]> git.gir.st - tmk_keyboard.git/blob - keyboard/lightsaber/backlight.c
Merge commit '20b787fc1284176834cbe7ca2134e4b36bec5828'
[tmk_keyboard.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 & BACKLIGHT_ALPHA)
39 {
40 PORTB |= (1<<1);
41 }
42 else
43 {
44 PORTB &= ~(1<<1);
45 }
46 if (level & BACKLIGHT_NUMERIC)
47 {
48 PORTB |= (1<<2);
49 }
50 else
51 {
52 PORTB &= ~(1<<2);
53 }
54 if (level & BACKLIGHT_MODNUM)
55 {
56 PORTB |= (1<<3);
57 }
58 else
59 {
60 PORTB &= ~(1<<3);
61 }
62 if (level & BACKLIGHT_BACKSIDE)
63 {
64 PORTD |= (1<<6);
65 }
66 else
67 {
68 PORTD &= ~(1<<6);
69 }
70 if (level & BACKLIGHT_TOPRIGHT)
71 {
72 PORTD &= ~(1<<7);
73 }
74 else
75 {
76 PORTD |= (1<<7);
77 }
78 if (level & BACKLIGHT_FROW)
79 {
80 PORTE |= (1<<6);
81 }
82 else
83 {
84 PORTE &= ~(1<<6);
85 }
86 }
Imprint / Impressum