Keyboard firmwares for Atmel AVR and Cortex-M
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.

layer_switch.c 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stdint.h>
  2. #include "keyboard.h"
  3. #include "action.h"
  4. #include "debug.h"
  5. #include "layer_switch.h"
  6. uint16_t layer_switch_stat = 0;
  7. uint16_t layer_switch_stat_get(void)
  8. {
  9. return layer_switch_stat;
  10. }
  11. void layer_switch_stat_set(uint16_t stat)
  12. {
  13. layer_switch_stat = stat;
  14. layer_switch_debug();
  15. }
  16. void layer_switch_clear(void)
  17. {
  18. layer_switch_stat = 0;
  19. layer_switch_debug();
  20. }
  21. void layer_switch_on(uint8_t layer)
  22. {
  23. layer_switch_stat |= (1<<layer);
  24. layer_switch_debug();
  25. }
  26. void layer_switch_off(uint8_t layer)
  27. {
  28. layer_switch_stat &= ~(1<<layer);
  29. layer_switch_debug();
  30. }
  31. void layer_switch_inv(uint8_t layer)
  32. {
  33. layer_switch_stat ^= (1<<layer);
  34. layer_switch_debug();
  35. }
  36. void layer_switch_debug(void)
  37. {
  38. debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n");
  39. }
  40. action_t layer_switch_get_action(key_t key)
  41. {
  42. action_t action;
  43. action.code = ACTION_TRANSPARENT;
  44. /* higher layer first */
  45. for (int8_t i = 15; i >= 0; i--) {
  46. if (layer_switch_stat & (1<<i)) {
  47. action = action_for_key(i, key);
  48. if (action.code != ACTION_TRANSPARENT) {
  49. layer_switch_debug();
  50. debug("layer_switch: used. "); debug_dec(i); debug("\n");
  51. return action;
  52. }
  53. }
  54. }
  55. return action;
  56. }