天嵌 ARM开发社区

 找回密码
 注册
查看: 2455|回复: 7

我想问一个很简单的问题关于led驱动的问题,希望指教……

[复制链接]
yunhen 发表于 2011-4-4 10:53:34 | 显示全部楼层 |阅读模式
我是刚学的,所以很多不懂,用的是tq2440,内核是2.6.30.4,按照手册led驱动的时候出现
它说implicit declaration of function 'class_decice_create',是不是头文件没包含进去?之前的错误什么s3c2410_GPB5没定义应该就是头文件路径错了,但是这个我不知道头文件是哪个?
我什么也不懂,第一次发帖,希望各位大神指教,谢谢了……
 楼主| yunhen 发表于 2011-4-4 14:00:17 | 显示全部楼层

能帮忙看看么?全部是按手册上做的
回复

使用道具 举报

shufexiu 发表于 2011-4-4 21:36:06 | 显示全部楼层
用这个函数
misc_register
回复

使用道具 举报

 楼主| yunhen 发表于 2011-4-9 23:16:34 | 显示全部楼层
群上的人帮忙解决了,谢谢他。
TQ2440在linux下控制LED实验
驱动程序:
#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>//官方此处为#i nclude <asm/arch/regs-gpio.h>
//#include <asm/arch/regs-gpio.h>
#include<mach/hardware.h>//官方为#i nclude <asm/hardware.h>
//#include <asm/hardware.h>
#include <linux/device.h>
#define DEVICE_NAME "EmbedSky-leds"
#define LED_MAJOR 231
#define IOCTL_LED_ON 1
#define IOCTL_LED_OFF 0
static unsigned long led_table [] =
{
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};
static unsigned int led_cfg_table [] =
{
S3C2410_GPB5_OUTP,
S3C2410_GPB6_OUTP,
S3C2410_GPB7_OUTP,
S3C2410_GPB8_OUTP,
};
static int EmbedSky_leds_open(struct inode *inode, struct file *file)
{
// int i;
// for (i = 0; i < 4; i++)
// {
// 设置GPIO 引脚的功能:本驱动中LED 所涉及的GPIO 引脚设为输出功能
// s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
// }
return 0;
}
static int EmbedSky_leds_ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
if (arg > 4)
{
return -EINVAL;
}
switch(cmd)
{
case IOCTL_LED_ON:
s3c2410_gpio_setpin(led_table[arg], 0);
return 0;
case IOCTL_LED_OFF:
s3c2410_gpio_setpin(led_table[arg], 1);
return 0;
default:
return -EINVAL;
}
}

static struct file_operations EmbedSky_leds_fops =
{
.owner = THIS_MODULE,
.open = EmbedSky_leds_open,
.ioctl = EmbedSky_leds_ioctl,
};
static char __initdata banner[] = "TQ2440LEDS";
static struct class *led_class;

static int __init EmbedSky_leds_init(void)
{
int ret;
printk(banner);

ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &EmbedSky_leds_fops);
if (ret < 0)
{
printk(DEVICE_NAME " can't register major number\n");
return ret;
}
//注册一个类,使mdev 可以在"/dev/"目录下面建立设备节点
led_class = class_create(THIS_MODULE, DEVICE_NAME);
if(IS_ERR(led_class))
{
printk("Err: failed in EmbedSky-leds class. \n");
return -1;
}
//创建一个设备节点,节点名为DEVICE_NAME
device_create(led_class, NULL, MKDEV(LED_MAJOR, 0), NULL, DEVICE_NAME);
//官方文档为class_device_create(led_class, NULL, MKDEV(LED_MAJOR, 0), NULL, DEVICE_NAME);
//class_device_create(led_class, NULL, MKDEV(LED_MAJOR, 0), NULL, DEVICE_NAME);
printk(DEVICE_NAME " initialized\n");
return 0;
}

static void __exit EmbedSky_leds_exit(void)
{

unregister_chrdev(LED_MAJOR, DEVICE_NAME);
device_destroy(led_class, MKDEV(LED_MAJOR, 0));
//删掉设备节点官方文档为class_device_destroy(led_class, MKDEV(LED_MAJOR, 0));
//class_device_destroy(led_class, MKDEV(LED_MAJOR, 0));
class_destroy(led_class); //注销类
}

module_init(EmbedSky_leds_init);
module_exit(EmbedSky_leds_exit);

MODULE_AUTHOR("http://www.embedsky.net");
MODULE_DESCRIPTION("TQ2440/SKY2440 LED Driver");
MODULE_LICENSE("GPL");
回复

使用道具 举报

Rick.w 发表于 2012-2-15 15:24:12 | 显示全部楼层
因为内核版本的不同 库什么的路径发生了变化 我先也没注意到这一点
在这里栽了跟头 感谢LZ问题解决后还把解决方法贴上来
回复

使用道具 举报

陈世超 发表于 2012-3-12 13:25:25 | 显示全部楼层
我的问题同上,求高手指导一下。
回复

使用道具 举报

陈世超 发表于 2012-3-12 13:40:30 | 显示全部楼层
非常感谢,刚才没看清楚,上面的很对,我编译通过而,非常感谢。
回复

使用道具 举报

afeikuo7 发表于 2012-8-9 16:56:23 | 显示全部楼层
shufexiu 发表于 2011-4-4 21:36
用这个函数
misc_register

为什么 我根据#include<xxxxx。h> 在内核include中添加相应的头文件不能通过呢? 说下大致原因吧~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2025-6-21 20:37 , Processed in 2.037802 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表