Today I learned how to do port scanning on a keyboard.
what is port scanning you ask?
a keyboard matrix works like this: you have rows and columns. each row is activated (set low) in turn. then each column is read and state is updated. so the firmware will loop over each row and then loop over each column.
when you read a pin you actually can read all the pins on that port at the same time. so if we put all of our columns on the same port (b0, b1, b2, b3, b4…) we can completely eliminate the inner loop and instead just write the port value to the current row in our state matrix.
I have implemented the code is a custom matrix.c and tested it today with great success.
what is the benefit of port scanning? It is more efficient which is important for wireless applications or situations where we want to run more feature code during each scan cycle.