LED驱动程序--可拓展的LED驱动程序

LED驱动程序–可拓展的LED驱动程序

一.把驱动拆分成通用的框架(leddrv.c),具体的硬件操作(board_X.c)

实现一个通用的框架leddrv.c和 具体的硬件操作。想要操作那个硬件就将相应的框架和硬件操作一起编译成对应的驱动程序。

二.以面向对象的思想,改进代码

抽象出一个结构体:

struct led_operations{
	int (*init) (int which);//初始化LED,which-哪个LED
	int (*ctl) (int which,int status);//控制LED,which 哪个LED,status;1-亮,0-灭
}

每个单板相关的board.c实现自己的led_operations结构体,供上层的leddrv.c调用
有四个文件,led_opr.h定义单板结构体,board_demo.c定义一个实实在在的单板,并且写传递这个单板的指针将用于leddrv.c,用于控制LED,其实就是在单板的控制函树套上一个外框满足read,open,write,close,等函数的外框。

三.怎么写LED驱动程序

详细步骤如下:
1.看原理图确定引脚,确定引脚输出什么点平才能点亮/熄灭LED
2.看芯片手册,确定寄存器操作方法;哪些寄存器?哪些位?地址是?
3.编写驱动程序:先写框架再写硬件操作的代码
注意:在芯片手册中去定的寄存器地址被称为物理地址,在Linux内核中无法直接使用。需要使用内核提供的ioremap函数把物理地址映射为虚拟地址,使用虚拟地址。
ioremap函数的使用:
1.函数原型:
void __iomem *ioremap(resource_size_t res_cookie,size_t size)
使用时,要包含头文件
#include<asm/io.h>
2.它的作用:
把物理地址phys_addr 开始的一段空间(大小为size),映射为虚拟地址;返回值是该段虚拟地址的首地址。
virt_addr = ioremap(puys_addr,size);
实际上,它是按页(4096字节)进行映射的,是整页整页地映射的。
假设phys_addr = ox10002,size = 4,ioremap 的内部实现是:
a.phys_addr按页取整,得到地址ox10000
b.size按页取整,得到4096
c.把起始地址0x10000,大小为4096的这一块物理地址空间,映射到虚拟地址空间,假设的得到的虚拟空间起始地址
为0xf001002
3.不再使用该段虚拟地址时,要iounmap(virt_addr);
void iounmap(volatile void __iomem * cookie)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HD2010操作说明(HD2010 operating instructions) ⅰ.软件安装(Installed software) 双击光盘HD2010 V2.0目录下的安装文件图标 ,将控制系统安装到个人电脑.如下图2-1 (Open Profile HD2010 V2.0 in the compact disk,Dblclick Installed the HD2010 V2.0 in your personal computer.As shown in Figure 2-1) 图(Figure)2-1 点击确定后进入下一步如图2-2 (Click确定intro- next step.As shown in Figure 2-2 ) 图(Figure)2-2 点击下一步后进入下一步(英文环境)在中文环境直接点击下一步完成安装)如图2-3 2-4 2-5 2-6 2-7 (Click next intro- next step.As shown in Figure 2-3 2-4 2-5 2-6 2-7) 图(Figure)2-3 注意:发送的文件保存在安装目录下的ProjFile文件夹里,点击下一步完成安装 (Announcements:The file what you send saved in the ProjFile in path of Install.And click next to install and finish) 图(Figure)2-4 图(Figure)2-5 图(Figure)2-6 安装最后一步如图2-7 (The final step of install. As shown in Figure 2-7) 图(Figure)2-7 点击完成打开软件主界面如图2-8 (Click finish open main interface of the software. As shown in Figure 2-8) ⅱ.软件设置(Setting software) ⅱ.ⅰ主界面如图2-8(Main interface.As shown in Figure 2-8) 图(Figure)2-8 ⅱ.ⅱ软件属性(Software properties) 1.文件菜单(File menu) a.新建--新建一个新的显示屏(New—Create a new screen) b.打开--打开一个显示屏(Open—Open a exist screen) c.保存--保存建立的文件(Save—Save file) d.另存为--保存副本(Save as—save a copy) e.导出.hds--导出.hds文件,用于u盘读取文件 (Export.hds—Export.hds file,for usb reading) f.退出--退出软件(Exit—Exit the software) 2.设置菜单(Settings menu) a.屏参设置--设置显示屏属性 (Screen settings—Display Screen configuration attributes) b.通信设置--通信端口/方式设置 (Communication settings—Set Communication prot and fashion) c.系统设置--配置系统默认项 (System settings—Set the acquice properties of software) 3.操作菜单(Operate menu) a.发送项目--发送节目(Send project—send the programmes) b.导出到U盘--把节目导入到U盘 (Export to U disk—send the programme to your U disk) c.时间设置--时间校对 (Time setting—get the right time im your computer) d.亮度设置--选择亮度模式 (Luminance setting—Choice the module of Luminance) e.固件更新--固件升级(Update Firmware—Update your controller Firmware) 4.语言菜单(Language menu) a.简体中文(Simplified Chinese) b.繁体中文(Chinese Traditional) c.英语(English) ⅱ.ⅲ节目编辑(Edit

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值