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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. CONFIG_MODE = 0,
  22. SWITCH_LAYOUT,
  23. SWITCH_BACKLIGHT
  24. };
  25. enum {
  26. CONFIG_LAYER = 8,
  27. };
  28. // Default
  29. #ifdef KEYMAP_SECTION_ENABLE
  30. const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
  31. #else
  32. const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  33. #endif
  34. [0] = KEYMAP( Z, X, ESC, NO, FN0 ),
  35. [1] = KEYMAP( BTN1,BTN2,ESC, NO, FN0 ),
  36. [2] = KEYMAP( LEFT,RGHT,ESC, NO, FN0 ),
  37. [3] = KEYMAP( UP, DOWN,ESC, NO, FN0 ),
  38. [4] = KEYMAP( PGUP,PGDN,ESC, NO, FN0 ),
  39. [5] = KEYMAP( SPC, ESC, ESC, NO, FN0 ),
  40. [CONFIG_LAYER] = KEYMAP( FN1, FN2, NO, NO, FN0 ),
  41. };
  42. /*
  43. * Fn action definition
  44. */
  45. #ifdef KEYMAP_SECTION_ENABLE
  46. const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = {
  47. #else
  48. const uint16_t fn_actions[] PROGMEM = {
  49. #endif
  50. [0] = ACTION_FUNCTION(CONFIG_MODE),
  51. [1] = ACTION_FUNCTION(SWITCH_LAYOUT),
  52. [2] = ACTION_FUNCTION(SWITCH_BACKLIGHT)
  53. };
  54. #ifdef KEYMAP_IN_EEPROM_ENABLE
  55. uint16_t keys_count(void) {
  56. return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS;
  57. }
  58. uint16_t fn_actions_count(void) {
  59. return sizeof(fn_actions) / sizeof(fn_actions[0]);
  60. }
  61. #endif
  62. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  63. {
  64. static uint8_t config_mode = 0;
  65. static uint8_t layer = 0;
  66. static uint8_t backlight = 0;
  67. switch (id) {
  68. case CONFIG_MODE:
  69. if (record->event.pressed) {
  70. if (config_mode) {
  71. config_mode = 0;
  72. layer_off(CONFIG_LAYER);
  73. }
  74. else {
  75. config_mode = 1;
  76. layer = 0;
  77. backlight = 0;
  78. layer_on(CONFIG_LAYER);
  79. }
  80. }
  81. break;
  82. case SWITCH_LAYOUT:
  83. if (record->event.pressed) {
  84. if (config_mode) {
  85. default_layer_set(1UL<<layer);
  86. eeconfig_write_default_layer(1UL<<layer);
  87. layer = (layer + 1) % 6;
  88. }
  89. }
  90. break;
  91. case SWITCH_BACKLIGHT:
  92. if (record->event.pressed) {
  93. if (config_mode) {
  94. backlight_level(backlight);
  95. backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1);
  96. }
  97. }
  98. break;
  99. }
  100. }