-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathecbutton.h
66 lines (47 loc) · 1.06 KB
/
ecbutton.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef ECBUTTON_H_
#define ECBUTTON_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
struct buttons_debouncing {
uint8_t depressed;
uint8_t previous;
};
struct buttons {
struct buttons_debouncing debounce;
struct {
uint8_t current;
uint8_t previous;
}level;
uint32_t change;
uint32_t tick;
};
struct encoder {
struct buttons A;
struct buttons B;
struct buttons S;
};
enum {
ROTARY_CW = 1,
ROTARY_CCW = 2,
};
enum {
BUTTON_NO_CHANGE = 0,
BUTTON_CHANGE_STATE = 1,
BUTTON_KEEP = 2,
BUTTON_DEPRESSED = 1 << 4,
BUTTON_RELEASED = 1 << 5,
BUTTON_SHORT = 1 << 6,
BUTTON_LONG = 1 << 7,
BUTTON_LONG_LONG = 1 << 8,
};
#define TIME_CONFIG {300, 300, 600, 600, 1000, 1200}
int16_t ecbutton(struct encoder *encoder, const uint8_t A, const uint8_t B, const uint8_t S);
static inline uint8_t ecbutton_switch(struct encoder *encoder){
return encoder->S.debounce.depressed ? BUTTON_DEPRESSED : BUTTON_RELEASED;
}
#ifdef __cplusplus
}
#endif
#endif