📄 lcd13xx.c
字号:
#define PHYS2LOG(x, y) LCD__aCol2Seg0[x], y
#endif
#define SETPIXEL(x, y, c) _SetPixel (PHYS2LOG(x, y), c)
#define GETPIXEL(x, y) GetPixelIndex(PHYS2LOG(x, y))
#define XORPIXEL(x, y) XorPixel (PHYS2LOG(x, y))
/*
*********************************************************
* *
* Register access routines *
* *
*********************************************************
*/
#if defined(LCD_READ_REG)
#if (LCD_BUSWIDTH == 8)
#define READ_REG_BYTE(Off) LCD_READ_REG(Off)
#else
#define READ_REG_BYTE(Off) ReadRegByte(Off)
U8 ReadRegByte(int Off) {
U16 Data = LCD_READ_REG((Off>>1));
#if LCD_SWAP_BYTE_ORDER
return (Off&1) ? Data>>8 : Data&255;
#else
return (Off&1) ? Data&255 : Data>>8;
#endif
}
#endif
#endif
/*
*********************************************************
* *
* Static routines
* *
*********************************************************
*/
#ifdef REQUIRE_SWAP
U16 Swap(U16 Data) {
return (Data<<8) | (Data>>8);
}
#endif
/*
*********************************************************
* *
* Next pixel routines *
* *
*********************************************************
*/
#if (LCD_OPTIMIZE) \
&& (LCD_BUSWIDTH == 8) \
&& (!LCD_MIRROR_X) \
&& (!LCD_MIRROR_Y) \
&& (LCD_SWAP_XY) \
&& (!defined (LCD_LUT_COM)) \
&& (!defined (LCD_LUT_SEG)) \
&& (LCD_BITSPERPIXEL == 4)
static int CurPosY; /* Physical x position !!! */
static tOff CurOff;
static void SetPosXY(int x, int y) {
y = LCD_YSIZE-1-y;
CurPosY = y;
CurOff = XY2OFF(y,x);
}
static void SetNextPixel(LCD_PIXELINDEX c) {
U8 Data;
READ_MEM(CurOff, Data);
if (CurPosY&1) {
Data = (Data & ~(15<<0)) | (c<<0);
CurOff++;
} else {
Data = (Data & ~(15<<4)) | (c<<4);
}
WRITE_MEM(CurOff, Data);
CurPosY++;
}
#elif (LCD_OPTIMIZE) \
&& (LCD_BUSWIDTH == 8) \
&& (!LCD_MIRROR_X) \
&& (!LCD_MIRROR_Y) \
&& (!LCD_SWAP_XY) \
&& (!defined (LCD_LUT_COM)) \
&& (!defined (LCD_LUT_SEG)) \
&& (LCD_BITSPERPIXEL == 4)
static int CurPosX; /* Physical x position !!! */
static tOff CurOff;
static U8 CurData;
static void SetPosXY(int x, int y) {
CurPosX = x;
CurOff = XY2OFF(x,y);
CurData = LCD_READ_MEM(CurOff);
}
#define SETNEXTPIXEL(c) { \
if (CurPosX&1) { \
CurData = (CurData & ~(15<<0)) | (c<<0); \
WRITE_MEM(CurOff, CurData); \
CurOff++; \
READ_MEM(CurOff, CurData); \
} else { \
CurData = (CurData & ~(15<<4)) | (c<<4); \
} \
CurPosX++; \
}
void SetNextPixel(int c) {
SETNEXTPIXEL(c);
}
#define END_SETNEXTPIXEL() if (CurPosX&1) WRITE_MEM(CurOff, CurData);
#else
#define END_SETNEXTPIXEL()
#endif
/*
*********************************************************
* *
* BitBlt access for SED1356/SED13806 *
* *
*********************************************************
*/
#if LCD_USE_BITBLT \
&& (LCD_BUSWIDTH==16) \
&& (!defined (LCD_LUT_COM)) \
&& (!defined (LCD_LUT_SEG)) \
&& ((LCD_CONTROLLER == 1356)||(LCD_CONTROLLER == 13806))
#if LCD_BITSPERPIXEL == 8
#define BITBLT_SET_DESTINATION(x,y) WRITE_REG(0x108 / 2, (((tOff)y * (tOff)BYTESPERLINE) + x)); \
WRITE_REG(0x10a / 2, (U32)(((tOff)y * (tOff)BYTESPERLINE) + x) >> 16)
#define BITBLT_SET_ACTIVE() WRITE_REG(0x100 / 2, 0x0000); WRITE_REG(0x100 / 2, 0x0080)
#elif LCD_BITSPERPIXEL == 16
#define BITBLT_SET_DESTINATION(x,y) WRITE_REG(0x108 / 2, (((tOff)y * (tOff)BYTESPERLINE) + (x << 1))); \
WRITE_REG(0x10a / 2, (((tOff)y * (tOff)BYTESPERLINE) + (x << 1)) >> 16)
#define BITBLT_SET_ACTIVE() WRITE_REG(0x100 / 2, 0x0100); WRITE_REG(0x100 / 2, 0x0180)
#endif
static void WaitForBltEnd(void) {
volatile U16 tmp;
do {
READ_REG(0x100 / 2, tmp);
} while (tmp & 0x80);
READ_REG(0x100000 / 2, tmp); /* dummy read */
}
static void LCD_FillRectBB(int x0, int y0, int x1, int y1) {
LCD_ENABLE_REG_ACCESS(); {
for (;x0 <= x1; x0 += 1024) {
int _y0 = y0;
int _x1 = x1;
if (_x1 > (x0 + 1023)) {
_x1 = x0 + 1023;
}
for (;_y0 <= y1; _y0 += 1024) {
int _y1 = y1;
if (_y1 > (_y0 + 1023)) {
_y1 = _y0 + 1023;
}
BITBLT_SET_DESTINATION(x0, _y0); /* set destination start address */
WRITE_REG(0x110 / 2, (_x1 - x0)); /* set width */
WRITE_REG(0x112 / 2, (_y1 - _y0)); /* set height */
WRITE_REG(0x118 / 2, (COLOR)); /* set foreground color */
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
WRITE_REG(0x102 / 2, 0x0605); /* pattern fill, ~D */
} else {
WRITE_REG(0x102 / 2, 0x0c00); /* solid fill, no ROP */
}
BITBLT_SET_ACTIVE(); /* engage bitblt engine */
WaitForBltEnd(); /* wait for pending blit to end */
}
}
} LCD_ENABLE_MEM_ACCESS();
}
static void LCD_DrawBitmap1BPPBB(int x, int y, U8 const*p, int Diff, int xsize, int ysize, int BytesPerLine, const LCD_PIXELINDEX*pTrans) {
volatile U16 tmp;
x+= Diff;
LCD_ENABLE_REG_ACCESS(); {
U16 StartBit = 7 - (Diff & 7);
U16 Data = StartBit | ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) ? 0x900 : 0x800);
int NumWords = ((Diff & 7) + xsize + 15) >> 4;
WRITE_REG(0x102 / 2, Data); /* set start bit and operation */
WRITE_REG(0x104 / 2, 0); /* set source start address */
BITBLT_SET_DESTINATION(x, y); /* set destination start address */
WRITE_REG(0x110 / 2, (xsize - 1)); /* set width */
WRITE_REG(0x112 / 2, (ysize - 1)); /* set height */
WRITE_REG(0x114 / 2, (*(pTrans + 0))); /* set background color */
WRITE_REG(0x118 / 2, (*(pTrans + 1))); /* set foreground color */
BITBLT_SET_ACTIVE(); /* engage bitblt engine */
do {
READ_REG(0x100 / 2, tmp);
} while ((tmp & 0x80) == 0);
for (;ysize; ysize--, p += BytesPerLine) {
U8 const *pLine= p;
int i;
for (i = NumWords; i; i--, pLine += 2) {
do {
READ_REG(0x100 / 2, tmp);
} while ((tmp & 0x40) == 0x40);
WRITE_REG(0x100000 / 2, ((*pLine) | ((*(pLine + 1)) << 8))); /* write data into FIFO */
}
}
WaitForBltEnd(); /* wait for pending blit to end */
} LCD_ENABLE_MEM_ACCESS();
}
#endif
/*
*********************************************************
* *
* Internal set pixel routines *
* *
*********************************************************
*/
static void _SetPixel(int x, int y, LCD_PIXELINDEX c) {
tOff Off = XY2OFF(x,y);
#if LCD_BUSWIDTH == 16
#if LCD_BITSPERPIXEL == 1
U8 BitNo = (~x)&15;
U16 Data;
READ_MEM(Off, Data);
if (c)
Data |= c<<BitNo;
else
Data &= ~(1<<BitNo);
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 2
U16 Data;
U8 Shift = 14 - ((x & 7) << 1);
READ_MEM(Off, Data);
Data = (Data & ~(3 << Shift)) | (c << Shift);
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 4
U8 Shift = ((~x)&3)<<2; /* 12,8,4 or 0 */
U16 Data;
READ_MEM(Off, Data);
Data &= ~(15<<Shift);
Data |= c<<Shift;
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 8
U16 Data;
READ_MEM(Off, Data);
switch (x&1) {
case 1:
Data = (Data & ~(0xff )) | (c );
break;
case 0:
Data = (Data & ~(0xff<<8)) | (c<<8);
break;
}
WRITE_MEM(Off, Data);
#elif (LCD_BITSPERPIXEL == 15) | (LCD_BITSPERPIXEL == 16)
WRITE_MEM(Off, c);
#else
#error unsupported LCD_BITSPERPIXEL
#endif
#elif LCD_BUSWIDTH == 8
#if LCD_BITSPERPIXEL == 1
U8 Data;
U8 BitNo;
READ_MEM(Off, Data);
BitNo = 7-(x&7);
if (c)
Data |= c<<BitNo;
else
Data &= ~(1<<BitNo);
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 2
U8 Data;
READ_MEM(Off, Data);
switch (x&3) {
case 3:
Data = (Data & ~(3<<0)) | (c<<0);
break;
case 2:
Data = (Data & ~(3<<2)) | (c<<2);
break;
case 1:
Data = (Data & ~(3<<4)) | (c<<4);
break;
case 0:
Data = (Data & ~(3<<6)) | (c<<6);
break;
}
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 4
U8 Data;
READ_MEM(Off, Data);
switch (x&1) {
case 1:
Data = (Data & ~(15<<0)) | (c<<0);
break;
case 0:
Data = (Data & ~(15<<4)) | (c<<4);
break;
}
WRITE_MEM(Off, Data);
#elif LCD_BITSPERPIXEL == 8
WRITE_MEM(Off, c);
#else
#error TBD
#endif
#else
#error unsupported LCD_BUSWIDTH
#endif
}
unsigned int GetPixelIndex(int x, int y) {
LCD_PIXELINDEX col;
tOff Off = XY2OFF(x,y);
#if LCD_BUSWIDTH == 16
U16 Data;
READ_MEM(Off,Data);
#if LCD_BITSPERPIXEL == 1
col = (Data >> (15-(x&15))) &1;
#elif LCD_BITSPERPIXEL == 2
col = (Data >> (14-((x&7)<<1))) &3;
#elif LCD_BITSPERPIXEL == 4
col = (Data >> (12-((x&3)<<2))) &15;
#elif LCD_BITSPERPIXEL == 8
col = ((x&1) ==0) ? Data>>8 : Data;
#elif LCD_BITSPERPIXEL == 15
col = Data;
#elif LCD_BITSPERPIXEL == 16
col = Data;
#endif
#else
U8 Data;
READ_MEM(Off,Data);
#if LCD_BITSPERPIXEL == 1
col = (Data >> (7-(x&7))) &1;
#elif LCD_BITSPERPIXEL == 2
col = (Data >> (6-((x&3)<<1))) &3;
#elif LCD_BITSPERPIXEL == 4
col = (x&1) ? Data&15 : Data>>4;
#elif LCD_BITSPERPIXEL == 8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -