按键平台驱动:
platfrom_device.c:
#include <linux/device.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
gpio.h> #include
#include
#include
#include
#include
static struct resource key_resource[]=
{
[0] = {
.start = IRQ_EINT8,
.end = IRQ_EINT8,
.flags = IORESOURCE_IRQ,
},
[1] = {
.start = IRQ_EINT11,
.end = IRQ_EINT11,
.flags = IORESOURCE_IRQ,
},
[2]= {
.start = IRQ_EINT13,
.end = IRQ_EINT13,
.flags = IORESOURCE_IRQ,
},
[3] = {
.start = IRQ_EINT14,
.end = IRQ_EINT14,
.flags = IORESOURCE_IRQ,
},
[4] = {
.start = IRQ_EINT15,
.end = IRQ_EINT15,
.flags = IORESOURCE_IRQ,
},
[5] = {
.start = IRQ_EINT19,
.end = IRQ_EINT19,
.flags = IORESOURCE_IRQ,
},
};
struct platform_device *my_buttons_dev;
static int __init platform_dev_init(void)
{
int ret;
my_buttons_dev = platform_device_alloc('my_buttons', -1);
platform_device_add_resources(my_buttons_dev,key_resource,6);//添加资源一定要用该函数,不能使用对platform_device->resource幅值
//否则会导致platform_device_unregister调用失败,内核异常。
ret = platform_device_add(my_buttons_dev);
if(ret)
platform_device_put(my_buttons_dev);
return ret;
}
static void __exit platform_dev_exit(void)
{
platform_device_unregister(my_buttons_dev);
}
module_init(platform_dev_init);
module_exit(platform_dev_exit);
MODULE_AUTHOR('Z-YP');
MODULE_LICENSE('GPL');
platfrom_derver.c:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME 'my_buttons'
struct button_irq_desc {
int irq;
int pin;
int pin_setting;
int number;
char *name;
};
static struct button_irq_desc button_irqs [] = {
{IRQ_EINT8 , S3C2410_GPG(0) , S3C2410_GPG0_EINT8 , 0, 'KEY0'},
{IRQ_EINT11, S3C2410_GPG(3) , S3C2410_GPG3_EINT11 , 1, 'KEY1'},
{IRQ_EINT13, S3C2410_GPG(5) , S3C2410_GPG5_EINT13 , 2, 'KEY2'},
{IRQ_EINT14, S3C2410_GPG(6) , S3C2410_GPG6_EINT14 , 3, 'KEY3'},
{IRQ_EINT15, S3C2410_GPG(7) , S3C2410_GPG7_EINT15 , 4, 'KEY4'},
{IRQ_EINT19, S3C2410_GPG(11), S3C2410_GPG11_EINT19, 5, 'KEY5'},
};
static volatile char key_values [] = {'0', '0', '0', '0', '0', '0'};
static DECLARE_WAIT_QUEUE_HEAD(button_waitq);
static volatile int ev_press = 0;
static irqreturn_t buttons_interrupt(int irq, void *dev_id)
{
struct button_irq_desc *button_irqs = (struct button_irq_desc *)dev_id;
int down;
// udelay(0);
down = !s3c2410_gpio_getpin(button_irqs->pin);
if (down != (key_values[button_irqs->number] & 1)) { // Changed
key_values[button_irqs->number] = '0' + down;
ev_press = 1;
wake_up_interruptible(&button_waitq);
}
return IRQ_RETVAL(IRQ_HANDLED);
}
static int s3c24xx_buttons_open(struct inode *inode, struct file *file)
{
int i;
int err = 0;
for (i = 0; i < sizeof(button_irqs)/sizeof(button_irqs[0]); i++) {
if (button_irqs[i].irq < 0) {
continue;
}
err = request_irq(button_irqs[i].irq, buttons_interrupt, IRQ_TYPE_EDGE_BOTH,
button_irqs[i].name, (void *)&button_irqs[i]);
if (err)
break;
}
if (err) {
i--;
for (; i >= 0; i--) {
上一篇:搭建一个mini2440开发板U-Boot的框架
下一篇:字符驱动设计----mini2440 LED驱动设计之路
推荐阅读最新更新时间:2026-01-18 05:23
- 使用 Analog Devices 的 LTC3130IUDC-1 的参考设计
- 使用 Microchip Technology 的 PD70201ILQ 的参考设计
- LTC2208IUP 演示板,CMOS 输出,130Msps,16 位 ADC,70MHz
- LT8330HDDB 8V 至 30V 输入、24V SEPIC 转换器的典型应用电路
- LTC3808EDE 演示板,具有输出跟踪功能的同步降压转换器,Vin= 2.7V-8V,Vout=1.8V@5A/3.5A/2.5A
- AD9238BCP-40EBZ,用于 AD9238、2 通道、10 位、40 MSPS 模数转换器的评估板
- ROTARYBCLICK,基于 EC12D 机械编码器旋转的评估套件
- LTC2917、3.3V、-10% 容限电源监视器
- L7908C 负电压稳压器的典型应用
- ZXLD1366EV3,使用内部开关评估 ZXLD1366 LED 驱动器



嵌入式系统技术与设计
现代雷达系统的信号设计
BFR340T






京公网安备 11010802033920号