Cloud6410 keypad Driver (lower)

Source: Internet
Author: User

Cloud6410 keypad Driver (lower)

1.1 key interrupt handling process

1.1.1 process of Button Scan

In the initial state, all the columns (outputs) are in the low level. When no buttons are pressed, all the rows (inputs) are in the high level (with the pull-up function ). When any key is pressed, the corresponding rows and columns are connected together, and the corresponding rows are driven to a low level, resulting in a keyboard interruption. Then, the CPU (software) writes a low level to a column by writing the column data output register keyifcol, and writes a high level to other columns. At each write time, the CPU reads the row data input register keyifro and presses the corresponding column key. In this way, after the scan is complete, you can find one or more buttons that are pressed.

Figure 24 Keyboard Scan initialization status

Let's assume that the process of pressing the button 27 is how to determine the button:

1) when the 27 key is pressed, the 3rd row of the key enters a low level, that is, the gpk11 input low level, which can be learned by reading the keyifrow register.

2) The CPU writes the keyifcol register to write 0th bits for low level, 1st to 7th bits for high level, and then reads the value of the keyifrow register. At this time, the read value is 11111111, if one row of input is not low, the buttons are not in The 0th column. See

Figure 25 Keyboard Scan Process II

3) until the CPU writes 11110111 to the keyifcol register at a lower eight bits, the value of the eight bits read to the keyifrow register is 11110111. We can see that the input of the second row is low, at this time, the corresponding is the low-level input of the 3rd columns when scanning conditions, so that you can judge the buttons at the intersection of the 3rd and 3rd columns, thus judging the specific buttons.

4) for multiple buttons, the scan principle is the same. See the description.

Figure 26 Keyboard Scan process III

1.1.2 PDD ist Processing

Next, let's take a look at the main processing part of the IST thread keymatrix: isrthreadproc :,

Figure 27 ist thread keymatrix: isrthreadproc ()

This ist process includes the following situations:

The following describes the called functions:

1) kscan_procio Function

Figure 28 kscan_procio function body

When you press the button for the 3rd rows and 3rd columns, changestate [3] = 0x8. Here 3 refers to the 3rd columns, and 0x8's binary number is 00001000, indicating 3rd rows, according to changestate [3] = 0x8, it can be seen that the press button in the 3rd columns of the 3rd row is pressed, and the value of changestate [idx] corresponding to other idx is 0. Similarly, changestate [2] = 0x8 is used to press the keys in the 3rd columns of rows. If both buttons are pressed, changestate [] = 0x8. That is to say, the idx value in the changestate array is used to indicate which column of buttons are used, while the value of changestate [idx] (non-zero) is used to indicate which row of buttons are used.

Note: The following is based on the 4*4 keyboard, which uses 4 lower lines (gpk8 ~ Gpk11) and four columns (gpl4 ~ Gpl7 ).

2) keybdeventcallback Function

The PDD layer sends the scan code and button status of the buttons pressed by the current device layout to the MDD layer by calling the keybdeventcallback function. The function body is as follows:

Figure 29 keybdeventthreadproc Function

3) keybdeventthreadproc thread

Receive the keyboard event sent by the keybdeventthreadproc function, convert the scan code to a virtual key code, and then send the re ing keyboard event to GWES. The main parts of this thread are as follows:

Figure 30 keybdeventthreadproc thread

The keyboard driver is introduced here first. In fact, there is still a lot of content. You can go deep into the MDD layer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.