-
Notifications
You must be signed in to change notification settings - Fork 2
/
ps2_keyboard.h
66 lines (49 loc) · 1.04 KB
/
ps2_keyboard.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
64
65
66
/*
* author : Shuichi TAKANO
* since : Sat Aug 31 2019 13:44:26
*/
#ifndef _5CAA7E2C_3134_1656_CD1F_159BFFE0628E
#define _5CAA7E2C_3134_1656_CD1F_159BFFE0628E
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
int isPS2KeyboardPushed(int code, int e0);
#ifdef __cplusplus
}
#include <gpiohs.h>
class PS2Keyboard
{
public:
void init(int clkPin, int clkGPIOHS,
int datPin, int datGPIOHS,
int prio);
void start();
inline bool isPushed(int code, bool e0) const
{
return pushed_[(code + (e0 ? 256 : 0)) >> 5] & (1 << (code & 31));
}
static PS2Keyboard &instance();
protected:
void callback();
private:
bool enabled_ = false;
uint8_t clkGPIO_;
uint8_t datGPIO_;
int prio_;
uint32_t buffer_;
int counter_;
int parity_;
bool f0_;
bool e0_;
uint32_t pushed_[512 / 32]{}; // normal + nullock
enum class State
{
RECEIVING,
SENDING,
};
State state_;
};
#endif
#endif /* _5CAA7E2C_3134_1656_CD1F_159BFFE0628E */