Keyboard interfacing

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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.

   

0 Likes
3 Replies
Anonymous
Not applicable

2. Encapsulating the key code obtained into the standard keyboard HID descriptor format and transmitting it through USB

   

For  a device to be recognized as a USB HID device it should conform to a standard USB descriptor format . A HID class device communicates with the HID class driver using either the Control (default) pipe or an Interrupt pipe.

       


   

 

   

Control pipe required during enumeration of USB device uses Endpoint 0 for communication whose configuration is taken care by creator.Endpoint 1 and Endpoint 2 (for this case) are used for IN and OUT transfer of data(relative to host/PC) in Interrupt pipe,which is used once the device is enumerated.Its configuration in PSoC creator is shown below.

   

   

   

              

   

   

The following represents a Report descriptor for a boot interface for a keyboard.USB component in Creator was configured accordingly.

   

   

              

   

Once a valid key press was registed ,it was encapsulated according to the above report descriptor  and sent through USB.

   

 

   

   

 

   

The code segment shown above can be used for single keypress detection.By modifing the code its possible to implement multiple key press detection.

0 Likes
Anonymous
Not applicable

2. Encapsulating the key code obtained into the standard keyboard HID descriptor format and transmitting it through USB

   

For  a device to be recognized as a USB HID device it should conform to a standard USB descriptor format . A HID class device communicates with the HID class driver using either the Control (default) pipe or an Interrupt pipe.

   

                    

   

              

   

Control pipe required during enumeration of USB device uses Endpoint 0 for communication whose configuration is taken care by creator.Endpoint 1 and Endpoint 2 (for this case) are used for IN and OUT transfer of data(relative to host/PC) in Interrupt pipe,which is used once the device is enumerated.Its configuration is shown below.

   

   

   

              

   

The following represents a Report descriptor for a boot interface for a keyboard and the USB component in Creator was configured accordingly

   

   

              

   

Once a valid key press was registed ,it was encapsulated according to the above report descriptor  and sent through USB.

   

 

   

   

The above codesegment successfully implements a single keypress detection. It can be further improved to detect multiple key press.

0 Likes
Anonymous
Not applicable

Hi Spectrum,

   

I am trying to build such keypad.

   

Is there example code for encapsulating the key code obtained into the standard keyboard HID descriptor format and transmitting it through USB.

   

Regards,

   

Pushkar.

0 Likes