aboutsummaryrefslogtreecommitdiff
path: root/keyboard/lightpad/backlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/lightpad/backlight.c')
-rw-r--r--keyboard/lightpad/backlight.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/keyboard/lightpad/backlight.c b/keyboard/lightpad/backlight.c
new file mode 100644
index 000000000..693c566fc
--- /dev/null
+++ b/keyboard/lightpad/backlight.c
@@ -0,0 +1,129 @@
1/*
2Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along 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 * FN1 PB0 (low)
24 * FN2 PB5 (low)
25 * FN3 PB4 (low)
26 * FN4 PD7 (low)
27 * REAR PD6 (high)
28 * NUMPAD PB2 (high)
29 * NUMLOCK PB1 (low)
30 */
31void backlight_init_ports() {
32 DDRB |= (1<<0) | (1<<1) | (1<<2) | (1<<4) | (1<<5);
33 DDRD |= (1<<6) | (1<<7);
34
35 backlight_disable_numlock();
36}
37
38void backlight_set(uint8_t level) {
39 (level & BACKLIGHT_FN1) ? backlight_enable_fn1() : backlight_disable_fn1();
40 (level & BACKLIGHT_FN2) ? backlight_enable_fn2() : backlight_disable_fn2();
41 (level & BACKLIGHT_FN3) ? backlight_enable_fn3() : backlight_disable_fn3();
42 (level & BACKLIGHT_FN4) ? backlight_enable_fn4() : backlight_disable_fn4();
43 (level & BACKLIGHT_NUMPAD) ? backlight_enable_numpad() : backlight_disable_numpad();
44 (level & BACKLIGHT_REAR) ? backlight_enable_rear() : backlight_disable_rear();
45}
46
47void backlight_enable_fn1() {
48 PORTB &= ~(1<<0);
49}
50
51void backlight_disable_fn1() {
52 PORTB |= (1<<0);
53}
54
55void backlight_invert_fn1() {
56 PORTB ^= (1<<0);
57}
58
59void backlight_enable_fn2() {
60 PORTB &= ~(1<<5);
61}
62
63void backlight_disable_fn2() {
64 PORTB |= (1<<5);
65}
66
67void backlight_invert_fn2() {
68 PORTB ^= (1<<5);
69}
70
71void backlight_enable_fn3() {
72 PORTB &= ~(1<<4);
73}
74
75void backlight_disable_fn3() {
76 PORTB |= (1<<4);
77}
78
79void backlight_invert_fn3() {
80 PORTB ^= (1<<4);
81}
82
83void backlight_enable_fn4() {
84 PORTD &= ~(1<<7);
85}
86
87void backlight_disable_fn4() {
88 PORTD |= (1<<7);
89}
90
91void backlight_invert_fn4() {
92 PORTD ^= (1<<7);
93}
94
95void backlight_enable_numpad() {
96 PORTB |= (1<<2);
97}
98
99void backlight_disable_numpad() {
100 PORTB &= ~(1<<2);
101}
102
103void backlight_invert_numpad() {
104 PORTB ^= (1<<2);
105}
106
107void backlight_enable_numlock() {
108 PORTB &= ~(1<<1);
109}
110
111void backlight_disable_numlock() {
112 PORTB |= (1<<1);
113}
114
115void backlight_invert_numlock() {
116 PORTB ^= (1<<1);
117}
118
119void backlight_enable_rear() {
120 PORTD |= (1<<6);
121}
122
123void backlight_disable_rear() {
124 PORTD &= ~(1<<6);
125}
126
127void backlight_invert_rear() {
128 PORTD ^= (1<<6);
129}