amptrics/0422 - Prevent OOB in update_leds_for_layer
(#25209)
This commit is contained in:
parent
c26449e64f
commit
3cf328c644
1 changed files with 7 additions and 6 deletions
|
@ -23,30 +23,31 @@
|
||||||
|
|
||||||
#define LED_PINS_COUNT 4
|
#define LED_PINS_COUNT 4
|
||||||
|
|
||||||
pin_t pins[LED_PINS_COUNT] = {LED_LAYER_0, LED_LAYER_1, LED_LAYER_2, LED_LAYER_3};
|
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
|
// Function to turn on all LEDs
|
||||||
void turn_on_all_leds(void) {
|
void turn_on_all_leds(void) {
|
||||||
for (int i = 0; i < LED_PINS_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
|
||||||
gpio_write_pin_high(pins[i]); // Turn on LED
|
gpio_write_pin_high(pins[i]); // Turn on LED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to turn off all LEDs
|
// Function to turn off all LEDs
|
||||||
void turn_off_all_leds(void) {
|
void turn_off_all_leds(void) {
|
||||||
for (int i = 0; i < LED_PINS_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
|
||||||
gpio_write_pin_low(pins[i]); // Turn off LED
|
gpio_write_pin_low(pins[i]); // Turn off LED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_leds_for_layer(uint8_t layer) {
|
void update_leds_for_layer(uint8_t layer) {
|
||||||
turn_off_all_leds();
|
turn_off_all_leds();
|
||||||
gpio_write_pin_high(pins[layer]);
|
if (layer < LED_PINS_COUNT) {
|
||||||
|
gpio_write_pin_high(pins[layer]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyboard_post_init_kb(void) {
|
void keyboard_post_init_kb(void) {
|
||||||
for (int i = 0; i < LED_PINS_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_PINS_COUNT; i++) {
|
||||||
gpio_set_pin_output(pins[i]);
|
gpio_set_pin_output(pins[i]);
|
||||||
gpio_write_pin_low(pins[i]);
|
gpio_write_pin_low(pins[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue