📄 ep7312_lcd.c
字号:
/*
* ep7312_lcd.c --- Primary C Source file of
* LCD Device Driver with Framebuffer
* for MGUI
* (C)opyright 2004 Bit 920 Labs
*
* Written by: Ye Nan <bye200009123@163.com>
* Created on: Sat. Mar 6 22:03:45 GMT +8:00 2004
*/
#ifndef __GAL_DRIVER_EP7312_C
#define __GAL_DRIVER_EP7312_C
#include <stdio.h>
#include <stdlib.h>
#include "../gal.h"
#include "ep7312_lcd.h"
// 设备文件指针
int LCD_FP = -1;
GAL_CLIP EP7312_clip; /* clipping infomation */
// 检测设备文件是否打开
void Assert_Device(int DevType)
{
int result = 0;
// 根据设备类型检查相应的设备文件指针是否为空,
// 为空: 设备文件尚未打开; 不为空:设备文件已打开
switch (DevType)
{
case DEV_LCD: /* 检查LCD设备状态 */
{
if (LCD_FP != -1)
result = 1;
else
printf("No LCD Device opened.\n");
break;
}
default:
break;
}
// 如果设备文件尚未打开, 则终止程序执行
if (!result)
exit(1);
}
// 打开LCD设备
void OpenLCD(char * devFile)
{
LCD_FP = open(devFile, 0);
if (LCD_FP < 0)
{
printf("Cannot open LCD device: %s!\n", devFile);
exit(1);
}
}
// 关闭LCD设备
void CloseLCD()
{
close(LCD_FP);
LCD_FP = -1;
}
// Retrieve screen width
unsigned int EP7312_GetScreenWidth()
{
return SCREEN_WIDTH;
}
// Retrieve screen height
unsigned int EP7312_GetScreenHeight()
{
return SCREEN_HEIGHT;
}
// Retrieve screen bpp(bits per pixel)
unsigned int EP7312_GetScreenBpp()
{
return SCREEN_BPP;
}
// Retrieve screen colors
unsigned int EP7312_GetScreenColors()
{
return (1 << SCREEN_BPP);
}
void EP7312_PutPixel(int x, int y, gal_color color){ struct lcd_display dis;
Assert_Device(DEV_LCD);
if (x < EP7312_clip.clipmin_x || x > EP7312_clip.clipmax_x ||
y < EP7312_clip.clipmin_y || y > EP7312_clip.clipmax_y)
{
return;
}
dis.x1 = dis.x2 = x;
dis.y1 = dis.y2 = y;
dis.color = _COLOR24_12(color);
ioctl(LCD_FP, LCD_Draw_Pixel, &dis);
}gal_color EP7312_GetPixel(int x, int y){}void EP7312_DrawLine_V(int x, int y1, int y2, gal_color color){ struct lcd_display dis;
Assert_Device(DEV_LCD);
y1 = (y1 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y1;
y2 = (y2 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y2;
y1 = (y1 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y1;
y2 = (y2 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y2;
if (x < EP7312_clip.clipmin_x || x > EP7312_clip.clipmax_x)
{
return;
}
if (y1 > y2)
{
short tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
dis.x1 = dis.x2 = x;
dis.y1 = y1;
dis.y2 = y2;
dis.color = _COLOR24_12(color);
ioctl(LCD_FP, LCD_Draw_VLine, &dis);
}void EP7312_DrawLine_H(int x1, int x2, int y, gal_color color){ struct lcd_display dis;
Assert_Device(DEV_LCD);
x1 = (x1 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x1;
x2 = (x2 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x2;
x1 = (x1 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x1;
x2 = (x2 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x2;
if (y < EP7312_clip.clipmin_y || y > EP7312_clip.clipmax_y)
{
return;
}
if (x1 > x2)
{
short tmp;
tmp = x1;
x1 = x2;
x2 = tmp;
}
dis.x1 = x1;
dis.x2 = x2;
dis.y1 = dis.y2 = y;
dis.color = _COLOR24_12(color);
ioctl(LCD_FP, LCD_Draw_HLine, &dis);
}
void EP7312_DrawRect(int x1, int y1, int x2, int y2, gal_color color)
{
struct lcd_display dis;
Assert_Device(DEV_LCD);
if (x1 > x2)
{
short tmp;
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
short tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
dis.x1 = x1;
dis.y1 = y1;
dis.x2 = x2;
dis.y2 = y2;
dis.color = _COLOR24_12(color);
ioctl(LCD_FP, LCD_Draw_Rectangle, &dis);
}
void EP7312_FillRect(int x1, int y1, int x2, int y2, gal_color color)
{
struct lcd_display dis;
int yLine;
Assert_Device(DEV_LCD);
if (x1 < EP7312_clip.clipmin_x || x1 > EP7312_clip.clipmax_x ||
x2 < EP7312_clip.clipmin_x || x2 > EP7312_clip.clipmax_x ||
y1 < EP7312_clip.clipmin_y || y1 > EP7312_clip.clipmax_y ||
y2 < EP7312_clip.clipmin_y || y2 > EP7312_clip.clipmax_y)
{
x1 = (x1 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x1;
x2 = (x2 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x2;
y1 = (y1 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y1;
y2 = (y2 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y2;
x1 = (x1 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x1;
x2 = (x2 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x2;
y1 = (y1 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y1;
y2 = (y2 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y2;
}
if (x1 > x2)
{
short tmp;
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
short tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
dis.x1 = x1;
dis.x2 = x2;
dis.color = _COLOR24_12(color);
for (yLine = y1; yLine <= y2; yLine++)
{
dis.y1 = dis.y2 = yLine;
ioctl(LCD_FP, LCD_Draw_HLine, &dis);
}
}
void EP7312_Clear(gal_color color)
{
EP7312_FillRect(EP7312_clip.clipmin_x, EP7312_clip.clipmin_y,
EP7312_clip.clipmax_x, EP7312_clip.clipmax_y, color);
}
void EP7312_SaveRange(int x1, int y1, int x2, int y2, unsigned char * buffer, int * sw, int *sh){ struct lcd_screen dis;
struct save_struct ss_buf;
Assert_Device(DEV_LCD);
if (x1 < EP7312_clip.clipmin_x || x1 > EP7312_clip.clipmax_x ||
x2 < EP7312_clip.clipmin_x || x2 > EP7312_clip.clipmax_x ||
y1 < EP7312_clip.clipmin_y || y1 > EP7312_clip.clipmax_y ||
y2 < EP7312_clip.clipmin_y || y2 > EP7312_clip.clipmax_y)
{
x1 = (x1 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x1;
x2 = (x2 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x2;
y1 = (y1 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y1;
y2 = (y2 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y2;
x1 = (x1 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x1;
x2 = (x2 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x2;
y1 = (y1 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y1;
y2 = (y2 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y2;
}
if (x1 > x2)
{
short tmp;
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
short tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
ss_buf.save_buf = buffer;
dis.x1 = x1;
dis.x2 = x2;
dis.y1 = y1;
dis.y2 = y2;
dis.buffer = &ss_buf;
ioctl(LCD_FP, LCD_Save_SCR, &dis);
if (sw != NULL)
*sw = ss_buf.save_w;
if (sh != NULL)
*sh = ss_buf.save_h;
// printf("[Load]: buffer = 0x%08X\n", buffer);
}void EP7312_LoadRange(int x1, int y1, int x2, int y2, unsigned char * buffer, int sw, int sh){ struct lcd_screen dis;
struct save_struct ss_buf;
Assert_Device(DEV_LCD);
if (x1 < EP7312_clip.clipmin_x || x1 > EP7312_clip.clipmax_x ||
x2 < EP7312_clip.clipmin_x || x2 > EP7312_clip.clipmax_x ||
y1 < EP7312_clip.clipmin_y || y1 > EP7312_clip.clipmax_y ||
y2 < EP7312_clip.clipmin_y || y2 > EP7312_clip.clipmax_y)
{
x1 = (x1 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x1;
x2 = (x2 < EP7312_clip.clipmin_x) ? EP7312_clip.clipmin_x : x2;
y1 = (y1 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y1;
y2 = (y2 < EP7312_clip.clipmin_y) ? EP7312_clip.clipmin_y : y2;
x1 = (x1 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x1;
x2 = (x2 > EP7312_clip.clipmax_x) ? EP7312_clip.clipmax_x : x2;
y1 = (y1 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y1;
y2 = (y2 > EP7312_clip.clipmax_y) ? EP7312_clip.clipmax_y : y2;
}
if (x1 > x2)
{
short tmp;
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
short tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
// printf("[Load]: buffer = 0x%08X\n", buffer);
ss_buf.save_buf = buffer;
ss_buf.save_w = x2 - x1 + 1;
ss_buf.save_h = y2 - y1 + 1;
dis.x1 = dis.x2 = x1;
dis.y1 = dis.y2 = y1;
dis.buffer = &ss_buf;
ioctl(LCD_FP, LCD_Load_SCR, &dis);
}
// GAL Interface functions
int InitLCD_EP7312(GFX * gfx)
{
if (strcmp(gfx->gfx_id, "EP7312_LCD") != 0)
return -1;
OpenLCD("/dev/LCD");
// Initialize clipping infomation
EP7312_clip.clipmin_x = 0;
EP7312_clip.clipmin_y = 0;
EP7312_clip.clipmax_x = SCREEN_WIDTH - 1;
EP7312_clip.clipmax_y = SCREEN_HEIGHT - 1 ;
gfx->gfx_width = EP7312_GetScreenWidth();
gfx->gfx_height = EP7312_GetScreenHeight();
gfx->gfx_bpp = EP7312_GetScreenBpp();
gfx->gfx_colors = EP7312_GetScreenColors();
gfx->gfx_clip = &EP7312_clip;
gfx->putpixel = EP7312_PutPixel;
gfx->getpixel = NULL;
gfx->drawvline = EP7312_DrawLine_V;
gfx->drawhline = EP7312_DrawLine_H;
gfx->drawrect = EP7312_DrawRect;
gfx->fillrect = EP7312_FillRect;
gfx->drawellipse = NULL;
gfx->fillellipse = NULL;
gfx->drawcircle = NULL;
gfx->fillcircle = NULL;
gfx->putchar = NULL;
gfx->putstr = NULL;
gfx->clearscreen = EP7312_Clear;
gfx->saverange = EP7312_SaveRange;
gfx->loadrange = EP7312_LoadRange;
return 0;
}
void ReleaseLCD_EP7312(GFX * gfx)
{
CloseLCD();
}
#endif // __GAL_DRIVER_EP7312_C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -