按照实例一,实现了从应用程序空间向内核空间传递数据,这一例实现从内核读取按键值到应用空间,然后把刚刚保存在应用空间按键值写到内核空间,内核空间按键值来操作对应的LED
驱动源码:keys_leds.c
驱动源码Makefile
测试源码: keys_leds_test.c
keys_leds.c:
/***************************************************************
* filename: keys_leds.c
* description: 无按键按下,熄灭全部LED,按键按下,点亮相应LED,松开熄灭相应LED
* author: xyc
* create time: 2014/6/2
* version:1
* modify info:
******************************************************/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <asm-arm/io.h>
#include <asm-arm/uaccess.h>
static int KEYS_LEDS_MAJOR;
static struct class *keys_leds;
static struct class_device *keys_leds_dev;
static volatile unsigned long *gpfcon=NULL;
static volatile unsigned long *gpfdat=NULL;
static int keys_leds_open(struct inode *inode, struct file *file)
{
/*配置按键为输入,LED为输出*/
*gpfcon &= ~(0x3<<(4*2)) & (~(0x3<<(0*2))) & (~(0x3<<(5*2)) ) & (~(0x3<<(2*2)));
*gpfcon |= 0x1<<(4*2) |(0x0<<(0*2)) | (0x1<<(5*2) )|(0x0<<(2*2));
*gpfdat |=1<<4|1<<5;
return 0;
}
static ssize_t keys_leds_read(struct file *file, char __user *userbuf, size_t count, loff_t *off)
{
char val =0;//初始化为0不要忘
/*记录按下的键*/
if( !(*gpfdat &a
版权声明:本文为ychongx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。