PS2 Library

Dependents:   Pong Brickbreaker

Committer:
wjohnsto
Date:
Sun Feb 27 23:34:31 2011 +0000
Revision:
0:ce15490e89e9

        

Who changed what in which revision?

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