2022-01-29 06:19:11 +06:00
|
|
|
/* Copyright 2021 Gondolindrim
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-04-15 17:08:15 +06:00
|
|
|
#include "quantum.h"
|
2022-01-29 06:19:11 +06:00
|
|
|
|
|
|
|
// Inits all indicator LEDs as push-pull outputs
|
|
|
|
void led_init_ports(void) {
|
|
|
|
palSetLineMode(LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
palSetLineMode(LED2_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
palSetLineMode(LED3_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
palSetLineMode(LED4_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
palSetLineMode(LED5_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
palSetLineMode(LED6_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function updates LEDs 1, 2 and 3 according to num, caps and scroll lock states
|
|
|
|
bool led_update_kb(led_t led_state) {
|
|
|
|
bool res = led_update_user(led_state);
|
|
|
|
if(res) {
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED1_PIN, !led_state.num_lock);
|
|
|
|
gpio_write_pin(LED2_PIN, !led_state.caps_lock);
|
|
|
|
gpio_write_pin(LED3_PIN, !led_state.scroll_lock);
|
2022-01-29 06:19:11 +06:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turns off all bottom LEDs
|
|
|
|
void turn_off_bottom_leds(void){
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED4_PIN, 1);
|
|
|
|
gpio_write_pin(LED5_PIN, 1);
|
|
|
|
gpio_write_pin(LED6_PIN, 1);
|
2022-01-29 06:19:11 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Here the bottom LEDs get updated. The idea being that LED4 is lit when the default layer is active, LED5 when layer 1 is active and LED6 when layer 2.
|
|
|
|
Before updating, however, all bottom LEDs are turned off.
|
|
|
|
*/
|
|
|
|
layer_state_t layer_state_set_kb(layer_state_t state) {
|
|
|
|
turn_off_bottom_leds();
|
|
|
|
switch (get_highest_layer(state)) {
|
|
|
|
// The base layer, or layer zero, will be handled by the default case.
|
|
|
|
case 1:
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED4_PIN, 1);
|
|
|
|
gpio_write_pin(LED5_PIN, 0);
|
|
|
|
gpio_write_pin(LED6_PIN, 1);
|
2022-01-29 06:19:11 +06:00
|
|
|
break;
|
|
|
|
case 2:
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED4_PIN, 1);
|
|
|
|
gpio_write_pin(LED5_PIN, 1);
|
|
|
|
gpio_write_pin(LED6_PIN, 0);
|
2022-01-29 06:19:11 +06:00
|
|
|
break;
|
|
|
|
default:
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED4_PIN, 0);
|
|
|
|
gpio_write_pin(LED5_PIN, 1);
|
|
|
|
gpio_write_pin(LED6_PIN, 1);
|
2022-01-29 06:19:11 +06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the keyboard starts at layer 0, the init function starts LED4 as lit up.
|
|
|
|
void keyboard_post_init_kb(void){
|
2024-05-03 11:21:29 +06:00
|
|
|
gpio_write_pin(LED4_PIN, 0);
|
2024-07-11 16:03:11 +06:00
|
|
|
|
|
|
|
keyboard_post_init_user();
|
2022-01-29 06:19:11 +06:00
|
|
|
}
|