Embedded keyboard design based on murphypinyin

Source: Internet
Author: User

Introduction

With the rapid development of embedded systems, in Embedded handheld devices, Human-Computer Interaction devices have the most contact with users, and can directly and quickly reflect the performance of the devices. Therefore, whether there is a friendly, fast, and reliable human-computer interaction device has become an important indicator for measuring a handheld device. In embedded Human-Computer Interaction devices, the keyboard is widely used because of its high accuracy and reliability. It can adapt to various harsh working environments and has a long service life.

Based on the features of the handheld terminal, this paper designs a matrix keyboard and develops a keyboard driver on the Linux platform. Use QT/embedded to build a graphical interface. Based on the analysis of the built-in Input Method of QT/embedded and the murphpinyin Chinese Input Method package, an embedded keyboard with numbers, Chinese characters, and English characters is built.

1. Hardware Design

The hardware part of the system is mainly a matrix keyboard with four columns and five rows, as shown in 1. The column line col0 ~ Col3 uses four interrupt pins of S3C2440, eint10, enit13, eint15, and eint20, and each column line has an upstream circuit of 4.7 kb, make sure that no interruption is triggered when the keys are idle; row0 ~ Row4 uses five general I/O Ports of S3C2440-gpe11, gpe13, gpg3, gpg6, and gpg11. It is important to note that the interruptions used by the column line are not used in Linux devices. Otherwise, the driver initialization will fail in the later drivers.

 

To facilitate operations on the handheld terminal, relay all the buttons, as shown in figure 2. Power keys are added to extend the life of handheld devices and improve reliability. In addition, considering the low power consumption requirements of handheld devices, the back-light control button is added to control the high and low levels of the LCD _pwren pin to control the LCD backlight switch. Among them, the power button and backlight control button are separate buttons, directly connected to the S3C2440 interrupt pin. This article focuses on the matrix keyboard. The processing mechanism of Power keys and backlight control keys is similar to that of matrix keyboards.

2 Software Design

2.1 matrix keyboard Linux Driver Design

The matrix keyboard is registered to the system as a character device of Linux. In order to reduce the loss of system resources, the interrupt processing function is used to handle the keys, and the timer is used to eliminate the jitter considering the jitter of keys.

The process of the driver is shown in step 3. First, use the s3c2440_kb_init () function to register the keyboard as a character device. The initialization line PIN is output, non-uplink, and all row outputs are set to low; register the keyboard device. The interrupt Pin connected to the initialization column line is: the input and the descent edge trigger the interrupt, and the connection between the interrupt and the interrupt processing function key_interrupt () is established.

When a key is pressed, because all actions are low, one line and one line are bound to be turned on, thus lowering the corresponding column line and triggering interruption. Then, the interrupt processing function key_interrupt () records the corresponding interrupt number. Due to the jitter of the buttons, it is determined by the trigger of an interrupt that the corresponding button is not reliable, therefore, enable the timer kb_timer to determine the button status again after the interruption is triggered.

Upper-layer applications use s3c2440_kb_open () to open the keyboard device, enable linefeed interruption, and initialize the timer. When the interrupt is triggered, enable the timer. When the timer time is reached, trigger the timer to interrupt kb_timer_handler (). Kb_timer_handler () first calls the Keyboard Scan function scan_keyboard () to scan the button status, as shown in scan_keyboard () process 4. If three keyboard scans show that the same key value is pressed each time, it indicates that a key is pressed. The scan_keyboard () function returns: keydown. If you press the key value different from the previous key value, save the key value to the cyclic queue, so that you do not save duplicate data to the buffer queue. If the key_down status is not found for 10 consecutive scans, it indicates that the key has been played up and the timer kb_timer is disabled.

The s3c2440_kb_read () function reads key values from the cyclic queue and reports them to upper-layer applications.

2.2 QT/Embedded keyboard ing

QT/Embedded is a comprehensive application platform developed by trolltech for electronic devices using embedded Linux. QT/Embedded contains the complete application layer, flexible user interfaces, window Operating Systems, Applications, and development framework.

QT/Embedded itself provides support for keys. It provides a qwskeyboardhandler class in the file qkeyboard_qws.cpp to process key events. In this system, a sub-class qwskeymatrixhandler of the qwskeyboardhandler class is created. In the constructor of the qwskeymatrixhandler class, open the matrix keyboard key_matrix through the open () function, create a qscoketnotifer for the opened keyboard device to monitor the key-pressing device, and use the signal and slot mechanism, establish the connection between the qscoketnotifer and the read keyboard function readkeyboarddata (). When key_matrix is activated, the read keyboard function is triggered.
Readkeyboarddata (). The Code is as follows:

