aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/amptrics/0422/0422.c
blob: 4c0ed2e5b80e2ff6c75aba201692281d0fba2ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright 2024 Vinod Chowl (@vchowl)
 *
 * 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.0 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/>.
 */

#include QMK_KEYBOARD_H

#define LED_LAYER_0 B3
#define LED_LAYER_1 B4
#define LED_LAYER_2 B5
#define LED_LAYER_3 B6

#define LED_PINS_COUNT 4

static pin_t pins[LED_PINS_COUNT] = {LED_LAYER_0, LED_LAYER_1, LED_LAYER_2, LED_LAYER_3};

// Function to turn on all LEDs
void turn_on_all_leds(void) {
    for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
        gpio_write_pin_high(pins[i]); // Turn on LED
    }
}

// Function to turn off all LEDs
void turn_off_all_leds(void) {
    for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
        gpio_write_pin_low(pins[i]); // Turn off LED
    }
}

void update_leds_for_layer(uint8_t layer) {
    turn_off_all_leds();
    if (layer < LED_PINS_COUNT) {
        gpio_write_pin_high(pins[layer]);
    }
}

void keyboard_post_init_kb(void) {
    for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
        gpio_set_pin_output(pins[i]);
        gpio_write_pin_low(pins[i]);
    }

    // Blink all LEDs
    turn_on_all_leds();
    wait_ms(500); // Keep LEDs on for 500ms
    turn_off_all_leds();

    update_leds_for_layer(0); // Update LEDs to indicate the default layer
    keyboard_post_init_user();
}

layer_state_t layer_state_set_kb(layer_state_t state) {
    uint8_t layer = get_highest_layer(state);
    update_leds_for_layer(layer);
    return layer_state_set_user(state);
}