Design of LED Display Based on ARM S3C44B0X

In the development of embedded systems, human-computer interaction is often realized through the keyboard. This article introduces a method of directly utilizing the I/O port of ARM to expand the matrix keyboard. At the same time, taking the TQ2440 development board as an example, the hardware circuit connection and the corresponding linux driver design method are described in detail.

In the development of embedded systems, human-computer interaction is often realized through the keyboard. This article introduces a method of directly utilizing the I/O port of ARM to expand the matrix keyboard. At the same time, taking the TQ2440 development board as an example, the hardware circuit connection and the corresponding linux driver design method are described in detail.

1 Introduction

ARM microprocessors have been widely used in industrial control, consumer electronics, communication systems and other fields. The matrix keyboard is a commonly used keyboard form. It designs the keys into M rows and N columns, which requires M+N signal lines in total, but can drive M×N keys, which greatly saves I/O resources. This article introduces a method of using the GPIO port of the TQ2440 development board to expand a 5×4 matrix keyboard, and rearranges all the keys into the keyboard form of a handheld terminal, which is convenient for operation.

2. Hardware Design

This design expands the matrix keyboard with 5 rows and 4 columns, as shown in Figure 1. The row lines ROW1-ROW5 are connected to the interrupt pins EINT8, EINT9, EINT11, EINT13, EINT14 of S3C2440[1]. These interrupt pins themselves are connected with a 10kΩ pull-up resistor, which pulls the interrupt pin level high to ensure that the interrupt will not be triggered when the button is idle. The column lines COL1-COL4 are connected to the ordinary I/O ports GPF3, GPF4, GPG7, and GPG10 of the S3C2440. The problem to be noted here is: make sure that the interrupts used by the line lines are not used in other Linux devices, otherwise it will cause the driver Program or other driver initialization failed.

Design of LED Display Based on ARM S3C44B0X

Considering the commonality of the keys of the handheld terminal device and the convenience of operation, only the first 18 keys of the matrix keyboard are taken, and they are rearranged into the form of FIG. 2 . The Ent key has dual functions, namely confirmation function (short press) and power on/off function (long press). This function will be implemented in the driver.

Design of LED Display Based on ARM S3C44B0X

3. Linux driver design of matrix keyboard

3.1 General overview of keyboard driver

Drivers are the interface between the operating system kernel and hardware devices.The device driver shields the details of the hardware for the application, so that the application can operate the hardware device like a normal file[2]. The driver has no main function, it takes a module initialization function as the entry, and it will not run after it completes the initialization, waiting for the system call.

The driver is a part of the linux kernel, so the expression of linux should be used in programming. First define the column I/O ports as an array: col_table [] ={ S3C2410_GPF3, S3C2410_GPF4, …}, row I/O ports are defined as structured:

button_irqs [] ={{IRQ_EINT8,S3C2410_GPG0,S3C2410_GPG0_EINT8,0,”R1″},

{IRQ_EINT9, S3C2410_GPG1, S3C2410_GPG1_EINT9, 1, “R2”},

…}.//Interrupt number (irq), pin (pin), pin setting, serial number, name

The matrix keyboard is registered with the system as a character device in Linux.We first register the matrix keyboard device with the system, including the device number, device name and file_operations structure; the member functions of the file_operations structure are the main content of the character device driver design, these functions will actually perform Linux open(), Finally called when system calls such as write(), read(), close(), etc.[3]. The user does not write to the keyboard, and the member functions of the file_operations structure are open(), read(), close(), poll().

The registration of interrupts and the initialization of ranks and columns are implemented when the keyboard is opened (that is, in the open() function). Registered interrupts include: interrupt number, interrupt entry program, interrupt mode, interrupt name and code. The key statement is: request_irq (button_irqs[i].irq, buttons_interrupt, IRQ_TYPE_EDGE_FALLING, button_irqs[i].name, (void*)&button_irqs[i]). IRQ_TYPE_EDGE_FALLING means falling edge trigger. Then perform row and column initialization: set row line to interrupt, enable pull-up, and its expression in linux is:

s3c2410_gpio_cfgpin(button_irqs[i].

pin, S3C2410_GPIO_SFN2); //Set the i-th row pin as interrupt

s3c2410_gpio_pullup(button_irqs[i].

pin, 1); //Pull-up on the i-th row pin

Set the column line as an output and set it low. The sentences are expressed in the same way. Due to space limitations, they will not be listed here.

The read() function implements reading data from the device. This function realizes that the program goes to sleep when no button is pressed. The key code:

static DECLARE_WAIT_QUEUE_HEAD(button_waitq); //Generate a waiting queue head queue named button_waitq

static volatile int ev_press = 0; //set to 1, indicating that a key is pressed

When ev_press is 0, execute the statement: wait_event_interruptible (button_waitq, ev_press), and the program goes to sleep. When ev_press is 1, the data is copied from the kernel space to the user space. The key statement:

copy_to_user(buff, (const void *) key_values, min(sizeof(key_values), count)); //buff is a pointer to user space, key_values ​​is a pointer to kernel space, and the last parameter is to copy data from kernel space to user space The number of bytes, we take the minimum of the actual size and the user-specified size. Returns zero when the data is copied successfully; returns the number of bytes of data that were not copied successfully when there is an error.

The close() function closes the matrix keyboard device and releases the registered interrupt, key statement: free_irq (button_irqs[i].irq, (void *) & button_irqs[i]).

The poll() function implements polling. If there is no key data, call the linux poll_wait function to wait; if there is key data, the select function will return immediately.

3.2 Interrupt Handling and Keyboard Scanner

The name of the interrupt handling function is the buttons_interrupt registered above. The specific program flow is shown in Figure 3. When a key is pressed, the row and column where the key is located are turned on. A low level on a column pulls the row level low, which in turn triggers an interrupt. Then, enter the interrupt handler. Due to the problem of key jitter, it is unreliable to determine that a key is pressed by only one interrupt trigger, so a timer is used to delay 10ms before entering the keyboard scan function.

Design of LED Display Based on ARM S3C44B0X

The keyboard scanning program of this design adopts the method of first determining the row and then determining the column, and finally the key value is obtained by performing certain operations on the row and column. First determine the row: scan row by row to determine whether any row pin is low. If so, save the row value (row). Continue to determine the column: set the low level column by column, when the column is pressed down on the column, the row will be low again, thereby determining the column (column). Then operate on the row and column: k=row*4+column, then each key of the matrix keyboard corresponds to the key number 0-19. After the keyboard layout is in the form shown in Figure 2, we only take the first 18 keys of the matrix keyboard ( The key number is 0-17), and the key value is saved as k+1. For the Ent key, it is determined whether the function or the power-on function is distinguished by the length of the pressing time. The pressing time is less than 0.5 seconds to confirm the function, and the pressing time is greater than 1.6 seconds. For the switch function, the time between 0.5 seconds and 1.6 seconds is regarded as an invalid operation. The timing method is:

If the line is still low and the integer cnt is less than 1700: the delay is 1ms, cnt++; according to the cnt value, the pressing time is obtained.

The switch function is saved as the 18th key number, and the key value is 19.

4. Driver testing

The test program belongs to the upper-level application program, and the operation of the keyboard can be realized by directly calling the interface provided by the keyboard driver. We call the open() function to open the matrix keyboard device, and then call the read() function to read the keyboard data and save it to the array defined by ourselves, and finally use the printf() function to Display the test results.

The function is applied to the author’s project, and the correct rate and response time of keyboard input meet the design requirements.

5. Summary

This paper introduces a method to directly expand the matrix keyboard from the I/O port of ARM. It does not need to add other interface components, the design is fast and practical, and the driver under the Linux system is implemented to expand the handheld terminal type for ARM embedded devices. Keyboards offer a solution.

The Links:   SKKT71/16D EP4CE40F23I7N

Related Posts