You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.8 KiB

  1. /* Copyright 2021 kuenhlee, Don Kjer, Tyler Tidman
  2. * Copyright 2021 Simon Arlott
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "k320.h"
  18. #include <ch.h>
  19. #include <hal.h>
  20. /* Private Functions */
  21. void off_all_leds(void) {
  22. #ifdef LED_NUM_LOCK_PIN
  23. gpio_write_pin_high(LED_NUM_LOCK_PIN);
  24. #endif
  25. gpio_write_pin_high(LED_CAPS_LOCK_PIN);
  26. gpio_write_pin_high(LED_SCROLL_LOCK_PIN);
  27. gpio_write_pin_high(LED_WIN_LOCK_PIN);
  28. gpio_write_pin_high(LED_MR_LOCK_PIN);
  29. }
  30. void on_all_leds(void) {
  31. #ifdef LED_NUM_LOCK_PIN
  32. gpio_write_pin_low(LED_NUM_LOCK_PIN);
  33. #endif
  34. gpio_write_pin_low(LED_CAPS_LOCK_PIN);
  35. gpio_write_pin_low(LED_SCROLL_LOCK_PIN);
  36. gpio_write_pin_low(LED_WIN_LOCK_PIN);
  37. gpio_write_pin_low(LED_MR_LOCK_PIN);
  38. }
  39. /* WinLock and MR LEDs are non-standard. Need to override led init */
  40. void led_init_ports(void) {
  41. #ifdef LED_NUM_LOCK_PIN
  42. gpio_set_pin_output(LED_NUM_LOCK_PIN);
  43. #endif
  44. gpio_set_pin_output(LED_CAPS_LOCK_PIN);
  45. gpio_set_pin_output(LED_SCROLL_LOCK_PIN);
  46. gpio_set_pin_output(LED_WIN_LOCK_PIN);
  47. gpio_set_pin_output(LED_MR_LOCK_PIN);
  48. off_all_leds();
  49. }
  50. #ifndef WINLOCK_DISABLED
  51. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  52. switch (keycode) {
  53. case GUI_TOG:
  54. if (record->event.pressed) {
  55. // Toggle LED on key press
  56. gpio_toggle_pin(LED_WIN_LOCK_PIN);
  57. }
  58. break;
  59. }
  60. return process_record_user(keycode, record);
  61. }
  62. #endif /* WINLOCK_DISABLED */
  63. #ifndef HW_RESET_PIN_DISABLED
  64. static void hardware_reset_cb(void *arg) {
  65. chSysLockFromISR();
  66. bootloader_jump();
  67. chSysUnlockFromISR();
  68. }
  69. #endif
  70. void keyboard_pre_init_kb(void) {
  71. setPinInputHigh(HARDWARE_RESET_PIN);
  72. #ifndef HW_RESET_PIN_DISABLED
  73. /* Jump to bootloader when the hardware reset button is pressed */
  74. palEnablePadEvent(PAL_PORT(HARDWARE_RESET_PIN), PAL_PAD(HARDWARE_RESET_PIN), PAL_EVENT_MODE_FALLING_EDGE);
  75. palSetPadCallback(PAL_PORT(HARDWARE_RESET_PIN), PAL_PAD(HARDWARE_RESET_PIN), hardware_reset_cb, NULL);
  76. /* The interrupt is edge-triggered so check that it's not already pressed */
  77. if (!gpio_read_pin(HARDWARE_RESET_PIN)) {
  78. bootloader_jump();
  79. }
  80. #endif
  81. }