2440 usb linux驱动,S3C2440 Linux驱动移植——按键

开发板:TQ2440

内核版本:2.6.321. 硬件链接图

四个输入引脚:

EINT0-----( GPF0 )----INPUT---K4

EINT2-----( GPF2 )----INPUT---K3

EINT4-----( GPF4 )----INPUT---K2

EINT1-----( GPF1 )----INPUT---K12. 相关的数据结构

移植所需要的数据结构位于include/linux/gpio_keys.h中。

#ifndef_GPIO_KEYS_H

#define_GPIO_KEYS_H

structgpio_keys_button{

/*Configurationparameters*/

intcode;/*inputeventcode(KEY_*,SW_*)*/

intgpio;

intactive_low;

char*desc;

inttype;/*inputeventtype(EV_KEY,EV_SW)*/

intwakeup;/*configurethebuttonasawake-upsource*/

intdebounce_interval;/*debounceticksintervalinmsecs*/

};

structgpio_keys_platform_data{

structgpio_keys_button*buttons;

intnbuttons;

unsignedintrep:1;/*enableinputsubsystemautorepeat*/

};

#endif

从名字上我们可以看出:gpio_keys_platform_data 结构体将作为平台设备的数据。

其中buttons字段指向gpio_keys_button结构体,nbuttons表示有多少个gpio_keys_button结构体。

每个gpio_keys_button结构体表示一个按键,在我的板子上,有四个按键,将会定义一个有4个元素的gpio_keys_button数组,buttons字段将指向该数组,同是,nubuttons字段将为4。

gpio_keys_button 结构体中,gpio字段表示按键所使用IO端口。desc字段为该按键的描述。debounce_interval字段表示软件去抖的时间,单位为ms。

type字段表示输入事件的类型。active_low表示低电平有效。开发板上的按键在按下时为低电平,松开时为高电平,active_low置0(不太确定)。

3. 移植代码

这里,我将所有代码均添加在arch/arm/mach-s3c2440/mach-smdk2440.c中。3.1 添加头文件

#include//addedbyyj423forbuttonsdriver

#include//addedbyyj423forbuttonsdriver

#include//addedbyyj423forbuttonsdriver3.2 添加gpio_keys_button和gpio_keys_platform_data结构体

/*buttonsdriver,addedbyyj423*/

staticstructgpio_keys_buttons3c_buttons[]=

{

{

.gpio=S3C2410_GPF(1),

.code=KEY_UP,

.desc="UP(K1)",

.active_low=0,

},

{

.gpio=S3C2410_GPF(4),

.code=KEY_DOWN,

.desc="DOWN(K2)",

.active_low=0,

},

{

.gpio=S3C2410_GPF(2),

.code=KEY_LEFT,

.desc="LEFT(K3)",

.active_low=0,

},

{

.gpio=S3C2410_GPF(0),

.code=KEY_RIGHT,

.desc="RIGHT(K4)",

.active_low=0,

},

};

staticstructgpio_keys_platform_databuttons_platdata=

{

.buttons=s3c_buttons,

.nbuttons=ARRAY_SIZE(s3c_buttons),

};

3. 3 将gpio_keys_platform_data添加到平台设备中

staticstructplatform_devices3c_device_buttons={

.name="gpio-keys",

.id=-1,

.num_resources=0,

.resource=NULL,

.dev={。

.platform_data=&buttons_platdata,

}

};

需要注意的是,根据platform总线的匹配函数,这里的name字段必须和文件drivers/input/keyboard/gpio_keys.c中的gpio_keys_device_driver.driver.name的值一致,即为gpio-keys。3.4 将按键的平台设备注册到内核中

在smdk2440_devices数组中增加s3c_device_buttons,如下:

staticstructplatform_device*smdk2440_devices[]__initdata={

&s3c_device_usb,

&s3c_device_lcd,

&s3c_device_wdt,

&s3c_device_i2c0,

&s3c_device_iis,

&s3c_device_dm9000,//addedbyyj423

&s3c_device_ds18b20,//addedbyyj423

&s3c_device_buttons,//addedbyyj423

};

4. 配置内核

在添加完代码以后,开始配置内核。需要配置两个模块,在这里我将它们编译进了内核,你也可以选择编译为模块。

c1ba2e9823881d1ed736e6c71343d162.png

5c9abd7e614433b3ca9c90bb422ec956.png

编译结束后,将内核烧入flash中,启动内核。如果你发现/dev/event0的存在,恭喜你,移植成功了。5. 测试

测试程序如下:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

intmain(intargc,char**argv)

{

intfd,ret;

char*str;

structinput_eventbutton_event;

fd=open("/dev/event0",O_RDWR);

if(fd<0){

printf("openwrongn");

return-1;

}

while(1)

{

ret=read(fd,&button_event,sizeof(button_event));

if(retprintf("incompletereadn");

return-1;

}

switch(button_event.type){

caseEV_KEY:

str = "key"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值