LCD画水平线和垂直线操作

#include 
#include 
#include 
#include 

#define SCREEN_BUFF_WIDTH			    480
#define SCREEN_BUFF_HEIGHT				272

extern unsigned char * g_screen_buffer_ptr;
extern int fd_fb;
extern long  screen_size;
extern struct fb_var_screeninfo vinfo;

void draw_H_line(int x,int y,int nWid,unsigned int color)
{
	unsigned int* pDest=((unsigned int*)g_screen_buffer_ptr)+y*SCREEN_BUFF_WIDTH+x;
	int i;
	for(i=0;i<nWid;i++)
		*pDest++=color;
	if(y>0)
	{
		pDest=((unsigned int*)g_screen_buffer_ptr)+(y-1)*SCREEN_BUFF_WIDTH+x;
		for(i=0;i<nWid;i++)
			*pDest++=color;
	}
	if(y<(SCREEN_BUFF_HEIGHT-1))
	{
		pDest=((unsigned int*)g_screen_buffer_ptr)+(y+1)*SCREEN_BUFF_WIDTH+x;
		for(i=0;i<nWid;i++)
			*pDest++=color;
	}
}

void draw_V_line(int x,int y,int nHei,unsigned int color)
{
	unsigned int* pDest=((unsigned int*)g_screen_buffer_ptr)+y*SCREEN_BUFF_WIDTH+x;
	int i;
	for(i=0;i<nHei;i++)
	{
		*pDest=color;
		pDest+=SCREEN_BUFF_WIDTH;
	}
	
	if(x>0)
	{
		pDest=((unsigned int*)g_screen_buffer_ptr)+y*SCREEN_BUFF_WIDTH+x-1;
		for(i=0;i<nHei;i++)
		{
			*pDest=color;
			pDest+=SCREEN_BUFF_WIDTH;
		}
	}
	if(x<(SCREEN_BUFF_WIDTH-1))
	{
		pDest=((unsigned int*)g_screen_buffer_ptr)+y*SCREEN_BUFF_WIDTH+x+1;
		for(i=0;i<nHei;i++)
		{
			*pDest=color;
			pDest+=SCREEN_BUFF_WIDTH;
		}
	}
	
}

int clear_lcd(void)
{
	int i;
	unsigned char *temp;
	screen_size = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
	g_screen_buffer_ptr = mmap(NULL,screen_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd_fb,0); 
	temp = g_screen_buffer_ptr;
	for (i=0;i < SCREEN_BUFF_HEIGHT;i++)
	{	
	memset (temp, 0, SCREEN_BUFF_WIDTH * vinfo.bits_per_pixel / 8);
	temp = temp + vinfo.xres * vinfo.bits_per_pixel / 8;
	 }


	return 0;
}


你可能感兴趣的:(linux,framebuffer,C,LINE,LCD)