⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-lcd.c

📁 在移植有linux的开发板上实现LCD驱动后
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <asm/page.h>#include "bmp_data.c"#include "test-lcd.h"#define UINT32T unsigned int
#define INT32T	int
#define UINT16T unsigned short
#define INT16T	short int
#define UINT8T  unsigned char
#define	INT8T  char#define TRUE 	1#define FALSE	0#define MAX(x,y)        ((x)>(y)?(x):y))#define MIN(x,y)        ((x)<(y)?(x):y))
#define GREEN 0x1c//#define frameBuffer (void *)fbdev.fb_mem + fbdev.fb_mem_offset
extern const UINT8T g_ucBitmap[][76800];//open & init a frame bufferint fb_open(PFBDEV pFbdev){	pFbdev->fb = open(pFbdev->dev, O_RDWR);	if(pFbdev->fb < 0)	{		printf("Error opening %s: %m. Check kernel config\n", pFbdev->dev);		return FALSE;	}	if (-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))	{		printf("ioctl FBIOGET_VSCREENINFO\n");		return FALSE;	}	if (-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))	{		printf("ioctl FBIOGET_FSCREENINFO\n");		return FALSE;	}		//map physics address to virtual address	pFbdev->fb_mem_offset = (unsigned long)(pFbdev->fb_fix.smem_start) & (~PAGE_MASK);	pFbdev->fb_mem = (unsigned long int)mmap(NULL, pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,		PROT_READ | PROT_WRITE, MAP_SHARED, pFbdev->fb, 0);	if(-1L ==(long)pFbdev->fb_mem) 	{		printf("mmap error! mem:%d offset:%d\n", pFbdev->fb_mem, pFbdev->fb_mem_offset);		return FALSE;	}		return TRUE;}//close frame bufferint fb_close(PFBDEV pFbdev){	close(pFbdev->fb);	pFbdev->fb=-1;}//get display depthint get_display_depth(PFBDEV pFbdev){	if(pFbdev->fb<=0)	{		printf("fb device not open, open it first\n");		return FALSE;	}	return pFbdev->fb_var.bits_per_pixel;}//full screen clearvoid fb_memset (void *addr, int c, size_t len){    memset(addr, c, len);}

//time delay
void delay(int i)
{
	int a,b;
	for(a=0;a<50000;a++)
	{
		for(b=0;b<i;b++)
		{
		}
	}

//drawHLine
}
void drawHLine(int x1,int x2,int y,int color,FBDEV fbdev)
{
	 
	if(x2>=x1)
        fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+y*320+x1, color, x2-x1); 
	else
		fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+y*320+x2, color, x1-x2);
}

//drawVLine
void drawVLine(int x,int y1,int y2,int color,FBDEV fbdev)
{
	int i,j;
	if(y2>=y1)
	{
		for( i=0;i<=y2-y1;i++)
		{
			fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+(y1+i)*320+x,color,1);
		}
	}  
    else
	{
		for(j=0;j<=y1-y2;j++)
		{
			fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+(y2+j)*320+x,color,1);
		}
	}
}

//drawRectangle
void drawRectangle(int x1,int y1,int x2,int y2,int color,FBDEV fbdev)
{
	drawHLine(x1,x2,y1,color,fbdev);
	drawHLine(x1,x2,y2,color,fbdev);
	drawVLine(x1,y1,y2,color,fbdev);
	drawVLine(x2,y1,y2,color,fbdev);
}

//display8BmpPic
void display8BmpPic(UINT8T * pBuffer,FBDEV fbdev)
{
	UINT32T frameBufferData;
	UINT32T screeSize;
	UINT32T couNum;
	screeSize=fbdev.fb_fix.smem_len;
	couNum=0;
	while(screeSize>0)
	{
		frameBufferData=((*pBuffer)<<24)+((*pBuffer)<<16)+((*pBuffer)<<8)+((*pBuffer)<<0);
		fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+couNum,frameBufferData,4);
		pBuffer+=4;
		screeSize-=4;
		couNum+=4;
	}}int main(int argc, char** argv){
	FBDEV fbdev;
	UINT8T * pBuffer;
	UINT32T frameBufferData;
	UINT32T screenSize;
	UINT32T *pView;
	UINT32T couNum;
	int i,j;
	
			memset(&fbdev, 0, sizeof(FBDEV));	strcpy(fbdev.dev, "/dev/fb0");	if(fb_open(&fbdev)==FALSE)	{		printf("open frame buffer error\n");		return;	}		//fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset, GREEN, fbdev.fb_fix.smem_len);    //_PutCstn8Bit(100,100,GREEN);
	
	
	
    //display  bmp picture
	
/*	for(i=0;i<5;i++)
	{
	  pBuffer=(UINT8T*)g_ucBitmap[i];
	  couNum=0;
	  screenSize=fbdev.fb_fix.smem_len;
	  
      while(screenSize>0)
	  {
        frameBufferData=((*pBuffer)<<24)+((*(pBuffer+1))<<16)+((*(pBuffer+2))<<8)+((*(pBuffer+3))<<0);
		//printf("%x",frameBuffer);
		fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset+couNum, frameBufferData, 4);
		
		pBuffer+=4;
		screenSize-=4;
        couNum+=4;
	  }
	  delay(1000);
	}*/

    for(i=0;i<5;i++)
	{
		pBuffer=(UINT8T*)g_ucBitmap[i];
		display8BmpPic(pBuffer,fbdev);
		delay(1000);

	}

	fb_memset((void *)fbdev.fb_mem + fbdev.fb_mem_offset,0xff,fbdev.fb_fix.smem_len);

    //drawHLine(2,320,239,GREEN,fbdev);
	//drawVLine(2,150,200,GREEN,fbdev);
    drawRectangle(39,39,280,200,GREEN,fbdev);
	fb_close(&fbdev);		printf(" end.\n");	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -