解决黑屏问题
进入qtopia后,如果10分钟内不使用键盘、鼠标,你会发现LCD将黑屏。这是为什么呢?这是由于内核定义了1个全局变量blankinterval(默认值为10),内核内部存在一个控制台定时器,该定时器每隔blankinterval时间运行一次,它会调用关闭显示器函数blank_screen_t(该函数最终会调用LCD驱动中的关闭LCD控制器的操作函数),导致显示器关闭(无视是否打开了电源管理功能)。
因此,解决办法有4种方法:
1. 修改LCD驱动,把关闭LCD控制器的函数变为空(不推荐)
2. 修改vt.c中的blank_screen_t函数,让其为空(在系统不需要使用关闭显示功能时推荐)
3. 修改vt.c中的blankinterval,让其为默认值为0(系统可能需要使用关闭显示功能,而且希望系统上电后正常状态下不会关闭显示时推荐)
4. 修改用户程序,加入设置blankinterval的代码(推荐)
分析内核代码,可知内核中修改blankinterval的函数调用顺序是:
con_write --> do_con_write --> do_con_trol --> setterm_command --> 修改blankinterval
请注意:上面的con_write是tty终端的写函数;而LCD的终端设备文件是/dev/tty0;do_con_trol会根据写入的内容,在switch-case大结构中来决定是实施真实的写操作,还是调用setterm_command。
下面是采用第4种方法的具体步骤:
1. 编写程序如下setblank.c
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/ioctl.h>
5 #include <unistd.h>
6 #include <string.h>
7
8 int main(int argc, char *argv[])
9 {
10 int fd;
11 int timeval;
12 char str[20];
13
14 if (argc == 1) {
15 timeval = 10;
16 } else {
17 timeval = atoi(argv[1]);
18 }
19
20 if ((fd = open("/dev/tty0", O_RDWR)) < 0) {
21 perror("open");
22 exit(-1);
23 }
24
25 sprintf(str, "\033[9;%d]", timeval);
26 // write(fd, "\033[9;1]", 8);
27 write(fd, str, strlen(str));
28 close(fd);
29 return 0;
30 }
注:27行会导致向LCD写入字符串\033[9;x],最终会导致blankinterval被设置为x
2. 进行交叉编译得到setblank,将其拷贝到/usr/bin目录
3. rcS中加入setblank 0