Merge commit '2fdab582be7a2327fbf34184b3c0c8da7efae1d7'

This commit is contained in:
Stefan `Sec` Zehl 2012-02-03 12:02:08 +01:00
commit 5d5ba8c4a7
1 changed files with 153 additions and 83 deletions

View File

@ -9,9 +9,118 @@
#include "basic/config.h" #include "basic/config.h"
#include "usb/usbmsc.h" #include "usb/usbmsc.h"
enum display_type {
DISPLAY_TYPE_N1200 = 0,
DISPLAY_TYPE_N1600 = 1,
};
#define DISPLAY_N1200 0 enum command_type {
#define DISPLAY_N1600 1 COMMAND_TYPE_CMD = 0,
COMMAND_TYPE_DATA = 1,
};
struct display_macro {
enum command_type type:1;
unsigned int data:8;
unsigned int delay_after:7;
} __attribute__((packed));
/* Small Nokia 1200 LCD docs:
* clear/ set
* on 0xae / 0xaf
* invert 0xa6 / 0xa7
* mirror-x 0xA0 / 0xA1
* mirror-y 0xc7 / 0xc8
*
* 0x20+x contrast (0=black - 0x2e)
* 0x40+x offset in rows from top (-0x7f)
* 0x80+x contrast? (0=black -0x9f?)
* 0xd0+x black lines from top? (-0xdf?)
*
*/
/* Decoded:
* E2: Internal reset
* AF: Display on/off: DON = 1
* A1: undefined?
* A4: all on/normal: DAL = 0
* 2F: charge pump on/off: PC = 1
* B0: set y address: Y[0-3] = 0
* 10: set x address (upper bits): X[6-4] = 0
*/
static const struct display_macro INIT_N1200[] = {
{COMMAND_TYPE_CMD, 0xE2, 5},
{COMMAND_TYPE_CMD, 0xAF},
{COMMAND_TYPE_CMD, 0xA1},
{COMMAND_TYPE_CMD, 0x2F},
{COMMAND_TYPE_CMD, 0xB0},
{COMMAND_TYPE_CMD, 0x10},
};
static const struct display_macro PREPARE_N1200[] = {
{COMMAND_TYPE_CMD, 0xB0},
{COMMAND_TYPE_CMD, 0x10},
{COMMAND_TYPE_CMD, 0x00},
};
/* Decoded:
* CMD 29: DISPON
* CMD BA: Data order (1)
* CMD 11: sleep out
* CMD 13: normal display mode on
* CMD 37: set scroll entry point
* DAT 00: scroll entry point
* CMD 3A: interface pixel format
* DAT 05: 16 bit/pixel
* CMD 2A: column address set
* DAT 0 : xs
* DAT 98-1 : xe
* CMD 2B: page address set
* DAT 0 : ys
* DAT 70-1 : ye
*/
static const struct display_macro INIT_N1600[] = {
{COMMAND_TYPE_CMD, 0x01, 10},
{COMMAND_TYPE_CMD, 0x29},
{COMMAND_TYPE_CMD, 0xBA},
{COMMAND_TYPE_CMD, 0x11},
{COMMAND_TYPE_CMD, 0x13},
{COMMAND_TYPE_CMD, 0x37},
{COMMAND_TYPE_DATA, 0x00},
{COMMAND_TYPE_CMD, 0x3A},
{COMMAND_TYPE_DATA, 0x05},
{COMMAND_TYPE_CMD, 0x2A},
{COMMAND_TYPE_DATA, 0x00},
{COMMAND_TYPE_DATA, 98-1},
{COMMAND_TYPE_CMD, 0x2B},
{COMMAND_TYPE_DATA, 0},
{COMMAND_TYPE_DATA, 70-1},
};
static const struct display_macro PREPARE_N1600[] = {
{COMMAND_TYPE_CMD, 0x2C},
};
struct display_descriptor {
/* Macro to execute in order to initialize the display from scratch */
const struct display_macro * init_macro;
int init_macro_length;
/* Macro to execute to prepare the display for sending raw contents */
const struct display_macro * prepare_macro;
int prepare_macro_length;
};
const struct display_descriptor DISPLAY_DESCRIPTORS[] = {
[DISPLAY_TYPE_N1200] = {
INIT_N1200, sizeof(INIT_N1200)/sizeof(INIT_N1200[0]),
PREPARE_N1200, sizeof(PREPARE_N1200)/sizeof(PREPARE_N1200[0])
},
[DISPLAY_TYPE_N1600] = {
INIT_N1600, sizeof(INIT_N1600)/sizeof(INIT_N1600[0]),
PREPARE_N1600, sizeof(PREPARE_N1600)/sizeof(PREPARE_N1600[0])
},
};
/**************************************************************************/ /**************************************************************************/
/* Utility routines to manage nokia display */ /* Utility routines to manage nokia display */
@ -20,10 +129,9 @@
uint8_t lcdBuffer[RESX*RESY_B]; uint8_t lcdBuffer[RESX*RESY_B];
uint32_t intstatus; // Caches USB interrupt state uint32_t intstatus; // Caches USB interrupt state
// (need to disable MSC while displaying) // (need to disable MSC while displaying)
uint8_t displayType; enum display_type displayType;
const struct display_descriptor *displayDescriptor;
#define TYPE_CMD 0
#define TYPE_DATA 1
static void lcd_select() { static void lcd_select() {
#if CFG_USBMSC #if CFG_USBMSC
@ -125,6 +233,13 @@ uint8_t lcdRead(uint8_t data)
return ret; return ret;
} }
static void lcdExecuteMacro(const struct display_macro *macro, int macro_length)
{
for(int i=0; i<macro_length; i++) {
lcdWrite(macro[i].type, macro[i].data);
delayms(macro[i].delay_after);
}
}
void lcdInit(void) { void lcdInit(void) {
int id; int id;
@ -146,53 +261,14 @@ void lcdInit(void) {
id=lcdRead(220); // ID3 id=lcdRead(220); // ID3
if(id==14) if(id==14)
displayType=DISPLAY_N1600; displayType=DISPLAY_TYPE_N1600;
else /* ID3 == 48 */ else /* ID3 == 48 */
displayType=DISPLAY_N1200; displayType=DISPLAY_TYPE_N1200;
displayDescriptor = DISPLAY_DESCRIPTORS + displayType;
/* Small Nokia 1200 LCD docs:
* clear/ set
* on 0xae / 0xaf
* invert 0xa6 / 0xa7
* mirror-x 0xA0 / 0xA1
* mirror-y 0xc7 / 0xc8
*
* 0x20+x contrast (0=black - 0x2e)
* 0x40+x offset in rows from top (-0x7f)
* 0x80+x contrast? (0=black -0x9f?)
* 0xd0+x black lines from top? (-0xdf?)
*
*/
lcd_select(); lcd_select();
lcdExecuteMacro(displayDescriptor->init_macro, displayDescriptor->init_macro_length);
if(displayType==DISPLAY_N1200){
static uint8_t initseq[]= { 0xE2,0xAF, // Display ON
0xA1, // Mirror-X
0xA4, 0x2F, 0xB0, 0x10};
int i = 0;
while(i<sizeof(initseq)){
lcdWrite(TYPE_CMD,initseq[i++]);
delayms(5); // actually only needed after the first
}
}else{ /* displayType==DISPLAY_N1600 */
static uint8_t initseq_d[] = {
0x36,
0x29, 0xBA, 0x07,
0x15, 0x25, 0x3f,
0x11, 0x13, 0x37,
0x00, 0x3A, 0x05,
0x2A, 0, 98-1,
0x2B, 0, 70-1};
uint32_t initseq_c = ~ 0x12BA7; // command/data bitstring
int i = 0;
lcdWrite(TYPE_CMD,0x01); //sw reset
delayms(10);
while(i<sizeof(initseq_d)){
lcdWrite(initseq_c&1, initseq_d[i++]);
initseq_c = initseq_c >> 1;
}
}
lcd_deselect(); lcd_deselect();
} }
@ -230,8 +306,8 @@ bool lcdGetPixel(char x, char y){
// Color display hepler functions // Color display hepler functions
static void _helper_pixel16(uint16_t color){ static void _helper_pixel16(uint16_t color){
lcdWrite(TYPE_DATA,color>>8); lcdWrite(COMMAND_TYPE_DATA,color>>8);
lcdWrite(TYPE_DATA,color&0xFF); lcdWrite(COMMAND_TYPE_DATA,color&0xFF);
} }
static void _helper_hline(uint16_t color){ static void _helper_hline(uint16_t color){
@ -239,18 +315,20 @@ static void _helper_hline(uint16_t color){
_helper_pixel16(color); _helper_pixel16(color);
} }
#define THECOLOR_R 0x0 #define COLORPACK_RGB565(r,g,b) (((r&0xF8) << 8) | ((g&0xFC)<<3) | ((b&0xF8) >> 3))
#define THECOLOR_G 0x60
#define THECOLOR_B 0x0 static const uint16_t COLOR_FG = COLORPACK_RGB565(0x00, 0x60, 0x00);
static const uint16_t COLOR_BG = COLORPACK_RGB565(0xff, 0xff, 0xff);
static const uint16_t COLOR_FRAME = COLORPACK_RGB565(0x00, 0x00, 0x80);
void lcdDisplay(void) { void lcdDisplay(void) {
char byte; char byte;
lcd_select(); lcd_select();
if(displayType==DISPLAY_N1200){ lcdExecuteMacro(displayDescriptor->prepare_macro, displayDescriptor->prepare_macro_length);
lcdWrite(TYPE_CMD,0xB0);
lcdWrite(TYPE_CMD,0x10); if(displayType==DISPLAY_TYPE_N1200){
lcdWrite(TYPE_CMD,0x00);
uint16_t i,page; uint16_t i,page;
for(page=0; page<RESY_B;page++) { for(page=0; page<RESY_B;page++) {
for(i=0; i<RESX; i++) { for(i=0; i<RESX; i++) {
@ -262,29 +340,19 @@ void lcdDisplay(void) {
if (GLOBAL(lcdinvert)) if (GLOBAL(lcdinvert))
byte=~byte; byte=~byte;
lcdWrite(TYPE_DATA,byte); lcdWrite(COMMAND_TYPE_DATA,byte);
} }
} }
} else { /* displayType==DISPLAY_N1600 */ } else { /* displayType==DISPLAY_TYPE_N1600 */
unsigned char r=THECOLOR_R,g=THECOLOR_G,b=THECOLOR_B;
unsigned char br=0xFF, bg=0xFF, bb=0xFF;
unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80;
uint16_t color,framecolor,backcolor;
uint16_t x,y; uint16_t x,y;
bool px; bool px;
uint16_t actualcolor;
color = ((r&0xF8) << 8) | ((g&0xFC)<<3) | ((b&0xF8) >> 3);
framecolor= ((frame_r&0xF8) << 8) | ((frame_g&0xFC)<<3) | ((frame_b&0xF8) >> 3);
backcolor= ((br&0xF8) << 8) | ((bg&0xFC)<<3) | ((bb&0xF8) >> 3);
lcdWrite(TYPE_CMD,0x2C);
//top line of the frame... //top line of the frame...
_helper_hline(framecolor); _helper_hline(COLOR_FRAME);
for(y=RESY;y>0;y--){ for(y=RESY;y>0;y--){
//left line of the frame //left line of the frame
_helper_pixel16(framecolor); _helper_pixel16(COLOR_FRAME);
for(x=RESX;x>0;x--){ for(x=RESX;x>0;x--){
if(GLOBAL(lcdmirror)) if(GLOBAL(lcdmirror))
@ -292,17 +360,19 @@ void lcdDisplay(void) {
else else
px=lcdGetPixel(x-1,y-1); px=lcdGetPixel(x-1,y-1);
if((!px)^(!GLOBAL(lcdinvert))) actualcolor=color; if((!px)^(!GLOBAL(lcdinvert))) {
else actualcolor=backcolor; /* white */ _helper_pixel16(COLOR_FG); /* foreground */
} else {
_helper_pixel16(COLOR_BG); /* background */
}
_helper_pixel16(actualcolor);
} }
//right line of the frame //right line of the frame
_helper_pixel16(framecolor); _helper_pixel16(COLOR_FRAME);
} }
//bottom line of the frame //bottom line of the frame
_helper_hline(framecolor); _helper_hline(COLOR_FRAME);
} }
lcd_deselect(); lcd_deselect();
} }
@ -315,13 +385,13 @@ inline void lcdInvert(void) {
void lcdSetContrast(int c) { void lcdSetContrast(int c) {
lcd_select(); lcd_select();
if(displayType==DISPLAY_N1200){ if(displayType==DISPLAY_TYPE_N1200){
if(c<0x1F) if(c<0x1F)
lcdWrite(TYPE_CMD,0x80+c); lcdWrite(COMMAND_TYPE_CMD,0x80+c);
}else{ /* displayType==DISPLAY_N1600 */ }else{ /* displayType==DISPLAY_TYPE_N1600 */
if(c<0x40) { if(c<0x40) {
lcdWrite(TYPE_CMD,0x25); lcdWrite(COMMAND_TYPE_CMD,0x25);
lcdWrite(TYPE_DATA,4*c); lcdWrite(COMMAND_TYPE_DATA,4*c);
}; };
} }
lcd_deselect(); lcd_deselect();
@ -331,7 +401,7 @@ void lcdSetInvert(int c) {
lcd_select(); lcd_select();
/* it doesn't harm N1600, save space */ /* it doesn't harm N1600, save space */
// if(displayType==DISPLAY_N1200) // if(displayType==DISPLAY_N1200)
lcdWrite(TYPE_CMD,(c&1)+0xa6); lcdWrite(COMMAND_TYPE_CMD,(c&1)+0xa6);
lcd_deselect(); lcd_deselect();
}; };