A version of the PS/2 library customized for MbedConsole. Also includes a few things that make it's behavior easier to control and a few bug fixes.
Fork of PS2 by
Diff: PS2KB.cpp
- Revision:
- 4:fc7f4cc9fbe8
- Parent:
- 1:823c2798e398
- Child:
- 5:ead90ca02b18
--- a/PS2KB.cpp Wed Sep 26 04:12:42 2012 +0000 +++ b/PS2KB.cpp Wed Sep 26 05:21:38 2012 +0000 @@ -6,32 +6,33 @@ */ #include "PS2KB.h" - +#include "nvic.h" /** * Create. * * @param clk_pin Clock pin. * @param dat_pin Data pin. */ -PS2KB::PS2KB(PinName clk_pin, PinName dat_pin) +PS2KB::PS2KB(PinName clk_pin, PinName dat_pin, KeyboardCallback cb) : clk(clk_pin), dat(dat_pin) { init_work(); + callback=cb; clk.fall(this, &PS2KB::func_fall); - timeout = 1; + } /** * Destory. */ PS2KB::~PS2KB() { - wdt.detach(); + //wdt.detach(); } /** * Get a data from a PS/2 device. * * @return A data from a PS/2 device. - */ + * int PS2KB::getc() { tot.reset(); tot.start(); @@ -48,13 +49,15 @@ work.cStart = work.cStart % RINGBUFSIZ; return c; -} + +}*/ /** * Set timeout. * * @param ms Timeout ms. */ + /* void PS2KB::setTimeout(int ms) { timeout = ms; } @@ -62,12 +65,13 @@ void PS2KB::func_timeout(void) { work.bitcnt = 0; } - +*/ void PS2KB::func_fall(void) { + NVIC_SetPriority( EINT3_IRQn, 255 ); int oddpar = 0; /* */ - switch (work.bitcnt) { + switch (bitcnt) { case 0: /* * Start bit. @@ -75,14 +79,14 @@ if (dat.read() != 0) { // printf("Illegal start bit condition.\n"); } - work.bitcnt++; + bitcnt++; break; case 9: /* * Parity bit. */ for (int i = 0; i < 8; i++) { - if ((work.buffer[work.cEnd] & (1 << i)) != 0) { + if ((buffer & (1 << i)) != 0) { oddpar++; } } @@ -92,34 +96,37 @@ if ((oddpar % 2) != 1) { // printf("Data parity error.\n"); } - work.bitcnt++; + bitcnt++; break; case 10: /* * Stop bit. */ - if (dat.read() != 1) { + //if (dat.read() != 1) { // printf("Illegal stop bit condition.\n"); - } - if (work.cStart != ((work.cEnd + 1) % RINGBUFSIZ)) { - work.cEnd++; - work.cEnd = work.cEnd % RINGBUFSIZ; - work.bitcnt = 0; - } else { + //} + //if (work.cStart != ((work.cEnd + 1) % RINGBUFSIZ)) { + //work.cEnd++; + //work.cEnd = work.cEnd % RINGBUFSIZ; + bitcnt = 0; + if(callback!=NULL){ + callback(this, buffer); + } + //} else { // printf("Buffer overrun.\n"); - } + //} break; default: - if ((1 <= work.bitcnt) && (work.bitcnt <= 8)) { + if ((1 <= bitcnt) && (bitcnt <= 8)) { /* * data bit. */ if (dat.read() == 1) { - work.buffer[work.cEnd] |= (1 << (work.bitcnt - 1)); + buffer |= (1 << (bitcnt - 1)); } else { - work.buffer[work.cEnd] &= ~(1 << (work.bitcnt - 1)); + buffer &= ~(1 << (bitcnt - 1)); } - work.bitcnt++; + bitcnt++; } else { /* * Illegal internal state. @@ -129,12 +136,12 @@ } break; } - wdt.detach(); - wdt.attach_us(this, &PS2KB::func_timeout, 250); + //wdt.detach(); + //wdt.attach_us(this, &PS2KB::func_timeout, 250); } void PS2KB::init_work(void) { - work.bitcnt = 0; - work.cStart = 0; - work.cEnd = 0; + bitcnt = 0; + //work.cStart = 0; + //work.cEnd = 0; }