forked from dacarsoft/DB9_2_Keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps2dev.h
213 lines (205 loc) · 5.08 KB
/
ps2dev.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* ps2dev.h - a library to interface with ps2 hosts. See comments in
* ps2dev.cpp.
* Written by Chris J. Kiick, January 2008.
* modified by Gene E. Scogin, August 2008.
* Release into public domain.
*/
#ifndef ps2dev_h
#define ps2dev_h
#include "Arduino.h"
class PS2dev
{
public:
PS2dev(int clk, int data);
// Enum containing all of the non-special keycodes/scancodes
// (if you can't find the scancode you're looking for here, check the special scancodes)
enum ScanCodes
{
ESCAPE = 0x76,
F1 = 0x05,
F2 = 0x06,
F3 = 0x04,
F4 = 0x0c,
F5 = 0x03,
F6 = 0x0b,
F7 = 0x83,
F8 = 0x0a,
F9 = 0x01,
F10 = 0x09,
F11 = 0x78,
F12 = 0x07,
SCROLL_LOCK = 0x7e,
ACCENT = 0x0e,
ONE = 0x16,
TWO = 0x1e,
THREE = 0x26,
FOUR = 0x25,
FIVE = 0x2e,
SIX = 0x36,
SEVEN = 0x3d,
EIGHT = 0x3e,
NINE = 0x46,
ZERO = 0x45,
MINUS = 0x4e,
EQUAL = 0x55,
BACKSPACE = 0x66,
TAB = 0x0d,
Q = 0x15,
W = 0x1d,
E = 0x24,
R = 0x2d,
T = 0x2c,
Y = 0x35,
U = 0x3c,
I = 0x43,
O = 0x44,
P = 0x4d,
OPEN_BRACKET = 0x54,
CLOSE_BRACKET = 0x5b,
BACKSLASH = 0x5d,
CAPS_LOCK = 0x58,
A = 0x1c,
S = 0x1b,
D = 0x23,
F = 0x2b,
G = 0x34,
H = 0x33,
J = 0x3b,
K = 0x42,
L = 0x4b,
SEMI_COLON = 0x4c,
TICK_MARK = 0x52,
ENTER = 0x5a,
LEFT_SHIFT = 0x12,
Z = 0x1a,
X = 0x22,
C = 0x21,
V = 0x2a,
B = 0x32,
N = 0x31,
M = 0x3a,
COMMA = 0x41,
PERIOD = 0x49,
SLASH = 0x4a,
RIGHT_SHIFT = 0x59,
LEFT_CONTROL = 0x14,
LEFT_ALT = 0x11,
SPACE = 0x29,
NUM_LOCK = 0x77,
ASTERISK = 0x7c,
NUMPAD_MINUS = 0x7b,
NUMPAD_SEVEN = 0x6c,
NUMPAD_EIGHT = 0x75,
NUMPAD_NINE = 0x7d,
PLUS = 0x79,
NUMPAD_FOUR = 0x6b,
NUMPAD_FIVE = 0x73,
NUMPAD_SIX = 0x74,
NUMPAD_ONE = 0x69,
NUMPAD_TWO = 0x72,
NUMPAD_THREE = 0x7a,
NUMPAD_ZERO = 0x70,
DECIMAL = 0x71
};
// Enum containing all of the special keycodes/scancodes
// All press transmissions using these are preceded with 0xE0
// All release transmissions using these are preceded with 0xE0, 0xF0
enum SpecialScanCodes
{
LEFT_WIN = 0x1f,
RIGHT_ALT = 0x11,
RIGHT_WIN = 0x27,
MENUS = 0x2f,
RIGHT_CONTROL = 0x14,
INSERT = 0x70,
HOME = 0x6c,
PAGE_UP = 0x7d,
DELETE = 0x71,
END = 0x69,
PAGE_DOWN = 0x7a,
UP_ARROW = 0x75,
LEFT_ARROW = 0x6b,
DOWN_ARROW = 0x72,
RIGHT_ARROW = 0x74,
DIVIDE = 0x4a,
NUMPAD_ENTER = 0x5a,
NEXT_TRACK = 0x4d,
PREVIOUS_TRACK = 0x15,
STOP = 0x3b,
PLAY_PAUSE = 0x34,
MUTE = 0x23,
VOLUME_UP = 0x32,
VOLUME_DOWN = 0x21,
MEDIA_SELECT = 0x50,
EMAIL = 0x48,
CALCULATOR = 0x2b,
MY_COMPUTER = 0x40,
WWW_SEARCH = 0x10,
WWW_HOME = 0x3a,
WWW_BACK = 0x38,
WWW_FORWARD = 0x30,
WWW_STOP = 0x28,
WWW_REFRESH = 0x20,
WWW_FAVORITES = 0x18,
POWER = 0x5e,
SLEEP = 0x5f,
WAKE = 0x63
};
// Enum containing all of the ESPectrum special keycodes/scancodes
// All press transmissions using these are preceded with 0xE2
// All release transmissions using these are preceded with 0xE2, 0xF0
enum ESPectrumSpecialScanCodes
{
ESP_JOY1LEFT = 0x40,
ESP_JOY1RIGHT = 0x41,
ESP_JOY1UP = 0x42,
ESP_JOY1DOWN = 0x43,
ESP_JOY1START = 0x44,
ESP_JOY1MODE = 0x45,
ESP_JOY1A = 0x46,
ESP_JOY1B = 0x47,
ESP_JOY1C = 0x48,
ESP_JOY1X = 0x49,
ESP_JOY1Y = 0x4a,
ESP_JOY1Z = 0x4b,
ESP_JOY2LEFT = 0x4c,
ESP_JOY2RIGHT = 0x4d,
ESP_JOY2UP = 0x4e,
ESP_JOY2DOWN = 0x4f,
ESP_JOY2START = 0x50,
ESP_JOY2MODE = 0x51,
ESP_JOY2A = 0x52,
ESP_JOY2B = 0x53,
ESP_JOY2C = 0x54,
ESP_JOY2X = 0x55,
ESP_JOY2Y = 0x56,
ESP_JOY2Z = 0x57
};
int write(unsigned char data);
int read(unsigned char * data);
int available();
void keyboard_init();
int keyboard_press(unsigned char code);
int keyboard_release(unsigned char code);
int keyboard_press_special(unsigned char code);
int keyboard_release_special(unsigned char code);
int keyboard_press_ESPectrum_special(unsigned char code);
int keyboard_release_ESPectrum_special(unsigned char code);
int keyboard_press_printscreen();
int keyboard_release_printscreen();
int keyboard_mkbrk_printscreen();
int keyboard_pausebreak();
int keyboard_reply(unsigned char cmd, unsigned char *leds);
int keyboard_handle(unsigned char *leds);
int keyboard_mkbrk(unsigned char code);
int keyboard_special_mkbrk(unsigned char code);
int keyboard_ESPectrum_special_mkbrk(unsigned char code);
private:
int _ps2clk;
int _ps2data;
void golo(int pin);
void gohi(int pin);
void ack();
};
#endif /* ps2dev_h */