encoder.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2018 Jack Humbert <jack.humb@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include "quantum.h"
  19. #include "util.h"
  20. void encoder_init(void);
  21. bool encoder_read(void);
  22. bool encoder_update_kb(uint8_t index, bool clockwise);
  23. bool encoder_update_user(uint8_t index, bool clockwise);
  24. #ifdef SPLIT_KEYBOARD
  25. void encoder_state_raw(uint8_t* slave_state);
  26. void encoder_update_raw(uint8_t* slave_state);
  27. # if defined(ENCODERS_PAD_A_RIGHT)
  28. # define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  29. # define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
  30. # else
  31. # define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  32. # define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
  33. # endif
  34. # define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT)
  35. #else // SPLIT_KEYBOARD
  36. # define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  37. # define NUM_ENCODERS_LEFT NUM_ENCODERS
  38. # define NUM_ENCODERS_RIGHT 0
  39. #endif // SPLIT_KEYBOARD
  40. #ifndef NUM_ENCODERS
  41. # define NUM_ENCODERS 0
  42. # define NUM_ENCODERS_LEFT 0
  43. # define NUM_ENCODERS_RIGHT 0
  44. #endif // NUM_ENCODERS
  45. #define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT)
  46. #ifdef ENCODER_MAP_ENABLE
  47. # define ENCODER_CCW_CW(ccw, cw) \
  48. { (cw), (ccw) }
  49. extern const uint16_t encoder_map[][NUM_ENCODERS][2];
  50. #endif // ENCODER_MAP_ENABLE