Shinichiro Nakamura
/
PS2_TestProgram
A test program for PS2 library.
main.cpp@1:e5eac8a97060, 2010-09-13 (annotated)
- Committer:
- shintamainjp
- Date:
- Mon Sep 13 23:00:29 2010 +0000
- Revision:
- 1:e5eac8a97060
- Parent:
- 0:aabf6427c82e
- Child:
- 2:b06d5cea5b11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:aabf6427c82e | 1 | /** |
shintamainjp | 0:aabf6427c82e | 2 | * Test program. |
shintamainjp | 0:aabf6427c82e | 3 | * |
shintamainjp | 0:aabf6427c82e | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:aabf6427c82e | 5 | * http://shinta.main.jp/ |
shintamainjp | 0:aabf6427c82e | 6 | */ |
shintamainjp | 0:aabf6427c82e | 7 | |
shintamainjp | 0:aabf6427c82e | 8 | #include "mbed.h" |
shintamainjp | 1:e5eac8a97060 | 9 | #include "PS2_Reader.h" |
shintamainjp | 1:e5eac8a97060 | 10 | #include "PS2_Writer.h" |
shintamainjp | 0:aabf6427c82e | 11 | |
shintamainjp | 1:e5eac8a97060 | 12 | Ticker tick; |
shintamainjp | 1:e5eac8a97060 | 13 | DigitalOut led(LED1); |
shintamainjp | 1:e5eac8a97060 | 14 | |
shintamainjp | 1:e5eac8a97060 | 15 | void func_tick() { |
shintamainjp | 1:e5eac8a97060 | 16 | led = !led; |
shintamainjp | 1:e5eac8a97060 | 17 | } |
shintamainjp | 0:aabf6427c82e | 18 | |
shintamainjp | 0:aabf6427c82e | 19 | int main() { |
shintamainjp | 1:e5eac8a97060 | 20 | tick.attach_us(&func_tick, 200 * 1000); |
shintamainjp | 1:e5eac8a97060 | 21 | |
shintamainjp | 1:e5eac8a97060 | 22 | { |
shintamainjp | 1:e5eac8a97060 | 23 | PS2_Writer ps2ms_write(p15, p16); |
shintamainjp | 1:e5eac8a97060 | 24 | ps2ms_write.write(0xff); |
shintamainjp | 1:e5eac8a97060 | 25 | ps2ms_write.write(0xff); |
shintamainjp | 1:e5eac8a97060 | 26 | ps2ms_write.write(0xff); |
shintamainjp | 1:e5eac8a97060 | 27 | ps2ms_write.write(0xf3); |
shintamainjp | 1:e5eac8a97060 | 28 | ps2ms_write.write(0xc8); |
shintamainjp | 1:e5eac8a97060 | 29 | ps2ms_write.write(0xf3); |
shintamainjp | 1:e5eac8a97060 | 30 | ps2ms_write.write(0x64); |
shintamainjp | 1:e5eac8a97060 | 31 | ps2ms_write.write(0xf3); |
shintamainjp | 1:e5eac8a97060 | 32 | ps2ms_write.write(0x50); |
shintamainjp | 1:e5eac8a97060 | 33 | ps2ms_write.write(0xf4); |
shintamainjp | 1:e5eac8a97060 | 34 | } |
shintamainjp | 1:e5eac8a97060 | 35 | |
shintamainjp | 1:e5eac8a97060 | 36 | PS2_Reader ps2kb(p11, p12, PS2_Reader::TIMEOUT_US_KEYBOARD); |
shintamainjp | 1:e5eac8a97060 | 37 | PS2_Reader ps2ms(p15, p16, PS2_Reader::TIMEOUT_US_MOUSE); |
shintamainjp | 1:e5eac8a97060 | 38 | |
shintamainjp | 1:e5eac8a97060 | 39 | uint8_t buf[1024]; |
shintamainjp | 1:e5eac8a97060 | 40 | |
shintamainjp | 0:aabf6427c82e | 41 | while (1) { |
shintamainjp | 0:aabf6427c82e | 42 | /* |
shintamainjp | 0:aabf6427c82e | 43 | * Keyboard. |
shintamainjp | 0:aabf6427c82e | 44 | */ |
shintamainjp | 1:e5eac8a97060 | 45 | const int nkb = ps2kb.read(buf, sizeof(buf)); |
shintamainjp | 1:e5eac8a97060 | 46 | if (0 < nkb) { |
shintamainjp | 1:e5eac8a97060 | 47 | printf("KB[%02d]:", nkb); |
shintamainjp | 1:e5eac8a97060 | 48 | for (int i = 0; i < nkb; i++) { |
shintamainjp | 0:aabf6427c82e | 49 | printf("%02X ", buf[i]); |
shintamainjp | 0:aabf6427c82e | 50 | } |
shintamainjp | 0:aabf6427c82e | 51 | printf("\n"); |
shintamainjp | 0:aabf6427c82e | 52 | } |
shintamainjp | 1:e5eac8a97060 | 53 | /* |
shintamainjp | 1:e5eac8a97060 | 54 | * Mouse. |
shintamainjp | 1:e5eac8a97060 | 55 | */ |
shintamainjp | 1:e5eac8a97060 | 56 | const int nms = ps2ms.read(buf, sizeof(buf)); |
shintamainjp | 1:e5eac8a97060 | 57 | if (0 < nms) { |
shintamainjp | 1:e5eac8a97060 | 58 | printf("MS[%02d]:", nms); |
shintamainjp | 1:e5eac8a97060 | 59 | for (int i = 0; i < nms; i++) { |
shintamainjp | 1:e5eac8a97060 | 60 | printf("%02X ", buf[i]); |
shintamainjp | 1:e5eac8a97060 | 61 | } |
shintamainjp | 1:e5eac8a97060 | 62 | printf("\n"); |
shintamainjp | 1:e5eac8a97060 | 63 | } |
shintamainjp | 1:e5eac8a97060 | 64 | wait_ms(20); |
shintamainjp | 0:aabf6427c82e | 65 | } |
shintamainjp | 0:aabf6427c82e | 66 | } |