I've dug up an old Arduino project (quoted here) of mine and ported it for the Spark Core.
It provides a basic, interrupt driven framework to talk to PS/2 devices (keyboard, mouse, ...).
For the topic above there is a PS/2 mouse example of how to talk to such a mouse.
Dedicated device classes (e.g. PS2Mouse, PS2Keyboard, PS2Scanner, ...) could be built on top of this.
In connection with the firmware/feature/usb-hid-support branch this would be a way to place the Core as a "man-in-the-middle" that could do both: pass through the devices data (a lot of USB devices still support PS/2 communication as legacy feature) and also remote control a PC via mouse/keyboard input via the cloud.
Please let me know if you find any issues with it or if there was any call for one of the above classes.
I’ve found some little bugs in connection with mouse button 4 & 5 in the sample and fixed them.
fix for buttons causing scroll wheel readings to add 64/128 steps per reading
fix for swapped buttons 4 & 5
PS2Mouse demo app starts with WiFi off. Cloud connect with 3+ button mouse press left/middle/right buttons together.
Some more debug info and some cleanup
Added application.cpp as local build demo for the use of core-firmware/feature/usb-hid-support together with PS/2 mouse. If anybody would be interested in testing the USB HID Mouse/Keyboard feature with or without PS/2 mouse support, I could provide a prebuilt bin.
@ScruffR I’ve started using your PS/2 Communication library in my code and it’s been great so far! I have a Photon hooked up to a PS/2 keyboard and have been using the keyboard as an input for the Photon. I’ve been running into an issue though: Normally when I power on my Photon, and consequently, the keyboard, the keyboard will power up and send the bytes FA and AA. All key presses after this properly map to the right values. However, sometimes, when I just reset the Photon instead of power it all the way off and back on, the keyboard will send the F4 followed by [. All the keys after these two bytes are shifted, but not shifted linearly within the scan codes. Do you have any insights?
So I tried adding a manual PS2->reset() as part of the main loop, with the condition that if the time elapsed since Photon reset was greater than 2 seconds and the device had only returned F4 and [, that it would reset, which I logged with Particle.publish on the dashboard. I saw the keyboard try to reset a few times, but it kept returning F4 instead of FA. Is is possible to extend the 10 ms delay in reset()? Alternatively, I might just power the PS2 keyboard with a spare digital pin and hard reset the keyboard whenever the Photon resets.
And directly include the .h/.cpp files in your project.
This way you can experiment with different times.
You’d need to change the include statement in your project from #include PS2Communication/PS2Communication.h" to only #include "PS2Communication.h".