![](/media/cache/profiles/1006ff12c465532f8c574aeaa4461b16.50x50_q85.jpg)
A test program for PS2 library.
mylib/PS2/PS2Keyboard.cpp@4:47b51250a168, 2010-10-13 (annotated)
- Committer:
- shintamainjp
- Date:
- Wed Oct 13 10:50:55 2010 +0000
- Revision:
- 4:47b51250a168
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 4:47b51250a168 | 1 | /** |
shintamainjp | 4:47b51250a168 | 2 | * PS/2 keyboard interface control class (Version 0.0.1) |
shintamainjp | 4:47b51250a168 | 3 | * |
shintamainjp | 4:47b51250a168 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 4:47b51250a168 | 5 | * http://shinta.main.jp/ |
shintamainjp | 4:47b51250a168 | 6 | */ |
shintamainjp | 4:47b51250a168 | 7 | #include "PS2Keyboard.h" |
shintamainjp | 4:47b51250a168 | 8 | |
shintamainjp | 4:47b51250a168 | 9 | PS2Keyboard::PS2Keyboard(PinName clk_pin, PinName dat_pin) |
shintamainjp | 4:47b51250a168 | 10 | : ps2kb_init(clk_pin, dat_pin), ps2kb(clk_pin, dat_pin) { |
shintamainjp | 4:47b51250a168 | 11 | } |
shintamainjp | 4:47b51250a168 | 12 | |
shintamainjp | 4:47b51250a168 | 13 | PS2Keyboard::~PS2Keyboard() { |
shintamainjp | 4:47b51250a168 | 14 | } |
shintamainjp | 4:47b51250a168 | 15 | |
shintamainjp | 4:47b51250a168 | 16 | bool PS2Keyboard::processing(keyboard_event_t *p) { |
shintamainjp | 4:47b51250a168 | 17 | bool emit = false; |
shintamainjp | 4:47b51250a168 | 18 | const int c = ps2kb.getc(); |
shintamainjp | 4:47b51250a168 | 19 | if (0 <= c) { |
shintamainjp | 4:47b51250a168 | 20 | scancode[count++] = c; |
shintamainjp | 4:47b51250a168 | 21 | switch (count) { |
shintamainjp | 4:47b51250a168 | 22 | case 1: |
shintamainjp | 4:47b51250a168 | 23 | if ((scancode[0] != 0xE0) |
shintamainjp | 4:47b51250a168 | 24 | && (scancode[0] != 0xE1) |
shintamainjp | 4:47b51250a168 | 25 | && (scancode[0] != 0xF0)) { |
shintamainjp | 4:47b51250a168 | 26 | p->type = KeyMake; |
shintamainjp | 4:47b51250a168 | 27 | p->length = count; |
shintamainjp | 4:47b51250a168 | 28 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 29 | emit = true; |
shintamainjp | 4:47b51250a168 | 30 | count = 0; |
shintamainjp | 4:47b51250a168 | 31 | } |
shintamainjp | 4:47b51250a168 | 32 | break; |
shintamainjp | 4:47b51250a168 | 33 | case 2: |
shintamainjp | 4:47b51250a168 | 34 | if (scancode[0] == 0xF0) { |
shintamainjp | 4:47b51250a168 | 35 | p->type = KeyBreak; |
shintamainjp | 4:47b51250a168 | 36 | p->length = count; |
shintamainjp | 4:47b51250a168 | 37 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 38 | emit = true; |
shintamainjp | 4:47b51250a168 | 39 | count = 0; |
shintamainjp | 4:47b51250a168 | 40 | } |
shintamainjp | 4:47b51250a168 | 41 | if ((scancode[0] == 0xE0) |
shintamainjp | 4:47b51250a168 | 42 | && (scancode[1] != 0xF0) |
shintamainjp | 4:47b51250a168 | 43 | && (scancode[1] != 0x12)) { |
shintamainjp | 4:47b51250a168 | 44 | p->type = KeyMake; |
shintamainjp | 4:47b51250a168 | 45 | p->length = count; |
shintamainjp | 4:47b51250a168 | 46 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 47 | emit = true; |
shintamainjp | 4:47b51250a168 | 48 | count = 0; |
shintamainjp | 4:47b51250a168 | 49 | } |
shintamainjp | 4:47b51250a168 | 50 | break; |
shintamainjp | 4:47b51250a168 | 51 | case 3: |
shintamainjp | 4:47b51250a168 | 52 | if ((scancode[0] == 0xE0) |
shintamainjp | 4:47b51250a168 | 53 | && (scancode[1] == 0xF0) |
shintamainjp | 4:47b51250a168 | 54 | && (scancode[2] != 0x7C)) { |
shintamainjp | 4:47b51250a168 | 55 | p->type = KeyBreak; |
shintamainjp | 4:47b51250a168 | 56 | p->length = count; |
shintamainjp | 4:47b51250a168 | 57 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 58 | emit = true; |
shintamainjp | 4:47b51250a168 | 59 | count = 0; |
shintamainjp | 4:47b51250a168 | 60 | } |
shintamainjp | 4:47b51250a168 | 61 | break; |
shintamainjp | 4:47b51250a168 | 62 | case 4: |
shintamainjp | 4:47b51250a168 | 63 | if ((scancode[0] == 0xE0) |
shintamainjp | 4:47b51250a168 | 64 | && (scancode[1] == 0x12) |
shintamainjp | 4:47b51250a168 | 65 | && (scancode[2] == 0xE0) |
shintamainjp | 4:47b51250a168 | 66 | && (scancode[3] == 0x7C)) { |
shintamainjp | 4:47b51250a168 | 67 | p->type = KeyMake; |
shintamainjp | 4:47b51250a168 | 68 | p->length = count; |
shintamainjp | 4:47b51250a168 | 69 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 70 | emit = true; |
shintamainjp | 4:47b51250a168 | 71 | count = 0; |
shintamainjp | 4:47b51250a168 | 72 | } |
shintamainjp | 4:47b51250a168 | 73 | break; |
shintamainjp | 4:47b51250a168 | 74 | case 5: |
shintamainjp | 4:47b51250a168 | 75 | // Do nothing. |
shintamainjp | 4:47b51250a168 | 76 | break; |
shintamainjp | 4:47b51250a168 | 77 | case 6: |
shintamainjp | 4:47b51250a168 | 78 | if ((scancode[0] == 0xE0) |
shintamainjp | 4:47b51250a168 | 79 | && (scancode[1] == 0xF0) |
shintamainjp | 4:47b51250a168 | 80 | && (scancode[2] == 0x7C) |
shintamainjp | 4:47b51250a168 | 81 | && (scancode[3] == 0xE0) |
shintamainjp | 4:47b51250a168 | 82 | && (scancode[4] == 0xF0) |
shintamainjp | 4:47b51250a168 | 83 | && (scancode[5] == 0x12)) { |
shintamainjp | 4:47b51250a168 | 84 | p->type = KeyBreak; |
shintamainjp | 4:47b51250a168 | 85 | p->length = count; |
shintamainjp | 4:47b51250a168 | 86 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 87 | emit = true; |
shintamainjp | 4:47b51250a168 | 88 | count = 0; |
shintamainjp | 4:47b51250a168 | 89 | } |
shintamainjp | 4:47b51250a168 | 90 | break; |
shintamainjp | 4:47b51250a168 | 91 | case 7: |
shintamainjp | 4:47b51250a168 | 92 | // Do nothing. |
shintamainjp | 4:47b51250a168 | 93 | break; |
shintamainjp | 4:47b51250a168 | 94 | case 8: |
shintamainjp | 4:47b51250a168 | 95 | if ((scancode[0] == 0xE1) |
shintamainjp | 4:47b51250a168 | 96 | && (scancode[1] == 0x14) |
shintamainjp | 4:47b51250a168 | 97 | && (scancode[2] == 0x77) |
shintamainjp | 4:47b51250a168 | 98 | && (scancode[3] == 0xE1) |
shintamainjp | 4:47b51250a168 | 99 | && (scancode[4] == 0xF0) |
shintamainjp | 4:47b51250a168 | 100 | && (scancode[5] == 0x14) |
shintamainjp | 4:47b51250a168 | 101 | && (scancode[6] == 0xF0) |
shintamainjp | 4:47b51250a168 | 102 | && (scancode[7] == 0x77)) { |
shintamainjp | 4:47b51250a168 | 103 | p->type = KeyMake; |
shintamainjp | 4:47b51250a168 | 104 | p->length = count; |
shintamainjp | 4:47b51250a168 | 105 | memcpy(p->scancode, scancode, sizeof(p->scancode)); |
shintamainjp | 4:47b51250a168 | 106 | emit = true; |
shintamainjp | 4:47b51250a168 | 107 | count = 0; |
shintamainjp | 4:47b51250a168 | 108 | } |
shintamainjp | 4:47b51250a168 | 109 | break; |
shintamainjp | 4:47b51250a168 | 110 | default: |
shintamainjp | 4:47b51250a168 | 111 | count = 0; |
shintamainjp | 4:47b51250a168 | 112 | break; |
shintamainjp | 4:47b51250a168 | 113 | } |
shintamainjp | 4:47b51250a168 | 114 | count = count % sizeof(scancode); |
shintamainjp | 4:47b51250a168 | 115 | } |
shintamainjp | 4:47b51250a168 | 116 | return emit; |
shintamainjp | 4:47b51250a168 | 117 | } |