134 lines
3.6 KiB
C
134 lines
3.6 KiB
C
#include "stdio.h"
|
||
#include <unistd.h>
|
||
#include <time.h>
|
||
#include <sys/time.h>
|
||
#include <sys/types.h>
|
||
#include <sys/ipc.h>
|
||
#include <sys/msg.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <sys/wait.h>
|
||
#include <sys/stat.h>
|
||
#include <unistd.h>
|
||
#include <errno.h>
|
||
#include <fcntl.h>
|
||
#include <limits.h>
|
||
#include <linux/spi/spidev.h>
|
||
|
||
#include "dir_lcd.h"
|
||
#include "lcd_init.h"
|
||
/******************************************************************************
|
||
函数说明:在指定区域填充颜色
|
||
入口数据:xsta,ysta 起始坐标
|
||
xend,yend 终止坐标
|
||
color 要填充的颜色
|
||
返回值: 无
|
||
******************************************************************************/
|
||
void LCD_Fill(u_int16_t xsta,u_int16_t ysta,u_int16_t xend,u_int16_t yend,u_int16_t color)
|
||
{
|
||
u_int16_t i,j,k;
|
||
u_int16_t width = xend - xsta;
|
||
u_int8_t buff[64] = {0};
|
||
memset(&buff[0],0,64);
|
||
LCD_Address_Set(xsta,ysta,xend-1,yend-1);//设置显示范围
|
||
for(i=ysta;i<yend;i++)
|
||
{
|
||
for(j=xsta;j<xend;j+=32)
|
||
{
|
||
for(k=0;k<64;k+=2)
|
||
{
|
||
buff[k] = color>>8;
|
||
buff[k+1] = color&0xff;
|
||
}
|
||
LCD_Write_Buffs(&buff[0],64);
|
||
}
|
||
j-=32;
|
||
for(k=0;k<((xend-j)*2);k+=2)
|
||
{
|
||
buff[k] = color>>8;
|
||
buff[k+1] = color&0xff;
|
||
}
|
||
LCD_Write_Buffs(&buff[0],64);
|
||
}
|
||
}
|
||
//在指定区域内填充指定颜色块
|
||
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
|
||
//color:要填充的颜色
|
||
void LCD_Color_Fill(u_int16_t sx,u_int16_t sy,u_int16_t ex,u_int16_t ey,u_int16_t *color)
|
||
{
|
||
u_int16_t height,width;
|
||
u_int16_t i,j,k;
|
||
u_int8_t buff[64] = {0};
|
||
u_int8_t* datas;
|
||
memset(&buff[0],0,64);
|
||
width=ex-sx; //得到填充的宽度
|
||
height=ey-sy; //高度
|
||
datas = malloc(width*2);
|
||
//printf("width:%d,height:%d\r\n",width,height);
|
||
LCD_Address_Set(sx,sy,ex-1,ey-1);//设置显示范围
|
||
for(i=0;i<height;i++)
|
||
{
|
||
k=0;
|
||
for(j=0;j<width*2;j+=2)
|
||
{
|
||
datas[j] = color[i*width+k]>>8;
|
||
datas[j+1] = color[i*width+k]&0xff;
|
||
k++;
|
||
}
|
||
k=0;
|
||
for(j=0;j<width/32;j++)
|
||
{
|
||
LCD_Write_Buffs(&datas[k*64],64);
|
||
k++;
|
||
}
|
||
//for(j=0;j<width%32;j++)
|
||
{
|
||
LCD_Write_Buffs(&datas[k*64],(width%32)*2);
|
||
}
|
||
//for(j=0;j<width;j++)LCD_WR_DATA(color[i*width+j]);//写入数据
|
||
}
|
||
free(datas);
|
||
}
|
||
|
||
|
||
|
||
|
||
u_int16_t color_buf[480*320] ={0};
|
||
|
||
void lcd_test(void)
|
||
{
|
||
LCD_Init();
|
||
printf("LCD_Init\r\n");
|
||
// LCD_Fill(0,0,LCD_W,LCD_H,RED);
|
||
// printf("BRED\r\n");
|
||
// sleep(1);
|
||
// LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
|
||
// printf("BLUE\r\n");
|
||
// sleep(1);
|
||
// LCD_Fill(120,60,LCD_W-120,LCD_H-60,GREEN);
|
||
|
||
// LCD_Fill(0,0,480,320,YELLOW);
|
||
|
||
// LCD_Fill(0,0,480,320,WHITE);
|
||
|
||
// LCD_Fill(0,0,480,320,GREEN);
|
||
// while (1)
|
||
// {
|
||
// LCD_Fill(0,0,40,40,YELLOW);
|
||
// sleep(1);
|
||
// }
|
||
|
||
// for(int i=0;i<320*100;i++)
|
||
// {
|
||
// if(i<320*20)color_buf[i]=YELLOW;
|
||
// else if(i<320*40)color_buf[i]=GREEN;
|
||
// else if(i<320*60)color_buf[i]=BLUE;
|
||
// else if(i<320*70)color_buf[i]=RED;
|
||
// else if(i<320*80)color_buf[i]=WHITE;
|
||
// else if(i<320*90)color_buf[i]=BROWN;
|
||
// else if(i<320*100)color_buf[i]=LIGHTBLUE;
|
||
// //color_buf[i] = YELLOW;
|
||
// }
|
||
// LCD_Color_Fill(10,10,LCD_W-10,50,&color_buf[0]);
|
||
// LCD_Color_Fill(0,80,30,100,&color_buf[0]);
|
||
} |