Soo…some time ago(like maybe 1-2 years?), I saw a video on youtube by the 8-bit guy where he showed how an optical mouse works.

He showed a really old mouse and was able to connect it to an old computer which ran BASIC. The he wrote a progam in BASIC to pixel grab data out of the sensor and display it on screen.

I was really amazed by this, But the image produced was very crude and the frame rate was very slow (more like spf instead of fps).

I use a logitech mouse and have several of them, long time ago my brother gave me his old logitech G402 gaming mouse which had double click issues.

I had fixed that mouse and used it for some time but the issues kept coming came back, so it was disassembled and inspected and thrown into the “nothing electronic is garbage will use it someplace later box”.

Recently I remembered about it and thought why not replicate what the 8-bit guy did but on a relatively newer mouse?

So here we are now!

First part of this project was to identify what specific STM32 MCU it was using and what sensor it was using.

After a bit of digging around in the PCB, I identified that the MCU to be STM32F102 and the sensor was a rebadged PMW3320 called AM010

My colleague shekhar suggested a nice way to reverse engineer the PCB layout as this was a 2 layer board ;)

PCB_TOP

PCB_BACK

I found that the sensor was connected to the MCU over SPI, and SWD pins were exposed at the bottom right as SMD pads, how convenient logitech.

SWD1 SWD2 SWD3

I was able to hook up a stlink v2 clone to the board and launched the ST-link utility and low and behold the firmware was locked(as expected).

LOCKED

Even though the lock bits were set, we could easily trigger a full flash erase to reset them, this also meant that the mouse would be destroyed and no longer will be recoverable (or not if maybe on the internet someone has the original firmware bin).

After that I could flash my own firmware and do some interesting things.

BLINK2

After that I spend some time writing the code to extract the pixels out of the sensor and send them over to my computer for display. This was done by creating custom USB vendor specific endpoints and writing a kernel module over at linux side to read the data out of the mouse.

This data was then displayed over by a GUI application made in SDL2.

Here is the outcome of this ;)

CAPTURE

Here I am reading the text on the back of my IPhone box.

You can grab the code for this project from here:

Github G402_camera