Fix color lcd detection (only check ID3 byte).
Also: some cleanup of the lcd code. Sorry, I felt compelled.
This commit is contained in:
parent
5f584adb82
commit
b10f12ba1f
|
@ -10,9 +10,8 @@
|
||||||
#include "usb/usbmsc.h"
|
#include "usb/usbmsc.h"
|
||||||
|
|
||||||
|
|
||||||
#define DISPLAY_UNKNOWN 0
|
#define DISPLAY_N1200 0
|
||||||
#define DISPLAY_N1200 1
|
#define DISPLAY_N1600 1
|
||||||
#define DISPLAY_N1600 2
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* Utility routines to manage nokia display */
|
/* Utility routines to manage nokia display */
|
||||||
|
@ -128,7 +127,7 @@ uint8_t lcdRead(uint8_t data)
|
||||||
|
|
||||||
|
|
||||||
void lcdInit(void) {
|
void lcdInit(void) {
|
||||||
int id1,id2,id3,id4;
|
int id;
|
||||||
|
|
||||||
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
|
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
|
||||||
|
|
||||||
|
@ -144,16 +143,12 @@ void lcdInit(void) {
|
||||||
gpioSetValue(RB_LCD_RST, 1);
|
gpioSetValue(RB_LCD_RST, 1);
|
||||||
delayms(100);
|
delayms(100);
|
||||||
|
|
||||||
id1=lcdRead(128+64+16+8 +2 ); // it will screw up everything.. better do it before anything else --the_nihilant
|
id=lcdRead(220); // ID3
|
||||||
id2=lcdRead(128+64+16+8 +2+1); // .. but after the code above! --the_nihilant
|
|
||||||
// id3=lcdRead(128+64+16+8+4 ); // id1 and id2 are enough for most screens
|
|
||||||
// id4=lcdRead(128+64+16+8+4 +1); // id3 and id4 would only use up PRECIOUS SPACE --the_nihilant
|
|
||||||
|
|
||||||
lcd_select();
|
if(id==14)
|
||||||
|
displayType=DISPLAY_N1600;
|
||||||
if((id1==69)&&(id2==214))displayType=DISPLAY_N1600;
|
else /* ID3 == 48 */
|
||||||
//if((id1==254)&&(id2==2))displayType=DISPLAY_N1200;
|
displayType=DISPLAY_N1200;
|
||||||
else displayType=DISPLAY_N1200; // unknown displays are treated like N1200s anyway, this saves an if (PRECIOUS SPACE) --the_nihilant
|
|
||||||
|
|
||||||
/* Small Nokia 1200 LCD docs:
|
/* Small Nokia 1200 LCD docs:
|
||||||
* clear/ set
|
* clear/ set
|
||||||
|
@ -168,67 +163,49 @@ void lcdInit(void) {
|
||||||
* 0xd0+x black lines from top? (-0xdf?)
|
* 0xd0+x black lines from top? (-0xdf?)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if(displayType<=DISPLAY_N1200){
|
lcd_select();
|
||||||
// lcdWrite(TYPE_CMD,0xE2);
|
|
||||||
// delayms(5);
|
if(displayType==DISPLAY_N1200){
|
||||||
uint8_t initseq[] = {0xE2,0xAF, // Display ON
|
uint8_t initseq[]= { 0xE2,0xAF, // Display ON
|
||||||
0xA1, // Mirror-X
|
0xA1, // Mirror-X
|
||||||
0xA4, 0x2F, 0xB0, 0x10};
|
0xA4, 0x2F, 0xB0, 0x10};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i<sizeof(initseq)){
|
while(i<sizeof(initseq)){
|
||||||
lcdWrite(TYPE_CMD,initseq[i++]);
|
lcdWrite(TYPE_CMD,initseq[i++]);
|
||||||
delayms(5); // this is only needed after the first command (0xE2), but doing like this saves space and it still works --the_nihilant
|
delayms(5); // actually only needed after the first
|
||||||
}
|
}
|
||||||
// lcdWrite(TYPE_CMD,0x00);
|
}else{ /* displayType==DISPLAY_N1600 */
|
||||||
goto end;
|
|
||||||
}/*else if(displayType==DISPLAY_N1600)*/{
|
|
||||||
uint8_t initseq_d[] = {
|
uint8_t initseq_d[] = {
|
||||||
0x36,
|
0x36,
|
||||||
0x29, 0xBA, 0x07,
|
0x29, 0xBA, 0x07,
|
||||||
0x15,0x25, 0x3f,
|
0x15, 0x25, 0x3f,
|
||||||
0x11, 0x13, 0X37,
|
0x11, 0x13, 0x37,
|
||||||
0x00, 0x3A, 0x05,
|
0x00, 0x3A, 0x05,
|
||||||
0x2A, 0, 98-1,
|
0x2A, 0, 98-1,
|
||||||
0x2B, 0, 70-1};
|
0x2B, 0, 70-1};
|
||||||
uint32_t initseq_c = ~/*0x95a7;*/0x12BA7; // this saves 12 bytes overall --the_nihilant
|
uint32_t initseq_c = ~ 0x12BA7; // command/data bitstring
|
||||||
int i = 0;
|
int i = 0;
|
||||||
//// delayms(10); // useless --the_nihilant
|
|
||||||
lcdWrite(TYPE_CMD,0x01); //sw reset
|
lcdWrite(TYPE_CMD,0x01); //sw reset
|
||||||
//// delayms(10); // useless
|
delayms(10);
|
||||||
//// lcdWrite(TYPE_CMD,0x11); //sleepout (useless --the_nihilant)
|
|
||||||
delayms(10); // NOT useless! --the_nihilant
|
|
||||||
|
|
||||||
// lcdWrite(TYPE_CMD,0x36); //MADCTL MY MX V LAO RGB X X X
|
|
||||||
//// lcdWrite(TYPE_DATA,0x00); // useless
|
|
||||||
|
|
||||||
//// lcdWrite(TYPE_CMD,0x25); // contrast... useless (set below anyway)
|
|
||||||
//// lcdWrite(TYPE_DATA,0x3F);
|
|
||||||
//// delayms(10); // useless --the_nihilant
|
|
||||||
|
|
||||||
while(i<sizeof(initseq_d)){
|
while(i<sizeof(initseq_d)){
|
||||||
lcdWrite(initseq_c&1, initseq_d[i++]);
|
lcdWrite(initseq_c&1, initseq_d[i++]);
|
||||||
initseq_c = initseq_c >> 1;
|
initseq_c = initseq_c >> 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end:
|
|
||||||
lcd_deselect();
|
lcd_deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdFill(char f){
|
void lcdFill(char f){
|
||||||
// using memset saves 4 bytes compared with the loop!
|
|
||||||
memset(lcdBuffer,f,RESX*RESY_B);
|
memset(lcdBuffer,f,RESX*RESY_B);
|
||||||
/* int x;
|
#if 0
|
||||||
|
int x;
|
||||||
for(x=0;x<RESX*RESY_B;x++) {
|
for(x=0;x<RESX*RESY_B;x++) {
|
||||||
lcdBuffer[x]=f;
|
lcdBuffer[x]=f;
|
||||||
}*/
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* it's not used... it would have no footprint anyway as it's apparently removed anyway at some point (yes I tried, same size) --the_nihilant
|
|
||||||
void lcdSafeSetPixel(char x, char y, bool f){
|
|
||||||
if (x>=0 && x<RESX && y>=0 && y < RESY)
|
|
||||||
lcdSetPixel(x, y, f);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void lcdSetPixel(char x, char y, bool f){
|
void lcdSetPixel(char x, char y, bool f){
|
||||||
if (x<0 || x> RESX || y<0 || y > RESY)
|
if (x<0 || x> RESX || y<0 || y > RESY)
|
||||||
return;
|
return;
|
||||||
|
@ -251,13 +228,15 @@ bool lcdGetPixel(char x, char y){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _helper_pixel16(uint16_t color){ // putting this here saves a few bytes overall --the_nihilant
|
// Color display hepler functions
|
||||||
|
static void _helper_pixel16(uint16_t color){
|
||||||
lcdWrite(TYPE_DATA,color>>8);
|
lcdWrite(TYPE_DATA,color>>8);
|
||||||
lcdWrite(TYPE_DATA,color&0xFF);
|
lcdWrite(TYPE_DATA,color&0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _helper_hline(uint16_t color){ // same for this --the_nihilant
|
static void _helper_hline(uint16_t color){
|
||||||
for(int cx=0;cx<98;cx++) _helper_pixel16(color);
|
for(int cx=0;cx<98;cx++)
|
||||||
|
_helper_pixel16(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define THECOLOR_R 0x0
|
#define THECOLOR_R 0x0
|
||||||
|
@ -268,7 +247,7 @@ void lcdDisplay(void) {
|
||||||
char byte;
|
char byte;
|
||||||
lcd_select();
|
lcd_select();
|
||||||
|
|
||||||
if(displayType<=DISPLAY_N1200){
|
if(displayType==DISPLAY_N1200){
|
||||||
lcdWrite(TYPE_CMD,0xB0);
|
lcdWrite(TYPE_CMD,0xB0);
|
||||||
lcdWrite(TYPE_CMD,0x10);
|
lcdWrite(TYPE_CMD,0x10);
|
||||||
lcdWrite(TYPE_CMD,0x00);
|
lcdWrite(TYPE_CMD,0x00);
|
||||||
|
@ -286,8 +265,7 @@ void lcdDisplay(void) {
|
||||||
lcdWrite(TYPE_DATA,byte);
|
lcdWrite(TYPE_DATA,byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto end;
|
} else { /* displayType==DISPLAY_N1600 */
|
||||||
}/*else if(displayType==DISPLAY_N1600)*/{
|
|
||||||
unsigned char r=THECOLOR_R,g=THECOLOR_G,b=THECOLOR_B;
|
unsigned char r=THECOLOR_R,g=THECOLOR_G,b=THECOLOR_B;
|
||||||
unsigned char br=0xFF, bg=0xFF, bb=0xFF;
|
unsigned char br=0xFF, bg=0xFF, bb=0xFF;
|
||||||
unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80;
|
unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80;
|
||||||
|
@ -326,9 +304,9 @@ void lcdDisplay(void) {
|
||||||
//bottom line of the frame
|
//bottom line of the frame
|
||||||
_helper_hline(framecolor);
|
_helper_hline(framecolor);
|
||||||
}
|
}
|
||||||
end:
|
|
||||||
lcd_deselect();
|
lcd_deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcdRefresh() __attribute__ ((weak, alias ("lcdDisplay")));
|
void lcdRefresh() __attribute__ ((weak, alias ("lcdDisplay")));
|
||||||
|
|
||||||
inline void lcdInvert(void) {
|
inline void lcdInvert(void) {
|
||||||
|
@ -337,32 +315,23 @@ inline void lcdInvert(void) {
|
||||||
|
|
||||||
void lcdSetContrast(int c) {
|
void lcdSetContrast(int c) {
|
||||||
lcd_select();
|
lcd_select();
|
||||||
if(displayType<=DISPLAY_N1200){
|
if(displayType==DISPLAY_N1200){
|
||||||
c+=0x80;
|
if(c<0x1F)
|
||||||
if(c>0x9F) goto end;
|
lcdWrite(TYPE_CMD,0x80+c);
|
||||||
lcdWrite(TYPE_CMD,c);
|
}else{ /* displayType==DISPLAY_N1600 */
|
||||||
goto end;
|
if(c<0x40) {
|
||||||
}/*else if(displayType==DISPLAY_N1600)*/{
|
|
||||||
if(c>=0x40) goto end;
|
|
||||||
lcdWrite(TYPE_CMD,0x25);
|
lcdWrite(TYPE_CMD,0x25);
|
||||||
lcdWrite(TYPE_DATA,4*c);
|
lcdWrite(TYPE_DATA,4*c);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
end:
|
|
||||||
lcd_deselect();
|
lcd_deselect();
|
||||||
};
|
};
|
||||||
|
|
||||||
void lcdSetInvert(int c) {
|
void lcdSetInvert(int c) {
|
||||||
/* if it's just to force c to be either 0 or 1, it can be done more efficiently --the_nihilant
|
|
||||||
if(c>1)
|
|
||||||
c=1;
|
|
||||||
if(c<0)
|
|
||||||
c=1;
|
|
||||||
*/
|
|
||||||
c=(c&1)+0xa6; // like this --the_nihilant
|
|
||||||
lcd_select();
|
lcd_select();
|
||||||
// if(displayType<=DISPLAY_N1200){ // it doesn't harm N1600 displays, does nothing. The if, on the other hand, uses PRECIOUS SPACE --the_nihilant
|
/* it doesn't harm N1600, save space */
|
||||||
lcdWrite(TYPE_CMD,c);
|
// if(displayType==DISPLAY_N1200)
|
||||||
// }
|
lcdWrite(TYPE_CMD,(c&1)+0xa6);
|
||||||
lcd_deselect();
|
lcd_deselect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -374,7 +343,6 @@ void __attribute__((__deprecated__)) lcdToggleFlag(int flag) {
|
||||||
GLOBAL(lcdinvert)=!GLOBAL(lcdinvert);
|
GLOBAL(lcdinvert)=!GLOBAL(lcdinvert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void lcdShiftH(bool right, bool wrap) {
|
void lcdShiftH(bool right, bool wrap) {
|
||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
for (int yb = 0; yb<RESY_B; yb++) {
|
for (int yb = 0; yb<RESY_B; yb++) {
|
||||||
|
@ -434,7 +402,6 @@ void lcdShiftV(bool up, bool wrap) {
|
||||||
}
|
}
|
||||||
lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8);
|
lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue