Download presentation
Presentation is loading. Please wait.
Published byRandolf Kennedy Modified over 9 years ago
1
指導教授 : 蔡亮宙 報告者 : 黃柏愷
2
Outline Introduction Hardware platform Software platform Design of driver program Traditional keyboard driver The first improved method The second improved method Summary Reference
3
Introduction The keyboard is a very important input device of HID (Human Interface Device) The commonly-used non-coded keyboard is divided into matrix keyboard and independent keyboard S3C2440 processor of SAMSUNG, with the dominant frequency 400MHz NAND Flash of 64MB and used SDRAM of 64MB
4
Hardware platform 4X4 matrix keyboards scanning
5
Software platform host machine development platform is the Red Hat Enterprise Linux5.5 the version of Linux kernel for the target board is 2.6.32 Toolchan: the cross-compiler is arm-Linux-GCC-4.3.2
6
Design of driver program Traditional keyboard driver The first improved method The second improved method
7
Traditional keyboard driver(1/4) The driver initialization struct file_operations button _fops struct button_dev struct class *btn_class; int button_init(void) class_device_create(btn_class,devno,NULL,"btndev ",0); Event handling key_interrupt() Keyboard scanning
8
Obtain key value keyboard driver flowchart Traditional keyboard driver(2/4) Init_keyboard Button_open() Scanning key Blocking thread Get key value By semphore Get key value By semphore Create wait queue Put the task into wait queue and sleep Put the task into wait queue and sleep Awake by semphore Obtain key value key value to userspce Task in sleeping Set the task runing,remove it from wait queue Interrupt occurred Interrupt occurred No yes No yes
9
Traditional keyboard driver(3/4) struct file_operations button _fops = {.owner = button _MODULE,.read = button _read,.open = button _open,.poll= button _poll,.release = button _release, }; struct button_dev { struct semaphore sem; /* mutual exclusion semaphore*/ wait_queue_head_t rq; struct cdev cdev; /* Char device structure*/ unsigned char key; };
10
Traditional keyboard driver(4/4) struct class *btn_class; int button_init(void){ int result; dev_t devno = MKDEV(btn _major, 0); if (btn _major) result = register_chrdev_region(devno,1, " btndev"); else{ result = alloc_chrdev_region(&devno,0, 1, " btndev "); btn _major = MAJOR(devno); } ………… btn _class =class_create(THIS_MODULE," btndev "); ………… class_device_create(btn_class,devno,NULL," btndev ",0); ………… }
11
The first improved method(1/4) Drive initialization static struct input_dev *simplekey_dev; static unsigned char simplekey_keycode[] set_bit(EV_KEY,simplekey_dev->evbit); set_bit(simplekey_keycode[i],simplekey_dev->keybit); Event Reporting input_report_key(simplekey_dev,simplekey _keycode[ code],1); input_sync(simplekey_dev);
12
The first improved method(2/4) 輸入子系統 (input subsystem) 的架構圖
13
The first improved method(3/4) static unsigned char simplekey_keycode[] = {…… [9] = KEY_RIGHT, [10] = KEY_DOWN, [11] = KEY_LEFT, [12] = KEY_UP, [13] = KEY_A, [14] = KEY_B, [15] = KEY_B, };
14
The first improved method(4/4) set_bit(EV_KEY,simplekey_dev->evbit); set_bit(simplekey_keycode[i],simplekey_dev->keybit); input_report_key(simplekey_dev,simplekey_keycode [code], 0); input_sync(simplekey_dev);
15
The second improved method(1/3) S3C2440 Linux 驅動移植 —— 按键 include/linux/gpio_keys.h struct gpio_keys_button struct gpio_keys_platform_data arch/arm/mach-s3c2440/mach-smdk2440.c static struct gpio_keys_button s3c_buttons[] static struct gpio_keys_platform_data buttons_platdata static struct platform_device s3c_device_buttons 添加 static struct gpio_keys_platform_data buttons_platdata static struct platform_device *smdk2440_devices[] __initdat a 添加 static struct platform_device s3c_device_buttons make xconfig qt3
16
The second improved method(2/3) static struct gpio_keys_button s3c2440_buttons[] = { {.gpio = S3C24XX_GPN(0),.code = KEY_DOWN,.desc= "Down",. active_low = 1, },…..} Static struct gpio_keys_platform_data s3c2440_but ton_data = {.buttons = s3c2440_but tons,.nbuttons = ARRAY_SIZE, };
17
The second improved method(3/3) Static struct platform_device s3c2440_device_button = {.name = "gpio-keys ",. id = -1,.dev = {.platform_data = &s3c2440_button_data, } };
18
Summary the improvement of driver design, the keyboard driver code has at least two-thirds reduction in the course the keystrokes have been transformed into a system message without a separate thread detecting button
19
Reference http://www.linuxidc.com/Linux/2011-03/32896.htm http://wenku.baidu.com/view/d34cd8300b4c2e3f5727635c.html http://blog.csdn.net/yj4231/article/details/8100068 http://blog.csdn.net/tianxiawuzhei/article/details/7606111 LIU Long , ZHANG Yun-cui , GUO Jing-fu Monitor System for Neutron Room Based on Embedded System Nuclear Electronics & Detection Technology 2009,7:892-894 Zhu Xiang-wei Lu Wei-zhong Design of a Byte Device of the Driving Program in LINUX System Journal of Huaihai Institute of Technology(Hamaitie & Science Edition) 2001,3:18-20 Luo Zhijie Interrupt Design of Embedded Linux System Computer & Telecommunication 2011, 9:58-61 YU Qi-jian , ZHANG Hai-feng Realization of touch screen‘s driver with Linux input subsystem MECHANICAL & ELECTRICAL ENGINEERING MAGAZINE 2009, 26(3)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.