📄 drv_lcd.c
字号:
#include <math.h>#include <stdlib.h>#include <malloc.h>#include "drv_lcd.h"#include "hz12.h"#include "hz10.h"#include "ascii24.h"#include "ascii14.h"#include "ascii10.h"#include "../../frame/frm_sys_param.h"#include "../../service/graph/srv_gui.h"#include "../../service/graph/srv_gui_multi_layer.h"static D_UINT8 *lcd_buff = NULL;static D_UINT8 buff_flag = 0;extern void frm_get_word_para(D_UINT8 size, D_UINT8 type, D_UINT8 hc, D_UINT8 *height, D_UINT8 *width);#define FILL_REC 1static D_INT8 layer_flag = -1; //multi layer global var;static D_UINT16 layer_x = 0;static D_UINT16 layer_y = 0;static D_INT16 layer_width = 0;//static D_INT16 layer_height = 0;static D_UINT32 *layer_color = NULL;void drv_lcd_set_layer(D_INT8 layer_flg, D_UINT16 x, D_UINT16 y, D_INT16 w, D_INT16 h, D_UINT32 *color ){ layer_flag = layer_flg; //multi layer global var; layer_x = x; layer_y = y; layer_width = w; //layer_height = h; layer_color = color;}void drv_lcd_init( void ){ *(volatile D_UINT32 *)(0xfffc2000) = 0xf200; /*控制寄存器:2(01)表示16位的色深*/ *(volatile D_UINT32 *)(0xfffc2008) = 0x030600ef; /*水平方向寄存器(240)*/ *(volatile D_UINT32 *)(0xfffc200c) = 0x0101013f; /*垂直方向寄存器(320)*/ *(volatile D_UINT32 *)(0xfffc2010) = 0x01190146; /* 水平与垂直方向长度*/ *(volatile D_UINT32 *)(0xfffc2014) = h_address_lcd; /*Lcd video基地址 */ *(volatile D_UINT32 *)(0xfffc2000) = 0xf201; /*最后1bit 比特表示 video 使能或禁止*/ lcd_buff = (D_INT8 *)malloc(LCD_BUFF_LEN); return;}void drv_lcd_off() /* 关闭 Lcd */{ *(volatile D_UINT32 *)(0xfffc2000) = 0xf200;}void drv_lcd_on() /* 打开 Lcd */{ *(volatile D_UINT32 *)(0xfffc2000) = 0xf201;}void drv_lcd_fill ( D_UINT16 x1, D_UINT16 y1, D_UINT16 x2, D_UINT16 y2, D_UINT32 fillcolor){ D_INT32 i, j; D_UINT16 tmpx, tmpy; if ( x1 > x2) { tmpx = x1; x1 = x2; x2 = tmpx; } if ( y1 > y2) { tmpy = y1; y1 = y2; y2 = tmpy; } for(i = y1 + 1; i < y2 - 1; i++) for(j = x1 + 1; j < x2 - 1; j++) { *(D_UINT16 *)(lcd_buff + (i * Xwidth + j) * 2) = fillcolor; if( buff_flag == 0 ) *(volatile D_UINT16 *)(h_address_lcd + (i * Xwidth + j) * 2) = fillcolor; } return;}void drv_lcd_clear () /* 把屏幕初始化为白色*/{/******************************************************************* *(volatile D_INT32 *)(0xfffc2000) = 0xf200; *(volatile D_INT32 *)(0xfffc2008) = 0x030600ef; *(volatile D_INT32 *)(0xfffc200c) = 0x0101013f; *(volatile D_INT32 *)(0xfffc2010) = 0x01190146; *(volatile D_INT32 *)(0xfffc2014) = h_address_lcd; *(volatile D_INT32 *)(0xfffc2000) = 0xf201; *********************************************************************/ D_INT8 *addr; addr = (D_INT8 *)h_address_lcd; memset(addr, 0xff, LCD_BUFF_LEN); if( buff_flag == 0 ) memset((D_UINT8 *)h_address_lcd, 0xff, LCD_BUFF_LEN);/* D_INT32 i, j; for(i = 0; i < Yheight; i++) for(j = 0; j < Xwidth; j++) *(volatile D_UINT16 *)(h_address_lcd + (i * Xwidth + j) * 2) = 0xffff;*/}/*画点函数: x,y 分别为点的横、纵坐标*/void drv_lcd_pixel( D_UINT16 row, D_UINT16 col, D_UINT32 color ){ D_UINT16 tmp_color; // IMAGEDESC * p_desc = NULL;// D_UINT16 begin_x = 0, begin_y = 0;// D_INT8 layer_flag=-1; /*使用的 Lcd 为 240*320,判断是否越界 */ if ((row > Xwidth) || (col > Yheight)) return; else { tmp_color = color; memcpy(lcd_buff+( col * Xwidth + row)*2, &tmp_color, 2); if( buff_flag == 0 ) *(volatile D_UINT16 *) (h_address_lcd + (col * Xwidth + row) * 2) = color; }#if 1 //use multi layer if( layer_flag == 0 ||layer_flag ==1 || layer_flag == 2 ||layer_flag == 3 ) //layer 0 { if(layer_color) { layer_color[( col - layer_y) * layer_width + (row - layer_x)] = color; } //printf("layer:%d, pixel row : %3d, col : %3d,b_x:%3d,b_y:%3d,w:%3d,h:%3d\n",layer_flag,row , col,layer_x,layer_y, //layer_width,layer_height); }#endif} /* 取得某像素点色彩值 (取寄存器的指针)*/D_UINT32 drv_lcd_getpixel( D_UINT16 row, D_UINT16 col ){ return *(volatile D_UINT16 *) (lcd_buff + (col * Xwidth + row) * 2);}/* 画线函数:x1,y1,x2,y2分别表示两个端点 */ /*增加了二个端点值*/void drv_lcd_line (D_UINT16 x1, D_UINT16 y1, D_UINT16 x2, D_UINT16 y2, D_UINT8 linetype, D_UINT32 color){ /* ** dy, dx: 为了计算斜率 ** t = 0.5:为了省去四舍五入加上0.5 */ D_INT16 i, tmp, dy, dx, ablx, ably; float t = 0, m; dy = y2 - y1; dx = x2 - x1; ablx = abs (dx); ably = abs (dy); /*首先考虑垂直线*/ if (dx == 0) { if (y1 <= y2) { if (linetype == 0) /* 0 表示实线 */ { for (i = y1; i < y2; i++ ) drv_lcd_pixel (x1, i, color); } else if (linetype == 1) /* 0 表示虚线 */ { for (i = y1; i <= y2; i+=2 ) drv_lcd_pixel (x1, i, color); } } else { if (linetype == 0) /* 0 表示实线 */ { for ( i = y2; i <= y1; i++) drv_lcd_pixel ( x1, i, color); } else if (linetype == 1) /* 0 表示虚线 */ { for ( i = y2; i <= y1; i+=2) drv_lcd_pixel ( x1, i, color); } } } /*再考虑水平线*/ else if (dy == 0) { if (x1 < x2) { if (linetype == 0) /* 0 表示实线 */ { for ( i = x1; i <= x2; i++ ) drv_lcd_pixel (i, y1, color); } else if (linetype == 1) /* 0 表示虚线 */ { for ( i = x1; i <= x2; i+=2 ) drv_lcd_pixel (i, y1, color); } } else { if (linetype == 0) /* 0 表示实线 */ { for ( i = x2; i <= x1; i++ ) drv_lcd_pixel (i, y2, color); } else if (linetype == 1) /* 0 表示虚线 */ { for ( i = x2; i <= x1; i+=2 ) drv_lcd_pixel (i, y2, color); } } } /* 现在考虑斜线 */ else if (ablx > ably ) { drv_lcd_pixel(x1, y1, color); t = 0.5; /* 四舍五入 */ /* slope < 1 */ m = (float) dy / (float) dx; /* 计算斜率*/ t += y1; dx = (dx < 0) ? -1 : 1; m *= dx; while (x1 != x2) { if ( linetype == 0) { x1 += dx; /* 下一步x的值 */ t += m; /* 增加y的值 */ tmp = (D_INT16) t; drv_lcd_pixel ( x1, tmp, color ); } if ( linetype == 1) { x1 += dx + 1; /* 下一步x的值 */ t += m; /* 增加y的值 */ tmp = (D_INT16) t; drv_lcd_pixel ( x1, tmp, color ); } } } else { /* slope >= 1 */ drv_lcd_pixel(x1, y1, color); m = (float)dx / (float)dy; /* 计算斜率*/ t += x1; dy = (dy < 0) ? -1 : 1; m *= dy; while (y1 != y2) { if (linetype == 0) { y1 += dy; /* 下一步y的值 */ t += m; /* 增加x的值 */ tmp = (D_INT16) t; drv_lcd_pixel ( tmp, y1, color ); } if (linetype == 1) { y1 += dy + 1; /* 下一步y的值 */ t += m; /* 增加x的值 */ tmp = (D_INT16) t; drv_lcd_pixel ( tmp, y1, color ); } } } return;}void drv_lcd_rect(D_UINT16 x1, D_UINT16 y1, D_UINT16 x2, D_UINT16 y2, /* 画矩形框函数,分别代表矩形的两个端点 */ D_UINT8 type, /* 线型,0:实;1:虚;2:不画 */ D_UINT32 color, /* 线框的颜色*/ D_UINT8 fill, /* 填充的图样*/ D_UINT32 fillcolor) /* 填充的背景色*/{ /* 填充矩形,默认x2>x1,y2>y1,否则交换x1,x2或者y1,y2 */ if (fill == FILL_REC) { drv_lcd_fill ( x1, y1, x2, y2, fillcolor); } if (type != 2) { drv_lcd_line ( x1, y1, x1, y2, type, color); drv_lcd_line ( x1, y2, x2, y2, type, color); drv_lcd_line ( x2, y2, x2, y1, type, color); drv_lcd_line ( x2, y1, x1, y1, type, color); /* drv_lcd_fill ( x1, y1, x2, y2, fillcolor); */ } return;}void drv_lcd_arc(D_UINT16 x, D_UINT16 y, /* 画弧线函数, x,y表示圆心坐标*/ D_UINT16 radius, /* 半径*/ D_UINT16 angle1, D_UINT16 angle2, /* 起始和终点弧度*/ D_UINT32 color) /* 弧线的颜色*/ /* D_UINT8 type) 弧线的线型*/ { /* rad: 角度转换成弧度的换算系数; tsl,tel:为起点和终点的弧度** deg: 经验参数,可以根据效果实际调整;** arc_stp:弧度增加的步长;** t_arc,t_cos,t_sin:临时变量*/ double rad, tsl, tel, deg, arc_stp, t_arc, t_cos, t_sin; D_UINT16 x1, y1; D_INT32 num, arc_i; rad = 0.0174533; tsl = angle1 * rad; tel = angle2 * rad; if (radius < 5.08) deg = 0.015; else if (radius < 7.62) deg = 0.04; else if (radius < 25.4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -