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