JapanDisplayInc / Mbed 2 deprecated MIP8f_FRDM_TransferMode_sample

Dependencies:   MIP8F_SPI_Ver50 MIP8f_FRDM_LineBuffer_sample mbed

Dependents:   MIP8f_FRDM_Animation_sample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002 * @file main.cpp
00003 * @brief Ver5.0 Sample source code for MIP8 diplay. 
00004 * @details  
00005 * Ver5.0 Addtional function is checking the refresh display speed between 4bit,3bit and 1bit transfer mode 
00006 * Ver4.0 Addtional function is Line buffer version.the Sample bitmap display color and monochrome by line buffer.
00007 * Ver3.0 Addtional function is font display. this demo code is the nunber is counted up like a meter panel
00008 * ver2.0 Addtional function is Monochome display by 1bit mode of SPI transfer.
00009 *
00010 * spi-transfer to Display has 3 mode. 
00011 * 4bit mode is color display, this bit arrange is  R,G,B,x.   R,G,B = R,G,B subpixel bit. x bit is Dummy.
00012 * 3bit mode is color display, this bit arrange is  R,G,B.   R,G,B = R,G,B subpixel bit.  No bit is Dummy.
00013 * 1bit mode is monocrome display,high speed refresh mode. a only Green subpixel of bitmap data is transfered.
00014 * <License>
00015 * Copyright 2018 Japan Display Inc.
00016 * Licensed under the Apache License, Version 2.0 (the "License");
00017 * you may not use this file except in compliance with the License.
00018 * You may obtain a copy of the License at
00019 *
00020 *     http://www.apache.org/licenses/LICENSE-2.0
00021 *
00022 * Unless required by applicable law or agreed to in writing, software
00023 * distributed under the License is distributed on an "AS IS" BASIS,
00024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025 * See the License for the specific language governing permissions and
00026 * limitations under the License.
00027 */
00028 #include "stdio.h"
00029 #include "string"
00030 #include "mbed.h"
00031 #include "MIP8F_SPI.h"
00032 #include "SDFileSystem.h"
00033 #include "StateSW.h"
00034 #include "TglSW.h"
00035 
00036 #include "Arial12x12.h"
00037 #include "Arial24x23.h"
00038 #include "Arial28x28.h"
00039 #include "Arial37x36.h"
00040 #include "Arial42x42.h"
00041 #include "font_big.h"
00042 #include "Arial94x94.h"
00043 
00044 #define ON  1
00045 #define OFF 0
00046 
00047 //K64F
00048 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // mosi,miso,sck,cs
00049 memLCD8 WD(PTD2,PTD3,PTD1,PTD0,PTC4,PTD3); //PTC12);  // mosi,miso,clk,cs,disp,power
00050 PwmOut BK(PTC3);
00051 PwmOut COM60HZ(PTC10);    //add 20161108 
00052 DigitalOut COMSEL(PTA2,0);    //add 20161108
00053 DigitalOut BLCTRL(PTB10,0);    //add 20171115
00054 // SW2
00055 StateSW swPWMorOFF(SW2); //PTC6); 
00056 InterruptIn PWMorOFF(SW2);
00057 // SW3
00058 TglSW HaltSW(SW3);  //PTA4); 
00059 DigitalIn TexSW(SW3);
00060 
00061 //for debug
00062 Serial pc(USBTX, USBRX); // tx, rx
00063 
00064 void SDtex2BUF(char *filepath);
00065 
00066 //function prototype
00067 void SD2BUF(char *filepath);
00068 void ifOFFseq(void);
00069 void ifswPWM(void);
00070 void OffSequence(void);
00071 void DispAllDir(const char *fsrc);
00072 void ReadBmp(const char *fsrc, uint32_t FileNum);
00073 uint32_t CntFile(const char *fsrc);
00074 //Grobal value
00075 int  ifMargeTXT = 0;
00076 int  width = 400;
00077 int  height= 240;
00078 
00079 float BKduty = 0;
00080 float BKjudge = 0;
00081 //double BKduty = 0;
00082 float bk_timer = 1.0;
00083 int   blduty = 0;
00084 int   bloff = 0;
00085 int   blctrl_sel = 0; //0:40mA, 1:160mA //Y.S
00086 // Readed bitmap format, Color bit size = 1,4,8,(16),24,32
00087 uint16_t bmp_bitcount;
00088 
00089 int main() {
00090 
00091     //uint32_t filenum;
00092     char filepath[40];
00093     char countup[3+1];
00094     char KMPH[4+1];
00095     char Trans[13+1];
00096     
00097     sd.disk_initialize();
00098     HaltSW.Enable(1);
00099 
00100 
00101     FILE *fp = fopen("/sd/settings2.txt", "rb");    //read binary
00102     if(fp != NULL) {
00103         fscanf(fp, "%d",&width);     //width read
00104         fscanf(fp, "%d",&height);    //height read
00105         fscanf(fp, "%d",&blctrl_sel);//blct_sel read //0:40mA, 1:160mA
00106         sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180")    //file name write to filepath
00107         fclose(fp);  
00108     } else {
00109         FILE *fp = fopen("/sd/settings.txt", "rb");    //read binary
00110         if(fp != NULL) {
00111             fscanf(fp, "%d",&width);     //width read
00112             fscanf(fp, "%d",&height);    //height read
00113             sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180")    //file name write to filepath
00114             fclose(fp);  
00115         } else{ 
00116             width =180;
00117             height=180;
00118             sprintf(filepath,"/sd/180x180"); //DispAllDir("/sd/180x180")
00119         }
00120     }
00121 
00122     COMSEL.write(1);    //
00123 
00124     BLCTRL.write(blctrl_sel);    //
00125     
00126     WD.setWH(width,height);    //input -> width, height
00127     WD.background(Black);      //background = black
00128     WD.clsBUF();               //data initialize
00129     WD.writeDISP();            //picture write(black)
00130     WD.SwDisp(1);              //disp on
00131     
00132     PWMorOFF.fall(&ifswPWM);  // Backlight    //sw2 fall edge
00133     PWMorOFF.rise(&ifOFFseq); // OFF Sequence    //sw2 rise edge
00134 
00135     swPWMorOFF.Enable(8, 2, 1);  //int ModeNum, int NoiseCancel, int OpenTime    //????
00136     swPWMorOFF.IfCntClose(ON);
00137     swPWMorOFF.IfCntState(ON);
00138 
00139     COM60HZ.period_ms(8);    //add 20161108
00140     COM60HZ.write(0.5);      //add 20161108
00141 
00142     BK.period_ms(1);    //1ms cycle    20161012 
00143     BK.write(1);    //low output    20160725 <- high output
00144 
00145     //DIR *d;
00146 
00147     //filenum = CntFile(filepath);    //file number read
00148     ReadBmp(filepath,0);
00149     while(1)
00150     { //BITMAPS
00151         //for(uint32_t i=0; i<filenum; i++)
00152         {
00153             for( int j = 0; j < 3; j++)
00154             {
00155 
00156                 while(HaltSW.State());    // VCOM invert when image is still
00157                 HaltSW.Clear();
00158 
00159                 //display bitmap
00160                 WD.foreground(0x0e);
00161                 WD.background(0x00);
00162                 WD.set_ActualFontWidth();
00163                 WD.set_font((unsigned char*) Arial28x28); 
00164                 //1bit trasfer mode = monochro diplay
00165                 if( j%3 == 0 )
00166                 {
00167                     sprintf(Trans,"4bit transfer");
00168                     WD.obliqueout(5,210,Trans);
00169                     WD.writeDISP(TrBIT4);
00170                 }else
00171                 if( j%3 == 1 ){         
00172                     sprintf(Trans,"3bit transfer");
00173                     WD.obliqueout(5,210,Trans);
00174                     WD.writeDISP(TrBIT3);
00175                 }else{
00176                     sprintf(Trans,"1bit transfer");
00177                     WD.obliqueout(5,210,Trans);
00178                     WD.writeDISP(TrBIT1);
00179                 }
00180                 
00181                 // print KM 
00182                 if( j%3 != 2 )
00183                 {
00184                     // for color diaplay
00185                     WD.foreground(0x04);//Greeen
00186                     WD.background(0x00);//black
00187                 }else{
00188                     // for monochrome diaplay
00189                     WD.foreground(0x0e);//white
00190                     WD.background(0x00);//black
00191                 }
00192                 sprintf(KMPH,"km/h");
00193                 WD.set_ActualFontWidth();
00194                 WD.set_font((unsigned char*) Arial28x28); 
00195                 WD.obliqueout(70+200+35,100+20+49,KMPH);
00196 
00197                 //print number
00198                 WD.set_font((unsigned char*) Arial94x94); 
00199                 WD.set_FixedFontWidth(50);
00200                 for(int t=0;t<31;t++)
00201                 {
00202                     sprintf(countup,"%2d",t);
00203                     WD.obliqueout(70+35+48,100+20,countup);
00204 
00205                     //transfer to display number                
00206                     if( j%3 == 0 )//4bit and 3bit trasfer 
00207                     {
00208                         // for color display
00209                         WD.writeDISP(100+20,190+20,TrBIT4);
00210                     }else
00211                     if( j%3 == 1 )//3bit and 3bit trasfer 
00212                     {
00213                         // for color diaplay
00214                         WD.writeDISP(100+20,190+20,TrBIT3);
00215                     }else//1bit and 3bit trasfer 
00216                     {
00217                         // for monochrome diaplay
00218                         WD.writeDISP(100+20,190+20,TrBIT1);
00219                     }
00220                     
00221                     //change charactor coloe
00222                     if(j%3 != 2 && t==10)
00223                     {
00224                         // 11 < t => 20 yellow char
00225                         WD.foreground(0x0C);
00226                     }else
00227                     if( j%3 != 2 && t==20)
00228                     {
00229                         // 21 < t => 30 red char
00230                         WD.foreground(0x08);
00231                     }
00232                     //wait(0.5);
00233                 }
00234             }
00235         }
00236     }
00237 }
00238 
00239 /**
00240 * @brief read a bitmap file in SD. 8color mode
00241 */
00242 void SD2BUF(char *filepath){
00243     char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2];
00244     char RGB;
00245     FILE *fp ;
00246 
00247     pc.printf("file=%s\n",filepath);
00248     fp = fopen(filepath, "rb");
00249     if(fp != NULL) {
00250         //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY);  // Discard Header 54bytes
00251         for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY);  // Discard Header 26bytes
00252         fscanf(fp,"%c",&(bc[0]));// color bit size 2bytes
00253         fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes
00254         for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY);  // Discard Header 26bytes
00255         bmp_bitcount = bc[0]+bc[1]*256;
00256         if( bmp_bitcount == 1 )
00257         {
00258             for(int i=0; i< 8 ; i++) fscanf(fp,"%c",DUMMY);  // Pallet Data
00259             int x;
00260             for(int y=height-1; y>=0; y--) {
00261                 for(x=0; x< width; x += 8) { //1bit monochrome 
00262                     fscanf(fp, "%c",G8);
00263                     for(int i=0; i < 8 ; i++ ){
00264                         RGB = 0;
00265                         if( (*G8 & 0x80) != 0)  RGB = RGB|0x0e;
00266                         WD.pixel(x+i,y,RGB);
00267                         *G8 = *G8 << 1;
00268                     }
00269                 }
00270                 if( width%8 != 0 )
00271                 {
00272                     fscanf(fp, "%c",G8);
00273                     int i;
00274                     for(i=0; i < (width%8) ; i++ ){
00275                         RGB = 0;
00276                         if( (*G8 & 0x40) != 0)  RGB = RGB|0x0e;
00277                         WD.pixel(x+i,y,RGB);
00278                         *G8 = *G8 << 1;
00279                     }
00280                 }
00281                 if( y!=0){  // The last data column doesn't need padding
00282                     int wbyte = width/8 + ( width%8 == 0 ? 0:1 );
00283                     for(int x=(wbyte*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY);// 4byte boundery for every column(only windows bitmap format)
00284                 }
00285             }
00286         }else
00287         if( bmp_bitcount == 24 )
00288         {
00289             for(int y=height-1; y>=0; y--) {
00290                 for(int x=0; x< width; x++) {    //24bit color  B 8bit -> G 8bit -> R 8bit
00291                     fscanf(fp, "%c",B8);
00292                     fscanf(fp, "%c",G8);
00293                     fscanf(fp, "%c",R8);
00294                 
00295                     RGB =  RGB8(*R8,*G8,*B8);    //6bit(8bit) MIP  MASK 0000 1110
00296                     WD.pixel(x,y,RGB);
00297                 }
00298                 if( y!=0)  // The last data column doesn't need padding
00299                 for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY);    // 4byte boundery for every column(only windows bitmap format)
00300             }
00301         }
00302     }
00303     fclose(fp);
00304 }
00305 
00306 /**
00307 * @brief read a text file in SD.
00308 */
00309 void SDtex2BUF(char *filepath){
00310     int x,y,font,color;
00311     char text[40];
00312     int  ifEOF;
00313     FILE *fp ;
00314 
00315     fp = fopen(filepath, "r");
00316     if(fp != NULL) {
00317         while(ifEOF != -1){
00318             ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text);
00319             WD.locate(x,y);
00320             WD.foreground(color);
00321             if      (font ==1)   WD.set_font((unsigned char*) Arial12x12);
00322             else if (font ==2)   WD.set_font((unsigned char*) Arial24x23); 
00323             else if (font ==3)   WD.set_font((unsigned char*) Arial28x28);
00324             else                 WD.set_font((unsigned char*) Neu42x35); 
00325 
00326             WD.printf("%s",text);
00327         }
00328     }
00329     fclose(fp);
00330 }
00331 
00332 /*
00333 void DispAllDir(const char *fsrc)
00334 {
00335     DIR *d = opendir(fsrc);
00336     struct dirent *p;
00337     char filepath[40];
00338     
00339     while ((p = readdir(d)) != NULL)  {
00340         sprintf(filepath, "%s/%s",fsrc,p->d_name);
00341         SD2BUF(filepath);
00342         WD.writeDISP();
00343     }
00344     closedir(d);
00345 }
00346 */
00347 
00348 /**
00349 * @brief read a bitmap file in SD by file number.
00350 */
00351 void ReadBmp(const char *fsrc, uint32_t FileNum)
00352 {
00353     DIR *d = opendir(fsrc);
00354     struct dirent *p;
00355     char filepath[40];
00356     
00357     for(uint32_t i=0; i< FileNum; i++) readdir(d);
00358     if ((p = readdir(d)) != NULL)  {
00359         sprintf(filepath, "%s/%s",fsrc,p->d_name);
00360         SD2BUF(filepath);
00361         if(ifMargeTXT){
00362             sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name);
00363             SDtex2BUF(filepath);
00364         }       
00365     }
00366     closedir(d);
00367 }
00368 
00369 uint32_t CntFile(const char *fsrc)
00370 {
00371     DIR *d = opendir(fsrc);
00372     uint32_t counter = 0;
00373     while (readdir(d)!= NULL) counter++;
00374     closedir(d);
00375     return counter;
00376 }
00377 
00378 void OffSequence(void){
00379     BK.write(0);    //add 20160712 17:00
00380     WD.background(Black);
00381     WD.clsBUF();
00382     WD.SwDisp(0);
00383     WD.writeDISP();
00384     WD.writeDISP();
00385     bloff = 1;
00386 }
00387 
00388 void ifswPWM(void){
00389     if(bloff == 0){
00390         if(blduty >= 10){    //0
00391             blduty = 0;    //10
00392             COMSEL.write(1);    //
00393         }else{
00394             blduty += 1;    //-=
00395             COMSEL.write(1);    //
00396         }
00397     }else{
00398         blduty = 0;
00399         COMSEL.write(1);    //
00400     }
00401 //    BKduty =  BKduty - 0.125;
00402 //    BKduty -= 0.125;
00403 //    if(BKduty <= 0) BKduty = 1;
00404 //    BK.write(BKduty);
00405     BK.write(blduty*0.1);     //
00406     if(blduty == 0){
00407         bk_timer = 1.0;
00408     }else{
00409         bk_timer = 0.008;    //0.016   20160712
00410     }
00411 }
00412 
00413 void ifOFFseq(void){
00414     if(swPWMorOFF.IfAtTime()){
00415         swPWMorOFF.IfCntClose(OFF);
00416         swPWMorOFF.IfCntState(OFF);
00417         OffSequence();
00418     }
00419 }
00420