1 /* Copyright 2018 Ryota Goto
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.
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.
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/>.
17 #include "split_util.h"
18 #include "transport.h"
21 // Call led_toggle to set LEDs easily
24 // (LEFT) 0 1 2 | 3 4 5 (RIGHT)
26 void led_toggle(int id, bool on) {
95 // Set all LEDs at once using an array of 6 booleans
98 // (LEFT) 0 1 2 | 3 4 5 (RIGHT)
100 // Ex. set_all_leds({ false, false, false, true, true, true }) would turn off left hand, turn on right hand
102 void set_all_leds(bool leds[6]) {
103 for (int i = 0; i < 6; i++) {
104 led_toggle(i, leds[i]);
108 void set_layer_indicators(uint8_t layer) {
114 led_toggle(1, false);
115 led_toggle(2, false);
120 led_toggle(2, false);
128 led_toggle(0, false);
133 led_toggle(0, false);
134 led_toggle(1, false);
139 led_toggle(1, false);
146 void matrix_init_kb(void) {
147 // put your keyboard start-up code here
148 // runs once when the firmware starts up
150 // Initialize indicator LEDs to output
170 set_layer_indicators(0);
175 void matrix_scan_kb(void) {
176 // put your looping keyboard code here
177 // runs every cycle (a lot)
182 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
183 // put your per-action keyboard code here
184 // runs for every action, just before processing by the firmware
186 return process_record_user(keycode, record);
189 void led_set_kb(uint8_t usb_led) {
190 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
192 if (is_keyboard_master()) {
194 serial_m2s_buffer.nlock_led = IS_LED_ON(usb_led, USB_LED_NUM_LOCK);
195 serial_m2s_buffer.clock_led = IS_LED_ON(usb_led, USB_LED_CAPS_LOCK);
196 serial_m2s_buffer.slock_led = IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK);
198 led_toggle(3, IS_LED_ON(usb_led, USB_LED_NUM_LOCK));
199 led_toggle(4, IS_LED_ON(usb_led, USB_LED_CAPS_LOCK));
200 led_toggle(5, IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK));
204 led_set_user(usb_led);
207 uint32_t layer_state_set_kb(uint32_t state) {
209 if (is_keyboard_master())
212 current_layer = biton32(state);
213 serial_m2s_buffer.current_layer = biton32(state);
215 // If left half, do the LED toggle thing
218 set_layer_indicators(biton32(state));
222 // NOTE: Do not set slave LEDs here.
223 // This is not called on slave
225 return layer_state_set_user(state);