金牌会员
- 积分
- 1289
- 金钱
- 1289
- 注册时间
- 2014-6-15
- 在线时间
- 143 小时
|
1金钱
本帖最后由 wang12zhe 于 2022-8-25 15:05 编辑
用出厂自带的程序
想用LCD屏幕做一个显示红绿蓝三原色的例子,但我得的屏幕上显示的颜色明显不正确,还请帮忙查找问题,非常感谢
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/mman.h>
#include<sys/ioctl.h>
#include<linux/fb.h>
typedef struct {
int fd;
long size;
unsigned char *fbp;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
}fbdev;
//画点函数
void draw_dot2(fbdev dev, int x, int y,unsigned int dwColor){
int xres=dev.vinfo.xres;
int yres=dev.vinfo.yres;
int bpp=dev.vinfo.bits_per_pixel;
long offset=(y*xres+x);
int color = 0;
int iRed;
int iGreen;
int iBlue;
unsigned short wColor16bpp; /* 565 */
iRed = (dwColor >> (16+3)) & 0x1f;
iGreen = (dwColor >> (8+2)) & 0x3f;
iBlue = (dwColor >> 3) & 0x1f;
wColor16bpp = (iRed << 11) | (iGreen << 5) | iBlue;
//wColor16bpp = 0X8010;
*(dev.fbp+offset)=wColor16bpp | 0xFF; //设置颜色,默认为白色
*(dev.fbp+offset + 1 )=wColor16bpp >> 8; //设置颜色,默认为白色
}
int main(){
fbdev dev;
dev.fd=open("/dev/fb0",O_RDWR);
unsigned int x=0;
unsigned int y=0;
ioctl(dev.fd,FBIOGET_VSCREENINFO,&dev.vinfo);
ioctl(dev.fd,FBIOGET_FSCREENINFO, &dev.finfo);
printf("vinfo.xres=%d\n",dev.vinfo.xres);
printf("vinfo.yres=%d\n",dev.vinfo.yres);
printf("vinfo.bits_per_bits=%d\n",dev.vinfo.bits_per_pixel);
printf("vinfo.xoffset=%d\n",dev.vinfo.xoffset);
printf("vinfo.yoffset=%d\n",dev.vinfo.yoffset);
printf("finfo.line_length=%d\n",dev.finfo.line_length);
dev.size=dev.vinfo.xres*dev.vinfo.yres*dev.vinfo.bits_per_pixel/8;
dev.fbp=(unsigned char*)mmap(0,dev.size,PROT_READ|PROT_WRITE,MAP_SHARED,dev.fd,0);
memset(dev.fbp,0,dev.size);
//红色
for(y=0;y<160;y ++){
for(x=0;x<800;x++)
draw_dot2(dev, x,y,0XFF0000);
}
//蓝色
for(;y<320;y ++){
for(x=0;x<800;x++)
draw_dot2(dev, x,y,0X00FF00);
}
//绿色
for(;y<480;y ++){
for(x=0;x<800;x++)
draw_dot2(dev, x,y,0X0000FF);
}
munmap(dev.fbp,dev.size);
close(dev.fd);
return 0;
}
|
最佳答案
查看完整内容[请看2#楼]
&lcdif {
pinctrl-names = "default";
pinctrl-0 = ;
display = ;
status = "okay";
display0: display {
bits-per-pixel = ;
bus-width = ;
display-timings {
native-mode = ;
timing0: timing0 {
clock-frequency = ;
hactive = ;
...
|