Led驱动程序及应用程序编写

本文介绍了LED驱动程序的编写,首先从LED的硬件原理图出发,理解其工作原理,然后列出驱动程序中成对出现的函数,并展示了手动创建设备节点的版本。此外,还提供了测试程序和shell脚本,帮助读者进行实践操作,熟悉驱动开发流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本来打算写一下NAND驱动和网卡驱动及USB驱动的,突然发现好长时间不写驱动,写驱动的套路都忘的差不多了,而且以前写的驱动程序都不够模块化,想复用的话还需要做些修改,所以,还是先写一下LED驱动,熟悉一下套路,顺便把程序模块化了,留着以后备用。

1.先看一下LED的硬件原理图


这里写图片描述


这里写图片描述

根据以上两张图片内容,可以列出如下表格:

LED-number LED-net GPIO
LED1 nLED_1 GPB5
LED2 nLED_2 GPB6
LED3 nLED_3 GPB7
LED4 nLED_4 GPB8

根据电路的基本知识,IO口低电平时,LED亮,IO口高电平时,LED灭.

CMD STATE GPIO-LEVEL
ON 0
OFF 1

用下列宏可以获得主设备号和次设备号

MAJOR(dev_t dev)
MANOR(dev_t dev)

用下列宏则可以通过主设备号和次设备号生成dev_t;

MKDEV(int major,int minor)

/**
Allocates a range of char device numbers.The major number will be chosen
dynamically ,and retured(along with the first minor number)in @dev.Returns zero or negative error code.
*/
int alloc_chrdev_region(dev_t *dev,unsigned baseminor,unsigned count,const char *name);
/*
This function will unregisters a range of @count device numbers,starting with @from,The
caller should normally be the one who allocated those numbers in the first place...
*/
void unregister_chrdev_region(dev_t from,unsigned count);

以上两个函数是动态分配设备号和注销设备号的函数,为了使函数可移植,使用上面两个函数处理设备号。

建立一个表格,列出成对出现的函数

Tables Are Cool
ioremap iounmap xxx

这里写图片描述
这里写图片描述

led驱动程序-手动创建设备节点版本

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <asm/irq.h><
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、付费专栏及课程。

余额充值