JapanDisplayInc / Mbed 2 deprecated MIP8f_FRDM_CountUpNumber_sample2

Dependencies:   mbed MIP8F_SPI_Ver50

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