1.如果关闭自带GUI
方法1:永久关闭GUI程序
直接把GUI程序从自启动目录移除
[root@100ask:~]# mv /etc/init.d/S99myirhmi2 /root
[root@100ask:~]# ls /etc/init.d
S01syslogd S10udev S40network S50sshd rcK
S02klogd S20urandom S49ntp S98swupdate rcS
S02sysctl S30dbus S50pulseaudio bluetooth
系统重启后,会卡在启动过程的界面
方法2:使用stop命令
使用stop命令,可以使S99myirhmi2停止使用LCD资源,
停止后LCD会卡在主界面,触摸屏不会反馈滑动事件。
[root@100ask:~]# /etc/init.d/S99myirhmi2 stop
参考:
关于IMX6ULL关闭GUI的问题:http://bbs.100ask.org/question/15476
IMX6ULL开发板关闭不了GUI: http://bbs.100ask.net/question/15275
2.framebuffer程序初体验
在ubuntu服务器上编译show_pixel:arm-linux-gnueabihf-gcc -o show_pixel show_pixel.c
再将它存放到nfs(方便访问):cp ./show_pixel /home/wang/nfs/
通过SCP命令拷贝二进制文件:
[root@100ask:~]# scp wang@192.168.31.59:/home/wang/nfs/show_pixel /root
运行命令:
[root@100ask:~]# ./show_pixel
参考:
Linux scp命令:https://www.runoob.com/linux/linux-comm-scp.html
3.framebuffer代码
应用程序的编程思路蛮简单的:
(1)使用open打开设备节点"/dev/fb0"
(2)使用ioctl将framebuffer的结构体fb_var_screeninfo和LCD的硬件操作绑定
(3)通过循环和munmap函数在LCD上显示一行直线
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <linux/fb.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
static int fd_fb;
static struct fb_var_screeninfo var; /* Current var */
static int screen_size;
static unsigned char *fb_base;
static unsigned int line_width;
static unsigned int pixel_width;
/**********************************************************************
* 函数名称: lcd_put_pixel
* 功能描述: 在LCD指定位置上输出指定颜色(描点)
* 输入参数: x坐标,y坐标,颜色
* 输出参数: 无
* 返 回 值: 会
* 修改日期 版本号 修改人 修改内容
* -----------------------------------------------
* 2020/05/12 V1.0 zh(angenao) 创建
***********************************************************************/
void lcd_put_pixel(int x, int y, unsigned int color)
{
unsigned char *pen_8 = fb_base+y*line_width+x*pixel_width;
unsigned short *pen_16;
unsigned int *pen_32;
unsigned int red, green, blue;
pen_16 = (unsigned short *)pen_8;
pen_32 = (unsigned int *)pen_8;
switch (var.bits_per_pixel)
{
case 8:
{
*pen_8 = color;
break;
}
case 16:
{
/* 565 */
red = (color >> 16) & 0xff;
green = (color >> 8) & 0xff;
blue = (color >> 0) & 0xff;
color = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
*pen_16 = color;
break;
}
case 32:
{
*pen_32 = color;
break;
}
default:
{
printf("can't surport %dbpp\n", var.bits_per_pixel);
break;
}
}
}
int main(int argc, char **argv)
{
int i;
fd_fb = open("/dev/fb0", O_RDWR);
if (fd_fb < 0)
{
printf("can't open /dev/fb0\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &var))
{
printf("can't get var\n");
return -1;
}
line_width = var.xres * var.bits_per_pixel / 8;
pixel_width = var.bits_per_pixel / 8;
screen_size = var.xres * var.yres * var.bits_per_pixel / 8;
fb_base = (unsigned char *)mmap(NULL , screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if (fb_base == (unsigned char *)-1)
{
printf("can't mmap\n");
return -1;
}
/* 清屏: 全部设为白色 */
memset(fb_base, 0xff, screen_size);
/* 随便设置出100个为红色 */
for (i = 0; i < 100; i++)
lcd_put_pixel(var.xres/2+i, var.yres/2, 0xFF0000);
munmap(fb_base , screen_size);
close(fd_fb);
return 0;
}