qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

0422.c (2008B)


      1 /* Copyright 2024 Vinod Chowl (@vchowl)
      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.0 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 
     17 #include QMK_KEYBOARD_H
     18 
     19 #define LED_LAYER_0 B3
     20 #define LED_LAYER_1 B4
     21 #define LED_LAYER_2 B5
     22 #define LED_LAYER_3 B6
     23 
     24 #define LED_PINS_COUNT 4
     25 
     26 static pin_t pins[LED_PINS_COUNT] = {LED_LAYER_0, LED_LAYER_1, LED_LAYER_2, LED_LAYER_3};
     27 
     28 // Function to turn on all LEDs
     29 void turn_on_all_leds(void) {
     30     for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
     31         gpio_write_pin_high(pins[i]); // Turn on LED
     32     }
     33 }
     34 
     35 // Function to turn off all LEDs
     36 void turn_off_all_leds(void) {
     37     for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
     38         gpio_write_pin_low(pins[i]); // Turn off LED
     39     }
     40 }
     41 
     42 void update_leds_for_layer(uint8_t layer) {
     43     turn_off_all_leds();
     44     if (layer < LED_PINS_COUNT) {
     45         gpio_write_pin_high(pins[layer]);
     46     }
     47 }
     48 
     49 void keyboard_post_init_kb(void) {
     50     for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
     51         gpio_set_pin_output(pins[i]);
     52         gpio_write_pin_low(pins[i]);
     53     }
     54 
     55     // Blink all LEDs
     56     turn_on_all_leds();
     57     wait_ms(500); // Keep LEDs on for 500ms
     58     turn_off_all_leds();
     59 
     60     update_leds_for_layer(0); // Update LEDs to indicate the default layer
     61     keyboard_post_init_user();
     62 }
     63 
     64 layer_state_t layer_state_set_kb(layer_state_t state) {
     65     uint8_t layer = get_highest_layer(state);
     66     update_leds_for_layer(layer);
     67     return layer_state_set_user(state);
     68 }