android驱动例子(led灯控制),Android驱动例子LED灯控制.doc

【转】android 驱动例子(LED控制)

作者:gooogleman 来源:博客园 发布时间:2012-02-18 16:38 阅读:78 次 原文链接 [收藏]

本例子,讲述在android2.1上完全自已开发一个驱动去控制硬件口并写应用测试该驱动,通过这样一个例子,解析android下的驱动开发流程的应用调用流程,可以说是很好的入门引导。要达到的效果:通过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 ledtest2、在/driver/ledtest目录下,新建leddriver.c ,leddriver.h , Kconfig, Makefile 等4个文件leddriver.c#include #include #include #include /* For __init/__exit/... */#include #include #include #include #include #include #include #include #include #include #include #include #include //for register_chrdev()#include #include #include "leddriver.h"#include /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */#include /* For the watchdog specific items */#include /* For file operations */#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 /* GIO minor no. */static dev_t dev; //申 请 到的主 设备 号static struct cdev *cdev_p;static int openCnt;//--全局变量------------int VIB_major = 97;//we asigment it for testint 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 0x22static 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 = co

你可能感兴趣的:(android驱动例子(led灯控制),Android驱动例子LED灯控制.doc)