内核版本: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. Gsoap编译

    gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多.gSOAP支持大多数平台,包括嵌入式系统和小系统. 你首先 ...

  2. Android控件源码分析--AndroidResideMenu菜单

    说明 早上看到一篇文章介绍了ResideMenu得使用,这是一个类似SlidingMenu的控件,感觉有点高尚大,反正我之前没见过,本着凑热闹的好奇心,立马clone把玩下,项目地址奉上: https ...

  3. 一起了解下Centos中‘vim配置’有多强大?

    在linux的系统上安装vim编辑器后,发现vim的页面设置还是不太习惯,没有显示的行号,也没有自动的缩进,页面的背景也不是很好看,但是vim编辑器是可以进行配置的,我们可以打造属于自己的vim风格. ...

  4. Python爬虫学习——使用selenium和phantomjs爬取js动态加载的网页

    1.安装selenium pip install selenium Collecting selenium Downloading selenium-3.4.1-py2.py3-none-any.wh ...

  5. [Hinton] Neural Networks for Machine Learning - Bayesian

    Link: Neural Networks for Machine Learning - 多伦多大学 Link: Hinton的CSC321课程笔记 Lecture 09 Lecture 10 提高泛 ...

  6. ThinkingInJava 学习 之 0000006 复用类

    1. 组合语法 将对象引用置于新类中. 2. 继承语法 衍生类自动获得基类中所有的域和方法 super关键字表示基类. 1. 初始化基类 当创建一个衍生类的对象时,该对象创建一个基类的子对象并包含子对 ...

  7. 51 IP核查询

    康芯的IP核 Oregano systems 公司的MC8051 IP CoreSynthesizeable VHDL Microcontroller IP-Core User Guide这个里面51 ...

  8. Orleans学习总结(五)--监控篇

    上篇说完了Orleans学习总结(四)--集群配置篇,这次我们来说下监控 Orleans有一个强大的社区,为Orleans开发着各种各样的扩展工具,我们用的是OrleansDashboard.Dash ...

  9. python string.py 源码分析 二:capwords

    def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into ...

  10. IDEA中将WEB-INF\lib下的Jar包添加到项目中

    打开Project Structure[可以使用快捷键:Ctrl+Alt+Shift+S]左侧选中Modules,在Dependecies中,点击右侧“+”号,选择JARS or directorie ...