基于am3358的lcd输出

简介: <p><br></p><p></p><pre name="code" class="cpp">/*#include<stdio.h>*/#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #incl


/*#include<stdio.h>

*/
#include <unistd.h>   
#include <stdio.h>   
#include <stdlib.h>   
#include <fcntl.h>   
#include <string.h>   
#include <linux/fb.h>   
#include <sys/mman.h>   
#include <sys/ioctl.h>   
#include <arpa/inet.h>   
  
  
//14byteÎÄŒþÍ·   
typedef struct  
{  
    char cfType[2];//ÎÄŒþÀàÐÍ£¬"BM"(0x4D42)   
    long cfSize;//ÎÄŒþŽóС£š×֜ڣ©   
    long cfReserved;//±£Áô£¬ÖµÎª0   
    long cfoffBits;//ÊýŸÝÇøÏà¶ÔÓÚÎÄŒþÍ·µÄÆ«ÒÆÁ¿£š×֜ڣ©   
}__attribute__((packed)) BITMAPFILEHEADER;  
//__attribute__((packed))µÄ×÷ÓÃÊÇžæËß±àÒëÆ÷È¡Ïûœá¹¹ÔÚ±àÒë¹ý³ÌÖеÄÓÅ»¯¶ÔÆë   
  
//40byteÐÅϢͷ   
typedef struct  
{  
    char ciSize[4];//BITMAPFILEHEADERËùÕŒµÄ×ÖœÚÊý   
    long ciWidth;//¿í¶È   
    long ciHeight;//žß¶È   
    char ciPlanes[2];//Ä¿±êÉ豞µÄλƜÃæÊý£¬ÖµÎª1   
    int ciBitCount;//ÿžöÏñËصÄλÊý   
    char ciCompress[4];//ѹËõ˵Ã÷   
    char ciSizeImage[4];//ÓÃ×֜ڱíÊŸµÄÍŒÏñŽóС£¬žÃÊýŸÝ±ØÐëÊÇ4µÄ±¶Êý   
    char ciXPelsPerMeter[4];//Ä¿±êÉ豞µÄˮƜÏñËØÊý/Ã×   
    char ciYPelsPerMeter[4];//Ä¿±êÉ豞µÄŽ¹Ö±ÏñËØÊý/Ã×   
    char ciClrUsed[4]; //λ͌ʹÓõ÷É«°åµÄÑÕÉ«Êý   
    char ciClrImportant[4]; //Öž¶šÖØÒªµÄÑÕÉ«Êý£¬µ±žÃÓòµÄÖµµÈÓÚÑÕÉ«Êýʱ£š»òÕßµÈÓÚ0ʱ£©£¬±íÊŸËùÓÐÑÕÉ«¶ŒÒ»ÑùÖØÒª   
}__attribute__((packed)) BITMAPINFOHEADER;  
  
typedef struct  
{  
    unsigned short blue;  
    unsigned short green;  
    unsigned short red;  
    unsigned short reserved;  
}__attribute__((packed)) PIXEL;//ÑÕɫģʜRGB   
  
BITMAPFILEHEADER FileHead;  
BITMAPINFOHEADER InfoHead;  
  
static char *fbp = 0;  
static int xres = 0;  
static int yres = 0;  
static int bits_per_pixel = 0;  
  
int  showbmp2();


int main ( int argc, char *argv[] )  
{  
    int fbfd = 0; 
    int index=0; 
    struct fb_var_screeninfo vinfo;  
    struct fb_fix_screeninfo finfo;  
    long int screensize = 0;  
    struct fb_bitfield red;  
    struct fb_bitfield green;  
    struct fb_bitfield blue;  
  
    //open the showdeviece
    fbfd = open("/dev/fb0", O_RDWR);  
    if (!fbfd)  
    {  
        printf("Error: cannot open framebuffer device.\n");  
        exit(1);  
    }  
  
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))  
    {  
        printf("Error£ºreading fixed information.\n");  
        exit(2);  
    }  
  
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))  
    {  
        printf("Error: reading variable information.\n");  
        exit(3);  
    }  
  
    printf("R:%d,G:%d,B:%d \n", vinfo.red, vinfo.green, vinfo.blue );  
  
    printf("%dx%d, %dbpp,%d clock\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel,vinfo.pixclock );  
    xres = vinfo.xres;  
    yres = vinfo.yres;  
    bits_per_pixel = vinfo.bits_per_pixel;  
  
    //ŒÆËãÆÁÄ»µÄ×ÜŽóС£š×֜ڣ©   
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;  
    printf("screensize=%d byte\n",screensize);  
  
    //¶ÔÏóÓ³Éä   
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);  
    if ((int)fbp == -1)  
    {  
        printf("Error: failed to map framebuffer device to memory.\n");  
        exit(4);  
    }  
  
    printf("sizeof file header=%d\n", sizeof(BITMAPFILEHEADER));  
  
    printf("into show_bmp function\n");  
  
    showbmp2();

    //ÉŸ³ý¶ÔÏóÓ³Éä   
    munmap(fbp, screensize);  


//
    close(fbfd);  

    return 0;  
}  
///*  
  unsigned char buf[3][1680*1050*4];
  unsigned char data[640*480*3];
int  showbmp2()
{
    int x,y;

    int index=0;
    unsigned char *p;
    FILE *fp[3];

        fp[0] = fopen("./000.bmp","rb+");
        fp[1] = fopen("./111.bmp","rb+");
        fp[2] = fopen("./222.bmp","rb+");

    fread(data,54,1,fp[0]);
    fread(data,640*480*3,1,fp[0]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<800;x++)
	{
            if(x<640)
            {
            	buf[0][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[0][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[0][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
//
    fread(data,54,1,fp[1]);
    fread(data,640*480*3,1,fp[1]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<1680;x++)
	{
            if(x<640)
            {
            	buf[1][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[1][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[1][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
//
    fread(data,54,1,fp[2]);
    fread(data,640*480*3,1,fp[2]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<1680;x++)
	{
            if(x<640)
             {
            	buf[2][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[2][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[2][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
    fclose(fp[0]); fclose(fp[1]); fclose(fp[2]);
    //
    while(1)
    { 

            memcpy(fbp,buf[index%3],800*480*4);
	    sleep(1);
           if(index++>100)
               break;
    }    
    printf("/nover!/n");
    return 0;
}


相关文章
|
7月前
|
存储
STM32F103标准外设库——GPIO 输入、输出 (五)
STM32F103标准外设库——GPIO 输入、输出 (五)
451 0
STM32F103标准外设库——GPIO 输入、输出 (五)
STM32F103C8 TIM输出比较与PWM
STM32F103C8 TIM输出比较与PWM
119 0
|
传感器 存储 C++
STM32读取BH1750光照强度数据打印到串口
BH1750是一种数字式环境光强度传感器(Digital Light Sensor),也称为其他名称,例如GY-302传感器、BH1750FVI传感器等。它的工作原理是通过收集光线照射到传感器上的量来测量环境亮度。
314 0
STM32F103C8 TIM输入捕获
STM32F103C8 TIM输入捕获
108 0
STM32的GPIO输入与输出
STM32的GPIO输入与输出
93 0
|
开发者 内存技术
LCD 常用接口介绍
LCD 常用接口介绍
769 0