void doLCD(){ // lcdWrite(TYPE_CMD,0x36); lcdWrite(TYPE_DATA,0b11000000); int i; lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3); lcdWrite(TYPE_CMD,0x2C); for (i=0;i<img12_len;i++){ lcdWrite(TYPE_DATA,img12_raw[i]); }; lcd_deselect(); int ct=0x3a; while(1){ switch(getInput()){ case BTN_UP: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcdWrite(TYPE_CMD,0x2C); for (i=0;i<img16_len;i++){ lcdWrite(TYPE_DATA,img16_raw[i]); }; lcd_deselect(); break; case BTN_DOWN: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3); lcdWrite(TYPE_CMD,0x2C); for (i=0;i<img12_len;i++){ lcdWrite(TYPE_DATA,img12_raw[i]); }; lcd_deselect(); break; case BTN_LEFT: ct-=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); // lcdWrite(TYPE_CMD,0x20); lcd_deselect(); break; case BTN_RIGHT: ct+=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); // lcdWrite(TYPE_CMD,0x21); lcd_deselect(); break; case BTN_ENTER: return; break; }; }; };
void lcdInit(void) { SETUPgout(LCD_BL_EN); SETUPgout(LCD_RESET); SETUPgout(LCD_CS); /* prepare SPI */ SETUPpin(LCD_MOSI); SETUPpin(LCD_SCK); // Reset the display OFF(LCD_RESET); delayms(100); /* 1 ms */ ON(LCD_RESET); delayms(100); /* 5 ms */ lcd_select(); static uint8_t initseq_d[] = { /* The controller is a PCF8833 - documentation can be found online. */ 0x11, // SLEEP_OUT (wake up) 0x3A, 2, // mode 8bpp (2= 8bpp, 3= 12bpp, 5= 16bpp) 0x36, 0b11000000, // my,mx,v,lao,rgb,x,x,x 0x25, 0x3a, // set contrast 0x29, // display on 0x03, // BSTRON (booster voltage) 0x2A, 1, RESX, 0x2B, 1, RESY }; uint16_t initseq_c = ~ ( /* commands: 1, data: 0 */ (1<< 0) | (1<< 1) | (0<< 2) | (1<< 3) | (0<< 4) | (1<< 5) | (0<< 6) | (1<< 7) | (1<< 8) | (1<< 9) | (0<<10) | (0<<11) | (1<<12) | (0<<13) | (0<<14) | 0); int i = 0; lcdWrite(0, 0x01); /* most color displays need the pause */ delayms(10); while(i<sizeof(initseq_d)){ lcdWrite(initseq_c&1, initseq_d[i++]); initseq_c = initseq_c >> 1; } lcd_deselect(); lcdFill(0xff); /* Clear display buffer */ setSystemFont(); }
void do_image(char * filename){ FATFS FatFs; FRESULT res; int i; FIL file; UINT readbytes; res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ); if(res!=F_OK){ lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); lcdPrintln("FOPEN ERROR"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; #define BLOCK 1024 uint8_t idata[BLOCK]; lcd_select(); lcdWrite(TYPE_CMD,0x2C); lcd_deselect(); do { res=f_read(&file, idata, BLOCK, &readbytes); lcd_select(); for (i=0;i<readbytes;i++) lcdWrite(TYPE_DATA,idata[i]); lcd_deselect(); }while(res==F_OK && readbytes==BLOCK); if(res!=F_OK){ lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); lcdPrint("Read Error:"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; };
void lcdDisplay(void) { lcd_select(); uint16_t x,y; lcdWrite(TYPE_CMD,0x2C); // memory write (RAMWR) for(y=0;y<RESY;y++){ for(x=0;x<RESX;x++){ lcdWrite(TYPE_DATA,lcdGetPixel(x,y)); }; } lcd_deselect(); }
void g_fill_rgb() { lcd_set_cursor(0, 0); lcd_write_index(0x022); uint16_t x, y; lcd_select(); lcd_write_data_start(); for (x = 0; x < LCD_X; x++) { for (y = 0; y < LCD_Y; y++) { lcd_write_data_body((x << 8) | y); } } lcd_end_gfx(); }
//# MENU img void img_menu() { char filename[FLEN]; FATFS FatFs; FRESULT res; int ct=0x3a; lcdClear(); lcdPrintln("Image"); lcdPrintln("up: 16bit"); lcdPrintln("down: 12bit"); lcdPrintln("l/r: contrast"); lcdDisplay(); getInputWaitRelease(); while(1){ switch(getInput()){ case BTN_UP: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); getInputWaitRelease(); if(selectFile(filename,"L16")){ lcdPrintln("Select ERROR"); lcdDisplay(); getInputWait(); return; }; lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcd_deselect(); do_image(filename); break; case BTN_DOWN: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); getInputWaitRelease(); if(selectFile(filename,"LCD")){ lcdPrintln("Select ERROR"); lcdDisplay(); getInputWait(); return; }; lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3); lcd_deselect(); do_image(filename); break; case BTN_LEFT: ct-=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_RIGHT: ct+=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_ENTER: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); return; }; }; };
//# MENU lcd void lcd_menu() { getInputWaitRelease(); lcdClear(); lcdPrintln("LCD:"); lcdDisplay(); ON(LED1); uint16_t x,y; uint8_t rgb=0; uint8_t ct=0x3a; uint16_t rgba[]= { RGB(0xff,0,0), RGB(0,0xff,0), RGB(0,0,0xff), RGB(0,0xff,0xff),RGB(0xff,0,0xff),RGB(0xff,0xff,0), RGB(0xff,0xff,0xff),0 }; while(1) { switch(getInputWaitRepeat()) { case BTN_DOWN: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcdWrite(TYPE_CMD,0x2C); for (y=0; y<128; y++) { for (x=0; x<RESX; x++) { if (x<20) { if(y<64) { PIX(0xff,(0xff-(0xff&(y<<2))),(0xff-(0xff&(y<<2)))); } else { PIX((0xff-(0xff&(y<<2))),0,0); }; } else if (x <40) { if(y<64) { PIX((0xff-(0xff&(y<<2))),0xff,(0xff-(0xff&(y<<2)))); } else { PIX(0,(0xff-(0xff&(y<<2))),0); }; } else if (x <60) { if(y<64) { PIX((0xff-(0xff&(y<<2))),(0xff-(0xff&(y<<2))),0xff); } else { PIX(0,0,(0xff-(0xff&(y<<2)))); }; } else if (x <80) { if(y<64) { PIX(((0xff&(y<<2))),0,0); } else { PIX(0xff,((0xff&(y<<2))),((0xff&(y<<2)))); }; } else if (x <100) { if(y<64) { PIX(0,((0xff&(y<<2))),0); } else { PIX(((0xff&(y<<2))),0xff,((0xff&(y<<2)))); }; } else if (x <120) { if(y<64) { PIX(0,0,((0xff&(y<<2)))); } else { PIX(((0xff&(y<<2))),((0xff&(y<<2))),0xff); }; } else { PIX(0,0,0); } }; }; for (y=128; y<RESY; y++) { for (x=0; x<RESX; x++) { PIX(0,0,0); }; }; lcd_deselect(); break; case BTN_LEFT: ct--; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_RIGHT: ct++; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_UP: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcdWrite(TYPE_CMD,0x2C); if(rgb==0) { for (y=0; y<RESY; y++) { for (x=0; x<RESX; x++) { if(x==0 || x==RESX-1 || y==0 || y==RESY-1) { PIX(0xff,0,0); } else if(x==1 || x==RESX-2 || y==1 || y==RESY-2) { PIX(0xff,0xff,0); } else if(x==2 || x==RESX-3 || y==2 || y==RESY-3) { PIX(0,0,0xff); } else { PIX(0xff,0xff,0xff); }; }; }; } else { for (y=0; y<RESY; y++) { for (x=0; x<RESX; x++) { lcdWrite(TYPE_DATA,rgba[rgb-1]>>8); lcdWrite(TYPE_DATA,rgba[rgb-1]&0xff); }; }; }; lcd_deselect(); rgb=(rgb+1)%(1+(sizeof(rgba)/sizeof(*rgba))); break; case BTN_ENTER: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); return; }; getInputWaitRelease(); }; };
void lcdInit(void) { int id; sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); gpioSetValue(RB_LCD_CS, 1); gpioSetValue(RB_LCD_RST, 1); gpioSetDir(RB_LCD_CS, gpioDirection_Output); gpioSetDir(RB_LCD_RST, gpioDirection_Output); delayms(100); gpioSetValue(RB_LCD_RST, 0); delayms(100); gpioSetValue(RB_LCD_RST, 1); delayms(100); id=lcdRead(220); // ID3 if(id==14) displayType=DISPLAY_N1600; else /* ID3 == 48 */ displayType=DISPLAY_N1200; /* 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(); if(displayType==DISPLAY_N1200){ 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 */ 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(); }
void lcdSetContrast(int c) { lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA,c); lcd_deselect(); }
int lcdShowImage(FIL* file) { uint8_t idata[BLOCK]; FRESULT res; UINT readbytes; image_t type=IMG_NONE; int len; res=f_read(file, &type, 1, &readbytes); switch(type){ case IMG_RAW_8: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); len=RESX*RESY; break; case IMG_RAW_12: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3); lcd_deselect(); len=RESX*RESY*3/2; break; case IMG_RAW_16: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcd_deselect(); len=RESX*RESY*2; break; default: lcdPrint("ERR: Image Type="); lcdPrintln(IntToStr(type,3,0)); lcdDisplay(); getInputWait(); return 1; }; lcd_select(); lcdWrite(TYPE_CMD,0x2C); lcd_deselect(); int rb; do { rb=BLOCK; if (len<BLOCK) rb=len; res=f_read(file, idata, rb, &readbytes); lcd_select(); for (int i=0;i<readbytes;i++) lcdWrite(TYPE_DATA,idata[i]); lcd_deselect(); len-=readbytes; }while(res==FR_OK && len>0 && rb==readbytes); if(res!=FR_OK){ lcdPrint("Read Error:"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return 1; }; return 0; }