天天看點

lcd顯示圖檔-應用(s3c2440)

main.c

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdlib.h>
//#include <unistd.h>
#include <sys/ioctl.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <fcntl.h>
//#include <signal.h>
//#include <sys/select.h>
#include <sys/time.h>
//#include <errno.h>
#include <sys/wait.h>
//#include <string.h>
#include <sys/ipc.h>
//#include <sys/shm.h>
#include"AK.h"
int main () {
    int fp=0;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    long screensize=0;
    char *fbp = 0;
    long x = 0, y = 0;
//    int location = 0;
    short color=0xffff;
    fp = open ("/dev/fb0",O_RDWR);

    if (fp < 0){
        printf("Error : Can not open framebuffer device\n");
        exit(1);
    }
puts("hello, world.\n");
printf("open framebuffer device\n");
    if (ioctl(fp,FBIOGET_FSCREENINFO,&finfo)){
        printf("Error reading fixed information\n");
        exit(2);
    }
    if (ioctl(fp,FBIOGET_VSCREENINFO,&vinfo)){
        printf("Error reading variable information\n");
        exit(3);
    }

    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;   //單幀畫面空間
    /*這就是把fp所指的檔案中從開始到screensize大小的内容給映射出來,得到一個指向這塊空間的指針*/
    
printf("vinfo.bits_per_pixel=%d\n",vinfo.bits_per_pixel);
fbp =(char *) mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fp,0);
    if ((int) fbp == -1)
    {
         printf ("Error: failed to map framebuffer device to memory.\n");
         exit (4);
    }


for(x=0;x<320;x++)
{
for(y=0;y<240*2;y++)
{
if(y%2==0)
fbp[x*240*2+y]=AK[x*240*2+y+1];
else
fbp[x*240*2+y]=AK[x*240*2+y-1];
}
}
/*
for(x=0;x<240;x++)
{
    for(y=0;y<320;y++)
   {
             *fbp  = color&0xff;
             fbp++;
             *fbp = color>>8;
             fbp++;
    }
}
*/
    munmap (fbp, screensize);
    close (fp);
    return 0;

}

           

繼續閱讀