Keyboard firmwares for Atmel AVR and Cortex-M
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
10 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <stdint.h>
  2. #include "keyboard.h"
  3. #include "action.h"
  4. #include "util.h"
  5. #include "action_layer.h"
  6. #ifdef DEBUG_ACTION
  7. #include "debug.h"
  8. #else
  9. #include "nodebug.h"
  10. #endif
  11. /*
  12. * Default Layer State
  13. */
  14. uint32_t default_layer_state = 0;
  15. static void default_layer_state_set(uint32_t state)
  16. {
  17. debug("default_layer_state: ");
  18. default_layer_debug(); debug(" to ");
  19. default_layer_state = state;
  20. default_layer_debug(); debug("\n");
  21. clear_keyboard_but_mods(); // To avoid stuck keys
  22. }
  23. void default_layer_debug(void)
  24. {
  25. dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state));
  26. }
  27. void default_layer_set(uint32_t state)
  28. {
  29. default_layer_state_set(state);
  30. }
  31. #ifndef NO_ACTION_LAYER
  32. void default_layer_or(uint32_t state)
  33. {
  34. default_layer_state_set(default_layer_state | state);
  35. }
  36. void default_layer_and(uint32_t state)
  37. {
  38. default_layer_state_set(default_layer_state & state);
  39. }
  40. void default_layer_xor(uint32_t state)
  41. {
  42. default_layer_state_set(default_layer_state ^ state);
  43. }
  44. #endif
  45. #ifndef NO_ACTION_LAYER
  46. /*
  47. * Keymap Layer State
  48. */
  49. uint32_t layer_state = 0;
  50. static void layer_state_set(uint32_t state)
  51. {
  52. dprint("layer_state: ");
  53. layer_debug(); dprint(" to ");
  54. layer_state = state;
  55. layer_debug(); dprintln();
  56. clear_keyboard_but_mods(); // To avoid stuck keys
  57. }
  58. void layer_clear(void)
  59. {
  60. layer_state_set(0);
  61. }
  62. void layer_move(uint8_t layer)
  63. {
  64. layer_state_set(1UL<<layer);
  65. }
  66. void layer_on(uint8_t layer)
  67. {
  68. layer_state_set(layer_state | (1UL<<layer));
  69. }
  70. void layer_off(uint8_t layer)
  71. {
  72. layer_state_set(layer_state & ~(1UL<<layer));
  73. }
  74. void layer_invert(uint8_t layer)
  75. {
  76. layer_state_set(layer_state ^ (1UL<<layer));
  77. }
  78. void layer_or(uint32_t state)
  79. {
  80. layer_state_set(layer_state | state);
  81. }
  82. void layer_and(uint32_t state)
  83. {
  84. layer_state_set(layer_state & state);
  85. }
  86. void layer_xor(uint32_t state)
  87. {
  88. layer_state_set(layer_state ^ state);
  89. }
  90. void layer_debug(void)
  91. {
  92. dprintf("%08lX(%u)", layer_state, biton32(layer_state));
  93. }
  94. #endif
  95. action_t layer_switch_get_action(keypos_t key)
  96. {
  97. action_t action;
  98. action.code = ACTION_TRANSPARENT;
  99. #ifndef NO_ACTION_LAYER
  100. uint32_t layers = layer_state | default_layer_state;
  101. /* check top layer first */
  102. for (int8_t i = 31; i >= 0; i--) {
  103. if (layers & (1UL<<i)) {
  104. action = action_for_key(i, key);
  105. if (action.code != ACTION_TRANSPARENT) {
  106. return action;
  107. }
  108. }
  109. }
  110. /* fall back to layer 0 */
  111. action = action_for_key(0, key);
  112. return action;
  113. #else
  114. action = action_for_key(biton32(default_layer_state), key);
  115. return action;
  116. #endif
  117. }