本文主要是介绍imx6q led灯驱动及测试代码(自动创建设备文件v1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
驱动层代码
/*************************************************************************
> File Name: led_drv.c
> Author: XXDK
> Email: v.manstein@qq.com
> Created Time: Sun 26 Feb 2017 04:28:00 AM PST
************************************************************************/
#include#include#include#include#include#include #include #define SABRESD_GPIO_LED4 IMX_GPIO_NR(3, 21) #define SABRESD_GPIO_LED5 IMX_GPIO_NR(3, 22) #define SABRESD_GPIO_LED6 IMX_GPIO_NR(3, 23) #define LED_ON 1 #define LED_OFF 0 struct led_resource { int gpio; char *name; int data; }; static struct cdev led_cdev; static dev_t led_dev_id; static struct class *cls; static struct led_resource led_res[] = { [0] = { .gpio = SABRESD_GPIO_LED4, .name = "xxdk_led4", }, [1] = { .gpio = SABRESD_GPIO_LED5, .name = "xxdk_led5", }, [2] = { .gpio = SABRESD_GPIO_LED6, .name = "xxdk_led6", } }; static int led_open(struct inode* ip, struct file* fp) { int i; printk("%s\n", __func__); for(i=0; i
应用层代码 /*************************************************************************
> File Name: led_test.c
> Author: XXDK
> Email: v.manstein@qq.com
> Created Time: Sun 26 Feb 2017 05:22:08 AM PST
************************************************************************/
#include#include#include#includeint main(void)
{
int fd;
fd = open("/dev/led@xxdk", O_RDWR);
if(fd < 0) {
printf("open led device failed!\n");
return -1;
}
sleep(3);
close(fd);
return 0;
}
Makefile代码 #Makefile
ifneq ($(KERNELRELEASE),)
obj-m += led_drv.o
else
KERNEL_DIR = /opt/EmbedSky/TQIMX6/TQ_COREC/linux_IMX6_CoreC_3.0.35_for_Linux
all:
PWD=$(shell pwd)
$(MAKE) -C $(KERNEL_DIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko *.tmp_versions module* Module*
endif
这篇关于imx6q led灯驱动及测试代码(自动创建设备文件v1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!