logo

qmk_firmware

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

delta.c (2621B)


  1. /* Copyright 2021 Gondolindrim
  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 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 "quantum.h"
  17. // Inits all indicator LEDs as push-pull outputs
  18. void led_init_ports(void) {
  19. palSetLineMode(LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  20. palSetLineMode(LED2_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  21. palSetLineMode(LED3_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  22. palSetLineMode(LED4_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  23. palSetLineMode(LED5_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  24. palSetLineMode(LED6_PIN, PAL_MODE_OUTPUT_PUSHPULL);
  25. }
  26. // This function updates LEDs 1, 2 and 3 according to num, caps and scroll lock states
  27. bool led_update_kb(led_t led_state) {
  28. bool res = led_update_user(led_state);
  29. if(res) {
  30. gpio_write_pin(LED1_PIN, !led_state.num_lock);
  31. gpio_write_pin(LED2_PIN, !led_state.caps_lock);
  32. gpio_write_pin(LED3_PIN, !led_state.scroll_lock);
  33. }
  34. return res;
  35. }
  36. // Turns off all bottom LEDs
  37. void turn_off_bottom_leds(void){
  38. gpio_write_pin(LED4_PIN, 1);
  39. gpio_write_pin(LED5_PIN, 1);
  40. gpio_write_pin(LED6_PIN, 1);
  41. }
  42. /*
  43. 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.
  44. Before updating, however, all bottom LEDs are turned off.
  45. */
  46. layer_state_t layer_state_set_kb(layer_state_t state) {
  47. turn_off_bottom_leds();
  48. switch (get_highest_layer(state)) {
  49. // The base layer, or layer zero, will be handled by the default case.
  50. case 1:
  51. gpio_write_pin(LED4_PIN, 1);
  52. gpio_write_pin(LED5_PIN, 0);
  53. gpio_write_pin(LED6_PIN, 1);
  54. break;
  55. case 2:
  56. gpio_write_pin(LED4_PIN, 1);
  57. gpio_write_pin(LED5_PIN, 1);
  58. gpio_write_pin(LED6_PIN, 0);
  59. break;
  60. default:
  61. gpio_write_pin(LED4_PIN, 0);
  62. gpio_write_pin(LED5_PIN, 1);
  63. gpio_write_pin(LED6_PIN, 1);
  64. break;
  65. }
  66. return state;
  67. }
  68. // Since the keyboard starts at layer 0, the init function starts LED4 as lit up.
  69. void keyboard_post_init_kb(void){
  70. gpio_write_pin(LED4_PIN, 0);
  71. keyboard_post_init_user();
  72. }