内核版本:linux2.6.22.6 硬件平台:JZ2440

驱动源码 key_drv.c :

#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<linux/init.h>
#include<linux/delay.h>
#include<asm/uaccess.h>
#include<asm/irq.h>
#include<asm/io.h>
#include<asm/arch/regs-gpio.h>
#include<asm/hardware.h> static struct class *key_class;
static struct class_device *key_class_device; volatile unsigned long *GPFCON=NULL;
volatile unsigned long *GPFDAT=NULL;
volatile unsigned long *GPGCON=NULL;
volatile unsigned long *GPGDAT=NULL; static int key_drv_open(struct inode *inode,struct file *file)
{
*GPFCON &= (~((0x03<<)|(0x03<<)));
*GPGCON &= (~((0x03<<)|(0x03<<))); return ;
} ssize_t key_drv_read(struct file *file,const char __user *buf,size_t count,loff_t *ppos)
{
unsigned char key_val[]={};
unsigned long keyval=; if(count != sizeof(key_val)) return -EINVAL; keyval = *GPFDAT;
key_val[] = (keyval & (<<))?: ;
key_val[] = (keyval & (<<))?: ; keyval = *GPGDAT;
key_val[] = (keyval & (<<))?: ;
key_val[] = (keyval & (<<))?: ; copy_to_user(buf,key_val,sizeof(key_val)); return sizeof(key_val);
} static struct file_operations key_drv_mode=
{
.owner = THIS_MODULE,
.open = key_drv_open,
.read = key_drv_read,
}; int major=;
static int key_drv_init(void)
{
major = register_chrdev(,"key_drv",&key_drv_mode); key_class = class_create(THIS_MODULE,"key_class");
key_class_device = class_device_create(key_class,NULL,MKDEV(major,),NULL,"key_devices"); GPFCON=(volatile unsigned long *)ioremap(0x56000050,);
GPFDAT=GPFCON+;
GPGCON=(volatile unsigned long *)ioremap(0x56000060,);
GPGDAT=GPGCON+; return ;
} static void key_drv_exit(void)
{
unregister_chrdev(major,"key_drv"); class_device_unregister(key_class_device);
class_destroy(key_class);
iounmap(GPFCON);
iounmap(GPGCON); } module_init(key_drv_init);
module_exit(key_drv_exit);
MODULE_LICENSE("GPL");

测试应用程序 key_drv_test.c :

#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h> int main(int argc,char **argv)
{
int fd=;
int cnt=;
unsigned char key_val[]={,,,};
fd = open("/dev/key_devices",O_RDWR);
if(fd <) printf("error: can't open device :/dev/key_devices"); while()
{
read(fd,key_val,sizeof(key_val));
if(!key_val[]) printf("key1 is down\n");
if(!key_val[]) printf("key2 is down\n");
if(!key_val[]) printf("key3 is down\n");
if(!key_val[]) printf("key4 is down\n");
}
return ;
}

Makefile文件:

KER_DIR=/work/systems/kernel/linux-/linux-2.6.22.6

all:
make -C $(KER_DIR) M=`pwd` modules clean:
make -C $(KER_DIR) M=`pwd` modules clean
rm -fr moudles.order obj-m +=key_drv.o

