k320.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2021 kuenhlee and Don Kjer
  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 "k320.h"
  17. /* Private Functions */
  18. void off_all_leds(void) {
  19. writePinHigh(LED_CAPS_LOCK_PIN);
  20. writePinHigh(LED_SCROLL_LOCK_PIN);
  21. writePinHigh(LED_WIN_LOCK_PIN);
  22. writePinHigh(LED_MR_LOCK_PIN);
  23. }
  24. void on_all_leds(void) {
  25. writePinLow(LED_CAPS_LOCK_PIN);
  26. writePinLow(LED_SCROLL_LOCK_PIN);
  27. writePinLow(LED_WIN_LOCK_PIN);
  28. writePinLow(LED_MR_LOCK_PIN);
  29. }
  30. /* WinLock and MR LEDs are non-standard. Need to override led init */
  31. void led_init_ports(void) {
  32. setPinOutput(LED_CAPS_LOCK_PIN);
  33. setPinOutput(LED_SCROLL_LOCK_PIN);
  34. setPinOutput(LED_WIN_LOCK_PIN);
  35. setPinOutput(LED_MR_LOCK_PIN);
  36. off_all_leds();
  37. }
  38. #ifndef WINLOCK_DISABLED
  39. static bool win_key_locked = false;
  40. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  41. switch (keycode) {
  42. case KC_TGUI:
  43. if (record->event.pressed) {
  44. // Toggle GUI lock on key press
  45. win_key_locked = !win_key_locked;
  46. writePin(LED_WIN_LOCK_PIN, !win_key_locked);
  47. }
  48. break;
  49. case KC_LGUI:
  50. if (win_key_locked) { return false; }
  51. break;
  52. }
  53. return process_record_user(keycode, record);
  54. }
  55. #endif /* WINLOCK_DISABLED */