knob_v2.h 684 B

12345678910111213141516171819202122232425262728
  1. // Rotary knob implementation - Version 2.
  2. // Uses 2 digital pins - D2 (via interrupt) & D6.
  3. // #include "rev1.h"
  4. #include <avr/io.h>
  5. #include <avr/interrupt.h>
  6. #include <stdbool.h>
  7. #ifndef ENCODER_PIN_1
  8. #define ENCODER_PIN_1 PD2
  9. #endif
  10. #ifndef ENCODER_PIN_2
  11. #define ENCODER_PIN_2 PD6
  12. #endif
  13. #ifndef ENCODER_INT
  14. #define ENCODER_INT INT2_vect
  15. #endif
  16. typedef struct knob_report_t {
  17. int8_t dir; // Contains number of rotations that happened
  18. int8_t phase; // Contains 0 if last rotation happened on 90 degrees, 1 if on 270
  19. } knob_report_t;
  20. void knob_init(void);
  21. knob_report_t knob_report_read(void);
  22. void knob_report_reset(void);
  23. bool knob_prev_a;
  24. int8_t knob_dir;