★总体介绍
LED驱动程序主要实现了TQ2440开发板上的4个LED灯的硬件驱动,实现了对引脚GPIOB5、GPIOB6、GPIOB7、GPIOB8的高低电平设置(common-smdk.c中已经实现了对引脚的配置),利用测试程序调用该驱动程序,通过命令控制LED灯的亮灭。
★详细介绍
1、驱动程序代码:My_led.c
#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 <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/device.h>
#define DEVICE_NAME "My_led" /**加载模块后执行cat/proc/devices中看到的设备名称**/
#define Led_MAJOR 103 /**主设备号**/
#define LED_ON 1
#define LED_OFF 0
/**Led的控制引脚**/
static unsigned long led_table[ ] =
{
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};
static int My_led_open(struct inode *inode,struct file *file)
{
printk("My_led open\n");
return 0;
}
static int My_led_ioctl(struct inode * inode, struct file * file,unsigned int cmd,unsigned long arg)
{
if(arg > 4)
{
return -1;
}
switch(cmd)
{
case LED_ON:
s3c2410_gpio_setpin(led_table[arg], 0);//设置指定引脚为输出电平为0
return 0;
case LED_OFF:
s3c2410_gpio_setpin(led_table[arg], 1);//设置指定引脚为输出电平为1
return 0;
default:
return -1