A complete matrix control module design based on embedded Linux kernel

To adapt to the diverse peripheral interfaces of embedded devices, this paper presents a comprehensive set of driver control modules, using a specific matrix keyboard as a case study. The hardware design employs three SN74HC164 shift registers to expand the number of available input lines, effectively reducing the consumption of GPIO pins and significantly improving resource utilization. In addition, the paper explains the characteristics and working mechanism of the input subsystem in the Linux kernel, detailing how input events are transmitted from kernel space to user space processes. Experimental results demonstrate that the designed driver module exhibits excellent real-time performance and accuracy.

With the rapid development of microprocessor technology and the widespread adoption of digital products, research and development in embedded systems have become increasingly prominent. Linux has emerged as the leading choice for embedded operating systems due to its open-source nature, stability, and high degree of customization. Among various input devices, keyboards remain one of the most commonly used components in embedded systems. However, due to the functional differences among embedded devices, it is not practical to use a universal keyboard. Instead, custom keyboards must be designed based on the specific needs of the system, along with the corresponding drivers to ensure proper functionality.

The S3C6410 is a high-performance 32-bit RISC microprocessor developed by Samsung, featuring multiple powerful hardware accelerators for video and image processing, making it a popular choice in the embedded market. This paper takes a 24-key matrix keyboard based on the S3C6410 as an example, outlining the overall process of developing device drivers in embedded systems and analyzing the underlying mechanisms for handling input events under the Linux operating system.

1. Interface Circuit Design

A common method for expanding a keyboard interface on an embedded device involves scanning the CPU's GPIO ports. However, this approach consumes a large number of GPIO resources, especially when dealing with a high number of keys, which can place a heavy burden on the embedded processor.

To address this issue, the hardware design of this system incorporates three SN74HC164 chips, which help reduce the usage of GPIO pins. The SN74HC164 is an 8-bit serial-in, parallel-out shift register composed of eight D flip-flops. Each time the clock signal transitions from low to high, the current input data is shifted out through the parallel output. The hardware schematic is illustrated in Figure 1.

Design of Keyboard Driver Control Module Based on Embedded Linux Kernel

By connecting the three SN74HC164 chips in series, their CLK pins are connected to the GPE4 port of the S3C6410 development board. The A and B input pins of the first chip are connected to the GPE3 port, both configured in output mode. The GPE2 port is linked to the pull-up resistor of the keyboard buttons. During operation, the system switches between interrupt and input modes to trigger interrupts and scan the keyboard. This configuration uses only three GPIO ports to support 24 keys, saving costs and avoiding unnecessary resource waste.

2. How Scanning Works

Expanding the hardware circuit introduces some complexity in implementing the keyboard driver. The driver must first activate the SN74HC164 before controlling the circuit. The output pin of the circuit is connected to the GPE2 port of the S3C6410, which is configured as an interrupt source. When no key is pressed, the port reads as high. During a keyboard scan, the SN74HC164 sets all 24 keys to a low level. If any key is pressed, the GPE2 port drops from high to low, triggering an interrupt.

During interrupt processing, the GPE2 port is set to input mode. Then, according to the input/output behavior of the SN74HC164, 24 high-level signals are sent to the three chips in sequence, setting all keys to high. On the next 24 clock pulses, each chip receives a 0 followed by 23 1s, so that only one key is at a low level at the GPE2 port. When the pressed key is at the 0 input, it will read a low level, allowing the system to identify which key was pressed.

3. Driver Module Structure

The input subsystem introduced in the Linux 2.6 release provides a complete model for handling input events, enabling drivers to pass information from the device to the user process. Based on this architecture, this paper designs a more advanced and efficient special keyboard driver module. The structure of the keyboard driver module is shown in Figure 2.

Design of Keyboard Driver Control Module Based on Embedded Linux Kernel

In the input subsystem's device model, the most important data structure is struct input_dev, which serves as the core of the driver. Each struct input_dev represents an individual input device, containing event types, button types, keyboard code tables, coordinate fields, and functions such as device open, close, and callback functions. These elements allow the driver to fully describe and manage the device's behavior. Before registering the input_dev with the kernel, it must be initialized, and an interrupt for the keyboard must be requested from the kernel.

TOPCON Solar Panel

The new product uses N-type TOPCon technology and is fully enhanced in performance, power, energy density and reliability.
The mass production efficiency of Sunket N-type TOPCon cells has reached 24.5%, the bifacial ratio of modules is up to 85%, and the additional power generation gain has increased by more than 3%. In 2022, Sunket will continue to focus on improving the efficiency of mass production of batteries, leading the efficiency and economy of TOPCon Series products to a new high, and bringing customers higher installed capacity.

TOPCON Solar, TOPCON Solar Panel, TOPCON Solar PV Module, TOPCON PV Module, TOPCON Solar Module

Wuxi Sunket New Energy Technology Co.,Ltd , https://www.sunketsolar.com