三星 arm9 linux,基于arm9内核三星s3c2410平台下linux四键按键驱动程序
#ifndef __kernel__
#define __kernel__
#endif
#ifndef module
#define module
#endif#include
#include
#include
#include
#include
#include
#include//声明中断
#include//声明file文件
#include/*cli(),*_flages*/
#include
#include
#include
#include
#include //devf
//-------------------------------
#include /* ioremap */
#include
#include
//--------------------------------
#include
#include
#include
#include
//define the interrupt no.
#define interrupt_k4 irq_eint0
#define interrupt_k3 irq_eint2
#define interrupt_k2 irq_eint11
#define interrupt_k1 irq_eint19
/*
struct irq_struct
{
unsigned int irq_no;
void (*irq_fun)();
};
static irq_struct irq_struct[4];
*/
//定义键盘的主设备号define the major of keypad
#define keypad_major 59
#ifndef mod_inc_use_count
#define mod_inc_use_count
#endif
#ifndef mod_dec_use_count
#define mod_dec_use_count
#endif
#define command1 1
#define kbd_getkey 1
static int keyvalue;
#define device_name "keypad"
//setup the gpio f ports register
#define key_rgpfcon (*(volatile unsigned long *) key_r_gpfcon)
#define key_rgpfup (*(volatile unsigned long *) key_r_gpfup)
#define key_rgpfdat (*(volatile unsigned long *) key_r_gpfdat)
//setup the gpio g ports register
#define key_rgpgcon (*(volatile unsigned long *) key_r_gpgcon)
#define key_rgpgup (*(volatile unsigned long *) key_r_gpgup)
#define key_rgpgdat (*(volatile unsigned long *) key_r_gpgdat)
unsigned long *key_r_gpfcon, *key_r_gpfdat, *key_r_gpfup;
unsigned long *key_r_gpgcon, *key_r_gpgdat, *key_r_gpgup;
static int __init keypad_init(void);
static void __exit keypad_cleanup(void);
static void key1_irq(int irq,void *dev_id,struct pt_regs *regs);
static void key2_irq(int irq,void *dev_id,struct pt_regs *regs);
static void key3_irq(int irq,void *dev_id,struct pt_regs *regs);
static void key4_irq(int irq,void *dev_id,struct pt_regs *regs);
static int keypad_getkey(void);
static int keypad_open(struct inode *inode,struct file *file);
static int keypad_close(struct inode *inode,struct file *file);
static int keypad_ioctl(struct inode *inode ,struct file* file,unsigned int cmd,unsigned long arg);
void keypad_setup(void);
/********************************************************************/
static devfs_handle_t devfs_handle;
static struct file_operations keypad_fops=
{
owner:this_module,
llseek:null,
read: null,
write: null,
ioctl: keypad_ioctl,
open: keypad_open,
release: keypad_close,
};
/********************************************************************/
void keypad_setup(void)
{
keyvalue = 0;
}
static int keypad_open(struct inode * inode,struct file *file)
{
printk(kern_crit"demo:keypad device open \n");
mod_inc_use_count;
return 0;
}static int keypad_close(struct inode * inode,struct file *file)
{
printk(kern_crit"demo:keypad device close\n");
mod_dec_use_count;
return 0;
}static int keypad_ioctl(struct inode *inode ,struct file* file,unsigned int cmd,unsigned long arg)
{
int value=0;
switch(cmd)
{//接受一个按键
case kbd_getkey:
value = keypad_getkey();
if(value!=0)
keyvalue=0;
return value;
}
}static void key1_irq(int irq,void *dev_id,struct pt_regs *regs)
{
//屏蔽键盘中断
disable_irq(irq);
printk("key1 interrupt ok\n");
keyvalue=1;
enable_irq(irq);
}static void key2_irq(int irq,void *dev_id,struct pt_regs *regs)
{
//屏蔽键盘中断
disable_irq(irq);
printk("key2 interrupt ok\n");
keyvalue=2;
enable_irq(irq);
}static void key3_irq(int irq,void *dev_id,struct pt_regs *regs)
{
//屏蔽键盘中断
disable_irq(irq);
printk("key3 interrupt ok\n");
keyvalue=3;
enable_irq(irq);
}
static void key4_irq(int irq,void *dev_id,struct pt_regs *regs)
{
//屏蔽键盘中断
disable_irq(irq);
printk("key4 interrupt ok\n");
keyvalue=4;
enable_irq(irq);
}static int keypad_getkey()
{
//如果有键按下,则反回键值
if (keyvalue)
{
return keyvalue;
}
//printk("waiting.......\n");
//无键按下,返回0
return 0;
}static int __init keypad_init(void)
{
int result;
//int i;
//setup the f_port register
key_r_gpfcon =ioremap(0x56000050,4);
key_r_gpfdat =ioremap(0x56000054,4);
key_r_gpfup =ioremap(0x56000058,4);
key_rgpfup =0xff;
key_rgpfcon = 0xffee;
//setup the g_port register
key_r_gpgcon = ioremap(0x56000060,4);
key_r_gpgdat = ioremap(0x56000064,4);
key_r_gpgup = ioremap(0x56000068,4);
key_rgpgup = 0xffff;
key_rgpfcon = 0xffbfffbf;
/*
irq_struct[0].irq_no=interrupt_k1;
irq_struct[0].irq_fun=key1_irq;
irq_struct[1].irq_no=interrupt_k2;
irq_struct[1].irq_fun=key2_irq;
irq_struct[2].irq_no=interrupt_k3;
irq_struct[2].irq_fun=key3_irq;
irq_struct[3].irq_no=interrupt_k4;
irq_struct[3].irq_fun=key4_irq;
*/
devfs_handle = devfs_register(null,device_name, devfs_fl_default,keypad_major, 0, s_ifchr | s_irusr | s_iwusr,&keypad_fops, null);
result = register_chrdev(keypad_major,device_name,&keypad_fops);
if(result<0)
{
printk(kern_info "[failed:cannot register keypad device!]\n");
return -eio;
}
else
printk("initializing keypad device\t---->\t\n");
keypad_setup();
//register the external interrupt
//for(i=0;i<4;i )
//{
set_external_irq(interrupt_k1, ext_falling_edge, gpio_pullup_en);
result=request_irq(interrupt_k1,&key1_irq,sa_interrupt,device_name,&key1_irq);
if (result<0)
{
printk(kern_info"[failed:cannot registe key1 interrupt!]\n");
return result;
}
else
printk("[key 1 has been registed!]\n"); set_external_irq(interrupt_k2, ext_falling_edge, gpio_pullup_en);
result=request_irq(interrupt_k2,&key2_irq,sa_interrupt,device_name,&key2_irq);
if (result<0)
{
printk(kern_info"[failed:cannot registe key2 interrupt!]\n");
return result;
}
else
printk("[key 2 has been registed!]\n"); set_external_irq(interrupt_k3, ext_falling_edge, gpio_pullup_en);
result=request_irq(interrupt_k3,&key3_irq,sa_interrupt,device_name,&key3_irq);
if (result<0)
{
printk(kern_info"[failed:cannot registe key3 interrupt!]\n");
return result;
}
else
printk("[key 3 has been registed!]\n"); set_external_irq(interrupt_k4, ext_falling_edge, gpio_pullup_en);
result=request_irq(interrupt_k4,&key4_irq,sa_interrupt,device_name,&key4_irq);
if (result<0)
{
printk(kern_info"[failed:cannot registe key4 interrupt!]\n");
return result;
}
else
printk("[key 4 has been registed!]\n");
//}
printk("keypad driver has been installed!\n");
return 0;
}
static void __exit keypad_cleanup(void)
{
//int i;
//for(i=0;i<4;i )
devfs_unregister(devfs_handle);
unregister_chrdev(keypad_major,device_name);
free_irq(interrupt_k1,key1_irq);
free_irq(interrupt_k2,key2_irq);
free_irq(interrupt_k3,key3_irq);
free_irq(interrupt_k4,key4_irq); printk("demo:keypad device is c
三星 arm9 linux,基于arm9内核三星s3c2410平台下linux四键按键驱动程序相关推荐
- linux程序卸载动态库,Intel平台下linux中ELF文件动态链接的加载、解析及实例分析(二): 函数解析与卸载...
在 IBM Bluemix 云平台上开发并部署您的下一个应用. 相信读者已经看过了 Intel平台下Linux中ELF文件动态链接的加载.解析及实例分析(一): 加载的内容了,了解了ELF文件被加载的 ...
- 【个人总结】基于项目的AI Studio平台下Linux深度学习环境配置心得
更新一下:现在AI Studio应该已经不能用其他深度学习框架了,用一会儿就会中断 前言 PS:本部分主要是对本周工作的总结,标题对应的内容可以跳过本部分 上周主要的工作是研究了一下项目utils文件 ...
- linux 音频驱动的流程,Intel平台下Linux音频驱动流程分析
[软件框架] 在对要做的事情一无所知的时候,从全局看看系统的拓扑图对我们认识新事物有很大的帮助.Audio 部分的驱动程序框架如下图所示: 这幅图明显地分为 3 级. 上方蓝色系的 ALSA Kern ...
- Linux 平台下PCI 接口视频采集卡的驱动程序编写技术
转自http://publishblog.blogchina.com/blog/tb.b?diaryID=2424186 Linux 平台下PCI 接口视频采集卡的驱动程序编写技术 李根深 邢汉承 0 ...
- linux怎么查看内核定义的结构体,Linux如何查找一个结构体的原始定义
下面以查找结构体FILE的原始定义为例: 1.我们知道,这些定义一般都在 /usr/include下面,所以首先到达目录 /usr/include 下面 2.用grep命令搜索 ,即grep FILE ...
- 矩形键盘 linux,基于ARM的矩阵键盘设计及其linux驱动实现
button_irqs [] ={ {IRQ_EINT8,S3C2410_GPG0,S3C2410_GPG0_EINT8, 0,"R1″}, {IRQ_EINT9,S3C2410_GPG1, ...
- linux mint 安装内核,使用Ukuu在Ubuntu/Linux Mint上安装Linux Kernel 5.0的方法
Linux Kernel 5.0已发布,具有大量新功能和错误修复,本文介绍使用Ukuu在Ubuntu 18.04/Linux Mint系统上安装Linux Kernel 5.0的方法.默认情况下,Ub ...
- keeplive linux平台下,Linux下搭建keepalive+nginx
一. 安装nginx(略) 二. 安装keepalive 安装依赖包 yum install –y popt* gcc* openssl* nmap tar fvxz keepalived-1.2.1 ...
- arm平台下linux c语言编程,简单分析针对ARM平台的C语言程序的编译问题
我们知道在C语言编译时,有那么几个常用的优化编译选项,分别是-O0,-O1,-O2,-O3以及-Os.之前一直觉得既然是优化选项,顶多是优化一下逻辑,提高一些效率或者减少一下程序大小而已.很少会觉得它 ...
最新文章
- SQL Server 2014 许可证(五)降级与升级
- SQL Server学习1(建数据库,建表,建约束)
- Form表单插件jquery.form.js
- 递归算法学习系列之寻找第K大
- csp 通信网络 java_CSP 通信网络
- 【网络传输与RTC】
- php页面修改器,读取器/修改器
- linux安装apache+mysql+php3.8练习环境
- java图的建立field_《Java虚拟机原理图解》1.4 class文件中的字段表集合--field字段在class文件中是怎样组织的...
- 计算机应用基础的文档,计算机应用基础
- IDEA中启动tomcat
- 万恶的火狐插件IE Tab Plus+引起的Superfish.com
- 奥尼捷多功能证件包护照包证件夹男士卡包女士必备 A101 黑色【图片 价格 品牌 报价】-京东商城...
- RabbitMQ高可用--Quorum Queue(仲裁队列)的原理
- 8个身家百万的儿童创业者
- GLSL——绘制平面图形(二)
- 夯实基础——P1830 轰炸III
- js中判断一个对象是否存在
- ffos下DTV开发总结
- socks5 转 http 代理