新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 嵌入式Linux之我行——LCD背光驅(qū)動(dòng)在2440上的實(shí)例開(kāi)發(fā)

嵌入式Linux之我行——LCD背光驅(qū)動(dòng)在2440上的實(shí)例開(kāi)發(fā)

作者: 時(shí)間:2016-11-20 來(lái)源:網(wǎng)絡(luò) 收藏
一、開(kāi)發(fā)環(huán)境
  • 機(jī):VMWare--Fedora 9
  • 開(kāi)發(fā)板:Mini2440--64MB Nand
  • 編譯器:arm-linux-gcc-4.3.2

二、實(shí)現(xiàn)步驟

本文引用地址:http://m.butianyuan.cn/article/201611/319005.htm

1. 硬件原理圖分析。由原理圖得知LCD的背光是由2440的GPG4口控制的

2. 編寫背光驅(qū)動(dòng)。文件名為my2440_backlight.c

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include
#include
#include
#include
#include

#defineDEVICE_NAME"backlight"//設(shè)備名稱
#defineDEVICE_MINOR5//次設(shè)備號(hào),這里我們將設(shè)備注冊(cè)為misc設(shè)備,這種設(shè)備的主設(shè)備號(hào)都為10

staticintmy2440_backlight_ioctl(structinode*inode,

structfile*file,

unsignedintcmd,

unsignedlongarg)
{
switch(cmd)
{
case0:

//當(dāng)接收的命令為0時(shí),就將GPG4引腳設(shè)為低電平,關(guān)閉背光
s3c2410_gpio_setpin(S3C2410_GPG4,0);
printk(DEVICE_NAME" turn off!n");
return0;
case1:

//當(dāng)接收的命令為1時(shí),就將GPG4引腳設(shè)為高電平,開(kāi)啟背光
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口的方式來(lái)控制背光
};

staticstructmiscdevice misc=
{
.minor=DEVICE_MINOR,
.name=DEVICE_NAME,
.fops=&dev_fops,
};

staticint__init dev_init(void)
{
intret;

ret=misc_register(&misc);//注冊(cè)成misc設(shè)備

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設(shè)備
}

module_init(dev_init);
module_exit(dev_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Huang Gang");
MODULE_DESCRIPTION("Backlight control for my2440");


3. 將驅(qū)動(dòng)添加到內(nèi)核中,這里我們將采用靜態(tài)加載的方法。

將my2440_backlight.c復(fù)制到內(nèi)核drivers/video/backlight/目錄下

#cp -f my2440_backlight.c linux-2.6.30.4/drivers/video/backlight/

修改backlight/目錄下的Kconfig文件,添加背光選項(xiàng)

#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. 配置內(nèi)核選項(xiàng),選中上面添加的配置項(xiàng)

Device Drivers --->
Graphics support --->
[*] Backlight & LCD device support --->
--- Backlight & LCD device support
<*> My2440 LCD Backlight Controls (NEW)
< > Lowlevel LCD controls
< > Lowlevel Backlight controls


5. 重新編譯內(nèi)核并下載到開(kāi)發(fā)板上,在開(kāi)發(fā)板/dev/目錄下建立設(shè)備的節(jié)點(diǎn)。設(shè)備名為backlight,主設(shè)備號(hào)為10,次設(shè)備號(hào)為5,在驅(qū)動(dòng)源碼里有注釋

#mknod /dev/backlight c 10 5

6. 編寫應(yīng)用程序測(cè)試背光驅(qū)動(dòng),文件名為backlight_test.c

#include
#include
#include
#include

intmain(intargc,char**argv)
{
intturn;
intfd;

//檢測(cè)命令后面帶的參數(shù)
if(argc==1||argc>2)
{
printf("Usage: backlight on|off!n");
exit(1);
}

//打開(kāi)背光設(shè)備
fd=open("/dev/backlight",O_RDWR);

if(fd<0)
{
printf("Open Backlight Device Faild!n");
exit(1);
}

//判斷輸入的參數(shù)
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);
}

//進(jìn)行IO控制
ioctl(fd,turn);

//關(guān)閉背光設(shè)備
close(fd);

return0;
}


7. 交叉編譯應(yīng)用程序,并下載到開(kāi)發(fā)板的/usr/sbin/目錄下

#arm-linux-gcc -o backlight_test backlight_test.c


8. 運(yùn)行效果。執(zhí)行應(yīng)用程序時(shí)內(nèi)核都會(huì)打印出背光狀態(tài)信息,同時(shí)觀察LCD的背光也得到了控制



評(píng)論


技術(shù)專區(qū)

關(guān)閉