Animation demo with MIP8F_SPI_Ver60
Dependencies: mbed MIP8F_SPI_Ver60 MIP8f_FRDM_LineBuffer_sample MIP8f_FRDM_TransferMode_sample
Introduction
Animation Demo. Some Goldfish swin in water, from left to right, from bottom to top. Color and monochrome version
Only for LPM027M128x (400x240) ,JDI DIsplay.
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. you can NOT use same sample color images of OTHER VERSION 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.
LPM027M128x (400x240) :/media/uploads/JDI_Mbed_Team/goldfish_400x240.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_animation_sample.k64f.bin
Diff: main.cpp
- Revision:
- 17:b1f9a00145b8
- Parent:
- 16:7c472f8a81a5
- Child:
- 18:81201ac909c6
--- a/main.cpp Mon Nov 12 05:09:38 2018 +0000 +++ b/main.cpp Wed Nov 21 07:30:33 2018 +0000 @@ -71,6 +71,12 @@ void DispAllDir(const char *fsrc); void ReadBmp(const char *fsrc, uint32_t FileNum); uint32_t CntFile(const char *fsrc); + +void fish_swim_RightToLeft(int y,int Speed,int No,int transfermode); +void fish_swim_LeftToRight(int y,int Speed,int No,int transfermode); +void fish_swim_BottomToTop(int x,int Speed,int No,int transfermode); +void fish_swim_TopToBottom(int x,int Speed,int No,int transfermode); +void fish_Surprise_LeftToRight(int y,int Speed,int no,int no2,int transfermode); //Grobal value int ifMargeTXT = 0; int width = 400; @@ -86,13 +92,17 @@ // Readed bitmap format, Color bit size = 1,4,8,(16),24,32 uint16_t bmp_bitcount; +void ReadMovieBmp(const char *fsrc, uint32_t FileNum); + int main() { - //uint32_t filenum; - char filepath[40]; - char countup[3+1]; - char KMPH[4+1]; - char Trans[13+1]; + uint32_t filenum; + char filepath[45]; + uint32_t filenum2; + char filepath2[45]; + //char countup[3+1]; + //char KMPH[4+1]; + //char Trans[13+1]; sd.disk_initialize(); HaltSW.Enable(1); @@ -103,7 +113,9 @@ fscanf(fp, "%d",&width); //width read fscanf(fp, "%d",&height); //height read fscanf(fp, "%d",&blctrl_sel);//blct_sel read //0:40mA, 1:160mA - sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath + //sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath + sprintf(filepath,"/sd/backgrand%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath + sprintf(filepath2,"/sd/fish%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath fclose(fp); } else { FILE *fp = fopen("/sd/settings.txt", "rb"); //read binary @@ -143,100 +155,161 @@ BK.write(1); //low output 20160725 <- high output //DIR *d; + filenum = CntFile(filepath); //file number read + pc.printf("filenum=%d\n",filenum); + + filenum2 = CntFile(filepath2); //file number read + pc.printf("filenum2=%d\n",filenum2); + for(int i = 0; i < filenum2; i++) + { + ReadMovieBmp(filepath2,i); + } - //filenum = CntFile(filepath); //file number read - ReadBmp(filepath,0); + + //int x,y; while(1) { //BITMAPS - //for(uint32_t i=0; i<filenum; i++) - { - for( int j = 0; j < 3; j++) - { - - while(HaltSW.State()); // VCOM invert when image is still - HaltSW.Clear(); - - //display bitmap - WD.foreground(0x0e); - WD.background(0x00); - WD.set_ActualFontWidth(); - WD.set_font((unsigned char*) Arial28x28); - //1bit trasfer mode = monochro diplay - if( j%3 == 0 ) - { - sprintf(Trans,"4bit transfer"); - WD.obliqueout(5,210,Trans); - WD.writeDISP(TrBIT4); - }else - if( j%3 == 1 ){ - sprintf(Trans,"3bit transfer"); - WD.obliqueout(5,210,Trans); - WD.writeDISP(TrBIT3); - }else{ - sprintf(Trans,"1bit transfer"); - WD.obliqueout(5,210,Trans); - WD.writeDISP(TrBIT1); - } - - // print KM - if( j%3 != 2 ) - { - // for color diaplay - WD.foreground(0x04);//Greeen - WD.background(0x00);//black - }else{ - // for monochrome diaplay - WD.foreground(0x0e);//white - WD.background(0x00);//black - } - sprintf(KMPH,"km/h"); - WD.set_ActualFontWidth(); - WD.set_font((unsigned char*) Arial28x28); - WD.obliqueout(70+200+35,100+20+49,KMPH); - - //print number - WD.set_font((unsigned char*) Arial94x94); - WD.set_FixedFontWidth(50); - for(int t=0;t<31;t++) - { - sprintf(countup,"%2d",t); - WD.obliqueout(70+35+48,100+20,countup); - - //transfer to display number - if( j%3 == 0 )//4bit and 3bit trasfer - { - // for color display - WD.writeDISP(100+20,190+20,TrBIT4); - }else - if( j%3 == 1 )//3bit and 3bit trasfer - { - // for color diaplay - WD.writeDISP(100+20,190+20,TrBIT3); - }else//1bit and 3bit trasfer - { - // for monochrome diaplay - WD.writeDISP(100+20,190+20,TrBIT1); - } - - //change charactor coloe - if(j%3 != 2 && t==10) - { - // 11 < t => 20 yellow char - WD.foreground(0x0C); - }else - if( j%3 != 2 && t==20) - { - // 21 < t => 30 red char - WD.foreground(0x08); - } - //wait(0.5); - } - } - } + + for(int i = 0; i < filenum;i++) + { + //pc.printf("1\n"); + while(HaltSW.State()); // VCOM invert when image is still + HaltSW.Clear(); + if( i%2 == 0 ) + { + //color anime + ReadBmp(filepath,i); + WD.writeDISP(TrBIT3); + fish_swim_RightToLeft(80,10,2,TrBIT3); + fish_swim_TopToBottom(200,15,0,TrBIT3); + fish_swim_BottomToTop(100,10,4,TrBIT3); + fish_Surprise_LeftToRight(120,30,2,6,TrBIT3); + fish_swim_RightToLeft(120,10,8,TrBIT3); + }else{ + //monochrome anime + ReadBmp(filepath,i); + WD.writeDISP(TrBIT1); + fish_swim_RightToLeft(80,10,2,TrBIT1); + fish_swim_TopToBottom(200,15,4,TrBIT1); + fish_swim_BottomToTop(100,10,4,TrBIT1); + fish_Surprise_LeftToRight(120,30,2,6,TrBIT1); + fish_swim_RightToLeft(120,5,8,TrBIT1); + } + } + } } +/** +* @brief Fish(bmp) swim from Right to Left +*/ +void fish_swim_RightToLeft(int y,int Speed,int no,int transfermode) +{ + int x; + int i=no; + for(x = width ; x >=-80 ; x-=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } +} +/** +* @brief Fish(bmp) swim from Left to Right +*/ +void fish_swim_LeftToRight(int y,int Speed,int no,int transfermode) +{ + int x; + int i=no; + for(x = -80 ; x <=width+80 ; x+=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame_Reverse(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } +} +/** +* @brief Fish(bmp) swim from Left to Right,but he surprise!! and return +*/ +void fish_Surprise_LeftToRight(int y,int Speed,int no,int no2,int transfermode) +{ + int x; + int i; + i=no; + for(x = -80 ; x <=width-120 ; x+=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame_Reverse(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } + //surprise + i = no2; + for(int j = 0 ; j < 6 ; j++ ) + { + x = width-120; + //pc.printf("2\n"); + WD.makeMovieFrame(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no2+1 ) i = no2; + } + // swim reverse + i = no; + for(x = width-120 ; x >= -80 ; x-=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } +} /** +* @brief Fish(bmp) swim from bottom to top +*/ +void fish_swim_BottomToTop(int x,int Speed,int no,int transfermode) +{ + int y; + int i=no; + for(y = height ; y >=-MOVIE_VERT_SIZE ; y-=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame(x,y,i); + //backgrand display + WD.writeDISP(y,y+MOVIE_VERT_SIZE+Speed,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } +} +/** +* @brief Fish(bmp) swim from top to bottom +*/ +void fish_swim_TopToBottom(int x,int Speed,int no,int transfermode) +{ + int y; + int i=no; + for(y = -MOVIE_VERT_SIZE ; y < height+Speed; y+=Speed ) + { + //pc.printf("2\n"); + WD.makeMovieFrame_Updown(x,y,i); + //backgrand display + WD.writeDISP(y-Speed,y+MOVIE_VERT_SIZE,transfermode); + WD.RestoreMovieFrame(x,y,i); + if( ++i > no+1 ) i = no; + } +} +/** * @brief read a bitmap file in SD. 8color mode */ void SD2BUF(char *filepath){ @@ -417,4 +490,90 @@ OffSequence(); } } +/** +* @brief read a bitmap,Animation page file in SD. +*/ +void SD2MOVIEBUF(char *filepath,int memnum){ + char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; + char RGB; + FILE *fp ; + pc.printf("[%d]%s\n",memnum,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]));// color bit size 2bytes + 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; + pc.printf("bitcount=%d\n",bmp_bitcount); + if( bmp_bitcount == 1 ) + { + for(int i=0; i< 8 ; i++) fscanf(fp,"%c",DUMMY); // Pallet Data + int x; + for(int y=MOVIE_VERT_SIZE-1; y>=0; y--) { + for(x=0; x< MOVIE_HORI_SIZE; x += 8) { //1bit monochrome + fscanf(fp, "%c",G8); + for(int i=0; i < 8 ; i++ ){ + RGB = 0; + if( (*G8 & 0x80) != 0) RGB = RGB|0x0e; + WD.movie_pixel(x+i,y,RGB,memnum); + *G8 = *G8 << 1; + } + } + if( MOVIE_HORI_SIZE%8 != 0 ) + { + fscanf(fp, "%c",G8); + int i; + for(i=0; i < (width%8) ; i++ ){ + RGB = 0; + if( (*G8 & 0x40) != 0) RGB = RGB|0x0e; + WD.movie_pixel(x+i,y,RGB,memnum); + *G8 = *G8 << 1; + } + } + if( y!=0){ // The last data column doesn't need padding + int wbyte = MOVIE_HORI_SIZE/8 + ( MOVIE_HORI_SIZE%8 == 0 ? 0:1 ); + for(int x=(wbyte*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY);// 4byte boundery for every column(only windows bitmap format) + } + } + }else + if( bmp_bitcount == 24 ) + { + for(int y=MOVIE_VERT_SIZE-1; y>=0; y--) { + for(int x=0; x< MOVIE_HORI_SIZE; 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.movie_pixel(x,y,RGB,memnum); + } + if( y!=0) // The last data column doesn't need padding + for(int x=(MOVIE_HORI_SIZE*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) + } + } + } + fclose(fp); +} +/** +* @brief read a bitmap,All Animation page file in SD. +*/ +void ReadMovieBmp(const char *fsrc, uint32_t FileNum) +{ + DIR *d = opendir(fsrc); + struct dirent *p; + char filepath[40]; + + if( FileNum >= MOVIE_NUM ) return; + + pc.printf("read bmp No%d\n",FileNum); + for(uint32_t i=0; i< FileNum; i++) readdir(d); + if ((p = readdir(d)) != NULL) { + sprintf(filepath, "%s/%s",fsrc,p->d_name); + SD2MOVIEBUF(filepath,FileNum); + pc.printf("read finish\n"); + } + closedir(d); +} \ No newline at end of file