2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
18 extern uint8_t ao_ps2_stdin;
27 ao_ps2_put(uint8_t b);
30 ao_ps2_is_down(uint8_t code);
33 ao_ps2_poll_key(void);
39 ao_ps2_ascii(uint8_t key);
42 _ao_ps2_pollchar(void);
50 /* From http://computer-engineering.org/ps2keyboard/ */
52 /* Device responds with ACK and then resets */
53 #define AO_PS2_RESET 0xff
55 /* Device retransmits last byte */
56 #define AO_PS2_RESEND 0xfe
58 /* Setting key report only works in mode 3 */
60 /* Disable break and typematic for specified mode 3 keys. Terminate with invalid key */
61 #define AO_PS2_SET_KEY_MAKE 0xfd
63 /* Disable typematic for keys */
64 #define AO_PS2_SET_KEY_MAKE_BREAK 0xfc
66 /* Disable break code for keys */
67 #define AO_PS2_SET_KEY_TYPEMATIC 0xfb
69 /* Enable make, break and typematic */
70 #define AO_PS2_SET_KEY_TYPEMATIC_MAKE_BREAK 0xfa
72 /* Disable break and typematic for all */
73 #define AO_PS2_SET_ALL_MAKE 0xf9
75 /* Disable typematic for all */
76 #define AO_PS2_SET_ALL_MAKE_BREAK 0xf8
78 /* Disable break for all */
79 #define AO_PS2_SET_ALL_TYPEMATIC 0xf7
81 /* Set keyboard to default (repeat, report and scan code set 2) */
82 #define AO_PS2_SET_DEFAULT 0xf6
84 /* Disable and reset to default */
85 #define AO_PS2_DISABLE 0xf5
88 #define AO_PS2_ENABLE 0xf4
90 /* Set repeat rate. Bytes 5-6 are the start delay, bits 0-4 are the rate */
91 #define AO_PS2_SET_REPEAT_RATE 0xf3
93 /* Read keyboard id. Returns two bytes */
94 #define AO_PS2_GETID 0xf2
96 /* Set scan code (1, 2, or 3) */
97 #define AO_PS2_SET_SCAN_CODE_SET 0xf0
99 /* Echo. Keyboard replies with Echo */
100 #define AO_PS2_ECHO 0xee
103 #define AO_PS2_SET_LEDS 0xed
104 # define AO_PS2_SET_LEDS_SCROLL 0x01
105 # define AO_PS2_SET_LEDS_NUM 0x02
106 # define AO_PS2_SET_LEDS_CAPS 0x04
108 #define AO_PS2_BREAK 0xf0
109 #define AO_PS2_ACK 0xfa
110 #define AO_PS2_ERROR 0xfc
111 #define AO_PS2_NAK 0xfe
113 /* Scan code set 3 */
115 #define AO_PS2_A 0x1c
116 #define AO_PS2_B 0x32
117 #define AO_PS2_C 0x21
118 #define AO_PS2_D 0x23
119 #define AO_PS2_E 0x24
120 #define AO_PS2_F 0x2b
121 #define AO_PS2_G 0x34
122 #define AO_PS2_H 0x33
123 #define AO_PS2_I 0x43
124 #define AO_PS2_J 0x3b
125 #define AO_PS2_K 0x42
126 #define AO_PS2_L 0x4b
127 #define AO_PS2_M 0x3a
128 #define AO_PS2_N 0x31
129 #define AO_PS2_O 0x44
130 #define AO_PS2_P 0x4d
131 #define AO_PS2_Q 0x15
132 #define AO_PS2_R 0x2d
133 #define AO_PS2_S 0x1b
134 #define AO_PS2_T 0x2c
135 #define AO_PS2_U 0x3c
136 #define AO_PS2_V 0x2a
137 #define AO_PS2_W 0x1d
138 #define AO_PS2_X 0x22
139 #define AO_PS2_Y 0x35
140 #define AO_PS2_Z 0x1a
141 #define AO_PS2_0 0x45
142 #define AO_PS2_1 0x16
143 #define AO_PS2_2 0x1e
144 #define AO_PS2_3 0x26
145 #define AO_PS2_4 0x25
146 #define AO_PS2_5 0x2e
147 #define AO_PS2_6 0x36
148 #define AO_PS2_7 0x3d
149 #define AO_PS2_8 0x3e
150 #define AO_PS2_9 0x46
151 #define AO_PS2_GRAVE 0x0e
152 #define AO_PS2_HYPHEN 0x4e
153 #define AO_PS2_EQUAL 0x55
154 #define AO_PS2_BACKSLASH 0x5c
155 #define AO_PS2_BACKSPACE 0x66
156 #define AO_PS2_SPACE 0x29
157 #define AO_PS2_TAB 0x0d
158 #define AO_PS2_CAPS_LOCK 0x14
159 #define AO_PS2_L_SHIFT 0x12
160 #define AO_PS2_L_CTRL 0x11
161 #define AO_PS2_L_WIN 0x8b
162 #define AO_PS2_L_ALT 0x19
163 #define AO_PS2_R_SHIFT 0x59
164 #define AO_PS2_R_CTRL 0x58
165 #define AO_PS2_R_WIN 0x8c
166 #define AO_PS2_R_ALT 0x39
167 #define AO_PS2_APPS 0x8d
168 #define AO_PS2_ENTER 0x5a
169 #define AO_PS2_ESC 0x08
170 #define AO_PS2_F1 0x07
171 #define AO_PS2_F2 0x0f
172 #define AO_PS2_F3 0x17
173 #define AO_PS2_F4 0x1f
174 #define AO_PS2_F5 0x27
175 #define AO_PS2_F6 0x2f
176 #define AO_PS2_F7 0x37
177 #define AO_PS2_F8 0x3f
178 #define AO_PS2_F9 0x47
179 #define AO_PS2_F10 0x4f
180 #define AO_PS2_F11 0x56
181 #define AO_PS2_F12 0x5e
182 #define AO_PS2_PRNT_SCRN 0x57
183 #define AO_PS2_SCROLL_LOCK 0x5f
184 #define AO_PS2_PAUSE 0x62
185 #define AO_PS2_OPEN_SQ 0x54
186 #define AO_PS2_INSERT 0x67
187 #define AO_PS2_HOME 0x6e
188 #define AO_PS2_PG_UP 0x6f
189 #define AO_PS2_DELETE 0x64
190 #define AO_PS2_END 0x65
191 #define AO_PS2_PG_DN 0x6d
192 #define AO_PS2_UP 0x63
193 #define AO_PS2_LEFT 0x61
194 #define AO_PS2_DOWN 0x60
195 #define AO_PS2_RIGHT 0x6a
196 #define AO_PS2_NUM_LOCK 0x76
197 #define AO_PS2_KP_TIMES 0x7e
198 #define AO_PS2_KP_PLUS 0x7c
199 #define AO_PS2_KP_ENTER 0x79
200 #define AO_PS2_KP_DECIMAL 0x71
201 #define AO_PS2_KP_0 0x70
202 #define AO_PS2_KP_1 0x69
203 #define AO_PS2_KP_2 0x72
204 #define AO_PS2_KP_3 0x7a
205 #define AO_PS2_KP_4 0x6b
206 #define AO_PS2_KP_5 0x73
207 #define AO_PS2_KP_6 0x74
208 #define AO_PS2_KP_7 0x6c
209 #define AO_PS2_KP_8 0x75
210 #define AO_PS2_KP_9 0x7d
211 #define AO_PS2_CLOSE_SQ 0x5b
212 #define AO_PS2_SEMICOLON 0x4c
213 #define AO_PS2_ACUTE 0x52
214 #define AO_PS2_COMMA 0x41
215 #define AO_PS2_PERIOD 0x49
216 #define AO_PS2_SLASH 0x4a
218 #define AO_PS2_RELEASE_FLAG 0x80
220 #endif /* _AO_PS2_H_ */