diff options
Diffstat (limited to 'keyboards/ai03/orbit/orbit.c')
-rw-r--r-- | keyboards/ai03/orbit/orbit.c | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/keyboards/ai03/orbit/orbit.c b/keyboards/ai03/orbit/orbit.c new file mode 100644 index 000000000..97553e318 --- /dev/null +++ b/keyboards/ai03/orbit/orbit.c | |||
@@ -0,0 +1,210 @@ | |||
1 | /* Copyright 2018 Ryota Goto | ||
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 "orbit.h" | ||
17 | #include "split_util.h" | ||
18 | #include "transport.h" | ||
19 | |||
20 | |||
21 | // Call led_toggle to set LEDs easily | ||
22 | // LED IDs: | ||
23 | // | ||
24 | // (LEFT) 0 1 2 | 3 4 5 (RIGHT) | ||
25 | |||
26 | void led_toggle(int id, bool on) { | ||
27 | |||
28 | if (isLeftHand) { | ||
29 | switch(id) { | ||
30 | case 0: | ||
31 | // Left hand C6 | ||
32 | if (on) | ||
33 | //PORTC |= (1<<6); | ||
34 | writePinHigh(C6); | ||
35 | else | ||
36 | //PORTC &= ~(1<<6); | ||
37 | writePinLow(C6); | ||
38 | break; | ||
39 | case 1: | ||
40 | // Left hand B6 | ||
41 | if (on) | ||
42 | //PORTB |= (1<<6); | ||
43 | writePinHigh(B6); | ||
44 | else | ||
45 | //PORTB &= ~(1<<6); | ||
46 | writePinLow(B6); | ||
47 | break; | ||
48 | case 2: | ||
49 | // Left hand B5 | ||
50 | if (on) | ||
51 | //PORTB |= (1<<5); | ||
52 | writePinHigh(B5); | ||
53 | else | ||
54 | //PORTB &= ~(1<<5); | ||
55 | writePinLow(B5); | ||
56 | break; | ||
57 | default: | ||
58 | break; | ||
59 | } | ||
60 | } else { | ||
61 | switch(id) { | ||
62 | case 3: | ||
63 | // Right hand F6 | ||
64 | if (on) | ||
65 | //PORTF |= (1<<6); | ||
66 | writePinHigh(F6); | ||
67 | else | ||
68 | //PORTF &= ~(1<<6); | ||
69 | writePinLow(F6); | ||
70 | break; | ||
71 | case 4: | ||
72 | // Right hand F7 | ||
73 | if (on) | ||
74 | //PORTF |= (1<<7); | ||
75 | writePinHigh(F7); | ||
76 | else | ||
77 | //PORTF &= ~(1<<7); | ||
78 | writePinLow(F7); | ||
79 | break; | ||
80 | case 5: | ||
81 | // Right hand C7 | ||
82 | if (on) | ||
83 | //PORTC |= (1<<7); | ||
84 | writePinHigh(C7); | ||
85 | else | ||
86 | //PORTC &= ~(1<<7); | ||
87 | writePinLow(C7); | ||
88 | break; | ||
89 | default: | ||
90 | break; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | // Set all LEDs at once using an array of 6 booleans | ||
96 | // LED IDs: | ||
97 | // | ||
98 | // (LEFT) 0 1 2 | 3 4 5 (RIGHT) | ||
99 | // | ||
100 | // Ex. set_all_leds({ false, false, false, true, true, true }) would turn off left hand, turn on right hand | ||
101 | |||
102 | void set_all_leds(bool leds[6]) { | ||
103 | for (int i = 0; i < 6; i++) { | ||
104 | led_toggle(i, leds[i]); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | void set_layer_indicators(uint8_t layer) { | ||
109 | |||
110 | switch (layer) | ||
111 | { | ||
112 | case 0: | ||
113 | led_toggle(0, true); | ||
114 | led_toggle(1, false); | ||
115 | led_toggle(2, false); | ||
116 | break; | ||
117 | case 1: | ||
118 | led_toggle(0, true); | ||
119 | led_toggle(1, true); | ||
120 | led_toggle(2, false); | ||
121 | break; | ||
122 | case 2: | ||
123 | led_toggle(0, true); | ||
124 | led_toggle(1, true); | ||
125 | led_toggle(2, true); | ||
126 | break; | ||
127 | case 3: | ||
128 | led_toggle(0, false); | ||
129 | led_toggle(1, true); | ||
130 | led_toggle(2, true); | ||
131 | break; | ||
132 | case 4: | ||
133 | led_toggle(0, false); | ||
134 | led_toggle(1, false); | ||
135 | led_toggle(2, true); | ||
136 | break; | ||
137 | default: | ||
138 | led_toggle(0, true); | ||
139 | led_toggle(1, false); | ||
140 | led_toggle(2, true); | ||
141 | break; | ||
142 | } | ||
143 | |||
144 | } | ||
145 | |||
146 | void matrix_init_kb(void) { | ||
147 | // put your keyboard start-up code here | ||
148 | // runs once when the firmware starts up | ||
149 | |||
150 | // Initialize indicator LEDs to output | ||
151 | if (isLeftHand) | ||
152 | { | ||
153 | setPinOutput(C6); | ||
154 | setPinOutput(B6); | ||
155 | setPinOutput(B5); | ||
156 | //DDRC |= (1<<6); | ||
157 | //DDRB |= (1<<6); | ||
158 | //DDRB |= (1<<5); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | setPinOutput(F6); | ||
163 | setPinOutput(F7); | ||
164 | setPinOutput(C7); | ||
165 | //DDRF |= (1<<6); | ||
166 | //DDRF |= (1<<7); | ||
167 | //DDRC |= (1<<7); | ||
168 | } | ||
169 | |||
170 | set_layer_indicators(0); | ||
171 | |||
172 | matrix_init_user(); | ||
173 | } | ||
174 | |||
175 | void led_set_kb(uint8_t usb_led) { | ||
176 | // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here | ||
177 | |||
178 | if (is_keyboard_master()) { | ||
179 | |||
180 | serial_m2s_buffer.nlock_led = IS_LED_ON(usb_led, USB_LED_NUM_LOCK); | ||
181 | serial_m2s_buffer.clock_led = IS_LED_ON(usb_led, USB_LED_CAPS_LOCK); | ||
182 | serial_m2s_buffer.slock_led = IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK); | ||
183 | |||
184 | led_toggle(3, IS_LED_ON(usb_led, USB_LED_NUM_LOCK)); | ||
185 | led_toggle(4, IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)); | ||
186 | led_toggle(5, IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)); | ||
187 | |||
188 | } | ||
189 | |||
190 | led_set_user(usb_led); | ||
191 | } | ||
192 | |||
193 | uint32_t layer_state_set_kb(uint32_t state) { | ||
194 | |||
195 | if (is_keyboard_master()) | ||
196 | { | ||
197 | serial_m2s_buffer.current_layer = biton32(state); | ||
198 | |||
199 | // If left half, do the LED toggle thing | ||
200 | if (isLeftHand) | ||
201 | { | ||
202 | set_layer_indicators(biton32(state)); | ||
203 | } | ||
204 | |||
205 | } | ||
206 | // NOTE: Do not set slave LEDs here. | ||
207 | // This is not called on slave | ||
208 | |||
209 | return layer_state_set_user(state); | ||
210 | } | ||