一、开发环境
- 主机:VMWare–Fedora 9
- 开发板:Mini2440–64MB Nand
- 编译器:arm-linux-gcc-4.3.2
二、完成过程
1. 硬件原理图剖析。由原理图得知LCD的背光是由2440的GPG4口操控的

2. 编写背光驱动。文件名为my2440_backlight.c
#include#include#include#include#include#include#include#include#include#include
#include #include #include #include #include#include #include
#defineDEVICE_NAME“backlight”//设备称号 #defineDEVICE_MINOR5//次设备号,这儿咱们将设备注册为misc设备,这种设备的主设备号都为10
staticintmy2440_backlight_ioctl(structinode*inode,
structfile*file,
unsignedintcmd,
unsignedlongarg) { switch(cmd) { case0:
//当接纳的指令为0时,就将GPG4引脚设为低电平,封闭背光 s3c2410_gpio_setpin(S3C2410_GPG4,0); printk(DEVICE_NAME” turn off!\n”); return0; case1:
//当接纳的指令为1时,就将GPG4引脚设为高电平,舱位背光 s3c2410_gpio_setpin(S3C2410_GPG4,1); printk(DEVICE_NAME” turn on!\n”); return0; default: return-EINVAL; } }
staticstructfile_operations dev_fops= { .owner=THIS_MODULE, .ioctl=my2440_backlight_ioctl,//这儿只运用操控IO口的办法来操控背光 };
staticstructmiscdevice misc= { .minor=DEVICE_MINOR, .name=DEVICE_NAME, .fops=&dev_fops, };
staticint__init dev_init(void) { intret;
ret=misc_register(&misc);//注册成misc设备
if(ret<0) { printk(“Register misc device fiald!”); returnret; }
//将GPG4口装备成输出口 s3c2410_gpio_cfgpin(S3C2410_GPG4,S3C2410_GPG4_OUTP);
returnret; }
staticvoid__exit dev_exit(void) { misc_deregister(&misc);//刊出该misc设备 }
module_init(dev_init); module_exit(dev_exit);
MODULE_L%&&&&&%ENSE(“GPL”); MODULE_AUTHOR(“Huang Gang”); MODULE_DESCRIPTION(“Backlight control for my2440”);
|
3. 将驱动增加到内核中,这儿咱们将选用静态加载的办法。
将my2440_backlight.c复制到内核drivers/video/backlight/目录下
#cp -f my2440_backlight.c linux-2.6.30.4/drivers/video/backlight/
|
修正backlight/目录下的Kconfig文件,增加背光选项
#gedit linux-2.6.30.4/drivers/video/backlight/Kconfig
|
configMY2440_LCD_BACKLIGHT tristate“My2440 LCD Backlight Controls” dependsonBACKLIGHT_LCD_SUPPORT default y
|
修正backlight/目录下的Makefile文件,在最终一行增加
#gedit linux-2.6.30.4/drivers/video/backlight/Makefile
|
obj-$(CONFIG_MY2440_LCD_BACKLIGHT)+=my2440_backlight.o
|
4. 装备内核选项,选中上面增加的装备项
Device Drivers —> Graphics support —> [*] Backlight & LCD device support —> — Backlight & LCD device support <*> My2440 LCD Backlight Controls (NEW) < > Lowlevel LCD controls < > Lowlevel Backlight controls
|
5. 从头编译内核并下载到开发板上,在开发板/dev/目录下树立设备的节点。设备名为backlight,主设备号为10,次设备号为5,在驱动源码里有注释
#mknod /dev/backlight c 10 5
|
6. 编写应用程序测验背光驱动,文件名为backlight_test.c
#include #include #include #include
intmain(intargc,char**argv) { intturn; intfd;
//检测指令后面带的参数 if(argc==1||argc>2) { printf(“Usage: backlight on|off!\n”); exit(1); }
//翻开背光设备 fd=open(“/dev/backlight”,O_RDWR);
if(fd<0) { printf(“Open Backlight Device Faild!\n”); exit(1); }
//判别输入的参数 if(strcmp(argv[1],“on”)==0) { turn=1; } elseif(strcmp(argv[1],“off”)==0) { turn=0; } else { printf(“Usage: backlight on|off!\n”); exit(1); }
//进行IO操控 ioctl(fd,turn);
//封闭背光设备 close(fd);
return0; }
|
7. 穿插编译应用程序,并下载到开发板的/usr/sbin/目录下
#arm-linux-gcc -o backlight_test backlight_test.c
|
8. 运转作用。碑文应用程序时内核都会打印出背光状况信息,一起调查LCD的背光也得到了操控
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/264539.html