logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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