4 #include <aversive/wait.h>
5 #include <aversive/list.h>
9 LIST_TYPEDEF(fifo_t, char, 32);
10 volatile fifo_t my_fifo;
12 #define SCANCODE_MAX_SIZE 8
14 #define SCANCODE_BREAK 1 /* break code */
15 #define SCANCODE_EXTENDED 2 /* is extended */
16 #define SCANCODE_HAS_NO_BREAK 4 /* no associated break code */
19 uint8_t buf[SCANCODE_MAX_SIZE];
177 #define SCANCODE_EXTENDED_LIST "\x11\x14\x4A\x5A\x69\x6B\x6C\x70\x71\x72\x74\x75\x7A\x7C\x7D"
178 #define SCANCODE_EXTENDED_LIST_SIZE 15
179 #define SCANCODE_EXTENDED_LIST_OFFSET 0x85
182 0, /* 0x0E14 CtrlR */
184 0, /* 0x0E5A Enter */
188 0, /* 0x0E70 Insert */
189 0, /* 0x0E71 Delete */
191 0, /* 0x0E74 Right */
196 0, /* 0x0E7C Ctrl-Prtscr */
203 #define SCANCODE_VAL_PAUSE "\xE1\x14\x77\xE1\xF0\x14\xF0\x77"
204 #define SCANCODE_VAL_PAUSE_SIZE 8
205 #define SCANCODE_VAL_PAUSE_OFFSET 0
207 #define SCANCODE_VAL_PRTSCR_BREAK "\xE0\xF0\x12\xE0\xF0\x7C"
208 #define SCANCODE_VAL_PRTSCR_BREAK_SIZE 6
209 #define SCANCODE_VAL_PRTSCR_BREAK_OFFSET 1
211 #define SCANCODE_VAL_CTRL_PAUSE "\xE0\x7E\xE0\xF0\x7E"
212 #define SCANCODE_VAL_CTRL_PAUSE_SIZE 5
213 #define SCANCODE_VAL_CTRL_PAUSE_OFFSET 2
215 #define SCANCODE_VAL_SHIFT_SLASH "\xE0\xF0\x12\xE0\x4A"
216 #define SCANCODE_VAL_SHIFT_SLASH_SIZE 5
217 #define SCANCODE_VAL_SHIFT_SLASH_OFFSET 3
219 #define SCANCODE_VAL_SHIFT_SLASH_BREAK "\xE0\xF0\x4A\xE0\x12"
220 #define SCANCODE_VAL_SHIFT_SLASH_BREAK_SIZE 5
221 #define SCANCODE_VAL_SHIFT_SLASH_BREAK_OFFSET 3
223 #define SCANCODE_VAL_PRTSCR "\xE0\x12\xE0\x7C"
224 #define SCANCODE_VAL_PRTSCR_SIZE 4
225 #define SCANCODE_VAL_PRTSCR_OFFSET 1
228 0, /* E11477E1F014F077 PAUSE */
229 0, /* E012E07C PRTSCR */
230 0, /* E07EE0F07E CTRL_PAUSE */
231 0, /* E0F012E04A SHIFT_SLASH */
235 char * scancode_extended_list = SCANCODE_EXTENDED_LIST;
240 int8_t get_scancode(struct scancode *s)
245 s->size = LIST_TO_ARRAY(my_fifo, s->buf, SCANCODE_MAX_SIZE);
246 printf("%d\n", s->size);
251 /* special case for 'pause' */
252 if (s->size >= SCANCODE_VAL_PAUSE_SIZE &&
253 !memcmp(SCANCODE_VAL_PAUSE, s->buf, SCANCODE_VAL_PAUSE_SIZE)) {
254 s->flags |= (SCANCODE_EXTENDED | SCANCODE_HAS_NO_BREAK);
255 s->size = SCANCODE_VAL_PAUSE_SIZE;
256 s->idx = SCANCODE_EXTENDED_LIST_OFFSET + SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_PAUSE_OFFSET;
262 if (s->buf[0] == 0xE0 && s->size >= 2) {
263 s->flags |= SCANCODE_EXTENDED;
265 /* special case for 'prtscr break' */
266 if (s->size >= SCANCODE_VAL_PRTSCR_BREAK_SIZE &&
267 !memcmp(SCANCODE_VAL_PRTSCR_BREAK, s->buf, SCANCODE_VAL_PRTSCR_BREAK_SIZE)) {
268 s->flags |= SCANCODE_BREAK;
269 s->size = SCANCODE_VAL_PRTSCR_BREAK_SIZE;
270 s->idx = SCANCODE_EXTENDED_LIST_OFFSET + SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_PRTSCR_BREAK_OFFSET;
274 /* special case for 'ctrl_pause' */
275 if (s->size >= SCANCODE_VAL_CTRL_PAUSE_SIZE &&
276 !memcmp(SCANCODE_VAL_CTRL_PAUSE, s->buf, SCANCODE_VAL_CTRL_PAUSE_SIZE)) {
277 s->flags |= SCANCODE_HAS_NO_BREAK;
278 s->size = SCANCODE_VAL_CTRL_PAUSE_SIZE;
279 s->idx = SCANCODE_EXTENDED_LIST_OFFSET + SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_CTRL_PAUSE_OFFSET;
283 /* special case for 'shift_slash' */
284 if (s->size >= SCANCODE_VAL_SHIFT_SLASH_SIZE &&
285 !memcmp(SCANCODE_VAL_SHIFT_SLASH, s->buf, SCANCODE_VAL_SHIFT_SLASH_SIZE)) {
286 s->size = SCANCODE_VAL_SHIFT_SLASH_SIZE;
287 s->idx = SCANCODE_EXTENDED_LIST_OFFSET + SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_SHIFT_SLASH_OFFSET;
291 /* special case for 'shift_slash_break' */
292 if (s->size >= SCANCODE_VAL_SHIFT_SLASH_BREAK_SIZE &&
293 !memcmp(SCANCODE_VAL_SHIFT_SLASH_BREAK, s->buf, SCANCODE_VAL_SHIFT_SLASH_BREAK_SIZE)) {
294 s->flags |= SCANCODE_BREAK;
295 s->size = SCANCODE_VAL_SHIFT_SLASH_BREAK_SIZE;
296 s->idx = SCANCODE_EXTENDED_LIST_OFFSET + SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_SHIFT_SLASH_BREAK_OFFSET;
300 /* special case for 'prtscr' */
301 if (s->size >= SCANCODE_VAL_PRTSCR_SIZE &&
302 !memcmp(SCANCODE_VAL_PRTSCR, s->buf, SCANCODE_VAL_PRTSCR_SIZE)) {
303 s->size = SCANCODE_VAL_PRTSCR_SIZE;
304 s->idx = SCANCODE_EXTENDED_LIST_OFFSET +SCANCODE_EXTENDED_LIST_SIZE + SCANCODE_VAL_PRTSCR_OFFSET;
308 /* break for extended codes */
309 if (s->size >= 3 && s->buf[1] == 0xF0) {
310 s->flags |= SCANCODE_BREAK;
312 p = strchr(scancode_extended_list, s->buf[2]);
315 s->idx = (p - scancode_extended_list) + SCANCODE_EXTENDED_LIST_OFFSET;
319 /* ext scancode, 2 bytes */
321 p = strchr(scancode_extended_list, s->buf[2]);
324 s->idx = (p - scancode_extended_list) + SCANCODE_EXTENDED_LIST_OFFSET;
328 /* break scancode (2 bytes) */
329 if (s->buf[0] == 0xF0) {
330 s->flags |= SCANCODE_BREAK;
333 if (s->idx >= SCANCODE_EXTENDED_LIST_OFFSET)
338 /* simple scancode, 1 byte */
340 if (s->idx >= SCANCODE_EXTENDED_LIST_OFFSET)
347 void print_scancode(struct scancode *s)
351 for (i=0 ; i<s->size ; i++)
352 printf("%.2x ", s->buf[i]);
353 printf("] '%c' ", tab[s->idx]);
354 if (s->flags & SCANCODE_BREAK)
356 if (s->flags & SCANCODE_EXTENDED)
358 if (s->flags & SCANCODE_HAS_NO_BREAK)
359 printf("HAS_NO_BREAK ");
360 printf("idx=%d\r\n", s->idx);
368 LIST_INIT(my_fifo, 0);
370 LIST_PUSH_END(my_fifo, 0x35);
371 LIST_PUSH_END(my_fifo, 0xF0);
372 LIST_PUSH_END(my_fifo, 0x35);
374 LIST_PUSH_END(my_fifo, 0xE1);
375 LIST_PUSH_END(my_fifo, 0x14);
376 LIST_PUSH_END(my_fifo, 0x77);
377 LIST_PUSH_END(my_fifo, 0xE1);
378 LIST_PUSH_END(my_fifo, 0xF0);
379 LIST_PUSH_END(my_fifo, 0x14);
380 LIST_PUSH_END(my_fifo, 0xF0);
381 LIST_PUSH_END(my_fifo, 0x77);
383 LIST_PUSH_END(my_fifo, 0xE0);
384 LIST_PUSH_END(my_fifo, 0xF0);
385 LIST_PUSH_END(my_fifo, 0x12);
386 LIST_PUSH_END(my_fifo, 0xE0);
387 LIST_PUSH_END(my_fifo, 0x4A);
389 LIST_PUSH_END(my_fifo, 0xE0);
390 LIST_PUSH_END(my_fifo, 0xF0);
391 LIST_PUSH_END(my_fifo, 0x11);
395 while(get_scancode(&s) >= 0) {
398 LIST_PULL_START(my_fifo, &c);