一、开发环境
主 机:fedora 14
(2.6.33.7)
开发板:FL2440(nandflash:K9F1G08
128m)
编译器:arm-linux-gcc 4.3.2
二、原理分析
硬件原理图分析。由原理图得知LCD的背光是由2440的GPG4口控制的,只要往GPG4口写入高电平,(1)则背光打开,写入低电平(0)则背光关闭。
三、实现步骤
1. 编写背光驱动。文件名为fl2440_backlight.c
- /*
- *==============================================
- *Name : fl2440_backlight.c
- *Author : y.q.yang
- *Date : 17/2/2011
- *Copyright : GPL
- *Description : fl2440 lcd backlight driver
- *==============================================
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/errno.h>
- #include <mach/hardware.h>
- #include <mach/regs-gpio.h>
- #include <mach/gpio-fns.h>
- #include <mach/gpio-nrs.h>
- #define DEVICE_NAME
“fl2440_backlight” - #define DEVICE_MAJOR 230
- #define BL_OFF 0
- #define BL_ON 1
- #define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
- #define S3C2410_GPIO_BANKG (32*6)
- #define S3C2410_GPG4
S3C2410_GPIONO(S3C2410_GPIO_BANKG, 4) - static int bl_open(struct inode *inode, struct file *filp)
- {
- return 0;
- }
- static int bl_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
- {
- if(cmd<0 || cmd>1)
- {
- return -EINVAL;
- }
- switch(cmd)
- {
- case BL_ON:
- {
- s3c2410_gpio_setpin(S3C2410_GPG4,BL_ON);
- printk(DEVICE_NAME ”
turn on!\n”); - break;
- }
- case BL_OFF:
- {
- s3c2410_gpio_setpin(S3C2410_GPG4,BL_OFF);
- printk(DEVICE_NAME ”
turn off!\n”); - break;
- }
- default:
- printk(“cmd
default!\n”); - return -EINVAL;
- }
- return 0;
- }
- struct file_operations bl_fops =
- {
- .owner = THIS_MODULE,
- .open = bl_open,
- .ioctl = bl_ioctl,
- };
- static int __init
bl_init(void) - {
- int ret;
- s3c2410_gpio_cfgpin(S3C2410_GPG4, 0×1 << 8);
- s3c2410_gpio_setpin(S3C2410_GPG4, BL_ON);
- ret = register_chrdev(DEVICE_MAJOR, DEVICE_NAME, &bl_fops);
- if(ret<0)
- {
- printk(“register
failed!\n”); - return ret;
- }
- return ret;
- }
- static void __exit
bl_exit(void) - {
- unregister_chrdev(DEVICE_MAJOR, DEVICE_NAME);
- }
- module_init(bl_init);
- module_exit(bl_exit);
- MODULE_LICENSE(“GPL”);
- MODULE_AUTHOR(“y.q.yang”);
- MODULE_DESCRIPTION(“FL2440 backlight
driver”);
2. 把背光驱动代码部署到内核中去
- #cp -f
fl2440_backlight.c /linux-2.6.33.7/drivers/char //把驱动源码复制到内核驱动的字符设备下 - #vim /linux-2.6.33.7/drivers/char/Kconfig //添加LCD背光设备配置
- config FL2440_BACKLIGHT
- tristate “FL2440 Backlight
Device” - depends on ARCH_S3C2440
- default y
- ---help---
- FL2440 User Backlight
- #vim /linux-2.6.33.7/drivers/char/Makefile //添加LCD背光设备配置
- obj-$(CONFIG_FL2440_BACKLIGHT) += fl2440_backlight.o
3. 配置内核,选择LCD背光设备选项
- #make menuconfig
- Device
Drivers ---> - Character
devices ---> - <*> FL2440 Backlight
Device (NEW)
4. 编译内核并下载到开发板上,查看已加载的设备:#cat
/proc/devices,可以看到fl2440_backlight的主设备号为230
- 90 mtd
- 99 ppdev
- 116 alsa
- 128 ptm
- 136 pts
- 180 usb
- 188 ttyUSB
- 189 usb_device
- 204 s3c2410_serial
- 230 fl2440_backlight
- 231 fl2440_leds
- 232 fl2440_buttons
- 254 rtc
- Block devices:
- 1 ramdisk
- 259 blkext
四、测试驱动
1. 编写应用程序测试LED驱动,文件名:bl_test.c
- /*
- *==============================================
- *Name : bl_test.c
- *Author : y.q.yang
- *Date : 17/2/2011
- *Copyright : GPL
- *Description : fl2440 lcd backlight test
- *==============================================
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- int main(int argc, char **argv)
- {
- int turn,fd;
- if(argc == 1 || argc >2)
- {
- printf(“Usage:
bl_test on|off\n”); - exit(1);
- }
- fd = open(“/dev/fl2440_backlight”, 0);
- if(fd<0)
- {
- printf(“Open
backlight device failed!\n”); - exit(1);
- }
- if(strcmp(argv[1], “on”) == 0)
- {
- turn = 1;
- }
- else if(strcmp(argv[1], “off”) == 0)
- {
- turn = 0;
- }
- else
- {
- printf(“Usage:
bl_test on|off\n”); - exit(1);
- }
- ioctl(fd,turn);
- close(fd);
- return 0;
- }
2.
在开发主机上交叉编译测试应用程序,并复制到文件系统的/usr/sbin目录下,然后重新编译文件系统下载到开发板上
- #arm-linux-gcc -o
bl_test bl_test.c
3.
在开发板上的文件系统中创建一个背光设备的节点,然后运行测试程序,效果图如下,观测开发板上的LED灯,可以看到每一步的操作对应的LCD液晶屏会点亮或者熄灭
[[email protected] /]# mknod /dev/fl2440_backlight
c 230 0
- [[email protected] /]# bl_test
–help - Usage: bl_test on|off
- [[email protected] /]# bl_test
off - fl2440_backlight turn off
- [[email protected] /]# bl_test
on - fl2440_backlight turn on
五、补充问题
暂无
From: http://www.w3c.com.cn/lcd%E8%83%8C%E5%85%89%E9%A9%B1%E5%8A%A8%E5%AD%97%E7%AC%A6%E8%AE%BE%E5%A4%87%E5%9C%A8fl2440%E7%9A%84%E5%BC%80%E5%8F%912-6-33-7%E5%86%85%E6%A0%B8
时间: 2024-10-19 11:17:07