按键控制led驱动的更多相关文章

  1. 集齐所有机制的按键控制LED驱动

    内核版本:linux2.6.22.6 硬件平台:JZ2440 驱动源码 final_key.c : #include <linux/module.h> #include <linux ...

  2. 51单片机-独立按键控制led矩阵的左移和右移

    51单片机学习 独立按键 控制led灯光矩阵的左移和右移 开发板采用的是普中的A2学习开发板,具体的代码如下: typedef unsigned int u16; void delay(u16 tim ...

  3. 外部按键 控制 LED 中断 (参考 http://www.oschina.net/question/565065_115196?sort=time )

    转帖: http://www.oschina.net/question/565065_115196?sort=time 实验目的: mini2440开发板上有6个按键,将其中的前4个按键设为外部中断方 ...

  4. CC2530学习路线-基础实验-GPIO 按键控制LED灯亮灭(2)

    目录 1.前期预备知识 1.1 新大陆Zigbee模块按键电路图 1.2 CC2530相关寄存器 1.3 CC2530中断走向图 1.4 使用C语言为51单片机编写中断程序 1.5 *函数指针 2. ...

  5. 基于Arduino的按键控制LED实验

    I/O 口的意思即为INPUT 接口和OUTPUT 接口,到目前为止我们设计的小灯实验都还只是应用到Arduino 的I/O 口的输出功能,这个实验我们来尝试一下使用Arduino的I/O 口的输入功 ...

  6. 【嵌入式】——arm裸机开发 step by step 之 按键控制 LED 和 蜂鸣器

    一.arm-9 TQ2440 key.h #ifndef __KEY_H__ #define __KEY_H__ #define GPFCON (*(volatile unsigned long *) ...

  7. 安卓控制LED驱动编写

    开发平台 * 芯灵思SinlinxA33开发板 淘宝店铺: https://sinlinx.taobao.com/ 嵌入式linux 开发板交流 QQ:641395230 打开Android Stud ...

  8. 按键控制LED灯-ESP32中断处理

    #include <driver/gpio.h> #include <esp_task_wdt.h> #include <freertos/FreeRTOS.h> ...

  9. 独立按键控制led灯

    #include "regx51.h"typedef unsigned int u16; void delay_us(u16 time){ while(time--){} }voi ...

随机推荐

  1. 教你一招:win10下JDK的安装与环境变量配置

    1.到官网下载最新版本的JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.安装JDK,同安装其他软件一样 ...

  2. Git 修正错误

    大部分的人都会犯错.所以每VCS提供了一个功能,修正错误,直到特定的点. Git提供功能使用,我们可以撤销已作出的修改到本地资源库. 假设用户不小心做了一些更改,以他的本地的仓库,现在他要扔掉这些变化 ...

  3. 基金 、 社保和QFII等机构的重仓股排名评测

    来源:基金前20大重仓股持仓股排名 基金前15大重仓股持仓股排名 基金重仓前15大个股,相较于同期沪深300的平均收益, 近1月:2.23%, 近3月:3.09%, 近6月:9.61%, 近1年:13 ...

  4. No suitable servers found (`serverselectiontryonce` set): [Failed connecting to '115.28.161.44:27017': Connection timed out] php mongodb 异常

    我 php mongodb 拓展使用的是  MongoDB driver 今天查询数据的时候 偶尔会提示, No suitable servers found (`serverselectiontry ...

  5. 使用Anaconda3配置多版本Python虚拟开发环境

    有时候,为了使用比较干净的开发环境,或者为了测试一些版本的扩展库,我们可能需要创建虚拟开发环境,在不同的虚拟开发环境中,只安装需要的扩展库,这样可以最大程度上减少不同扩展库之间的兼容性带来的冲突或其他 ...

  6. officewebapps 服务器部署问题

    officewebapps 服务器部署问题 部署文档 http://technet.microsoft.com/zh-cn/library/jj219455 New-OfficeWebAppsFarm ...

  7. 查找C++代码中某一范围内的内存泄露

    #include <string.h> #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> int _tmain(int argc, _ ...

  8. MySQL+Amoeba实现数据库读写分离

    参考:https://www.cnblogs.com/liuyisai/p/6009379.html 一,Amoeba是什么 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与C ...

  9. 腾讯云短信服务使用记录与.NET Core C#代码分享

    1.即使是相同的短信签名与短信正文模板,也需要针对“国内文本短信”与“海外文本短信”分别申请.开始不知道,以为只要申请一次,给国外手机发短信时给api传对应的国家码就行,后来才发现需要分别申请. 2. ...

  10. Sql Server :SELECT a.*,b.HZXM FROM YG_LIS_JCBYTK a(nolock)中的NOLOCK作用

    转自 http://blog.csdn.net/xingxing1828/article/details/34850771 先说下其区别,之后再做测试. 大家都知道,每新建一个查询,都相当于创建一个会 ...