Simon Ford / Mbed 2 deprecated keyboard

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PS2Kbd.cpp Source File

PS2Kbd.cpp

00001 #include "PS2Kbd.h"
00002 #include "mbed.h"
00003 
00004 
00005 /* ==================================================================
00006  * Constructor
00007  ================================================================= */
00008 
00009 PS2Kbd::PS2Kbd(PinName clk, PinName din) 
00010     : _ps2clk(clk), _ps2din(din) {
00011    
00012 }    
00013 
00014 // =============================
00015 // 
00016 // =============================
00017 unsigned char PS2Kbd::rd(void)
00018 {
00019     unsigned int buf = 0x00;
00020     int i;
00021     
00022     _ps2clk = 0;
00023 
00024     // both input
00025     _ps2din.input();
00026     _ps2clk.input();
00027 
00028     for(i=0;i<11;i++) {
00029         while(_ps2clk);
00030         while(!_ps2clk);
00031         buf = buf >> 1;
00032         buf |= _ps2din ? 512 : 0;
00033     }
00034 
00035     // output
00036     _ps2clk.output();
00037 
00038     buf &= 0xFF;
00039 
00040     return(ps2KeyMap[(unsigned char)buf]);
00041     //return (unsigned char)buf;
00042 }
00043 
00044 
00045 // =============================
00046 // 
00047 // =============================
00048 void PS2Kbd::wr(unsigned char)
00049 {
00050     unsigned int buf = 0x00;
00051     int i;
00052     
00053     _ps2clk = 0;
00054 
00055     // both input
00056     _ps2din.input();
00057     _ps2clk.input();
00058 
00059     for(i=0;i<11;i++) {
00060         while(_ps2clk);
00061         while(!_ps2clk);
00062         buf = buf >> 1;
00063         buf |= _ps2din ? 512 : 0;
00064     }
00065 
00066     // output
00067     _ps2clk.output();
00068 
00069     buf &= 0xFF;
00070 
00071 }
00072 
00073