![]()
For reasons I won’t go into (future projects) I needed a PS/2 Mouse driver. That is, I didn’t want to make a mouse, but read input from a mouse. There didn’t seem to be much on the net about this. Lots of code for emulating a mouse, and links to the same PS/2 Protocol guide.
So I started to write, from scratch the PS/2 Protocol and mouse control for the PIC. I wrote the entire thing in notepad from scratch with no compiler :p Only 8 typos and one code mistake. When I took the program and compiled it (after fixing that one mistake) it worked almost first time.
The PIC resets the mouse connected to the PS/2 Port, puts it into remote (only sends data when you request it instead of streaming) and requests data bytes on movement and buttons.
The PS/2 protocol is actualy quite simple, it was quite easy to write in C, with only a little mis-interperetation of the protocol causing that one mistake (I read the start bit twice, dont ask). The next step is to add in the extended protocols for things like the Microsoft mouse, scroll wheels etc.
The code runs on an 18f2520 (smt) and outputs diagnostic and mouse data over its serial port. This will be the basis of the next 2 projects 🙂
Example output,
PIC Init [OK]
Mouse Init [OK]
Set Remote Mode [OK]
Check Mouse Status[OK]
Scaling [1:1]
Mode [Remote]
Streaming [OFF]
Showing Mouse Data,
X= -4 Y= 3 Z= 9 L=1 M=0 R=0 Right – Up
I Hooked this up to my widget for graphical output and made it draw a simple line from where the pixel was to where you move the mouse, a sort of mouse controlled etch’a’sketch if you will. It looks quite cool. Left button clears the screen and right button shuts it all down.
There is a new video of the device using a Synaptics touchpad in absolute position mode. In this mode the pixel is plotted at the exact position of your finger as reported by the touchpad, rather than ‘moving’ it with direction packets from the mouse. This means you can lift your finger, and draw a line from anywhere to anyhwere without them being joined etch’a’sketch style.