aboutsummaryrefslogtreecommitdiff
path: root/keyboards/duck/jetfire/jetfire.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/duck/jetfire/jetfire.c')
-rw-r--r--keyboards/duck/jetfire/jetfire.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/keyboards/duck/jetfire/jetfire.c b/keyboards/duck/jetfire/jetfire.c
new file mode 100644
index 000000000..9bb02ca22
--- /dev/null
+++ b/keyboards/duck/jetfire/jetfire.c
@@ -0,0 +1,161 @@
1/* Copyright 2018 MechMerlin
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "jetfire.h"
17#include "indicator_leds.h"
18
19enum BACKLIGHT_AREAS {
20 BACKLIGHT_ALPHA = 0b0000001,
21 BACKLIGHT_MOD = 0b0000010,
22 BACKLIGHT_FROW = 0b0000100,
23 BACKLIGHT_NUMBLOCK = 0b0001000,
24 BACKLIGHT_RGB = 0b0010000,
25 BACKLIGHT_SWITCH = 0b0001111
26};
27
28enum StateLed {
29 STATE_LED_SCROLL_LOCK,
30 STATE_LED_CAPS_LOCK,
31 STATE_LED_NUM_LOCK,
32 STATE_LED_LAYER_0,
33 STATE_LED_LAYER_1,
34 STATE_LED_LAYER_2,
35 STATE_LED_LAYER_3,
36 STATE_LED_LAYER_4
37};
38
39uint8_t backlight_rgb_r = 255;
40uint8_t backlight_rgb_g = 0;
41uint8_t backlight_rgb_b = 0;
42uint8_t backlight_state_led = 1<<STATE_LED_LAYER_0;
43
44
45void backlight_toggle_rgb(bool enabled)
46{
47 if(enabled) {
48 uint8_t rgb[RGBLED_NUM][3] = {
49 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
50 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
51 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
52 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
53 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
54 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
55 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
56 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
57 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
58 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
59 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
60 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
61 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
62 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
63 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
64 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
65 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
66 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
67 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
68 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
69 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
70 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
71 {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b}
72 };
73 backlight_set_rgb(rgb);
74 } else {
75 uint8_t rgb[RGBLED_NUM][3] = {
76 {0, 0, 0},
77 {0, 0, 0},
78 {0, 0, 0},
79 {0, 0, 0},
80 {0, 0, 0},
81 {0, 0, 0},
82 {0, 0, 0},
83 {0, 0, 0},
84 {0, 0, 0},
85 {0, 0, 0},
86 {0, 0, 0},
87 {0, 0, 0},
88 {0, 0, 0},
89 {0, 0, 0},
90 {0, 0, 0},
91 {0, 0, 0},
92 {0, 0, 0},
93 {0, 0, 0},
94 {0, 0, 0},
95 {0, 0, 0},
96 {0, 0, 0},
97 {0, 0, 0},
98 {0, 0, 0}
99 };
100 backlight_set_rgb(rgb);
101 }
102}
103
104void backlight_set_rgb(uint8_t cfg[RGBLED_NUM][3])
105{
106 cli();
107 for(uint8_t i = 0; i < RGBLED_NUM; ++i) {
108 send_color(cfg[i][0], cfg[i][1], cfg[i][2], Device_PCBRGB);
109 }
110 sei();
111 show();
112}
113
114
115void backlight_set(uint8_t level)
116{
117 level & BACKLIGHT_ALPHA ? (PORTB |= 0b00000010) : (PORTB &= ~0b00000010);
118 level & BACKLIGHT_MOD ? (PORTB |= 0b00000100) : (PORTB &= ~0b00000100);
119 level & BACKLIGHT_FROW ? (PORTB |= 0b00001000) : (PORTB &= ~0b00001000);
120 level & BACKLIGHT_NUMBLOCK ? (PORTE |= 0b01000000) : (PORTE &= ~0b01000000);
121 backlight_toggle_rgb(level & BACKLIGHT_RGB);
122}
123
124void backlight_update_state()
125{
126 cli();
127 send_color(backlight_state_led & (1<<STATE_LED_SCROLL_LOCK) ? 255 : 0,
128 backlight_state_led & (1<<STATE_LED_CAPS_LOCK) ? 255 : 0,
129 backlight_state_led & (1<<STATE_LED_NUM_LOCK) ? 255 : 0,
130 Device_STATUSLED);
131 send_color(backlight_state_led & (1<<STATE_LED_LAYER_1) ? 255 : 0,
132 backlight_state_led & (1<<STATE_LED_LAYER_2) ? 255 : 0,
133 backlight_state_led & (1<<STATE_LED_LAYER_0) ? 255 : 0,
134 Device_STATUSLED);
135 send_color(backlight_state_led & (1<<STATE_LED_LAYER_4) ? 255 : 0,
136 backlight_state_led & (1<<STATE_LED_LAYER_3) ? 255 : 0,
137 0,
138 Device_STATUSLED);
139 sei();
140 show();
141}
142
143void led_set_kb(uint8_t usb_led)
144{
145 if(usb_led & (1<<USB_LED_CAPS_LOCK)) {
146 backlight_state_led |= 1<<STATE_LED_CAPS_LOCK;
147 } else {
148 backlight_state_led &= ~(1<<STATE_LED_CAPS_LOCK);
149 }
150 if(usb_led & (1<<USB_LED_SCROLL_LOCK)) {
151 backlight_state_led |= 1<<STATE_LED_SCROLL_LOCK;
152 } else {
153 backlight_state_led &= ~(1<<STATE_LED_SCROLL_LOCK);
154 }
155 if(usb_led & (1<<USB_LED_NUM_LOCK)) {
156 backlight_state_led |= 1<<STATE_LED_NUM_LOCK;
157 } else {
158 backlight_state_led &= ~(1<<STATE_LED_NUM_LOCK);
159 }
160 backlight_update_state();
161}