rev1.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * ----------------------------------------------------------------------------
  3. * "THE BEER-WARE LICENSE" (Revision 42):
  4. * <https://github.com/Legonut> wrote this file. As long as you retain this
  5. * notice you can do whatever you want with this stuff. If we meet some day, and
  6. * you think this stuff is worth it, you can buy me a beer in return. David Rauseo
  7. * ----------------------------------------------------------------------------
  8. */
  9. #include "rev1.h"
  10. #include "touch_encoder.h"
  11. #include "common_oled.h"
  12. #include "transactions.h"
  13. #define NUMBER_OF_TOUCH_ENCODERS 2
  14. #define TOUCH_ENCODER_OPTIONS TOUCH_SEGMENTS + 2
  15. typedef struct PACKED {
  16. uint8_t r;
  17. uint8_t c;
  18. } encodermap_t;
  19. const encodermap_t touch_encoder_map[NUMBER_OF_TOUCH_ENCODERS][TOUCH_ENCODER_OPTIONS] =
  20. {
  21. { { 6, 0 }, { 6, 1 }, { 6, 2 }, { 6, 3 }, { 6, 4 } }, // Touch Encoder 1 matrix entries
  22. { { 13, 0 }, { 13, 1 }, { 13, 2 }, { 13, 3 }, { 13, 4 } } // Touch Encoder 2 matrix entries
  23. };
  24. static void process_encoder_matrix(encodermap_t pos) {
  25. action_exec(MAKE_KEYEVENT(pos.r, pos.c, true));
  26. #if TAP_CODE_DELAY > 0
  27. wait_ms(TAP_CODE_DELAY);
  28. #endif
  29. action_exec(MAKE_KEYEVENT(pos.r, pos.c, false));
  30. }
  31. bool touch_encoder_tapped_kb(uint8_t index, uint8_t section) {
  32. if (!touch_encoder_tapped_user(index, section))
  33. return false;
  34. process_encoder_matrix(touch_encoder_map[index][section + 2]);
  35. return false;
  36. }
  37. void keyboard_post_init_kb(void) {
  38. touch_encoder_init();
  39. transaction_register_rpc(TOUCH_ENCODER_SYNC, touch_encoder_slave_sync);
  40. transaction_register_rpc(RGB_MENU_SYNC, rgb_menu_slave_sync);
  41. keyboard_post_init_user();
  42. }
  43. void housekeeping_task_kb(void) {
  44. touch_encoder_update(TOUCH_ENCODER_SYNC);
  45. rgb_menu_update(RGB_MENU_SYNC);
  46. }