2
0

keymap.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. void numlock_led_on(void) {
  59. PORTF |= (1<<7);
  60. }
  61. void numlock_led_off(void) {
  62. PORTF &= ~(1<<7);
  63. }
  64. static bool numlock_down = false;
  65. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  66. switch (keycode) {
  67. case KC_NLCK:
  68. if (record->event.pressed) {
  69. numlock_down = true;
  70. if (IS_LAYER_ON(_ALT)) {
  71. layer_on(_ADJUST);
  72. }
  73. } else{
  74. if(!IS_LAYER_ON(_ADJUST)) {
  75. if (!IS_LAYER_ON(_NAV)){
  76. numlock_led_off();
  77. layer_on(_NAV);
  78. } else {
  79. numlock_led_on();
  80. layer_off(_NAV);
  81. }
  82. } else {
  83. layer_off(_ADJUST);
  84. }
  85. numlock_down = false;
  86. }
  87. return false;
  88. break;
  89. case KC_LALT:
  90. if (record->event.pressed) {
  91. if (numlock_down) {
  92. layer_on(_ADJUST);
  93. } else {
  94. layer_on(_ALT);
  95. }
  96. } else {
  97. if(IS_LAYER_ON(_ADJUST)) {
  98. layer_off(_ADJUST);
  99. } else {
  100. layer_off(_ALT);
  101. }
  102. }
  103. // Allow normal processing of ALT?
  104. return false;
  105. break;
  106. }
  107. return true;
  108. }
  109. void matrix_init_user(void) {
  110. // set Numlock LED to output and low
  111. DDRF |= (1<<7);
  112. PORTF &= ~(1<<7);
  113. }
  114. void matrix_scan_user(void) {
  115. }
  116. void led_set_user(uint8_t usb_led) {
  117. }