Line buffer mode. sammple code with MIP8F_SPI_Ver40
Dependencies: MIP8F_SPI_Ver40 mbed
Dependents: MIP8f_FRDM_TransferMode_sample MIP8f_FRDM_Animation_sample
Introduction
Line buffer mode sample with MIP8F_SPI_Ver40 Display some color and monochrome bitmap.
Other information , please refer to https://os.mbed.com/teams/JapanDisplayInc/code/MIP8f_FRDM_sample/
Usage
Copy Setting File and Image to micro SD-CARD. (Same setting File and bitmap of MIP8f_FRDM_sample.)
a) Download the following file corresponding to the target panel, and rename file identifier (.bin -> .zip), and unzip the file on micro SD Card's root directory.
- LPM013M126x (176x176) :/media/uploads/JDI_Mbed_Team/sdcard_176x176.bin
- LPM027M128x (400x240) :/media/uploads/JDI_Mbed_Team/sdcard_400x240.bin
- LPM044M141x (640x480): /media/uploads/JDI_Mbed_Team/sdcard_640x480.bin
b) Insert micro SD-CARD to FRDM-K64F. c) Upload binary file to FRDM-K64F.and push Reset Button.
Other information
refer to Usage on https://os.mbed.com/teams/JapanDisplayInc/code/MIP8f_FRDM_sample/
this Sample Code (.bin)
/media/uploads/JDI_Mbed_Team/mip8f_frdm_linebuffer_sample.k64f.bin
Diff: main.cpp
- Revision:
- 10:167df76b02d0
- Parent:
- 7:c7a676157b4d
- Child:
- 12:40156f03a763
diff -r 0550432c22b5 -r 167df76b02d0 main.cpp --- a/main.cpp Wed Oct 31 02:18:53 2018 +0000 +++ b/main.cpp Tue Nov 06 02:16:33 2018 +0000 @@ -1,9 +1,9 @@ /** * @file main.cpp -* @brief Ver3.0 Sample source code for MIP8 diplay. +* @brief Ver4.0 Sample source code for MIP8 diplay. * @details -* -* Ver3.0 Addtional function is font display. this demo code is tha degit is counted up like a meter panel +* Ver4.0 Addtional function is Line buffer version.the Sammple bitmap display color and monochrome by line buffer. +* Ver3.0 Addtional function is font display. this demo code is the nunber is counted up like a meter panel * ver2.0 Addtional function is Monochome display by 1bit mode of SPI transfer. * * spi-transfer to Display has 3 mode. @@ -63,17 +63,25 @@ DigitalIn TexSW(SW3); //for debug -Serial pc(USBTX, USBRX); // tx, rx +//Serial pc(USBTX, USBRX); // tx, rx -void SDtex2BUF(char *filepath); //function prototype +#if FRAMEBUFF_MODE void SD2BUF(char *filepath); +void SDtex2BUF(char *filepath); +void ReadBmp(const char *fsrc, uint32_t FileNum); +#endif + +#if LINEBUFF_MODE +void SD2LINEBUF(char *filepath,int transfermode); +void ReadBmp2LineBuffer(const char *fsrc, uint32_t FileNum,int transfermode); +#endif + void ifOFFseq(void); void ifswPWM(void); void OffSequence(void); void DispAllDir(const char *fsrc); -void ReadBmp(const char *fsrc, uint32_t FileNum); uint32_t CntFile(const char *fsrc); //Grobal value int ifMargeTXT = 0; @@ -94,13 +102,13 @@ uint32_t filenum=0; char filepath[40]; - char countup[3+1]; - char KMPH[4+1]; - + //char countup[3+1]; + //char KMPH[4+1]; + + sd.disk_initialize(); HaltSW.Enable(1); - FILE *fp = fopen("/sd/settings2.txt", "rb"); //read binary if(fp != NULL) { fscanf(fp, "%d",&width); //width read @@ -128,12 +136,18 @@ WD.setWH(width,height); //input -> width, height WD.background(Black); //background = black +#if FRAMEBUFF_MODE WD.clsBUF(); //data initialize WD.writeDISP(); //picture write(black) +#endif +#if LINEBUFF_MODE + WD.clsLINEBUF(); //data initialize + WD.writeDISPLinebuffer(); //picture write(black) +#endif WD.SwDisp(1); //disp on -// OffSW.fall(&OffSequence); // Renamed "OffSW" as "PWMorOFF" for BK PWM setting -// SW settings for PWM or OFF + //OffSW.fall(&OffSequence); // Renamed "OffSW" as "PWMorOFF" for BK PWM setting + //SW settings for PWM or OFF PWMorOFF.fall(&ifswPWM); // Backlight //sw2 fall edge PWMorOFF.rise(&ifOFFseq); // OFF Sequence //sw2 rise edge @@ -156,167 +170,20 @@ { for( int j = 0; j < 2; j++) { - ReadBmp(filepath,0); - - while(HaltSW.State()) { // VCOM invert when image is still - // pol++; - // WD.command( (pol << 6) & 0x40 ); - // wait(bk_timer); //1Hz - } + #if LINEBUFF_MODE + if( j%2 == 0 ) //&& bmp_bitcount != 8) + ReadBmp2LineBuffer(filepath,i,TrBIT4); + else + ReadBmp2LineBuffer(filepath,i,TrBIT1); + #endif + while(HaltSW.State()); HaltSW.Clear(); - //1bit trasfer mode = monochro diplay - if( j%2 == 0 && bmp_bitcount != 8) - WD.writeDISP(TrBIT4); - else - WD.writeDISP(TrBIT1); - //wait(2); - - if( j%2 == 0 ) - { - // for color diaplay - WD.foreground(0x04); - WD.background(0x00); - }else{ - // for monochrome diaplay - WD.foreground(0x0e); - WD.background(0x00); - } - //WD.fillrect(0,115,399,205, WD.get_Background() ); - - sprintf(KMPH,"km/h"); - WD.set_ActualFontWidth(); - WD.set_font((unsigned char*) Arial28x28); - WD.obliqueout(70+200+35,100+20+49,KMPH); - - WD.set_font((unsigned char*) Arial94x94); - WD.set_FixedFontWidth(50); - for(int t=0;t<100;t++) - { - sprintf(countup,"%2d",t); - WD.obliqueout(70+35+48,100+20,countup); - - //1bit trasfer mode = monochro diplay - if( j%2 == 0 /*&& bmp_bitcount != 8*/) - // for color display - WD.writeDISP(100+20,190+20,TrBIT4); - else - // for color diaplay - WD.writeDISP(100+20,190+20,TrBIT1); - - if( j%2 == 0 && t==60) - { - // 60 < t => 80 yellow char - WD.foreground(0x0C); - }else - if( j%2 == 0 && t==80) - { - // 80 < t => 99 rec char - WD.foreground(0x08); - } - //wait(0.5); - } } } } } -/** -* @brief read a bitmap file in SD. 8color mode -*/ -void SD2BUF(char *filepath){ - char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; - int RGB; - FILE *fp ; - - pc.printf("file=%s\n",filepath); - fp = fopen(filepath, "rb"); - if(fp != NULL) { - //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes - for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes - fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes - for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes - bmp_bitcount = bc[0]+bc[1]*256; - - for(int y=height-1; y>=0; y--) { - for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit - fscanf(fp, "%c",B8); - fscanf(fp, "%c",G8); - fscanf(fp, "%c",R8); - - RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 - WD.pixel(x,y,RGB); - } - if( y!=0) // The last data column doesn't need padding - for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) - } - } - fclose(fp); -} - -/** -* @brief read a text file in SD. -*/ -void SDtex2BUF(char *filepath){ - int x,y,font,color; - char text[40]; - int ifEOF; - FILE *fp ; - - fp = fopen(filepath, "r"); - if(fp != NULL) { - while(ifEOF != -1){ - ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text); - WD.locate(x,y); - WD.foreground(color); - if (font ==1) WD.set_font((unsigned char*) Arial12x12); - else if (font ==2) WD.set_font((unsigned char*) Arial24x23); - else if (font ==3) WD.set_font((unsigned char*) Arial28x28); - else WD.set_font((unsigned char*) Neu42x35); - - WD.printf("%s",text); - } - } - fclose(fp); -} - -/* -void DispAllDir(const char *fsrc) -{ - DIR *d = opendir(fsrc); - struct dirent *p; - char filepath[40]; - - while ((p = readdir(d)) != NULL) { - sprintf(filepath, "%s/%s",fsrc,p->d_name); - SD2BUF(filepath); - WD.writeDISP(); - } - closedir(d); -} -*/ - -/** -* @brief read a bitmap file in SD by file number. -*/ -void ReadBmp(const char *fsrc, uint32_t FileNum) -{ - DIR *d = opendir(fsrc); - struct dirent *p; - char filepath[40]; - - for(uint32_t i=0; i< FileNum; i++) readdir(d); - if ((p = readdir(d)) != NULL) { - sprintf(filepath, "%s/%s",fsrc,p->d_name); - SD2BUF(filepath); - if(ifMargeTXT){ - sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name); - SDtex2BUF(filepath); - } - } - closedir(d); -} - uint32_t CntFile(const char *fsrc) { DIR *d = opendir(fsrc); @@ -329,10 +196,17 @@ void OffSequence(void){ BK.write(0); //add 20160712 17:00 WD.background(Black); +#if LINEBUFF_MODE + WD.clsLINEBUF(); + WD.SwDisp(0); + WD.writeDISPLinebuffer(); +#endif +#if FRAMEBUFF_MODE WD.clsBUF(); WD.SwDisp(0); WD.writeDISP(); - WD.writeDISP(); +#endif + WD.SwDisp(0); bloff = 1; } @@ -368,4 +242,139 @@ OffSequence(); } } +#if FRAMEBUFF_MODE +/** +* @brief read a bitmap file in SD. 8color mode +*/ +void SD2BUF(char *filepath){ + char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; + int RGB; + FILE *fp ; + //pc.printf("file=%s\n",filepath); + fp = fopen(filepath, "rb"); + if(fp != NULL) { + //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes + for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes + fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes + for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes + bmp_bitcount = bc[0]+bc[1]*256; + + for(int y=height-1; y>=0; y--) { + for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit + fscanf(fp, "%c",B8); + fscanf(fp, "%c",G8); + fscanf(fp, "%c",R8); + + RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 + WD.pixel(x,y,RGB); + } + if( y!=0) // The last data column doesn't need padding + for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) + } + } + fclose(fp); +} +/** +* @brief read a text file in SD. +*/ +void SDtex2BUF(char *filepath){ + int x,y,font,color; + char text[40]; + int ifEOF; + FILE *fp ; + + fp = fopen(filepath, "r"); + if(fp != NULL) { + while(ifEOF != -1){ + ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text); + WD.locate(x,y); + WD.foreground(color); + if (font ==1) WD.set_font((unsigned char*) Arial12x12); + else if (font ==2) WD.set_font((unsigned char*) Arial24x23); + else if (font ==3) WD.set_font((unsigned char*) Arial28x28); + else WD.set_font((unsigned char*) Neu42x35); + + WD.printf("%s",text); + } + } + fclose(fp); +} +//** +/* @brief read a bitmap file in SD by file number. +*/ +void ReadBmp(const char *fsrc, uint32_t FileNum) +{ + DIR *d = opendir(fsrc); + struct dirent *p; + char filepath[40]; + + for(uint32_t i=0; i< FileNum; i++) readdir(d); + if ((p = readdir(d)) != NULL) { + sprintf(filepath, "%s/%s",fsrc,p->d_name); + pc.printf( "%s/%s[%u]\n",fsrc,p->d_name,p->d_type); + SD2BUF(filepath); + if(ifMargeTXT){ + sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name); + //SDtex2BUF(filepath); + } + } + closedir(d); +} +#endif + +#if LINEBUFF_MODE +/** +* @brief read a bitmap file in SD. 8color mode +*/ +void SD2LINEBUF(char *filepath,int transfermode){ + char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; + int RGB; + FILE *fp ; + + //pc.printf("file=%s\n",filepath); + fp = fopen(filepath, "rb"); + if(fp != NULL) { + //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes + for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes + fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes + for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes + bmp_bitcount = bc[0]+bc[1]*256; + for(int y=height-1; y>=0; y--) { + for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit + fscanf(fp, "%c",B8); + fscanf(fp, "%c",G8); + fscanf(fp, "%c",R8); + + RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 + WD.pixel(x,RGB); + } + if( y!=0) // The last data column doesn't need padding + for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) + + //Pixel Data Transfer by SPI + WD.writeDISP(y,transfermode); + } + + } + fclose(fp); +} + +//** +/* @brief read a bitmap file in SD by file number. +*/ +void ReadBmp2LineBuffer(const char *fsrc,uint32_t FileNum,int transfermode) +{ + DIR *d = opendir(fsrc); + struct dirent *p; + char filepath[40]; + + for(uint32_t i=0; i< FileNum; i++) readdir(d); + if ((p = readdir(d)) != NULL) { + sprintf(filepath, "%s/%s",fsrc,p->d_name); + //pc.printf( "%s/%s[%u]\n",fsrc,p->d_name,p->d_type); + SD2LINEBUF(filepath,transfermode); + } + closedir(d); +} +#endif