Author: Liu Xuhui Raymond reprinted. Please indicate the source
The keypad here is not a portable keyboard on a PC, but a non-portable keyboard that is common in embedded devices. Common keypad connection methods include matrix scanning and direct gpio detection. In terms of detection methods, you can use gpio scanning to perform detection. Some CPUs integrate the scanning circuit logic to perform automatic detection. Some key-value values of certain key-bits have fixed errors.
In most cases, the read value of some key bits is a constant error value. For example, the value should be 0x20 in theory, and the read value should be 0 or 0x420, sometimes the correct key value can be read at the moment of release. Different boards are basically the same keys. Some keys will never cause read errors.
I started to think it was a technical problem with the keyboard. Poor contact led to crosstalk between some intersections. But I found that all the problematic buttons were on the same scan line, in addition, the keys of all the rows to be scanned are incorrect. As a result, the keys in the same column of the next row are superimposed. The analysis shows that during keyboard drive scanning, the scanning level between adjacent rows changes too fast. due to factors such as capacitance in the hardware, the scanning level is not stable when reading the key value, the key value is incorrectly read. The main contradiction is that the chip selection and clock signal of the SPI port of the CPU used cannot be independently controlled from the data cable.
In terms of hardware, it is necessary to minimize the additional capacitance on the scanning line. In terms of software, it can increase the delay time between changing the line scan voltage and reading registers, waiting for the completion of the charging and discharging process. Only one key is pressed, but multiple key values are read.
After a key is pressed, multiple key values can be detected simultaneously.
This problem is actually another manifestation of the previous problem. Due to the interference in the charging and discharging process, the array scanning process may be misjudged.
Same as above. Some key-value drivers have been detected, but Upper-layer applications cannot read them.
After pressing some keys, you can see that the key value has been detected in the driver, but the upper-layer application did not read the corresponding value from the device node.
This problem is usually caused by incorrect settings of the input_dev-> keybit mask of the keyboard event in the input subsystem. If the mask of the corresponding key value is not set, the input subsystem discards the corresponding event, the application is not distributed to the upper layer.
Correctly set the mask bit for each button