I've been working on a project to reverse engineer a keyboard matrix. This keyboard came from when I used to volunteer for FreeGeek back in college. The controller board was long gone, but the pins were still there, so interfacing with AVR was rather simple. Or so I thought.
After getting all the wires soldered up and debugging for a while, I noticed that one key in particular wouldn't work, the g
key. After throwing my head at this problem for a couple days I had to put the project away to work on other stuff. After 6 months I decided I would try again at this problem.
This week I pulled out the keyboard, all my documentation, and tried to understand the problem again. After about 1 hour I think I understood the problem. There appeared to be a rogue voltage across the g
key diode. This voltage was similar to the voltage across all the other keys in the g
row. I figured that we had a short somewhere and voltage was being pulled in from that. I traced the voltage leak all the way to the MCU pin, PB4
, which is the pin of the column that the g
key was assigned to.
I started looking at the code again and noticed something funny in my code. Previously I had 0xE0
there, which is very wrong. Essentially I am putting d5-d7
as outputs and making d4
and input. Luckly I had the comments there showing what I meant. If I hadn't, I don't know if I would have found the error or not.
I never did figure out why the other keys didn't worked on that column, I didn't care after I got it working.
I'm not a ECE major and don't look at code like this much, so it seems very possible and easy to miss. I'm not entirely sure there is a lesson to learned from this. I could have been more verbose when writing the code, but this is mostly from copypasta than me writing.
While the code does look ugly, they keyboard works. YAY!. Now I just need to clean up this code and build a case for it.