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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. uint8_t config_mode = 0;
  62. static uint8_t layer = 0;
  63. static uint8_t backlight = 0;
  64. static uint8_t layer_modified = 0;
  65. static uint8_t backlight_modified = 0;
  66. extern backlight_config_t backlight_config;
  67. void enter_config_mode(void);
  68. void exit_config_mode(void);
  69. void switch_layout(void);
  70. void switch_backlight(void);
  71. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  72. {
  73. switch (id) {
  74. case CONFIG_MODE:
  75. if (record->event.pressed) {
  76. if (config_mode) {
  77. exit_config_mode();
  78. }
  79. else {
  80. enter_config_mode();
  81. }
  82. }
  83. break;
  84. case SWITCH_LAYOUT:
  85. if (record->event.pressed) {
  86. if (config_mode) {
  87. switch_layout();
  88. }
  89. }
  90. break;
  91. case SWITCH_BACKLIGHT:
  92. if (record->event.pressed) {
  93. if (config_mode) {
  94. switch_backlight();
  95. }
  96. }
  97. break;
  98. }
  99. }
  100. void enter_config_mode(void)
  101. {
  102. config_mode = 1;
  103. layer_modified = 0;
  104. backlight_modified = 0;
  105. backlight = backlight_config.level;
  106. backlight_level(8);
  107. layer_on(CONFIG_LAYER);
  108. }
  109. void exit_config_mode(void)
  110. {
  111. config_mode = 0;
  112. backlight_level(backlight);
  113. layer_off(CONFIG_LAYER);
  114. if (layer_modified) {
  115. default_layer_set(1UL<<layer);
  116. eeconfig_write_default_layer(1UL<<layer);
  117. }
  118. }
  119. void switch_layout(void)
  120. {
  121. if (!layer_modified) {
  122. layer = 0;
  123. layer_modified = 1;
  124. }
  125. else {
  126. layer = (layer + 1) % (last_layer() + 1);
  127. }
  128. softpwm_led_set(0, 32 * (layer + 1));
  129. }
  130. void switch_backlight(void)
  131. {
  132. if (!backlight_modified) {
  133. backlight = 0;
  134. backlight_modified = 1;
  135. }
  136. else {
  137. backlight = (backlight + 1) % (BACKLIGHT_LEVELS);
  138. }
  139. softpwm_led_set(1, 32 * (backlight + 1));
  140. }