Notifier = new qsocketnotifier (key_matrix, qsock-etnotifier: read, this );
Connect (notifier, signal (activated (INT), this, slot (readkeyboarddata ()));

In readkeyboarddata (), call the READ function read () of the matrix keyboard driver to obtain the key value. To transfer key values to applications, use the processkeyevent (INT Unicode, int keycode, int modifiers, bool ispress, bool autorepeat) member function of the qwskeyboardhandler class. The functions of these parameters are as follows:

① UNICODE: the Unicode code of the key. For example, the Unicode code of Number 1 is 1, and the Unicode code of letter A is. If the value is 0, it is the function key shift, left, right, etc. If the value is 0 xFFFF, only the key value keycode is transmitted and no encoding is printed.

② Keycode: key name used in QT, such as QT: key_backspace and QT: key_enter.

③ Modifiers: the keyboard keys supported by QT.

④ Ispress: determines whether the button is in the "Press" or "Pop Up" status ".

⑤ Autorepeat: determines whether the event is generated by an automatic repetition mechanism or by a real button.

The processkeyevent () function can be used to send numbers, lowercase English letters, and uppercase English letters. However, currently, there is no Chinese Input Method on QT/embedded and Chinese characters cannot be entered.

2.3 transplantation of murphpinyin PinYin Input Method

Murphypinyin is a good open-source Chinese Input Method Based on QT/embedded so far, and murphypinyin has a soft keyboard. You can enter Chinese, English, numbers, and symbols through the touch screen. There are many references for porting murphypinyin to QT/embedded on the network.

But there is still another problem when we apply murphypinyin to a handheld terminal: The murphypinyin comes with a standard keyboard named pc101, with a large number of buttons. On hand-held terminals with demanding volume and weight requirements, the size of the touch screen is severely restricted. The pc101 keyboard occupies most of the display area of the touch screen, and the area occupied by a single button is very small, therefore, the positioning accuracy of the touch screen is very high. However, the touch screen itself is greatly affected by the surrounding environment, and it is easy to cause inaccurate positioning. The system maps the matrix keyboard to murphypinyin and uses the matrix keyboard to input Chinese characters, English letters, and numbers. This allows you to use a common LCD on a handheld terminal, this reduces system costs and improves system reliability.

The first question to consider is: how to use the keyboard to open the murphypinyin input method? Here, you can modify the pinyinframe. cpp file in the murphypinyin software package:

Boot qpinyinframe: Filter (INT Unicode, int keycode, int modifiers, bool ispress, bool autorepeat)

Where: If (! The ishidden () & ispress) statement is used to determine whether the murphypinyin input method is enabled and a key is pressed. If yes, the current Chinese or English mode is used. In Chinese mode, the getkey (UNICODE, keycode) function is called to search for Chinese Characters Based on the input pinyin; in English mode, the sendKey (UNICODE, keycode) function is called to send uppercase or lowercase English letters. If Unicode = 9 & keycode = QT: key_tab, switch between Chinese and English. Here you can add a judgment statement: If (keycode = QT: Key
Numlock ). When numlock is pressed, call the qpinyinframe: sizehint () and qpinyinframe: Show () functions to enable the murphypinyin Input Method interface. If you press the numlock button again, call qpinyinframe: Hide () to hide the input method interface.

After you enable the murphypinyin Input Method on the keyboard, you can send pinyin letters to input Chinese characters. Send Unicode = 9 & keycode = QT: key_tab to switch between Chinese and English.

2.4 Key-press multiplexing

Because handheld terminal devices have strict requirements on their own sizes, in order to reduce the size of the keyboard, the system imitates the layout of the mobile phone keyboard and uses the key reuse method to reduce the size of the keyboard. Sort 26 English letters in 3 or 4 alphabetical order in 2 ~ 9. These 8 numeric keys are reused with Arabic numerals (see figure 2 ).

Hardware simplification will inevitably lead to an increase in software complexity. The qwskeymatrixhandler: readkeyboarddata () function of qkeyboard_qws.cpp in QT/Embedded must be modified to enable the system to automatically recognize numbers, uppercase letters, lowercase letters, or pinyin letters after pressing the next button.

When a key is pressed, you must first determine the current mode: Numbers, Pinyin, lowercase English, or uppercase English. The process is shown in step 5. You can use the numlock button and the status flag English-mode to switch between numeric and other States. Use the tab key to switch between the Chinese and English modes, and use the capslock button to switch between uppercase and lowercase letters.

To enable a key to enter different characters, the system uses different key_id values to identify each character. In this way, each key is different. Figure 6 shows the reuse process of key 2. Send numbers, lowercase letters, or uppercase letters based on the key_id and the current input mode.

3. Summary

This article introduces the hardware design method and software driver development method of matrix keyboard based on S3C2440. by integrating the murphpinyin open source software package with the built-in Input Method of QT/embeded, the key reuse strategy is used, using a few buttons, an embedded keyboard with numbers and Chinese and English characters can be built and implemented on S3C2440. Provides an embedded keyboard solution for handheld terminals.

 

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.