ugfx/drivers/lcd/ssd1289_lld.c

282 lines
7.1 KiB
C
Raw Normal View History

2012-06-10 20:28:02 +00:00
#include "ssd1289_lld.h"
#ifdef LCD_USE_SSD1289
2012-06-10 21:51:36 +00:00
uint8_t orientation;
2012-06-11 10:53:59 +00:00
uint16_t DeviceCode;
2012-06-10 20:28:02 +00:00
extern uint16_t lcd_width, lcd_height;
2012-06-15 20:09:19 +00:00
static __inline void lld_lcdWriteIndex(uint16_t index) {
2012-06-10 20:28:02 +00:00
Clr_RS;
Set_RD;
palWritePort(LCD_DATA_PORT, index);
Clr_WR;
Set_WR;
}
2012-06-15 20:09:19 +00:00
static __inline void lld_lcdWriteData(uint16_t data) {
2012-06-10 20:28:02 +00:00
Set_RS;
palWritePort(LCD_DATA_PORT, data);
Clr_WR;
Set_WR;
}
2012-06-15 20:09:19 +00:00
static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
2012-06-10 21:10:25 +00:00
Clr_CS;
2012-06-15 20:09:19 +00:00
lld_lcdWriteIndex(lcdReg);
lld_lcdWriteData(lcdRegValue);
2012-06-10 21:10:25 +00:00
Set_CS;
}
2012-06-15 20:09:19 +00:00
static __inline uint16_t lld_lcdReadData(void) {
2012-06-10 20:28:02 +00:00
uint16_t value;
Set_RS;
Set_WR;
Clr_RD;
// change pin mode to digital input
LCD_DATA_PORT->CRH = 0x44444444;
LCD_DATA_PORT->CRL = 0x44444444;
value = palReadPort(LCD_DATA_PORT); // dummy
value = palReadPort(LCD_DATA_PORT);
// change pin mode back to digital output
LCD_DATA_PORT->CRH = 0x33333333;
LCD_DATA_PORT->CRL = 0x33333333;
Set_RD;
return value;
}
2012-06-15 20:09:19 +00:00
static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
2012-06-10 21:10:25 +00:00
uint16_t lcdRAM;
Clr_CS;
2012-06-15 20:09:19 +00:00
lld_lcdWriteIndex(lcdReg);
lcdRAM = lld_lcdReadData();
2012-06-10 21:10:25 +00:00
Set_CS;
return lcdRAM;
}
2012-06-10 21:51:36 +00:00
static __inline void lcdDelay(uint16_t us) {
chThdSleepMicroseconds(us);
}
__inline void lld_lcdWriteStreamStart(void) {
#ifdef LCD_USE_GPIO
Clr_CS
lld_lcdWriteIndex(0x0022);
#endif
2012-06-16 23:43:06 +00:00
#ifdef LCD_USE_SPI
#endif
#ifdef LCD_USE_FSCM
#endif
}
__inline void lld_lcdWriteStreamStop(void) {
#ifdef LCD_USE_GPIO
Set_CS;
#endif
#ifdef LCD_USE_SPI
#endif
#ifdef LCD_USE_FSMC
#endif
}
__inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
uint16_t i;
Set_RS;
for(i = 0; i < 100; i++) {
2012-06-17 01:01:05 +00:00
palWritePort(LCD_DATA_PORT, buffer[i]);
Clr_WR;
Set_WR;
}
2012-06-16 23:43:06 +00:00
}
2012-06-10 21:51:36 +00:00
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
if(PORTRAIT) {
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x004e, x);
lld_lcdWriteReg(0x004f, y);
2012-06-10 21:51:36 +00:00
} else if(LANDSCAPE) {
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x004e, y);
lld_lcdWriteReg(0x004f, x);
2012-06-10 21:51:36 +00:00
}
}
void lld_lcdSetOrientation(uint8_t newOrientation) {
orientation = newOrientation;
switch(orientation) {
case portrait:
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x0001, 0x2B3F);
lld_lcdWriteReg(0x0011, 0x6070);
2012-06-10 21:51:36 +00:00
lcd_height = SCREEN_HEIGHT;
lcd_width = SCREEN_WIDTH;
break;
case landscape:
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x0001, 0x293F);
lld_lcdWriteReg(0x0011, 0x6078);
2012-06-10 21:51:36 +00:00
lcd_height = SCREEN_WIDTH;
lcd_width = SCREEN_HEIGHT;
break;
case portraitInv:
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x0001, 0x693F);
lld_lcdWriteReg(0x0011, 0x6040);
2012-06-10 21:51:36 +00:00
lcd_height = SCREEN_HEIGHT;
lcd_width = SCREEN_WIDTH;
break;
case landscapeInv:
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x0001, 0x6B3F);
lld_lcdWriteReg(0x0011, 0x6048);
2012-06-10 21:51:36 +00:00
lcd_height = SCREEN_WIDTH;
lcd_width = SCREEN_HEIGHT;
break;
}
}
void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
2012-06-15 20:09:19 +00:00
lld_lcdSetCursor(x0, y0);
2012-06-10 21:51:36 +00:00
switch(lcdGetOrientation()) {
case portrait:
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x45, y0);
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x46, y1-1);
2012-06-10 21:51:36 +00:00
break;
case landscape:
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x45, x0);
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x46, x1-1);
2012-06-10 21:51:36 +00:00
break;
case portraitInv:
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x44, ((x1-1) << 8) | x0);
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x45, y0);
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x46, y1-1);
2012-06-10 21:51:36 +00:00
break;
case landscapeInv:
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x44, ((y1-1) << 8) | y1);
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x45, x0);
2012-06-16 23:36:39 +00:00
lld_lcdWriteReg(0x46, x1-1);
2012-06-10 21:51:36 +00:00
break;
}
}
2012-06-15 20:09:19 +00:00
void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
uint32_t index = 0, area;
area = ((x1-x0)*(y1-y0));
lld_lcdSetWindow(x0, y0, x1, y1);
Clr_CS;
lld_lcdWriteIndex(0x0022);
for(index = 0; index < area; index++)
lld_lcdWriteData(color);
Set_CS;
}
2012-06-10 21:51:36 +00:00
void lld_lcdClear(uint16_t color) {
uint32_t index = 0;
2012-06-15 20:09:19 +00:00
lld_lcdSetCursor(0, 0);
2012-06-10 21:51:36 +00:00
Clr_CS;
2012-06-15 20:09:19 +00:00
lld_lcdWriteIndex(0x0022);
2012-06-10 21:51:36 +00:00
for(index = 0; index < SCREEN_WIDTH * SCREEN_HEIGHT; index++)
2012-06-15 20:09:19 +00:00
lld_lcdWriteData(color);
2012-06-10 21:51:36 +00:00
Set_CS;
}
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y) {
uint16_t dummy;
lld_lcdSetCursor(x,y);
Clr_CS;
2012-06-15 20:09:19 +00:00
lld_lcdWriteIndex(0x0022);
dummy = lld_lcdReadData();
dummy = lld_lcdReadData();
2012-06-10 21:51:36 +00:00
Set_CS;
2012-06-11 10:41:02 +00:00
return dummy;
2012-06-10 21:51:36 +00:00
}
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
lld_lcdSetCursor(x, y);
2012-06-15 20:09:19 +00:00
lld_lcdWriteReg(0x0022, color);
2012-06-10 21:51:36 +00:00
}
2012-06-10 21:10:25 +00:00
void lld_lcdInit(void) {
2012-06-15 20:09:19 +00:00
DeviceCode = lld_lcdReadReg(0x0000);
lld_lcdWriteReg(0x0000,0x0001); lcdDelay(5);
lld_lcdWriteReg(0x0003,0xA8A4); lcdDelay(5);
lld_lcdWriteReg(0x000C,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x000D,0x080C); lcdDelay(5);
lld_lcdWriteReg(0x000E,0x2B00); lcdDelay(5);
lld_lcdWriteReg(0x001E,0x00B0); lcdDelay(5);
lld_lcdWriteReg(0x0001,0x2B3F); lcdDelay(5);
lld_lcdWriteReg(0x0002,0x0600); lcdDelay(5);
lld_lcdWriteReg(0x0010,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0011,0x6070); lcdDelay(5);
lld_lcdWriteReg(0x0005,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0006,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0016,0xEF1C); lcdDelay(5);
lld_lcdWriteReg(0x0017,0x0003); lcdDelay(5);
lld_lcdWriteReg(0x0007,0x0133); lcdDelay(5);
lld_lcdWriteReg(0x000B,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x000F,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0041,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0042,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0048,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0049,0x013F); lcdDelay(5);
lld_lcdWriteReg(0x004A,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x004B,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0044,0xEF00); lcdDelay(5);
lld_lcdWriteReg(0x0045,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0046,0x013F); lcdDelay(5);
lld_lcdWriteReg(0x0030,0x0707); lcdDelay(5);
lld_lcdWriteReg(0x0031,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0032,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0033,0x0502); lcdDelay(5);
lld_lcdWriteReg(0x0034,0x0507); lcdDelay(5);
lld_lcdWriteReg(0x0035,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0036,0x0204); lcdDelay(5);
lld_lcdWriteReg(0x0037,0x0502); lcdDelay(5);
lld_lcdWriteReg(0x003A,0x0302); lcdDelay(5);
lld_lcdWriteReg(0x003B,0x0302); lcdDelay(5);
lld_lcdWriteReg(0x0023,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0024,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x0025,0x8000); lcdDelay(5);
lld_lcdWriteReg(0x004f,0x0000); lcdDelay(5);
lld_lcdWriteReg(0x004e,0x0000); lcdDelay(5);
2012-06-10 21:10:25 +00:00
}
2012-06-10 22:00:07 +00:00
uint16_t lld_lcdGetOrientation(void) {
return orientation;
}
2012-06-10 20:28:02 +00:00
uint16_t lld_lcdGetHeight(void) {
return lcd_height;
}
uint16_t lld_lcdGetWidth(void) {
return lcd_width;
}
#endif