It mainly analyzes the three CPP files in the BSP package.
The first is the pddlist. cpp file.
This file introduces the function name of the API entry of Wince for the three types of keyboards plus winapi). This article only focuses on the second type of matrix keyboard.
Then, you can find the entry function matrix_entry In The KBD. cpp file.
It is worth noting that this driver is a full-keyboard driver, which involves the processing of shift keys and FN keys, that is, the handling of key combinations. This is not an analysis here, because it is not used for the time being.
After analyzing this function, we can see that the upper-layer keyboard initialization process is as follows:
Keybddriverinitializeaddresses →
Keyboard-> keybdpoweron →
Keyboard-> isrthreadstart
All these functions are implemented in the keymatrix. cpp file.
1: The keybddriverinitializeaddresses function establishes a basic Io address ing, which maps the gpio and keyif device addresses that keyboard may use to the corresponding virtual addresses. Here is where the driver porting needs to be modified, that is, base_reg_pa_gpio and base_reg_pa_keyif and base_reg_pa_cmu_clk are replaced with the physical address of the actual board, and the remaining code remains unchanged.
This step is the foundation behind, and the base address in the base address plus offset used later is the virtual address after the ing.
2: The keyboard-> keybdpoweron function initializes the hardware of this module, including enabling the clock switch corresponding to keyif in the system clock module, and setting the clock frequency of the keyboard, the gpio registers used.
This part is the initialization process of all the hardware of the keyboard, which is changed to the initialization of the 6410 platform register, mainly to change gpio and clock.
3: The keyboard-> isrthreadstart function is used to register the keypad interrupt and create the keyboard daemon thread.
This function first uses the createthread function to create the kbdisrthread thread, which is actually the encapsulation of keymatrix: isrthreadproc. We can see that this function is the registration of the keypad interrupt service program, followed by a while (1) main thread process. this thread first calls waitforsingleobject to wait for the keyboard event. If the event arrives, it calls keyif_status_clear and kscan_procio to clear the interrupt and read the keyboard matrix. Then, call v_pfnkeybdevent to upload the key value to the upper layer. Don't look at this function for a long time. In fact, FB, shift, and num
Lock and so on. Here we need to refer to the matrix array. From the code, we can see that there are 4 keyboard layout0 ~ 3. Replace the keyboard layout with the matrix_layout = parameter.
Then, an eint15 daemon thread is created, waiting for the eint15 to be interrupted. The main significance of the eint15ist thread is to set gbboardkeydown to ture. This is to identify whether the buttons are pressed or popped up. For 6410, you can refer to datasheet to find one by yourself.
This is the process of Wince keyboard driver.