AM335X用RGB888连接LCD如何以16位色彩模式显示图片

Posted bigmagic

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AM335X用RGB888连接LCD如何以16位色彩模式显示图片相关的知识,希望对你有一定的参考价值。

在AM335x中,在连接显示屏的时候,存在一个问题。这个在am335x Sillicon Errata已经提到过
在RGB888模式中
 
而对于RGB565模式的硬件连接
不难看出,这个RGB是反的。
看一下我们自己硬件的连接方式
我们自己的硬件连接是RGB888
 
 在模式设置成32位真彩显示时没有问题,但是一旦把32位换成32位时,就会发现图片的颜色显示异常。换一张纯色的红色bmp图片到开发板上,显示成蓝色。效果如图
 
 
 
那么如何让RGB888的硬件连接也能正常显示16位呢?
 
第一步:首先将开发板的bpp从32位改成16位
 
 
 
接下来修改驱动程序da8xx-fb.c
修改函数fb_check_var
 
实际上就是将红色与蓝色调换一下
 
static int fb_check_var(struct fb_var_screeninfo *var,
			struct fb_info *info)
{
	int err = 0;
	struct da8xx_fb_par *par = info->par;
	int bpp = var->bits_per_pixel >> 3;
	unsigned long line_size = var->xres_virtual * bpp;

	switch (var->bits_per_pixel) {
	case 1:
	case 8:
		var->red.offset = 0; 
		var->red.length = 8; 
		var->green.offset = 0;
		var->green.length = 8;
		var->blue.offset = 0;
		var->blue.length = 8;
		var->transp.offset = 0;
		var->transp.length = 0;
		break;
	case 4:
		var->red.offset = 0;
		var->red.length = 4;
		var->green.offset = 0;
		var->green.length = 4;
		var->blue.offset = 0;
		var->blue.length = 4;
		var->transp.offset = 0;
		var->transp.length = 0;
		break;
	case 16:		/* RGB 565 */
		var->red.offset = 11;  //改成var->blue.offset = 11;
		var->red.length = 5;   //改成var->blue.length = 5; 
		var->green.offset = 5;
		var->green.length = 6;
		var->blue.offset = 0;  //改成var->red.offset = 0; 
		var->blue.length = 5;  //改成var->red.length = 5;
		var->transp.offset = 0;
		var->transp.length = 0;
		break;
	case 24:
		var->red.offset = 16;
		var->red.length = 8;
		var->green.offset = 8;
		var->green.length = 8;
		var->blue.offset = 0;
		var->blue.length = 8;
		break;
	case 32:
		var->transp.offset = 24;
		var->transp.length = 8;
		var->red.offset = 16;
		var->red.length = 8;
		var->green.offset = 8;
		var->green.length = 8;
		var->blue.offset = 0;
		var->blue.length = 8;
		break;
	default:
		err = -EINVAL;
	}

	var->red.msb_right = 0;
	var->green.msb_right = 0;
	var->blue.msb_right = 0;
	var->transp.msb_right = 0;

	if (line_size * var->yres_virtual > par->vram_size)
		var->yres_virtual = par->vram_size / line_size;

	if (var->yres > var->yres_virtual)
		var->yres = var->yres_virtual;

	if (var->xres > var->xres_virtual)
		var->xres = var->xres_virtual;

	if (var->xres + var->xoffset > var->xres_virtual)
		var->xoffset = var->xres_virtual - var->xres;
	if (var->yres + var->yoffset > var->yres_virtual)
		var->yoffset = var->yres_virtual - var->yres;

	return err;
}
 
 
x
 
 
1
static int fb_check_var(struct fb_var_screeninfo *var,
2
struct fb_info *info)
3
{
4
int err = 0;
5
struct da8xx_fb_par *par = info->par;
6
int bpp = var->bits_per_pixel >> 3;
7
unsigned long line_size = var->xres_virtual * bpp;
8

9
switch (var->bits_per_pixel) {
10
case 1:
11
case 8:
12
var->red.offset = 0; 
13
var->red.length = 8; 
14
var->green.offset = 0;
15
var->green.length = 8;
16
var->blue.offset = 0;
17
var->blue.length = 8;
18
var->transp.offset = 0;
19
var->transp.length = 0;
20
break;
21
case 4:
22
var->red.offset = 0;
23
var->red.length = 4;
24
var->green.offset = 0;
25
var->green.length = 4;
26
var->blue.offset = 0;
27
var->blue.length = 4;
28
var->transp.offset = 0;
29
var->transp.length = 0;
30
break;
31
case 16:/* RGB 565 */
32
var->red.offset = 11;  //改成var->blue.offset = 11;
33
var->red.length = 5;   //改成var->blue.length = 5; 
34
var->green.offset = 5;
35
var->green.length = 6;
36
var->blue.offset = 0;  //改成var->red.offset = 0; 
37
var->blue.length = 5;  //改成var->red.length = 5;
38
var->transp.offset = 0;
39
var->transp.length = 0;
40
break;
41
case 24:
42
var->red.offset = 16;
43
var->red.length = 8;
44
var->green.offset = 8;
45
var->green.length = 8;
46
var->blue.offset = 0;
47
var->blue.length = 8;
48
break;
49
case 32:
50
var->transp.offset = 24;
51
var->transp.length = 8;
52
var->red.offset = 16;
53
var->red.length = 8;
54
var->green.offset = 8;
55
var->green.length = 8;
56
var->blue.offset = 0;
57
var->blue.length = 8;
58
break;
59
default:
60
err = -EINVAL;
61
}
62

63
var->red.msb_right = 0;
64
var->green.msb_right = 0;
65
var->blue.msb_right = 0;
66
var->transp.msb_right = 0;
67

68
if (line_size * var->yres_virtual > par->vram_size)
69
var->yres_virtual = par->vram_size / line_size;
70

71
if (var->yres > var->yres_virtual)
72
var->yres = var->yres_virtual;
73

74
if (var->xres > var->xres_virtual)
75
var->xres = var->xres_virtual;
76

77
if (var->xres + var->xoffset > var->xres_virtual)
78
var->xoffset = var->xres_virtual - var->xres;
79
if (var->yres + var->yoffset > var->yres_virtual)
80
var->yoffset = var->yres_virtual - var->yres;
81

82
return err;
83
}
 
 
这样就能在开发板上正常显示颜色了
 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

以上是关于AM335X用RGB888连接LCD如何以16位色彩模式显示图片的主要内容,如果未能解决你的问题,请参考以下文章

安富莱专题教程第1期基于STM32的硬件RGB888接口实现emWin的快速刷新方案,32位色或24

16位BMP图的RGB444和RGB565如何区分

资料更新丨AM335x系列产品用户资料

16位色、24位色、32位色有多大差别?

干货分享丨AM335x平台如何通过udev固定4G模块串口号的解决方法

为AM335x移植Linux内核主线代码