some cleanups

This commit is contained in:
Tectu 2012-06-10 23:10:25 +02:00
parent b008620171
commit 8b2f6ae66d
4 changed files with 82 additions and 377 deletions

View File

@ -2,9 +2,10 @@
#ifdef LCD_USE_SSD1289
extern uint16_t DeviceCode;
extern uint16_t lcd_width, lcd_height;
void lld_lcdWriteIndex(uint16_t index) {
__inline void lcdWriteIndex(uint16_t index) {
Clr_RS;
Set_RD;
@ -14,7 +15,7 @@ void lld_lcdWriteIndex(uint16_t index) {
Set_WR;
}
void lld_lcdWriteData(uint16_t data) {
__inline void lcdWriteData(uint16_t data) {
Set_RS;
palWritePort(LCD_DATA_PORT, data);
@ -23,7 +24,14 @@ void lld_lcdWriteData(uint16_t data) {
Set_WR;
}
uint16_t lld_lcdReadData(void) {
__inline void lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
Clr_CS;
lcdWriteIndex(lcdReg);
lcdWriteData(lcdRegValue);
Set_CS;
}
__inline uint16_t lcdReadData(void) {
uint16_t value;
Set_RS;
@ -46,6 +54,64 @@ uint16_t lld_lcdReadData(void) {
return value;
}
__inline uint16_t lcdReadReg(uint16_t lcdReg) {
uint16_t lcdRAM;
Clr_CS;
lcdWriteIndex(lcdReg);
lcdRAM = lcdReadData();
Set_CS;
return lcdRAM;
}
void lld_lcdInit(void) {
DeviceCode = lcdReadReg(0x0000);
lcdWriteReg(0x0000,0x0001); lcdDelay(5);
lcdWriteReg(0x0003,0xA8A4); lcdDelay(5);
lcdWriteReg(0x000C,0x0000); lcdDelay(5);
lcdWriteReg(0x000D,0x080C); lcdDelay(5);
lcdWriteReg(0x000E,0x2B00); lcdDelay(5);
lcdWriteReg(0x001E,0x00B0); lcdDelay(5);
lcdWriteReg(0x0001,0x2B3F); lcdDelay(5);
lcdWriteReg(0x0002,0x0600); lcdDelay(5);
lcdWriteReg(0x0010,0x0000); lcdDelay(5);
lcdWriteReg(0x0011,0x6070); lcdDelay(5);
lcdWriteReg(0x0005,0x0000); lcdDelay(5);
lcdWriteReg(0x0006,0x0000); lcdDelay(5);
lcdWriteReg(0x0016,0xEF1C); lcdDelay(5);
lcdWriteReg(0x0017,0x0003); lcdDelay(5);
lcdWriteReg(0x0007,0x0133); lcdDelay(5);
lcdWriteReg(0x000B,0x0000); lcdDelay(5);
lcdWriteReg(0x000F,0x0000); lcdDelay(5);
lcdWriteReg(0x0041,0x0000); lcdDelay(5);
lcdWriteReg(0x0042,0x0000); lcdDelay(5);
lcdWriteReg(0x0048,0x0000); lcdDelay(5);
lcdWriteReg(0x0049,0x013F); lcdDelay(5);
lcdWriteReg(0x004A,0x0000); lcdDelay(5);
lcdWriteReg(0x004B,0x0000); lcdDelay(5);
lcdWriteReg(0x0044,0xEF00); lcdDelay(5);
lcdWriteReg(0x0045,0x0000); lcdDelay(5);
lcdWriteReg(0x0046,0x013F); lcdDelay(5);
lcdWriteReg(0x0030,0x0707); lcdDelay(5);
lcdWriteReg(0x0031,0x0204); lcdDelay(5);
lcdWriteReg(0x0032,0x0204); lcdDelay(5);
lcdWriteReg(0x0033,0x0502); lcdDelay(5);
lcdWriteReg(0x0034,0x0507); lcdDelay(5);
lcdWriteReg(0x0035,0x0204); lcdDelay(5);
lcdWriteReg(0x0036,0x0204); lcdDelay(5);
lcdWriteReg(0x0037,0x0502); lcdDelay(5);
lcdWriteReg(0x003A,0x0302); lcdDelay(5);
lcdWriteReg(0x003B,0x0302); lcdDelay(5);
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);
}
uint16_t lld_lcdGetHeight(void) {
return lcd_height;
}

View File

@ -5,9 +5,12 @@
#ifndef LCD_USE_SSD1289
void lld_lcdWriteIndex(uint16_t index);
void lld_lcdWriteData(uint16_t data);
void lld_lcdWriteData(uint16_t data);
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);
uint16_t lld_lcdGetHeight(void);
uint16_t lld_lcdGetWidth(void);

377
glcd.c
View File

@ -2,42 +2,11 @@
#include "fonts.h"
#include <math.h>
static uint8_t orientation;
static uint16_t DeviceCode;
static uint8_t font_width = 8, font_height = 16;
uint8_t orientation;
uint16_t DeviceCode;
uint8_t font_width = 8, font_height = 16;
uint16_t lcd_width, lcd_height;
static __inline void lcdWriteIndex(uint16_t index) {
lld_lcdWriteIndex(index);
}
static __inline void lcdWriteData(uint16_t data) {
lld_lcdWriteData(data);
}
static __inline uint16_t lcdReadData(void) {
return lld_lcdReadData();
}
static __inline void lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
Clr_CS;
lcdWriteIndex(lcdReg);
lcdWriteData(lcdRegValue);
Set_CS;
}
static __inline uint16_t lcdReadReg(uint16_t lcdReg) {
uint16_t lcdRAM;
Clr_CS;
lcdWriteIndex(lcdReg);
lcdRAM = lcdReadData();
Set_CS;
return lcdRAM;
}
uint16_t lcdGetHeight(void) {
return lld_lcdGetHeight();
}
@ -70,13 +39,8 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
}
}
static void lcdDelay(uint16_t nCount) {
uint16_t TimingDelay;
while(nCount--) {
for(TimingDelay=0; TimingDelay<10000; TimingDelay++)
asm("nop");
}
void lcdDelay(uint16_t us) {
chThdSleepMicroseconds(us);
}
void lcdSetOrientation(uint8_t newOrientation) {
@ -384,338 +348,9 @@ void lcdTest(void) {
}
void lcdInit() {
lcdDelay(5);
DeviceCode = lcdReadReg(0x0000);
if(DeviceCode==0x9325 || DeviceCode==0x9328)
{
lcdWriteReg(0x00e7,0x0010);
lcdWriteReg(0x0000,0x0001);
lcdWriteReg(0x0001,0x0100);
lcdWriteReg(0x0002,0x0700);
lcdWriteReg(0x0003,(1<<12)|(1<<5)|(1<<4)|(0<<3) );
lcdWriteReg(0x0004,0x0000);
lcdWriteReg(0x0008,0x0207);
lcdWriteReg(0x0009,0x0000);
lcdWriteReg(0x000a,0x0000);
lcdWriteReg(0x000c,0x0001);
lcdWriteReg(0x000d,0x0000);
lcdWriteReg(0x000f,0x0000);
lcdWriteReg(0x0010,0x0000);
lcdWriteReg(0x0011,0x0007);
lcdWriteReg(0x0012,0x0000);
lcdWriteReg(0x0013,0x0000);
lcdDelay(5);
lcdWriteReg(0x0010,0x1590);
lcdWriteReg(0x0011,0x0227);
lcdDelay(5);
lcdWriteReg(0x0012,0x009c);
lcdDelay(5);
lcdWriteReg(0x0013,0x1900);
lcdWriteReg(0x0029,0x0023);
lcdWriteReg(0x002b,0x000e);
lcdDelay(5);
lcdWriteReg(0x0020,0x0000);
lcdWriteReg(0x0021,0x0000);
lcdDelay(5);
lcdWriteReg(0x0030,0x0007);
lcdWriteReg(0x0031,0x0707);
lcdWriteReg(0x0032,0x0006);
lcdWriteReg(0x0035,0x0704);
lcdWriteReg(0x0036,0x1f04);
lcdWriteReg(0x0037,0x0004);
lcdWriteReg(0x0038,0x0000);
lcdWriteReg(0x0039,0x0706);
lcdWriteReg(0x003c,0x0701);
lcdWriteReg(0x003d,0x000f);
lcdDelay(5);
lcdWriteReg(0x0050,0x0000);
lcdWriteReg(0x0051,0x00ef);
lcdWriteReg(0x0052,0x0000);
lcdWriteReg(0x0053,0x013f);
lcdWriteReg(0x0060,0xa700);
lcdWriteReg(0x0061,0x0001);
lcdWriteReg(0x006a,0x0000);
lcdWriteReg(0x0080,0x0000);
lcdWriteReg(0x0081,0x0000);
lcdWriteReg(0x0082,0x0000);
lcdWriteReg(0x0083,0x0000);
lcdWriteReg(0x0084,0x0000);
lcdWriteReg(0x0085,0x0000);
lcdWriteReg(0x0090,0x0010);
lcdWriteReg(0x0092,0x0000);
lcdWriteReg(0x0093,0x0003);
lcdWriteReg(0x0095,0x0110);
lcdWriteReg(0x0097,0x0000);
lcdWriteReg(0x0098,0x0000);
lcdWriteReg(0x0007,0x0133);
lcdWriteReg(0x0020,0x0000);
lcdWriteReg(0x0021,0x0000);
}
else if(DeviceCode==0x9320 || DeviceCode==0x9300)
{
lcdWriteReg(0x00,0x0000);
lcdWriteReg(0x01,0x0100);
lcdWriteReg(0x02,0x0700);
lcdWriteReg(0x03,0x1018);
lcdWriteReg(0x04,0x0000);
lcdWriteReg(0x08,0x0202);
lcdWriteReg(0x09,0x0000);
lcdWriteReg(0x0a,0x0000);
lcdWriteReg(0x0c,(1<<0));
lcdWriteReg(0x0d,0x0000);
lcdWriteReg(0x0f,0x0000);
lcdDelay(10);
lcdWriteReg(0x07,0x0101);
lcdDelay(10);
lcdWriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));
lcdWriteReg(0x11,0x0007);
lcdWriteReg(0x12,(1<<8)|(1<<4)|(0<<0));
lcdWriteReg(0x13,0x0b00);
lcdWriteReg(0x29,0x0000);
lcdWriteReg(0x2b,(1<<14)|(1<<4));
lcdWriteReg(0x50,0);
lcdWriteReg(0x51,239);
lcdWriteReg(0x52,0);
lcdWriteReg(0x53,319);
lcdWriteReg(0x60,0x2700);
lcdWriteReg(0x61,0x0001);
lcdWriteReg(0x6a,0x0000);
lcdWriteReg(0x80,0x0000);
lcdWriteReg(0x81,0x0000);
lcdWriteReg(0x82,0x0000);
lcdWriteReg(0x83,0x0000);
lcdWriteReg(0x84,0x0000);
lcdWriteReg(0x85,0x0000);
lcdWriteReg(0x90,(0<<7)|(16<<0));
lcdWriteReg(0x92,0x0000);
lcdWriteReg(0x93,0x0001);
lcdWriteReg(0x95,0x0110);
lcdWriteReg(0x97,(0<<8));
lcdWriteReg(0x98,0x0000);
lcdWriteReg(0x07,0x0173);
}
else if(DeviceCode==0x9331)
{
lcdWriteReg(0x00E7, 0x1014);
lcdWriteReg(0x0001, 0x0100);
lcdWriteReg(0x0002, 0x0200);
lcdWriteReg(0x0003, 0x1030);
lcdWriteReg(0x0008, 0x0202);
lcdWriteReg(0x0009, 0x0000);
lcdWriteReg(0x000A, 0x0000);
lcdWriteReg(0x000C, 0x0000);
lcdWriteReg(0x000D, 0x0000);
lcdWriteReg(0x000F, 0x0000);
lcdWriteReg(0x0010, 0x0000);
lcdWriteReg(0x0011, 0x0007);
lcdWriteReg(0x0012, 0x0000);
lcdWriteReg(0x0013, 0x0000);
lcdDelay(20);
lcdWriteReg(0x0010, 0x1690);
lcdWriteReg(0x0011, 0x0227);
lcdDelay(5);
lcdWriteReg(0x0012, 0x000C);
lcdDelay(5);
lcdWriteReg(0x0013, 0x0800);
lcdWriteReg(0x0029, 0x0011);
lcdWriteReg(0x002B, 0x000B);
lcdDelay(5);
lcdWriteReg(0x0020, 0x0000);
lcdWriteReg(0x0021, 0x0000);
lcdWriteReg(0x0030, 0x0000);
lcdWriteReg(0x0031, 0x0106);
lcdWriteReg(0x0032, 0x0000);
lcdWriteReg(0x0035, 0x0204);
lcdWriteReg(0x0036, 0x160A);
lcdWriteReg(0x0037, 0x0707);
lcdWriteReg(0x0038, 0x0106);
lcdWriteReg(0x0039, 0x0707);
lcdWriteReg(0x003C, 0x0402);
lcdWriteReg(0x003D, 0x0C0F);
lcdWriteReg(0x0050, 0x0000);
lcdWriteReg(0x0051, 0x00EF);
lcdWriteReg(0x0052, 0x0000);
lcdWriteReg(0x0053, 0x013F);
lcdWriteReg(0x0060, 0x2700);
lcdWriteReg(0x0061, 0x0001);
lcdWriteReg(0x006A, 0x0000);
lcdWriteReg(0x0080, 0x0000);
lcdWriteReg(0x0081, 0x0000);
lcdWriteReg(0x0082, 0x0000);
lcdWriteReg(0x0083, 0x0000);
lcdWriteReg(0x0084, 0x0000);
lcdWriteReg(0x0085, 0x0000);
lcdWriteReg(0x0090, 0x0010);
lcdWriteReg(0x0092, 0x0600);
lcdWriteReg(0x0007,0x0021);
lcdDelay(5);
lcdWriteReg(0x0007,0x0061);
lcdDelay(5);
lcdWriteReg(0x0007,0x0133);
lcdDelay(5);
}
else if(DeviceCode==0x9919)
{
lcdWriteReg(0x28,0x0006);
lcdWriteReg(0x00,0x0001);
lcdWriteReg(0x10,0x0000);
lcdWriteReg(0x01,0x72ef);
lcdWriteReg(0x02,0x0600);
lcdWriteReg(0x03,0x6a38);
lcdWriteReg(0x11,0x6874);
lcdWriteReg(0x0f,0x0000);
lcdWriteReg(0x0b,0x5308);
lcdWriteReg(0x0c,0x0003);
lcdWriteReg(0x0d,0x000a);
lcdWriteReg(0x0e,0x2e00);
lcdWriteReg(0x1e,0x00be);
lcdWriteReg(0x25,0x8000);
lcdWriteReg(0x26,0x7800);
lcdWriteReg(0x27,0x0078);
lcdWriteReg(0x4e,0x0000);
lcdWriteReg(0x4f,0x0000);
lcdWriteReg(0x12,0x08d9);
lcdWriteReg(0x30,0x0000);
lcdWriteReg(0x31,0x0104);
lcdWriteReg(0x32,0x0100);
lcdWriteReg(0x33,0x0305);
lcdWriteReg(0x34,0x0505);
lcdWriteReg(0x35,0x0305);
lcdWriteReg(0x36,0x0707);
lcdWriteReg(0x37,0x0300);
lcdWriteReg(0x3a,0x1200);
lcdWriteReg(0x3b,0x0800);
lcdWriteReg(0x07,0x0033);
}
else if(DeviceCode==0x1505)
{
lcdWriteReg(0x0007,0x0000);
lcdDelay(5);
lcdWriteReg(0x0012,0x011C);
lcdWriteReg(0x00A4,0x0001);
lcdWriteReg(0x0008,0x000F);
lcdWriteReg(0x000A,0x0008);
lcdWriteReg(0x000D,0x0008);
lcdWriteReg(0x0030,0x0707);
lcdWriteReg(0x0031,0x0007);
lcdWriteReg(0x0032,0x0603);
lcdWriteReg(0x0033,0x0700);
lcdWriteReg(0x0034,0x0202);
lcdWriteReg(0x0035,0x0002);
lcdWriteReg(0x0036,0x1F0F);
lcdWriteReg(0x0037,0x0707);
lcdWriteReg(0x0038,0x0000);
lcdWriteReg(0x0039,0x0000);
lcdWriteReg(0x003A,0x0707);
lcdWriteReg(0x003B,0x0000);
lcdWriteReg(0x003C,0x0007);
lcdWriteReg(0x003D,0x0000);
lcdDelay(5);
lcdWriteReg(0x0007,0x0001);
lcdWriteReg(0x0017,0x0001);
lcdDelay(5);
lcdWriteReg(0x0010,0x17A0);
lcdWriteReg(0x0011,0x0217);
lcdWriteReg(0x0012,0x011E);
lcdWriteReg(0x0013,0x0F00);
lcdWriteReg(0x002A,0x0000);
lcdWriteReg(0x0029,0x000A);
lcdWriteReg(0x0012,0x013E);
lcdWriteReg(0x0050,0x0000);
lcdWriteReg(0x0051,0x00EF);
lcdWriteReg(0x0052,0x0000);
lcdWriteReg(0x0053,0x013F);
lcdWriteReg(0x0060,0x2700);
lcdWriteReg(0x0061,0x0001);
lcdWriteReg(0x006A,0x0000);
lcdWriteReg(0x0080,0x0000);
lcdWriteReg(0x0081,0x0000);
lcdWriteReg(0x0082,0x0000);
lcdWriteReg(0x0083,0x0000);
lcdWriteReg(0x0084,0x0000);
lcdWriteReg(0x0085,0x0000);
lcdWriteReg(0x0090,0x0013);
lcdWriteReg(0x0092,0x0300);
lcdWriteReg(0x0093,0x0005);
lcdWriteReg(0x0095,0x0000);
lcdWriteReg(0x0097,0x0000);
lcdWriteReg(0x0098,0x0000);
lcdWriteReg(0x0001,0x0100);
lcdWriteReg(0x0002,0x0700);
lcdWriteReg(0x0003,0x1030);
lcdWriteReg(0x0004,0x0000);
lcdWriteReg(0x000C,0x0000);
lcdWriteReg(0x000F,0x0000);
lcdWriteReg(0x0020,0x0000);
lcdWriteReg(0x0021,0x0000);
lcdWriteReg(0x0007,0x0021);
lcdDelay(20);
lcdWriteReg(0x0007,0x0061);
lcdDelay(20);
lcdWriteReg(0x0007,0x0173);
lcdDelay(20);
}
else if(DeviceCode==0x8989)
{
lcdWriteReg(0x0000,0x0001); lcdDelay(5);
lcdWriteReg(0x0003,0xA8A4); lcdDelay(5);
lcdWriteReg(0x000C,0x0000); lcdDelay(5);
lcdWriteReg(0x000D,0x080C); lcdDelay(5);
lcdWriteReg(0x000E,0x2B00); lcdDelay(5);
lcdWriteReg(0x001E,0x00B0); lcdDelay(5);
lcdWriteReg(0x0001,0x2B3F);
lcdWriteReg(0x0002,0x0600); lcdDelay(5);
lcdWriteReg(0x0010,0x0000); lcdDelay(5);
lcdWriteReg(0x0011,0x6070); lcdDelay(5);
lcdWriteReg(0x0005,0x0000); lcdDelay(5);
lcdWriteReg(0x0006,0x0000); lcdDelay(5);
lcdWriteReg(0x0016,0xEF1C); lcdDelay(5);
lcdWriteReg(0x0017,0x0003); lcdDelay(5);
lcdWriteReg(0x0007,0x0133); lcdDelay(5);
lcdWriteReg(0x000B,0x0000); lcdDelay(5);
lcdWriteReg(0x000F,0x0000); lcdDelay(5);
lcdWriteReg(0x0041,0x0000); lcdDelay(5);
lcdWriteReg(0x0042,0x0000); lcdDelay(5);
lcdWriteReg(0x0048,0x0000); lcdDelay(5);
lcdWriteReg(0x0049,0x013F); lcdDelay(5);
lcdWriteReg(0x004A,0x0000); lcdDelay(5);
lcdWriteReg(0x004B,0x0000); lcdDelay(5);
lcdWriteReg(0x0044,0xEF00); lcdDelay(5);
lcdWriteReg(0x0045,0x0000); lcdDelay(5);
lcdWriteReg(0x0046,0x013F); lcdDelay(5);
lcdWriteReg(0x0030,0x0707); lcdDelay(5);
lcdWriteReg(0x0031,0x0204); lcdDelay(5);
lcdWriteReg(0x0032,0x0204); lcdDelay(5);
lcdWriteReg(0x0033,0x0502); lcdDelay(5);
lcdWriteReg(0x0034,0x0507); lcdDelay(5);
lcdWriteReg(0x0035,0x0204); lcdDelay(5);
lcdWriteReg(0x0036,0x0204); lcdDelay(5);
lcdWriteReg(0x0037,0x0502); lcdDelay(5);
lcdWriteReg(0x003A,0x0302); lcdDelay(5);
lcdWriteReg(0x003B,0x0302); lcdDelay(5);
lcdWriteReg(0x0023,0x0000); lcdDelay(5);
lcdWriteReg(0x0024,0x0000); lcdDelay(5);
lcdWriteReg(0x0025,0x8000); lcdDelay(5);
lcdWriteReg(0x004f,0);
lcdWriteReg(0x004e,0);
}
lcdDelay(5);
lld_lcdInit();
lcd_height = SCREEN_HEIGHT;
lcd_width = SCREEN_WIDTH;
}

1
glcd.h
View File

@ -51,6 +51,7 @@ 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);