Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: eee212projectWithSD
Diff: PS2Kbd.cpp
- Revision:
- 0:ea6fa42df9ec
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PS2Kbd.cpp Sat Jun 02 09:31:29 2018 +0000
@@ -0,0 +1,73 @@
+#include "PS2Kbd.h"
+#include "mbed.h"
+
+
+/* ==================================================================
+ * Constructor
+ ================================================================= */
+
+PS2Kbd::PS2Kbd(PinName clk, PinName din)
+ : _ps2clk(clk), _ps2din(din) {
+
+}
+
+// =============================
+//
+// =============================
+unsigned char PS2Kbd::rd(void)
+{
+ unsigned int buf = 0x00;
+ int i;
+
+ _ps2clk = 0;
+
+ // both input
+ _ps2din.input();
+ _ps2clk.input();
+
+ for(i=0;i<11;i++) {
+ while(_ps2clk);
+ while(!_ps2clk);
+ buf = buf >> 1;
+ buf |= _ps2din ? 512 : 0;
+ }
+
+ // output
+ _ps2clk.output();
+
+ buf &= 0xFF;
+
+ return(ps2KeyMap[(unsigned char)buf]);
+ //return (unsigned char)buf;
+}
+
+
+// =============================
+//
+// =============================
+void PS2Kbd::wr(unsigned char)
+{
+ unsigned int buf = 0x00;
+ int i;
+
+ _ps2clk = 0;
+
+ // both input
+ _ps2din.input();
+ _ps2clk.input();
+
+ for(i=0;i<11;i++) {
+ while(_ps2clk);
+ while(!_ps2clk);
+ buf = buf >> 1;
+ buf |= _ps2din ? 512 : 0;
+ }
+
+ // output
+ _ps2clk.output();
+
+ buf &= 0xFF;
+
+}
+
+