--作者:赖玉平(Peter Lai)aulyp@163.com
要达到的效果:通过android的应用,调用驱动程序,在开发板上控制4个LED的亮灭。
一、硬件原理
如上图,通过4个IO口控制这LED,低电平LED亮,
这4个IO口分别是GPM1, GPM2, GPM3, GPM4,
二、驱动程序
1、在kernel文件夹下的driver目录,新键驱动文件夹
# cd kernel_android_2.6.28.6/drivers
进到开发板的kernel目录,建驱动文件夹
#mkdir ledtest
2、在/driver/ledtest目录下,新建leddriver.c ,leddriver.h , Kconfig, Makefile 等4个文件
leddriver.c
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/module.h>
#include <mach/hardware.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <plat/gpio-cfg.h>
#include <plat/regs-clock.h>
#include <plat/regs-lcd.h>
#include <plat/regs-gpio.h>
#include <mach/map.h>
#include <linux/gpio.h>
#include <plat/gpio-bank-m.h>
#include <linux/cdev.h>
#include <linux/fs.h> //for register_chrdev()
#include <linux/device.h>
#include <mach/map.h>
#include "leddriver.h"
#include <linux/miscdevice.h>
#include <linux/watchdog.h>
#include <linux/fs.h>
#define Viberator_MAJOR 97 //主设备号
#define SCULL_NR_DEVS 4
#define SCULL_QUANTUM 4000
#define SCULL_QSET 1000
//---do as the GIO driver
#define DEVCOUNT 4
#define GIO_MINOR 2
static dev_t dev; //申 请 到的主 设备 号
static struct cdev *cdev_p;
static int openCnt;
//--全局变量------------
int VIB_major = 97;//we asigment it for test
int VIB_minor = 0;
int VIB_nr_devs = SCULL_NR_DEVS;
int VIB_quantum = SCULL_QUANTUM;
int VIB_qset = SCULL_QSET;
static struct class *vib_dev_class;
#define GPNCON S3C64XX_GPNCON
#define GPNDAT S3C64XX_GPNDAT
#define GPNPUD S3C64XX_GPNPUD
#define GPMCON S3C64XX_GPMCON
#define GPMDAT S3C64XX_GPMDAT
#define GPMPUD S3C64XX_GPMPUD
#define VIB_ON 0x11
#define VIB_OFF 0x22
static const struct file_operations GPIO_Viberator_ctl_ops={
.owner = THIS_MODULE,
.open = GPIO_VIB_open,
.read =GPIO_VIB_read,
.write =GPIO_VIB_write,
.ioctl = GPIO_VIB_ioctl,
.release =GPIO_VIB_release,
};
ssize_t GPIO_VIB_read(struct file * file,char * buf,size_t count,loff_t * f_ops)
{
char sdas[5]={1,3,8,1,6};
ssize_t status = 5;
unsigned long missing;
missing = copy_to_user(buf, sdas, stat