Linux Device Driver displaying what character pressed

Theory:

When a key is pressed, the keyboard sends a

  • start bit(low) 
  • 8 data bits for the scancode
  • odd parity
  • stop bit(high)



Keyboard controller reads the data and performs error checking (parity) and if any error asks for retransmission

What is scan code?

A scan code is a number sent by the keyboard controller once a key has been pressed or released.

E.g. "Enter" has a scan code of 0x1C.

A keyboard generates two scan codes for each key typed on the system, one scan code for press and the other for release.

Release scan code is 128 (80h) plus the press scan code

Code:







Output:




Notes:

1. This driver will not work for USB Keyboard, as there scan codes are different, it works only for the integrated keyboard on the Laptop.
2. kbdus array is for US Keyboard layout.
3. When you press a key, interrupt is generated, the interrupt handler reads the keyboard data register which exists at 0x60, which is the scan code, this scan code is converted to ASCII Character

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto