【Linux驱动】TQ2440 LED驱动程序

★总体介绍

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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值