With the rapid development of embedded systems, in embedded handheld devices, human-computer interaction devices are the part that contacts the user the most, and can most directly and quickly reflect the performance of the device. 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, keyboards are widely used because of their high accuracy and reliability, ability to adapt to various harsh working environments, and long service life.
According to the characteristics of handheld terminals, this paper designs a matrix keyboard and develops the keyboard driver under the Linux platform. Qt/Embedded is used to build the graphical interface. By analyzing the input method provided by Qt/Embedded and combining the Murphpinyin Chinese input method software package, an embedded keyboard that can input numbers, Chinese/English is built.
1 Hardware Design
The hardware part of this system is mainly a matrix keyboard with 4 columns and 5 rows, as shown in Figure 1. The column lines COL0~COL3 use the 4 interrupt pins of S3C2440 - EINT10, ENIT13, EINT15, EINT20, and each column line has a 4.7 kΩ pull-up circuit to pull the interrupt pin level high to ensure that the key will not trigger an interrupt when it is idle; the row lines ROW0~ROW4 use the 5 common I/O ports of S3C2440 - GPE11, GPE13, GPG3, GPG6, GPG11. The problem that needs to be paid attention to here is to ensure that the interrupts used by the column lines have not been used in various Linux devices, otherwise the driver initialization will fail in the subsequent driver.
Considering the convenience of handheld terminal operation, all buttons are re-arranged, as shown in Figure 2. In order to extend the service life of the handheld device and improve reliability, a power button Power is added. In addition, considering the low power consumption requirements of handheld devices, a backlight control button Back-Light is added to control the switch of the LCD backlight by controlling the high and low levels of the LCD_PWREN pin. The power button Power and the backlight control button BackLight are separate buttons, which are directly connected to the interrupt pin of S3C2440. This article focuses on a detailed introduction to the matrix keyboard. The processing mechanism of the power button and the backlight control button is similar to that of the matrix keyboard, so it will not be introduced here.
2 Software Design
2.1 Linux driver design for matrix keyboard
The matrix keyboard is registered in the system as a character device of Linux. In order to reduce the loss of system resources, the interrupt processing function is used to process the keys; at the same time, considering the jitter problem of the keys, a timer is used to eliminate the jitter.
The process of the driver is shown in Figure 3. First, use the S3C2440_Kb_init() function to register the keyboard as a character device, initialize the row line pins as output, non-pull-up, and set all row outputs to low level; register the keyboard device. Initialize the interrupt pins connected to the column lines as input, falling edge trigger interrupt, and establish a connection between the interrupt and the interrupt processing function Key_interrupt().
[page]
When a key is pressed, since all the lines are low, there must be a row and a column line turned on, which will pull the corresponding column line low and trigger an interrupt. Then, the interrupt processing function Key_interrupt() records the corresponding interrupt number. Due to the jitter of the key, it is unreliable to determine that the corresponding key is pressed based on the triggering of an interrupt. Therefore, after the interrupt is triggered, the timer kb_timer is started to determine the key status again.
The upper application uses S3C2440_Kb_open() to open the keyboard device, enable the column line interrupt, and initialize the timer. When the interrupt is triggered, the timer is turned on. When the timer timing is up, the timer interrupt kb_timer_handler() is triggered. kb_timer_handler() will first call the keyboard scanning function Scan_keyboard() to scan the key status. The Scan_keyboard() process is shown in Figure 4. If the same key value is scanned as pressed each time after three keyboard scans, it proves that a key is indeed pressed, and the Scan_keyboard() function returns: KEYDOWN. If the key value pressed this time is different from the previous key value, the key value is saved in the circular queue, so that duplicate data is not saved in the buffer queue. If the key status is not KEY_DOWN for 10 consecutive scans, it proves that the key has been popped up and the timer kb_timer is turned off.
The S3C2440_Kb_read() function is responsible for reading the key value from the circular queue and feeding it back to the upper-level application.
2.2 Qt/Embedded Keyboard Mapping
Qt/Embedded is a comprehensive application platform developed by Trolltech for electronic devices using embedded Linux. Qt/Embedded includes a complete application layer, a flexible user interface, a window operating system, application programs, and a development framework.
Qt/Embedded itself provides support for keystrokes. It provides a QWSKeyboardHandler class in the file qkeyboard_qws.cpp to handle keystroke events. This system creates a subclass of the QWSKeyboardHandler class, QWSKEYMATRIXHandler. In the constructor of the QWSKEYMATRIXHandler class, the matrix keyboard key_matrix is opened through the open() function, and a QscoketNotifer is created for the opened keyboard device to monitor the keystroke device. Through the signal and slot mechanism, the connection between the QscoketNotifer and the keyboard reading function ReadKeyboardData() is established. When key_matrix is activated, the keyboard reading function ReadKeyboardData() is triggered. The code is as follows:
notifier=new QSocketNotifier(key_matrix, QSock-etNotifier::Read, this);
connect(notifier, SIGNAL(activated(int)), this, SLOT(ReadKeyboardData()));
In the keyboard reading function ReadKeyboardData(), call the matrix keyboard driver's reading function Read() to obtain the key value. In order to transmit the key value to the application, use the member function processKeyEvent(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) of the QWSKeyboardHandler class. The functions of each parameter are as follows:
①Unicode: Unicode code of the key, such as the Unicode code of the number 1 is 1, and the Unicode code of the letter A is A. If this item is 0, it is a function key such as Shift, Left, Right, etc.; if this item is 0xFFFF, only the key value keycode is transmitted, and the code is not printed.
②Keycode: The key name used in Qt, such as Qt::Key_Backspace, Qt::Key_Enter, etc.
③Modifiers: Keyboard key combinations supported by Qt.
④isPress: Determine whether the button is "pressed" or "up".
⑤autoRepeat: Determine whether this event is generated by an automatic repeat mechanism or by a real button.
Numbers, lowercase English, and uppercase English can be sent through the processKeyEvent() function, but there is currently no Chinese input method on Qt/Embedded, so Chinese cannot be input.
2.3 Transplantation of Murphpinyin Pinyin Input Method
Murphypinyin is a relatively good open source Chinese input method based on Qt/Embedded so far, and Murphypinyin has a soft keyboard, and users can input Chinese, English, numbers and symbols through the touch screen. There are many reference materials on the Internet about the transplantation of Murphypinyin to Qt/Embedded, which will not be introduced here.
However, there is still a problem in applying Murphypinyin to handheld terminals: the soft keyboard of Murphypinyin is a standard PC101 keyboard with a large number of keys. On handheld terminals with strict requirements on volume and weight, the size of the touch screen itself is severely restricted. The PC101 keyboard will occupy most of the display area of the touch screen; and the area occupied by a single key is very small, so the positioning accuracy of the touch screen is very high. However, the touch screen itself is greatly affected by the surrounding environment, which can easily cause inaccurate positioning. This system maps the matrix keyboard to Murphypinyin, and inputs Chinese, English and numbers through the matrix keyboard. In this way, ordinary LCDs can be used on handheld terminals, thereby reducing system costs and improving system reliability. [page]
The first question to consider is: How to open the Murphypinyin input method with the keyboard? 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)
Among them: if(!isHidden()&& isPress) statement is used to determine whether the Murphypinyin input method has been opened and a key has been pressed. If so, it is determined whether the current mode is Chinese or English. 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, Chinese and English are switched. Here you can add a judgment statement: if(keycode==Qt::Key NumLock). When the NumLock key is pressed, the two functions: QPinyinFrame::sizeHint() and QPinyinFrame::show() are called to open the Murphypinyin input method interface. If the NumLock key is pressed again, QPinyinFrame::hide() is called to hide the input method interface.
After opening the Murphypinyin input method with the keyboard, you can input Chinese characters by sending pinyin letters through the keyboard. You can switch between Chinese and English by sending unicode=9&&keycode==Qt::Key_Tab.
2.4 Button Multiplexing
Since handheld terminal devices have strict requirements on their own size, in order to reduce the size of the keyboard, this system imitates the layout of the mobile phone keyboard and uses key reuse to reduce the size of the keyboard. The 26 English letters are arranged in groups of 3 or 4 in alphabetical order on the 8 numeric keys 2 to 9, and reused with Arabic numerals (see Figure 2).
The simplification of hardware will inevitably lead to the increase of software complexity. In order to enable the system to automatically identify whether it is a number, uppercase English letter, lowercase English letter or pinyin letter after pressing a key, it is necessary to modify the QWSKEYMATRIXHandler::ReadKeyboardData() function in qkeyboard_qws.cpp in Qt/Embedded.
When a key is pressed, the first thing to do is to determine the current mode: digital, pinyin, lowercase English, or uppercase English. The implementation process is shown in Figure 5. The NumLock key and the status flag English-Mode are used to switch between the digital state and several other states. The Tab key is used to switch between the Chinese and English modes, and the CapsLock key is used to switch between uppercase and lowercase English letters.
In order to enable a key to input different characters, the system uses different key_ID values to identify each character, so that each key press is different. Figure 6 shows the multiplexing process for key 2. According to different key_IDs combined with the current input mode, the corresponding numbers, lowercase English or uppercase English characters are sent.
3. Conclusion
This paper introduces the hardware design method and software driver development method of matrix keyboard based on S3C2440. By integrating Murphpinyin open source software package with Qt/Embeded built-in input method, using key reuse strategy and fewer keys, an embedded keyboard capable of inputting numbers, Chinese/English is constructed and implemented on S3C2440. This provides an embedded keyboard solution for handheld terminals.
References:
[1]. S3C2440 datasheet http://www.dzsc.com/datasheet/S3C2440_589562.html.
[2]. Power datasheet http://www.dzsc.com/datasheet/Power_1093617.html.
[3]. PC101 datasheet http://www.dzsc.com/datasheet/PC101_1147923.html.
Previous article:Design of smart home embedded system based on S3C44B0X and μC/OS-Ⅱ
Next article:Construction of wind power generation monitoring system development platform based on embedded Linux
Recommended ReadingLatest update time:2024-11-16 15:40
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【micropython】Bluetooth module has been added to ESP32
- 97% off e-coins (can join in group)
- LED Art: Halloween Badge
- How to continue working if you modify socket parameters during operation without restarting
- EEWORLD University - UCOS operating system foundation of the Internet of Things
- Smart module PIP keyboard to set real time clock
- Innovate, accelerate and connect across every band and protocol with the SimpleLink MCU platform
- Disassemble the original Keil artifact DSTREAM
- There is no one to teach me how to learn FPGA. Can I learn it just by watching tutorials?
- Brushed DC and brushless DC driver chips