Jack Gassett Posted April 30, 2015 Report Share Posted April 30, 2015 We've had several requests for how to use the keyboard and mouse with the PS/2 connectors on the Papilio DUO's computing shield. Unfortunately I haven't had any time to look into this. I'm 95% sure there are nice Arduino libraries out there to do this with standard GPIO pins. If anyone has the time to locate Arduino libraries for keyboard and mouse functionality and then get them to work with the AVR side and the ZPUino side of the Papilio DUO then that would really help the community out. To help get the ball rolling on this functionality I'm happy to offer a $100 Gadget Factory store credit to the first person who can provide these DesignLab libraries. The $100 credit is for an existing Arduino library working on standard GPIO pins of the AVR and ZPUino. But as a bonus, if someone can provide also provide a DesignLab library that builds on Hamster's HDL code as covered in the following videos, then I would make it a $200 store credit.http://gadgetfactory.net/learn/2015/04/03/designlab-libraries-library-from-internet-code/http://gadgetfactory.net/learn/2015/04/03/designlab-libraries-make-a-wishbone-library/ So, if someone can make a DesignLab library that includes hamster's HDL to scan keyboard codes into the wishbone bus, and then c code to easily read those codes from a sketch then we would double the store credit to $200. Thanks!Jack. Quote Link to comment Share on other sites More sharing options...
alvieboy Posted April 30, 2015 Report Share Posted April 30, 2015 Jack, we have a PS/2 controller from OpenCores, and it's already integrated, so all you need is to interact with it. https://github.com/alvieboy/ZPUino-HDL/tree/work-0200/zpu/hdl/zpuino/contrib/ps2 It's a rather simple controller, easy to interface with. Alvie Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted April 30, 2015 Author Report Share Posted April 30, 2015 Ah, ok. This would be a better Wishbone device to use since it will do both keyboard and mouse. Jack. Quote Link to comment Share on other sites More sharing options...
Filip Posted May 1, 2015 Report Share Posted May 1, 2015 Is this challenge still on? or will there be another? Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted May 1, 2015 Author Report Share Posted May 1, 2015 It's still on! Quote Link to comment Share on other sites More sharing options...
Filip Posted May 3, 2015 Report Share Posted May 3, 2015 Hello Jack, Alvie, today I had some free time, and made (added keyboard functions to a mouse library ) an "Arduino library working on standard GPIO pins of the AVR and ZPUino". BUT since it has to work on all GPIO pins I can't use interrupts and have to use delay ().. I will test it tomorrow and I think it will work, but I really don't thing the usage of delay () here is good. I thought of using the FPGA and for the AVR Bridge (although it uses SPI which is maybe overkill ). What do you think ? Alvie what do you mean by "... it's already integrated" ? In the ZPUno 2.0 which is in Designlab 1.05 ? How can I figure out on which slot it is ?thanks. Filip Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted May 4, 2015 Author Report Share Posted May 4, 2015 Hey Filip, Any luck with the delay approach, its probably ideal to go that direction. It will prevent other libraries from working correctly... it is better to use a timer interrupt which should be independent from any pins. There is a sketch called Timer_Example that shows how to set this up on the ZPUino. For the HDL controller that Alvie is talking about we would need to convert it to DesignLab schematic format before using it. Jack. Quote Link to comment Share on other sites More sharing options...
Filip Posted May 5, 2015 Report Share Posted May 5, 2015 Hello Jack,Lately I have little free time to spend on fun thing, but - with the delay () the mouse is working and if I held down a key on keyboard it gets really "interesting" .. I will implement the HDL controller and test the timer or use the avr bridge. Filip Quote Link to comment Share on other sites More sharing options...
monsonite Posted May 5, 2015 Report Share Posted May 5, 2015 Jack I have used the standard Arduino PS2 library which I found here: http://playground.arduino.cc/ComponentLib/Ps2mouse The link to download the library is http://playground.arduino.cc/uploads/ComponentLib/ps2.zip Please note - that in the header file ps2.h you have to change WProgram.h" with "Arduino.h".I put the mouse into PS2/A and the keyboard into PS2/B You set up the pins with the following lines of code: PS2 mouse(5, 4); //PS2/A Mouse Clock = 5, Data = 4PS2 kbd(39, 41); //PS2/B Keyboard Clock = 39, Data = 41 Here's the simple test sketch #include <ps2.h>#define circuit Computing_Shieldunsigned int x_abs = 32767;unsigned int y_abs = 32767;int delta_x = 0;int delta_y = 0;/* * an arduino sketch to interface with a ps/2 mouse. * Also uses serial protocol to talk back to the host * and report what it finds. *//* * Pin 5 is the mouse data pin, pin 6 is the clock pin * Feel free to use whatever pins are convenient. */PS2 mouse(5, 4);PS2 kbd(39, 41);void kbd_init(){ char ack; kbd.write(0xff); // send reset code ack = kbd.read(); // byte, kbd does self test ack = kbd.read(); // another ack when self test is done}/* * initialize the mouse. Reset it, and place it into remote * mode, so we can get the encoder data on demand. */void mouse_init(){ mouse.write(0xff); // reset mouse.read(); // ack byte mouse.read(); // blank */ mouse.read(); // blank */ mouse.write(0xf0); // remote mode mouse.read(); // ack delayMicroseconds(100);}void setup(){ Serial.begin(115200); mouse_init(); kbd_init(); Serial.println("Starting"); }/* * get a reading from the mouse and report it back to the * host via the serial line. */void loop(){ char mstat; char mx; char my; unsigned char code; /* get a reading from the mouse */ mouse.write(0xeb); // give me data! mouse.read(); // ignore ack mstat = mouse.read(); // left button = 001, right = 010 mx = mouse.read(); my = mouse.read(); if(mx>=0 && mx <= 127) { delta_x = mx; } if(mx>=128 && mx <= 255) { delta_x = -(255 - mx); } if(my>=0 && my <= 127) { delta_y = my; } if(my>=128 && my <= 255) { delta_y = -(255 - my); } x_abs = x_abs +delta_x; y_abs = y_abs +delta_y; Serial.print(mstat, BIN); Serial.print(" "); Serial.print("\tX="); Serial.print(mx, DEC); Serial.print("\tY="); Serial.print(my, DEC); Serial.print("\dX="); Serial.print(delta_x, DEC); Serial.print("\dY="); Serial.print(delta_y, DEC); Serial.print(x_abs, DEC); Serial.print(" "); Serial.print(y_abs, DEC); Serial.println();// code = kbd.read(); // Serial.print(code, HEX); // Serial.print(" ");} My more complicated sketch can be found on github gists here https://gist.github.com/anonymous/892a097bc8bbbbf1c5ca regards Ken 1 Quote Link to comment Share on other sites More sharing options...
Jack Gassett Posted May 6, 2015 Author Report Share Posted May 6, 2015 Excellent! I just tested it out with both the AVR and the ZPUino and it works for both mouse and keyboard. I will be adding this library with the DesignLab 1.0.6 release - hopefully this Friday. Dhia will send you the $100 store credit through a PM. Thank you!Jack. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.