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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keymap_default.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright 2014 Kai Ryu <[email protected]>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/pgmspace.h>
  15. #include "keycode.h"
  16. #include "action_layer.h"
  17. #include "eeconfig.h"
  18. #include "backlight.h"
  19. #include "keymap_common.h"
  20. enum function_id {
  21. TOUCH_PROXIMITY = 0,
  22. CONFIG_MODE,
  23. SWITCH_LAYOUT,
  24. SWITCH_BACKLIGHT
  25. };
  26. // Default
  27. #ifdef KEYMAP_SECTION_ENABLE
  28. const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
  29. #else
  30. const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  31. #endif
  32. [0] = KEYMAP( Z, X, ESC ),
  33. [1] = KEYMAP( BTN1,BTN2,ESC ),
  34. [2] = KEYMAP( LEFT,RGHT,ESC ),
  35. [3] = KEYMAP( UP, DOWN,ESC ),
  36. [4] = KEYMAP( PGUP,PGDN,ESC ),
  37. [5] = KEYMAP( SPC, ESC, ESC ),
  38. [CONFIG_LAYER] = KEYMAP( FN30, FN31, NO )
  39. };
  40. /*
  41. * Fn action definition
  42. */
  43. #ifdef KEYMAP_SECTION_ENABLE
  44. const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = {
  45. #else
  46. const uint16_t fn_actions[] PROGMEM = {
  47. #endif
  48. [28] = ACTION_FUNCTION(TOUCH_PROXIMITY),
  49. [29] = ACTION_FUNCTION(CONFIG_MODE),
  50. [30] = ACTION_FUNCTION(SWITCH_LAYOUT),
  51. [31] = ACTION_FUNCTION(SWITCH_BACKLIGHT)
  52. };
  53. #ifdef KEYMAP_IN_EEPROM_ENABLE
  54. uint16_t keys_count(void) {
  55. return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS;
  56. }
  57. uint16_t fn_actions_count(void) {
  58. return sizeof(fn_actions) / sizeof(fn_actions[0]);
  59. }
  60. #endif
  61. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  62. {
  63. static uint8_t config_mode = 0;
  64. static uint8_t layer = 0;
  65. static uint8_t backlight = 0;
  66. switch (id) {
  67. case CONFIG_MODE:
  68. if (record->event.pressed) {
  69. if (config_mode) {
  70. config_mode = 0;
  71. layer_off(CONFIG_LAYER);
  72. }
  73. else {
  74. config_mode = 1;
  75. layer = 0;
  76. backlight = 0;
  77. layer_on(CONFIG_LAYER);
  78. }
  79. }
  80. break;
  81. case SWITCH_LAYOUT:
  82. if (record->event.pressed) {
  83. if (config_mode) {
  84. default_layer_set(1UL<<layer);
  85. eeconfig_write_default_layer(1UL<<layer);
  86. layer = (layer + 1) % (last_layer() + 1);
  87. }
  88. }
  89. break;
  90. case SWITCH_BACKLIGHT:
  91. if (record->event.pressed) {
  92. if (config_mode) {
  93. backlight_level(backlight);
  94. backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1);
  95. }
  96. }
  97. break;
  98. }
  99. }