Keyboard interfacing | Cypress Semiconductor
Interfacing a keyboard consists mainly of two parts.
1) Getting the key code for a valid key press.
2) Encapsulating the key code obtained into the standard keyboard HID descriptor format and transmitting it through USB.
1. Getting the keycode for a valid key press.
The method used to find a key-press was by driving low individual rows and then reading the columns to see if a key is pressed. The firmware is written to detect only one key-press at a time and neglect multiple key presses in the same row.When any key is pressed or released, due to mechanical structure of the switch, the contacts may make/break connection multiple times. Because of this, switching waveform is obtained at the row/column line as shown below.
If the CPU is reading the ports at higher rate, this may wrongly be detected as multiple switch press. To eliminate this problem, a fixed delay is given when a key-press is first detected and the ports are read again at the end of this delay. This delay ensures that signal at the port pins are stable during CPU read operation. Using oscilloscope, the typical bounce duration was found to be 130us to 200us.A de-bounce delay of 2ms is given to ensure multiple presses aren’t registered.
Next is the issue of typematic delay. When a key is held pressed for a duration longer than a certain time , it should be considered as a continuous press and the firmware should be written to send successive instances of the same key press. The normal key-tap duration for a human being was found out to lie between 180ms to 350ms.The typematic delay is taken to be 400ms.The flow chart depicting this logic is given below.