]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - orphan/nerd/backlight.c
Merge commit '22b6e15a179031afb7c3534cf7b109b0668b602c'
[max/tmk_keyboard.git] / orphan / nerd / 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 #include "led.h"
21
22 void backlight_init_ports()
23 {
24     DDRB |= 0b11100000; // PB7 (switch), PB6 (pcb), PB5 (caps)
25 }
26
27 void led_set(uint8_t usb_led)
28 {
29     (usb_led & (1<<USB_LED_CAPS_LOCK)) ? backlight_caps_enable() : backlight_caps_disable();
30 }
31
32 void backlight_set(uint8_t level)
33 {
34     (level & BACKLIGHT_SWITCH) ? backlight_switch_enable() : backlight_switch_disable();
35     (level & BACKLIGHT_PCB) ? backlight_pcb_enable() : backlight_pcb_disable();
36 }
37
38 void backlight_switch_enable()
39 {
40     PORTB |= 0b10000000;
41 }
42
43 void backlight_switch_disable()
44 {
45     PORTB &= ~0b10000000;
46 }
47
48 void backlight_switch_invert()
49 {
50     PORTB ^= 0b10000000;
51 }
52
53 void backlight_pcb_enable()
54 {
55     PORTB |= 0b01000000;
56 }
57
58 void backlight_pcb_disable()
59 {
60     PORTB &= ~0b01000000;
61 }
62
63 void backlight_pcb_invert()
64 {
65     PORTB ^= 0b01000000;
66 }
67
68 void backlight_caps_enable()
69 {
70     PORTB |= 0b00100000;
71 }
72
73 void backlight_caps_disable()
74 {
75     PORTB &= ~0b00100000;
76 }
77
78 void backlight_caps_invert()
79 {
80     PORTB ^= 0b00100000;
81 }