keymap.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright 2017 REPLACE_WITH_YOUR_NAME
  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 "woodpad.h"
  17. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  18. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  19. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  20. // entirely and just use numbers.
  21. #define _NUMLOCK 0
  22. #define _NAV 1
  23. #define _ALT 2
  24. #define _ADJUST 3
  25. // Fillers to make layering more clear
  26. #define _______ KC_TRNS
  27. #define XXXXXXX KC_NO
  28. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  29. [_NUMLOCK] = KEYMAP( /* Base */
  30. KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS,\
  31. KC_P7, KC_P8, KC_P9, KC_PPLS, \
  32. KC_P4, KC_P5, KC_P6, KC_PEQL, \
  33. KC_P1, KC_P2, KC_P3, KC_COMM, \
  34. KC_LALT, KC_P0, KC_PDOT, KC_PENT \
  35. ),
  36. [_NAV] = KEYMAP( /* Base */
  37. _______, _______, _______, _______,\
  38. KC_HOME, KC_UP, KC_PGUP, _______, \
  39. KC_LEFT, XXXXXXX, KC_RIGHT, _______, \
  40. KC_END, KC_DOWN, KC_PGDN, _______, \
  41. _______, KC_INS, KC_DEL, _______ \
  42. ),
  43. [_ALT] = KEYMAP( /* Base */
  44. _______, KC_MUTE, KC_VOLD, KC_VOLU,\
  45. _______, _______, _______, _______, \
  46. _______, _______, _______, _______, \
  47. _______, _______, _______, _______, \
  48. _______, _______, _______, _______ \
  49. ),
  50. [_ADJUST] = KEYMAP( /* Base */
  51. _______, KC_A, _______, RESET,\
  52. _______, _______, _______, _______, \
  53. _______, _______, _______, _______, \
  54. _______, _______, _______, _______, \
  55. _______, _______, _______, _______ \
  56. ),
  57. };
  58. const uint16_t PROGMEM fn_actions[] = {
  59. };
  60. void numlock_led_on(void) {
  61. PORTF |= (1<<7);
  62. }
  63. void numlock_led_off(void) {
  64. PORTF &= ~(1<<7);
  65. }
  66. static bool numlock_down = false;
  67. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  68. switch (keycode) {
  69. case KC_NLCK:
  70. if (record->event.pressed) {
  71. numlock_down = true;
  72. if (IS_LAYER_ON(_ALT)) {
  73. layer_on(_ADJUST);
  74. }
  75. } else{
  76. if(!IS_LAYER_ON(_ADJUST)) {
  77. if (!IS_LAYER_ON(_NAV)){
  78. numlock_led_off();
  79. layer_on(_NAV);
  80. } else {
  81. numlock_led_on();
  82. layer_off(_NAV);
  83. }
  84. } else {
  85. layer_off(_ADJUST);
  86. }
  87. numlock_down = false;
  88. }
  89. return false;
  90. break;
  91. case KC_LALT:
  92. if (record->event.pressed) {
  93. if (numlock_down) {
  94. layer_on(_ADJUST);
  95. } else {
  96. layer_on(_ALT);
  97. }
  98. } else {
  99. if(IS_LAYER_ON(_ADJUST)) {
  100. layer_off(_ADJUST);
  101. } else {
  102. layer_off(_ALT);
  103. }
  104. }
  105. // Allow normal processing of ALT?
  106. return false;
  107. break;
  108. }
  109. return true;
  110. }
  111. void matrix_init_user(void) {
  112. // set Numlock LED to output and low
  113. DDRF |= (1<<7);
  114. PORTF &= ~(1<<7);
  115. }
  116. void matrix_scan_user(void) {
  117. }
  118. void led_set_user(uint8_t usb_led) {
  119. }