📄 lcdslin.c
字号:
#include <string.h> /* for memset */
#include <stddef.h> /* needed for definition of NULL */
#include <i_pwin.h>
#include "GUI.h"
#include "GUIDebug.h"
//static const LCD_PIXELINDEX LCD_ConversionTable[2] = {0, 1};
// pico WIN --------------------------
//extern const Pw_Byte _bm_edgemask[2][9];
const Pw_Byte LineMask[2][8] ={
{0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01},
{0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF}
};
static Pw_Int xinput_values[4] = {24, 60, 0, 99};
Pw_DD dd;
Pw_LLD lld;
// pico WIN --------------------------
static int Cache[((LCD_XSIZE+7)>>3)*LCD_YSIZE];
#if (!LCD_MIRROR_X && LCD_MIRROR_Y && !LCD_SWAP_XY)
#define SETPIXEL(x, y, c) _SetPixel(x, LCD_YSIZE-1-(y), c)
#define SETPIXELS(x, y, bits,c) _SetPixels(x, LCD_YSIZE-1-(y), bits, c)
#define GETPIXEL(x, y) _GetPixel(x, LCD_YSIZE-1-(y))
#define XORPIXEL(x, y) XorPixel (x, LCD_YSIZE-1-(y))
#endif
#define XY2OFF(x,y) ((x>>3)+y*((LCD_XSIZE_PHYS+7)>>3))
int LCD_Adr;
#define LCD_READCMD0 LCD_READ_A0
#define LCD_READDATA0 LCD_READ_A1
#define LCD_WRITECMD0 LCD_WRITE_A1
#define LCD_WRITEDATA0 LCD_WRITE_A0
#ifndef LCD_WAIT
#define LCD_WAIT()
#endif
#define LCD_WRITECMD(cmd) { LCD_WRITECMD0(cmd); }
#define LCD_WRITEDATA(Data) { LCD_WRITEDATA0(Data);}
#define GSTART (0x0)
#if (LCD_YSIZE > 128)
#define TSTART 30000
#else
#define TSTART 7000
#endif
static void LCD_SetSystem(void) {
LCD_WRITECMD (0x40);
LCD_WRITEDATA(0x30); /* P1 */
LCD_WRITEDATA(0x87); /* P2 : FX : hor. char size-1 */
LCD_WRITEDATA(0x7); /* P3 : FY : ver. char size-1 (not imp.) */
LCD_WRITEDATA(((LCD_XSIZE+7)>>3)-1); /* P4 : Characters per row */
LCD_WRITEDATA(0x4a); /* P5 : Timing charcters per row */
LCD_WRITEDATA(LCD_YSIZE_PHYS-1); /* P6 : Number of lines per screen */
LCD_WRITEDATA((LCD_XSIZE_PHYS+7)>>3); /* P7 : Address pitch low */
LCD_WRITEDATA(0x00); /* P8 : Address pitch high */
}
static void LCD_SetScroll(int Adr) {
LCD_WRITECMD(0x44);
LCD_WRITEDATA(TSTART&255); /* address of screen 1 (text) */
LCD_WRITEDATA(TSTART>>8);
LCD_WRITEDATA((LCD_YSIZE_PHYS)-1);
LCD_WRITEDATA(Adr); /* address of screen 2 (graphic) */
LCD_WRITEDATA(Adr>>8);
LCD_WRITEDATA((LCD_YSIZE_PHYS)-1);
}
static void LCD_SetAdr(int Off) {
LCD_Adr=Off;
LCD_WRITECMD (0x46);
LCD_WRITEDATA(Off&255);
LCD_WRITEDATA(Off>>8);
}
#define LCD_SETADR(Off) LCD_SetAdr(Off)
//static void LCD_Write1(char Byte) {
static void LCD_Write1(int Byte) {
LCD_WRITECMD (0x42);
LCD_WRITEDATA(Byte);
LCD_Adr++;
}
#define LCD_WRITE1(Byte) LCD_Write1(Byte)
/* LCD_L0_ReInit */
void LCD_L0_ReInit(void) {
int i;
LCD_INIT_CONTROLLER();
LCD_SetSystem();
LCD_SetScroll(GSTART) ;
LCD_WRITECMD (0x4c); /* Set cursor move direction */
LCD_WRITECMD (0x5a); /* HDOT SCR : Set horiz. scroll position */
LCD_WRITEDATA(0);
LCD_WRITECMD (0x5b); /* OVLAY */
LCD_WRITEDATA(1);
/* Clear display memory */
LCD_SETADR(0);
LCD_WRITECMD (0x42);
// #if (LCD_YSIZE_PHYS >128)
for (i=0; i<32000; i++)
// #else
// for (i=0; i<8000; i++)
// #endif
LCD_WRITEDATA(0);
memset(Cache,0x0,sizeof(Cache));
LCD_WRITECMD (0x59); /* Display on */
LCD_WRITEDATA(0x14); /* All screens on, curosr off */
}
/* LCD_FirstInit */
/*static*/ void LCD_FirstInit(void) {
LCD_L0_ReInit();
LCD_Adr = 0xffff;
}
/*
*********************************************************
* *
* Write 1 byte and manage cache *
* *
*********************************************************
*/
//static void LCD_Write(int Adr, U8 Byte) {
static void LCD_Write(int Adr, int Byte) {
if (Cache[Adr] != (int)Byte) {
Cache[Adr]= (int)Byte;
if (LCD_Adr != Adr) {
LCD_SETADR(Adr);
}
LCD_WRITE1(Byte);
}
}
#define LCD_WRITE(Adr,Byte) LCD_Write(Adr,Byte);
void LCD_Off (void) {
LCD_WRITECMD (0x58)
}
void LCD_On (void) {
LCD_WRITECMD (0x59);
}
void _SetColor(int color) {
//int c;
// c = color->red & color->green & color->blue;
Display._Color_ = color;
// GUI_Log1("DISPLAY COLOR ", Display._Color_);
}
//------------------------------------
static void _SetPixel(int x, int y, int c) {
int Mask = 1<<(7-(x&7));
int Adr = XY2OFF(x,y);
int CacheByte = Cache[Adr];
if (c)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE(Adr,CacheByte)
}
static void _SetPixels(int x, int y, int bits, int c) {
int mask;
int b = bits;
int Adr = XY2OFF(x,y);
int CacheByte = Cache[Adr];
int LeftBits = x & 0x0007;
if (LeftBits) {
b >>= (LeftBits); // align to x
}
if (c != 0)
CacheByte |= b;
else
CacheByte &= ~b;
LCD_WRITE(Adr,CacheByte)
Adr++;
CacheByte = Cache[Adr];
if (LeftBits) {
mask = 0x00FF ;//<< LeftBits;
b = (bits & mask) << (8-LeftBits);
if (c != 0)
CacheByte |= b;
else
CacheByte &= ~b;
LCD_WRITE(Adr,CacheByte)
}
}
void _DrawPoint(Pw_GC* gc, Pw_Coord x, Pw_Coord y){
SETPIXEL(x, y, gc->color);
}
void _DrawPoints(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Byte bits){
SETPIXELS(x, y, bits, gc->color);
}
void _DrawHorLine(Pw_GC* gc, Pw_Coord x1, Pw_Coord y1, Pw_Coord x2){
int CacheByte;
int Mask, Bytes, i;
int AdrA, AdrB;//, AdrC;
int LeftBits, RigthBits;
_SetColor(Pw_GCGetColor(gc));
y1 = LCD_YSIZE-1-(y1);
AdrA = XY2OFF(x1,y1);
AdrB = XY2OFF(x2,y1);
if (AdrA == AdrB) { // all bits in one byte !
LeftBits = LineMask[0][x1 & 0x0007];
RigthBits = LineMask[1][x2 & 0x0007];
Mask = LeftBits & RigthBits;
CacheByte = Cache[AdrA];
if (Display._Color_) {
CacheByte |= Mask;
}
else {
CacheByte &= ~Mask;
}
LCD_WRITE(AdrA,CacheByte);
return;
}
if ((AdrB - AdrA) == 1) { // more then 1 byte
CacheByte = Cache[AdrA];
LeftBits = x1 & 0x0007;
if (LeftBits) {
Mask = LineMask[0][LeftBits];
if (Display._Color_)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE(AdrA, CacheByte);
}
CacheByte = Cache[AdrB];
RigthBits = x2 & 0x0007;
Mask = LineMask[1][RigthBits];
if (RigthBits) {
if (Display._Color_)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE(AdrB, CacheByte);
}
return;
}
else {
CacheByte = Cache[AdrA];
LeftBits = x1 & 0x0007;
Mask = LineMask[0][LeftBits];
if (LeftBits) {
if (Display._Color_)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE(AdrA, CacheByte);
AdrA++;
}
// x1 += 0x0007/*8*/ - (x1 & 0x0007);
Bytes = AdrB - AdrA;
Mask = (Display._Color_) ? 0xFF : 0x00;
for (i = 0; i < Bytes; i++) {
LCD_WRITE(AdrA, Mask);
AdrA++;
}
CacheByte = Cache[AdrB];
RigthBits = x2 & 0x0007;
if (RigthBits) {
Mask = LineMask[1][RigthBits];
if (Display._Color_)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE(AdrB, CacheByte);
}
}
}
void _DrawVerLine(Pw_GC* gc, Pw_Coord x1, Pw_Coord y1, Pw_Coord y2){
gc = gc;
while (y1 <= y2) {
// SETPIXEL(x, y0, COLOR);
SETPIXEL(x1, y1, 1);
y1++;
}
}
void _FillRect(Pw_GC* gc, Pw_Coord x, Pw_Coord y, Pw_Coord w, Pw_Coord h){
int y2;
int x2;
_SetColor(Pw_GCGetColor(gc));
y2 = y + h;
x2 = x + w;
for (; y <= y2; y++) {
_DrawHorLine(gc, x, y, x2);
}
}
void _DisplayRefresh(Pw_Display* dpy, Pw_Rectangle* area){
dpy = dpy;
area = area;
//pw_dpy
}
extern Pw_Bool Pw_Init(Pw_Display* dpy);
Pw_Int mainInit (void){
lld.draw_point = _DrawPoint;
lld.draw_points = _DrawPoints;
lld.draw_hor_line = _DrawHorLine;
lld.draw_ver_line = _DrawVerLine;
lld.fill_rect = _FillRect;
dd.lld = &lld;
dd.display_refresh = _DisplayRefresh;
// dd.get_xinput_value = _DisplayGetXInputValue;
dd.init_components = Pw_Init;
// if(!_OpenDisplay()) return(-1);
// GUI_DEBUG_LOG("MAIN INIT");
IPw_InitInternals();
IPw_DisplayOpen(DPY_WIDTH, DPY_HEIGHT, &dd, &Display);
if (!IPw_InitComponents(&Display)) {
GUI_DEBUG_LOG("ERROR InitComponents");
IPw_DisplayClose(&Display);
return(0);
}
// GUI_DEBUG_LOG("OK InitComponents");
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -