1
0

encoder.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <stdint.h>
  19. #include <stdbool.h>
  20. #include "gpio.h"
  21. #include "util.h"
  22. void encoder_init(void);
  23. bool encoder_read(void);
  24. bool encoder_update_kb(uint8_t index, bool clockwise);
  25. bool encoder_update_user(uint8_t index, bool clockwise);
  26. #ifdef SPLIT_KEYBOARD
  27. void encoder_state_raw(uint8_t* slave_state);
  28. void encoder_update_raw(uint8_t* slave_state);
  29. # if defined(ENCODERS_PAD_A_RIGHT)
  30. # define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  31. # define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
  32. # else
  33. # define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  34. # define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
  35. # endif
  36. # define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT)
  37. #else // SPLIT_KEYBOARD
  38. # define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
  39. # define NUM_ENCODERS_LEFT NUM_ENCODERS
  40. # define NUM_ENCODERS_RIGHT 0
  41. #endif // SPLIT_KEYBOARD
  42. #ifndef NUM_ENCODERS
  43. # define NUM_ENCODERS 0
  44. # define NUM_ENCODERS_LEFT 0
  45. # define NUM_ENCODERS_RIGHT 0
  46. #endif // NUM_ENCODERS
  47. #define NUM_ENCODERS_MAX_PER_SIDE MAX(NUM_ENCODERS_LEFT, NUM_ENCODERS_RIGHT)
  48. #ifdef ENCODER_MAP_ENABLE
  49. # define NUM_DIRECTIONS 2
  50. # define ENCODER_CCW_CW(ccw, cw) \
  51. { (cw), (ccw) }
  52. extern const uint16_t encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS];
  53. #endif // ENCODER_MAP_ENABLE