版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一个在PC上注册的led类打印设备及操作方法/*leds_w380.c*/include include #include #include include linux/string#includc #includc #includc 严* Blue led.* (it can only be blue flashing led)*/static void w38O_blueled_set(struct Ied_classdev *lcd_dcv, enum Ied_brightness value)s3c_gpio_cfgpii】(S5PV210_GPJ3(4), S3C_GPIO_SFN(
2、2); /s3c_gpio_setpull(S5PV210_GPJ3(4), 0);switch (value) case LED_HALF:s3c_gpio_sctpin(S5PV210_GPJ3(4), 1); printk(Mw3801eds_onnH);break:case LED_FULL:s3c_gpio_sctpin(S5PV210_GPJ3(4), 1); printk(Mw3801eds_oniiH);break:default:case LED_OFF:/s3c_gpio_setpin(S5PV210_GPJ3(4), 0);primk(”v7w3801cds_offn”)
3、;break;static ssizej w380_blue_show(struct device *dcv,struct device_attribute *attr, char *buf)struct lcd_classdcv *bled =container_of(dev,stnict lcd_classdc:dcv );/w380_blueled_set(bled); return sprintf(buf, ,r%unM, 0);static ssizej w380_blue_store(struct device *dev, struct deviceattribute *attr,
4、 const char *buf, sizej count)struct lcd_classdcv *blcd =container_of(dev,stnict lcd_classdcv.dcv );w380_bluelcd_set(bled.255);return 0;static DEVICE_ATTR(bIue, 0644、w380_bluc_show, w380_blue_store);static stnict attribute *w3801ed_attributes = & dev_attr_blue.attr.NULLstatic stnict attribute_group
5、w3801ed_attribute_group = ars = w3801ed_at tributesstatic stnict led_classdev w380_blueIed = .name= Hw38O:blue.brightness_set= w380_blueled_set,;*/static int w3801eds_probe(stnict platforni_device *pdcv)int ret;printk(Hw3801eds_probenM);ret = Ied_classdev_register(&pdcvdcv, &w380_blueled);if (ret)go
6、to err_blue; printk(Hw380Ieds_probe_device_create_fiIenH);/ret = device_create_file(&pdev-dev, &dev_attr_blue);/ret = sysfs_creatc_group(&pdcvdcv.kobj, &w3801ed_attribute_group); printk(,w3801eds_probe_device-create-file00000nn);if (ret != 0)dev_err(&pdcvdcvNo source control for LED: %dnM, ret);retu
7、rn 0;err_blue:dev_err(&pdcvdcv, lcd_classdcv_rcgislcr failednM); printk(Hw3801eds_probefaiIednH);lcd_classdev_unregister(&w380_blueled);static int w3801eds_remove(struct platform_device *pdev)led_classdev_unregister(&w380_bluclcd);return 0;static stnict platforni_driver w3801eds_driver = .driver= .n
8、ame= Mw380Jeds*.owner= THIS_MODULE.,.probe= w3801eds_probe,.remove= w3801cds_rcmovc,;static stnict platform_device w3801cds_dcvicc = .name = Hw380Jeds;static int _init w3801edsjnit(void)printk(ww3801edsJnitnH);printk(uw3801edsJnitnH);int ret;ret=platforin_driver_register(&w3801cds_drivcr);if(!ret) p
9、rintk(Hplatforni_dcvice_registerir,);ret = platform_device_register(&w3801eds_device);if (ret)printk(,platform_driver_unregisternu); platform_driver_unregister(&w3801eds_driver);)return ret;static void exit w3801cds_exit(void)printk(Hw3801eds_exitnM);platform_device_register(&w3801cds_dcvicc); platf
10、orm_driver_unregister(&w3801eds_driver);module_init(w3801edsjnit);module_exit(w3801eds_exit);MODULE_AUTHOR(Hwang tao H);MODULE_DESCRIPTION(MLED driver for the w38OH);M0DULE_LICENSE(9PLJ;MODULE_ALIAS(Mplatform:w380Jedsn);其Makefile文件如下:注意命令的开头是一个tabifneq ($( KERNELRELEASE),)#kbuild syntax. dependency
11、relationshsip of files and target modules are listed here.mymodule-objs := leds_w380.oobj-m := leds_w380.oelsePWD := $(shell pwd)KVER ?= $(shell uname -r)KDIR := /lib/modules/$(KVER)/buildall:$(MAKE) -C $(KDIR) M=$(PWD)clean:rm -rf *.cmd *.o *.mod.c *.ko .tmp_versions end if步骤一:编译,make 一下生成lcds_w380
12、.o和lcds_w380ko等步骤二:复制,将 lcds_w380.ko 复制至iJ/lib/module/2.6.32-21 -generic/kernel/drivers/leds F 步骤三:加载 sudo modprobe lcds_w380Sudo rmmod lcds_w380.koSudo insmod lcds_w380.ko这样反复的目的是利用modprobe的依赖关系。00 lxxulinux: -/shares/test/iedFile Edit View Terminal Helplxxulinux:$ cd shares/test/led/ lxxjlinux:/sh
13、ares/test/leds make make -C /lib/modules/2.6.32-21-generic/build M=/home/lxx/shares/test/led makel: Entering directory /usr7src/liniixheaders26.32-2generic1cc M /home八xx/shares7test/led/leds_w380o /home/lxx/shares/te5t/l.ed/leds_w380. c: In function 4w3801ed5_init *: /home/lxx/shares/test/led/leds_w
14、380.c:140: warning: ISO C90 forbids roixed declar ations and code/home/lxx/shares/test/led/leds_w380.c: In function w380leds_probe: /home/lxx/shares/test/led/leds_w380.c:112: warning: control reaches end of non oid functionBuilding modules, stage 2MODPOST 1 modulesCC /home/lxx/shares/test/led/leds_w
15、38D.mod.oLD M /home/lxx/shares/test/led/leds2w389.koleds_w380 onodules.orderMakefileModule syroversleds w380.ko leds jv380.mod.c leds w380.mod.o lxxaulinux:Vshares/test/leds c/kernel/drivers/leds/ sudo password for Ixx: ixxulinux:-/shares/test/leds lxxjlinux:/shaes/test/leds lxxulinux:-/shares/test/
16、ledsmakel: Leaving directory /usr/src/linux-headers-2.5.32-21-generic lxxulinux:-/shares/testAedS Is built-in.oMakefile.bakcp leds_w380.ko /lib/modules/2.6.32-21-generileds_w38e.csudosudo sudo sudoleds w386.c.bakmodprobe leds_w38 rmnod leds_w380.ko insmod leds w380.kolxxulinux:-/shares/test/leds |步骤
17、四:成功验证,Sudo lsmodRxxulinux:*/shares/test/led$ IsDuilt-in.oledsw380.koleds w336.cledsw380.mod.cleds w38G.c.bak leds w380.mod.o Lxxulinux:-/shares/test/led$ sudoc/kernel/drivers/leds/sudo password for Ixx: lxxulinux:*/sha res/test/led$ lxxulinux:-/shares/test/led$ lxxulinux:Vshares/test/led$ lxx(aulin
18、ux:*-/shares/test/led$Leds_w380 omodules o rderMakefileModule symversMakefile.bakcp leds_w380.ko /lib/modules/2.6.32-21-generiModule leds w380 ledclass vsock vmmenic tl vmblock i/mci vmhgfs pvscsiSize17452864370707296 10766 26826 48805 11732sudo modprobe leds w380 sudo rnmod Leds_w380.ko sudo insnri
19、od leds_w38G ko sudo IsmodUsed by01 leds w3800e11 vsock10以下是测试代码:/*ledtest.c*/#includc #include #include /include /#include #define DEVNAME 7sys/class/leds/w38O:blue/brightnessH /*需要注意的是这个宏可以针对操作不同的设备而修改*/ static int writejnt(char const* path, int value)int fd;static int already.warned = 0;fd = open
20、(path. O_RDWR);if (fd = 0) char buffer20;int bytes = sprintf(buffer, M%dnn, value); printf(Hbuffer:%sn, buffer);int amt = write(fd buffer, bytes);close(fd);return amt = -l ? 1: 0; else if (already_warned = 0) printf(Mwrite_int failed to open %sn”,path); already_warned = 1;)return -1;int main(int arg
21、c, char *argv)int turn;检测命令后而带的参数if(argc = 1 II argc 2)printf(uUsage: Led onloff!nM); exit(l);判断输入的参数if(strcmp(argvl, HonH) = 0)turn = 255; printf(uUsage: Led on!nH);else if(strcmp(argvl, off1) = 0)turn = 0;printf(uUsage: Led off!nN);elseprintf(uUsage: Led onloff!nM); exit(l);write_int(DEVNAME.turn)
22、;return 0;进入lcdtest g录,编译生成ledtest执行/ledtest on0 0 0 lxxulinux: /sl Browse the World Wide WebFile Edit view Terminal Helpmptscsih313251 mptspimptbase830222 mptspi,mptscsihfloppy530160scsi transportspi210961 mptspivmxnet154180lxx(aul.inux:-/shares/test/led$ cd . lxxulinux:/shares/test$ Iscmd.txt H le
23、dtest ledtest.c ledtest.c.bak Makefile Makefile.bak lxxulinux:/shdes/test$ nakeMakefile:l: * commands commence before first target Stop lxx(aulinux:Vshares/test$ gcc -o ledtest ledtestc lxxulinux:-/shares/test$ /ledtest onUsage: Led on!writeint failed to open /sys/class/leds/w380:blue/brightness lxx
24、ulinux:-/shares/test$ sudo /ledtest onUsage: Led on!buffer:255lxxulinux:*/shares/test$ sudo ./ledtest off Usage: Led off!buffer:lxxulmux:-/shares/test$执行dmesg查看结果:O O lxxulinux: -*/shares/testFile Edit View Iferminal Help=691 n ame=,7usr/lib/cups/backend/cups-pdf,18.336168 type=i505 audit(1293694211.023:1引:operaTion=*profile_IoadM pid=691 nafne=M /usr/sbin/cupsdn8.38
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023-2024学年湖北省襄阳市襄州区片区联考七年级9月月考语文试题含答案
- 河北版小学科学三年级下册教案 全册
- 人教版小学语文五年级上册教案 全册
- 2024-2025年秋季第一学期小学升旗仪式演讲安排表+2024-2025学年度第一学期国旗下讲话安排表
- 保育员培训-卫生清洁与消毒
- 妊娠高血压综合征病人的护理课件
- 世界是永恒发展的+学案 高中政治统编版必修四哲学与文化
- 大学美育 课件 第三篇 第四章 第一节 仪容添彩
- 高一上学期第三周周测数学试题
- 应用文写作+邮件+学校上周举办了高三启动仪式(Kick-off+Ceremony)+讲义 高三上学期摸底联考英语试题
- 浅谈劳动教育在小学体育课程中的运用 论文
- CFA计算器德州仪器BAII说明书中文版
- 基于核心素养导向大单元教学设计培训课件(共41张ppt)
- 钢管贝雷梁柱式支架法整体现浇箱梁施工技术
- 普通话和方言(人教版高二选修) 教案教学设计共3篇
- 高三英语试卷doc
- 工程项目客户评价表
- 数字技术的发展历程
- (2023)纪检监察考试题库(附参考答案)
- (3.3.1)-免疫治疗作用机制
- 《单人旁双人旁》教学设计
评论
0/150
提交评论