ssd1289 support
This commit is contained in:
parent
8b2f6ae66d
commit
12427eb272
@ -2,10 +2,11 @@
|
||||
|
||||
#ifdef LCD_USE_SSD1289
|
||||
|
||||
uint8_t orientation;
|
||||
extern uint16_t DeviceCode;
|
||||
extern uint16_t lcd_width, lcd_height;
|
||||
|
||||
__inline void lcdWriteIndex(uint16_t index) {
|
||||
static __inline void lcdWriteIndex(uint16_t index) {
|
||||
Clr_RS;
|
||||
Set_RD;
|
||||
|
||||
@ -15,7 +16,7 @@ __inline void lcdWriteIndex(uint16_t index) {
|
||||
Set_WR;
|
||||
}
|
||||
|
||||
__inline void lcdWriteData(uint16_t data) {
|
||||
static __inline void lcdWriteData(uint16_t data) {
|
||||
Set_RS;
|
||||
|
||||
palWritePort(LCD_DATA_PORT, data);
|
||||
@ -24,14 +25,14 @@ __inline void lcdWriteData(uint16_t data) {
|
||||
Set_WR;
|
||||
}
|
||||
|
||||
__inline void lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
|
||||
static __inline void lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
|
||||
Clr_CS;
|
||||
lcdWriteIndex(lcdReg);
|
||||
lcdWriteData(lcdRegValue);
|
||||
Set_CS;
|
||||
}
|
||||
|
||||
__inline uint16_t lcdReadData(void) {
|
||||
static __inline uint16_t lcdReadData(void) {
|
||||
uint16_t value;
|
||||
|
||||
Set_RS;
|
||||
@ -54,7 +55,7 @@ __inline uint16_t lcdReadData(void) {
|
||||
return value;
|
||||
}
|
||||
|
||||
__inline uint16_t lcdReadReg(uint16_t lcdReg) {
|
||||
static __inline uint16_t lcdReadReg(uint16_t lcdReg) {
|
||||
uint16_t lcdRAM;
|
||||
|
||||
Clr_CS;
|
||||
@ -66,6 +67,110 @@ __inline uint16_t lcdReadReg(uint16_t lcdReg) {
|
||||
return lcdRAM;
|
||||
}
|
||||
|
||||
static __inline void lcdDelay(uint16_t us) {
|
||||
chThdSleepMicroseconds(us);
|
||||
}
|
||||
|
||||
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
|
||||
if(PORTRAIT) {
|
||||
lcdWriteReg(0x004e, x);
|
||||
lcdWriteReg(0x004f, y);
|
||||
} else if(LANDSCAPE) {
|
||||
lcdWriteReg(0x004e, y);
|
||||
lcdWriteReg(0x004f, x);
|
||||
}
|
||||
}
|
||||
|
||||
void lld_lcdSetOrientation(uint8_t newOrientation) {
|
||||
orientation = newOrientation;
|
||||
|
||||
switch(orientation) {
|
||||
case portrait:
|
||||
lcdWriteReg(0x0001, 0x2B3F);
|
||||
lcdWriteReg(0x0011, 0x6070);
|
||||
lcd_height = SCREEN_HEIGHT;
|
||||
lcd_width = SCREEN_WIDTH;
|
||||
break;
|
||||
case landscape:
|
||||
lcdWriteReg(0x0001, 0x293F);
|
||||
lcdWriteReg(0x0011, 0x6078);
|
||||
lcd_height = SCREEN_WIDTH;
|
||||
lcd_width = SCREEN_HEIGHT;
|
||||
break;
|
||||
case portraitInv:
|
||||
lcdWriteReg(0x0001, 0x693F);
|
||||
lcdWriteReg(0x0011, 0x6040);
|
||||
lcd_height = SCREEN_HEIGHT;
|
||||
lcd_width = SCREEN_WIDTH;
|
||||
break;
|
||||
case landscapeInv:
|
||||
lcdWriteReg(0x0001, 0x6B3F);
|
||||
lcdWriteReg(0x0011, 0x6048);
|
||||
lcd_height = SCREEN_WIDTH;
|
||||
lcd_width = SCREEN_HEIGHT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
lcdSetCursor(x0, y0);
|
||||
|
||||
switch(lcdGetOrientation()) {
|
||||
case portrait:
|
||||
lcdWriteReg(0x44, ((x0+x1-1) << 8) | x0);
|
||||
lcdWriteReg(0x45, y0);
|
||||
lcdWriteReg(0x46, y0+y1-1);
|
||||
break;
|
||||
case landscape:
|
||||
lcdWriteReg(0x44, ((y0+y1-1) << 8) | y1);
|
||||
lcdWriteReg(0x45, x0);
|
||||
lcdWriteReg(0x46, x0+x1-1);
|
||||
break;
|
||||
case portraitInv:
|
||||
lcdWriteReg(0x44, ((x0+x1-1) << 8) | x0);
|
||||
lcdWriteReg(0x45, y0);
|
||||
lcdWriteReg(0x46, y0+y1-1);
|
||||
break;
|
||||
case landscapeInv:
|
||||
lcdWriteReg(0x44, ((y0+y1-1) << 8) | y1);
|
||||
lcdWriteReg(0x45, x0);
|
||||
lcdWriteReg(0x46, x0+x1-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lld_lcdClear(uint16_t color) {
|
||||
uint32_t index = 0;
|
||||
|
||||
lld_lcdSetCursor(0,0);
|
||||
Clr_CS;
|
||||
lcdWriteIndex(0x0022);
|
||||
for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++)
|
||||
lcdWriteData(color);
|
||||
Set_CS;
|
||||
}
|
||||
|
||||
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y) {
|
||||
uint16_t dummy;
|
||||
|
||||
lld_lcdSetCursor(x,y);
|
||||
Clr_CS;
|
||||
lcdWriteIndex(0x0022);
|
||||
dummy = lcdReadData();
|
||||
dummy = lcdReadData();
|
||||
Set_CS;
|
||||
|
||||
if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
|
||||
return dummy;
|
||||
else
|
||||
return lcdBGR2RGB(dummy);
|
||||
}
|
||||
|
||||
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
|
||||
lld_lcdSetCursor(x, y);
|
||||
lcdWriteReg(0x0022, color);
|
||||
}
|
||||
|
||||
void lld_lcdInit(void) {
|
||||
DeviceCode = lcdReadReg(0x0000);
|
||||
|
||||
@ -108,8 +213,8 @@ void lld_lcdInit(void) {
|
||||
lcdWriteReg(0x0023,0x0000); lcdDelay(5);
|
||||
lcdWriteReg(0x0024,0x0000); lcdDelay(5);
|
||||
lcdWriteReg(0x0025,0x8000); lcdDelay(5);
|
||||
lcdWriteReg(0x004f,0); lcdDelay(5);
|
||||
lcdWriteReg(0x004e,0); lcdDelay(5);
|
||||
lcdWriteReg(0x004f,0x0000); lcdDelay(5);
|
||||
lcdWriteReg(0x004e,0x0000); lcdDelay(5);
|
||||
}
|
||||
|
||||
uint16_t lld_lcdGetHeight(void) {
|
||||
|
@ -5,12 +5,13 @@
|
||||
|
||||
#ifndef LCD_USE_SSD1289
|
||||
|
||||
void lcdWriteIndex(uint16_t index);
|
||||
void lcdWriteData(uint16_t data);
|
||||
void lcdWriteReg(uint16_t lcdReg, uint16_t lcdRegValue);
|
||||
uint16_t lcdReadData(void);
|
||||
uint16_t lcdReadReg(uint16_t lcdReg);
|
||||
uint16_t lld_lcdInit(void);
|
||||
void lld_lcdSetCursor(uint16_t x, uint16_t y);
|
||||
void lld_lcdSetOrientation(uint8_t newOrientation);
|
||||
void lld_lcdSetWindow(x0, y0, x1, y1);
|
||||
void lld_lcdClear(uint16_t color);
|
||||
void lld_lcdDrawPixel(uint16_t x, uint16_ty, uint16_t color);
|
||||
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||
uint16_t lld_lcdGetHeight(void);
|
||||
uint16_t lld_lcdGetWidth(void);
|
||||
|
||||
|
110
glcd.c
110
glcd.c
@ -2,7 +2,7 @@
|
||||
#include "fonts.h"
|
||||
#include <math.h>
|
||||
|
||||
uint8_t orientation;
|
||||
extern uint8_t orientation;
|
||||
uint16_t DeviceCode;
|
||||
uint8_t font_width = 8, font_height = 16;
|
||||
uint16_t lcd_width, lcd_height;
|
||||
@ -16,62 +16,11 @@ uint16_t lcdGetWidth(void) {
|
||||
}
|
||||
|
||||
static void lcdSetCursor(uint16_t x, uint16_t y) {
|
||||
if(DeviceCode==0x8989) {
|
||||
if(PORTRAIT) {
|
||||
lcdWriteReg(0x004e, x);
|
||||
lcdWriteReg(0x004f, y);
|
||||
} else if(LANDSCAPE) {
|
||||
lcdWriteReg(0x004e, y);
|
||||
lcdWriteReg(0x004f, x);
|
||||
}
|
||||
}
|
||||
else if(DeviceCode==0x9919) {
|
||||
if(PORTRAIT) {
|
||||
lcdWriteReg(0x004e, x);
|
||||
lcdWriteReg(0x004f, y);
|
||||
} else if(LANDSCAPE) {
|
||||
lcdWriteReg(0x004e, y);
|
||||
lcdWriteReg(0x004f, x);
|
||||
}
|
||||
} else {
|
||||
lcdWriteReg(0x0020, x);
|
||||
lcdWriteReg(0x0021, y);
|
||||
}
|
||||
}
|
||||
|
||||
void lcdDelay(uint16_t us) {
|
||||
chThdSleepMicroseconds(us);
|
||||
lld_lcdSetCursor(x, y);
|
||||
}
|
||||
|
||||
void lcdSetOrientation(uint8_t newOrientation) {
|
||||
orientation = newOrientation;
|
||||
|
||||
switch(orientation) {
|
||||
case portrait:
|
||||
lcdWriteReg(0x0001, 0x2B3F);
|
||||
lcdWriteReg(0x0011, 0x6070);
|
||||
lcd_height = SCREEN_HEIGHT;
|
||||
lcd_width = SCREEN_WIDTH;
|
||||
break;
|
||||
case landscape:
|
||||
lcdWriteReg(0x0001, 0x293F);
|
||||
lcdWriteReg(0x0011, 0x6078);
|
||||
lcd_height = SCREEN_WIDTH;
|
||||
lcd_width = SCREEN_HEIGHT;
|
||||
break;
|
||||
case portraitInv:
|
||||
lcdWriteReg(0x0001, 0x693F);
|
||||
lcdWriteReg(0x0011, 0x6040);
|
||||
lcd_height = SCREEN_HEIGHT;
|
||||
lcd_width = SCREEN_WIDTH;
|
||||
break;
|
||||
case landscapeInv:
|
||||
lcdWriteReg(0x0001, 0x6B3F);
|
||||
lcdWriteReg(0x0011, 0x6048);
|
||||
lcd_height = SCREEN_WIDTH;
|
||||
lcd_width = SCREEN_HEIGHT;
|
||||
break;
|
||||
}
|
||||
lld_lcdSetOrientation(newOrientation);
|
||||
}
|
||||
|
||||
uint16_t lcdGetOrientation(void) {
|
||||
@ -79,62 +28,19 @@ uint16_t lcdGetOrientation(void) {
|
||||
}
|
||||
|
||||
void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
lcdSetCursor(x0, y0);
|
||||
|
||||
switch(lcdGetOrientation()) {
|
||||
case portrait:
|
||||
lcdWriteReg(0x44, ((x0+x1-1) << 8) | x0);
|
||||
lcdWriteReg(0x45, y0);
|
||||
lcdWriteReg(0x46, y0+y1-1);
|
||||
break;
|
||||
case landscape:
|
||||
lcdWriteReg(0x44, ((y0+y1-1) << 8) | y1);
|
||||
lcdWriteReg(0x45, x0);
|
||||
lcdWriteReg(0x46, x0+x1-1);
|
||||
break;
|
||||
case portraitInv:
|
||||
lcdWriteReg(0x44, ((x0+x1-1) << 8) | x0);
|
||||
lcdWriteReg(0x45, y0);
|
||||
lcdWriteReg(0x46, y0+y1-1);
|
||||
break;
|
||||
case landscapeInv:
|
||||
lcdWriteReg(0x44, ((y0+y1-1) << 8) | y1);
|
||||
lcdWriteReg(0x45, x0);
|
||||
lcdWriteReg(0x46, x0+x1-1);
|
||||
break;
|
||||
}
|
||||
lld_lcdSetWindow(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
void lcdClear(uint16_t color) {
|
||||
uint32_t index = 0;
|
||||
|
||||
lcdSetCursor(0,0);
|
||||
Clr_CS;
|
||||
lcdWriteIndex(0x0022);
|
||||
for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++)
|
||||
lcdWriteData(color);
|
||||
Set_CS;
|
||||
lld_lcdClear(color);
|
||||
}
|
||||
|
||||
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y) {
|
||||
uint16_t dummy;
|
||||
|
||||
lcdSetCursor(x,y);
|
||||
Clr_CS;
|
||||
lcdWriteIndex(0x0022);
|
||||
dummy = lcdReadData();
|
||||
dummy = lcdReadData();
|
||||
Set_CS;
|
||||
|
||||
if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
|
||||
return dummy;
|
||||
else
|
||||
return lcdBGR2RGB(dummy);
|
||||
lld_lcdGetPixelColor(x, y);
|
||||
}
|
||||
|
||||
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point) {
|
||||
lcdSetCursor(x, y);
|
||||
lcdWriteReg(0x0022, point);
|
||||
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
|
||||
lld_lcdDrawPixel(x, y, color);
|
||||
}
|
||||
|
||||
void lcdDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
|
||||
|
1
glcd.h
1
glcd.h
@ -51,7 +51,6 @@ void lcdDrawRectString(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8
|
||||
void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint16_t color);
|
||||
void lcdDrawString(uint16_t x, uint16_t y, unsigned char *str, uint16_t color, uint16_t bkColor);
|
||||
void lcdDrawChar(uint16_t x, uint16_t y, unsigned char c, uint16_t charcolor, uint16_t bkColor);
|
||||
void lcdDelay(uint16_t us);
|
||||
uint16_t lcdGetHeight(void);
|
||||
uint16_t lcdGetWidth(void);
|
||||
uint16_t lcdGetOrientation(void);
|
||||
|
Loading…
Reference in New Issue
Block a user