cleanups
This commit is contained in:
parent
8a20373132
commit
7d1a46d2fc
60
glcd.c
60
glcd.c
@ -2,8 +2,6 @@
|
|||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define LANDSCAPE 1
|
|
||||||
|
|
||||||
static uint8_t orientation;
|
static uint8_t orientation;
|
||||||
static uint16_t DeviceCode, temp;
|
static uint16_t DeviceCode, temp;
|
||||||
|
|
||||||
@ -70,10 +68,10 @@ uint16_t lcdReadReg(uint16_t lcdReg) {
|
|||||||
|
|
||||||
static void lcdSetCursor(uint16_t x, uint16_t y) {
|
static void lcdSetCursor(uint16_t x, uint16_t y) {
|
||||||
if(DeviceCode==0x8989) {
|
if(DeviceCode==0x8989) {
|
||||||
if(orientation == 0) {
|
if(orientation == portrait) {
|
||||||
lcdWriteReg(0x004e, x);
|
lcdWriteReg(0x004e, x);
|
||||||
lcdWriteReg(0x004f, y);
|
lcdWriteReg(0x004f, y);
|
||||||
} else if(orientation == 1) {
|
} else if(orientation == landscape) {
|
||||||
lcdWriteReg(0x004e, y);
|
lcdWriteReg(0x004e, y);
|
||||||
lcdWriteReg(0x004f, x);
|
lcdWriteReg(0x004f, x);
|
||||||
}
|
}
|
||||||
@ -89,6 +87,7 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
|
|||||||
|
|
||||||
static void lcdDelay(uint16_t nCount) {
|
static void lcdDelay(uint16_t nCount) {
|
||||||
uint16_t TimingDelay;
|
uint16_t TimingDelay;
|
||||||
|
|
||||||
while(nCount--) {
|
while(nCount--) {
|
||||||
for(TimingDelay=0;TimingDelay<10000;TimingDelay++)
|
for(TimingDelay=0;TimingDelay<10000;TimingDelay++)
|
||||||
asm("nop");
|
asm("nop");
|
||||||
@ -99,11 +98,11 @@ void lcdSetOrientation(uint8_t newOrientation) {
|
|||||||
orientation = newOrientation;
|
orientation = newOrientation;
|
||||||
|
|
||||||
switch(orientation) {
|
switch(orientation) {
|
||||||
case 0:
|
case portrait:
|
||||||
lcdWriteReg(0x0001, 0x2B3F);
|
lcdWriteReg(0x0001, 0x2B3F);
|
||||||
lcdWriteReg(0x0011, 0x6070);
|
lcdWriteReg(0x0011, 0x6070);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case landscape:
|
||||||
lcdWriteReg(0x0001, 0x293F);
|
lcdWriteReg(0x0001, 0x293F);
|
||||||
lcdWriteReg(0x0011, 0x6078);
|
lcdWriteReg(0x0011, 0x6078);
|
||||||
break;
|
break;
|
||||||
@ -114,12 +113,22 @@ void lcdSetOrientation(uint8_t newOrientation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdSetWindows(uint16_t xStart,uint16_t yStart,uint16_t xLong,uint16_t yLong) {
|
void lcdSetWindows(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
|
||||||
lcdSetCursor(xStart,yStart);
|
if(orientation == portrait) {
|
||||||
lcdWriteReg(0x0050,xStart);
|
lcdWriteReg(0x0050, x); /* Horizontal GRAM Start Address */
|
||||||
lcdWriteReg(0x0051,xStart+xLong-1);
|
lcdWriteReg(0x0051, x+width-1); /* Horizontal GRAM End Address (-1) */
|
||||||
lcdWriteReg(0x0052,yStart);
|
lcdWriteReg(0x0052, y); /* Vertical GRAM Start Address */
|
||||||
lcdWriteReg(0x0053,yStart+yLong-1);
|
lcdWriteReg(0x0053, y+height-1); /* Vertical GRAM End Address (-1) */
|
||||||
|
lcdWriteReg(0x0020, x);
|
||||||
|
lcdWriteReg(0x0021, y);
|
||||||
|
} else if(orientation == landscape) {
|
||||||
|
lcdWriteReg(0x0050, y); /* Vertical GRAM Start Address */
|
||||||
|
lcdWriteReg(0x0051, y+height-1); /* Vertical GRAM End Address (-1) */
|
||||||
|
lcdWriteReg(0x0052, x); /* Horizontal GRAM Start Address */
|
||||||
|
lcdWriteReg(0x0053, x+width-1); /* Horizontal GRAM End Address (-1) */
|
||||||
|
lcdWriteReg(0x0020, y);
|
||||||
|
lcdWriteReg(0x0021, x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdClear(uint16_t color) {
|
void lcdClear(uint16_t color) {
|
||||||
@ -134,24 +143,24 @@ void lcdClear(uint16_t color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t lcdGetPoint(uint16_t x,uint16_t y) {
|
uint16_t lcdGetPoint(uint16_t x,uint16_t y) {
|
||||||
u16 dummy;
|
uint16_t dummy;
|
||||||
|
|
||||||
lcdSetCursor(x,y);
|
lcdSetCursor(x,y);
|
||||||
Clr_CS;
|
Clr_CS;
|
||||||
lcdWriteIndex(0x0022);
|
lcdWriteIndex(0x0022);
|
||||||
dummy = lcdReadData();
|
dummy = lcdReadData();
|
||||||
dummy = lcdReadData();
|
dummy = lcdReadData();
|
||||||
Set_CS;
|
Set_CS;
|
||||||
|
|
||||||
if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
|
if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
|
||||||
return dummy;
|
return dummy;
|
||||||
else
|
else
|
||||||
return lcdBGR2RGB( dummy );
|
return lcdBGR2RGB(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdDrawPixel(uint16_t x,uint16_t y,uint16_t point) {
|
void lcdDrawPixel(uint16_t x,uint16_t y,uint16_t point) {
|
||||||
lcdSetCursor(x,y);
|
lcdSetCursor(x,y);
|
||||||
lcdWriteReg(0x0022,point);
|
lcdWriteReg(0x0022,point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
|
void lcdDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
|
||||||
@ -283,6 +292,7 @@ void lcdFillArea2(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c
|
|||||||
|
|
||||||
lcdSetWindows(x0, y0, x1, y1);
|
lcdSetWindows(x0, y0, x1, y1);
|
||||||
lcdSetCursor(x0, x1);
|
lcdSetCursor(x0, x1);
|
||||||
|
|
||||||
Clr_CS;
|
Clr_CS;
|
||||||
lcdWriteIndex(0x0022);
|
lcdWriteIndex(0x0022);
|
||||||
for(index = 0; index < area; index++)
|
for(index = 0; index < area; index++)
|
||||||
|
2
glcd.h
2
glcd.h
@ -33,7 +33,7 @@
|
|||||||
(( green >> 2 ) << 5 ) | \
|
(( green >> 2 ) << 5 ) | \
|
||||||
( blue >> 3 ))
|
( blue >> 3 ))
|
||||||
|
|
||||||
enum orientation { Portrait = 0, Landscape = 1 };
|
enum orientation {portrait = 0, landscape = 1};
|
||||||
|
|
||||||
uint16_t lcdReadReg(uint16_t reg);
|
uint16_t lcdReadReg(uint16_t reg);
|
||||||
void lcdInit(void);
|
void lcdInit(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user