c3_pro.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright 2024 @ Keychron (https://www.keychron.com)
  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 "c3_pro.h"
  17. void keyboard_post_init_kb(void) {
  18. gpio_set_pin_output_push_pull(LED_MAC_OS_PIN);
  19. gpio_set_pin_output_push_pull(LED_WIN_OS_PIN);
  20. gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
  21. gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
  22. keyboard_post_init_user();
  23. }
  24. void housekeeping_task_kb(void) {
  25. if (get_highest_layer(default_layer_state) == 0) {
  26. gpio_write_pin(LED_MAC_OS_PIN, LED_OS_PIN_ON_STATE);
  27. gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
  28. }
  29. if (get_highest_layer(default_layer_state) == 2) {
  30. gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
  31. gpio_write_pin(LED_WIN_OS_PIN, LED_OS_PIN_ON_STATE);
  32. }
  33. }
  34. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  35. if (!process_record_user(keycode, record)) {
  36. return false;
  37. }
  38. switch (keycode) {
  39. case KC_OSSW:
  40. if (record->event.pressed) {
  41. // Switches default layer between `MAC_BASE` and `WIN_BASE` (0 and 2)
  42. if (get_highest_layer(default_layer_state) == 2 ) {
  43. set_single_persistent_default_layer(0);
  44. } else {
  45. set_single_persistent_default_layer(2);
  46. }
  47. }
  48. return false;
  49. default:
  50. return true;
  51. }
  52. }
  53. void suspend_power_down_kb(void) {
  54. gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
  55. gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
  56. suspend_power_down_user();
  57. }