Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MIP8F_SPI_Ver30 mbed
main.cpp
00001 /** 00002 * @file main.cpp 00003 * @brief Ver3.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/%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 while(1) 00153 { //BITMAPS 00154 filenum = CntFile(filepath); //file number read 00155 for(uint32_t i=0; i<filenum; i++) 00156 { 00157 for( int j = 0; j < 2; j++) 00158 { 00159 ReadBmp(filepath,0); 00160 00161 while(HaltSW.State()) { // VCOM invert when image is still 00162 // pol++; 00163 // WD.command( (pol << 6) & 0x40 ); 00164 // wait(bk_timer); //1Hz 00165 } 00166 HaltSW.Clear(); 00167 00168 //1bit trasfer mode = monochro diplay 00169 if( j%2 == 0 && bmp_bitcount != 8) 00170 WD.writeDISP(TrBIT4); 00171 else 00172 WD.writeDISP(TrBIT1); 00173 //wait(2); 00174 00175 if( j%2 == 0 ) 00176 { 00177 // for color diaplay 00178 WD.foreground(0x04); 00179 WD.background(0x00); 00180 }else{ 00181 // for monochrome diaplay 00182 WD.foreground(0x0e); 00183 WD.background(0x00); 00184 } 00185 //WD.fillrect(0,115,399,205, WD.get_Background() ); 00186 00187 sprintf(KMPH,"km/h"); 00188 WD.set_ActualFontWidth(); 00189 WD.set_font((unsigned char*) Arial28x28); 00190 WD.obliqueout(70+200+35,100+20+49,KMPH); 00191 00192 WD.set_font((unsigned char*) Arial94x94); 00193 WD.set_FixedFontWidth(50); 00194 for(int t=0;t<100;t++) 00195 { 00196 sprintf(countup,"%2d",t); 00197 WD.obliqueout(70+35+48,100+20,countup); 00198 00199 //1bit trasfer mode = monochro diplay 00200 if( j%2 == 0 /*&& bmp_bitcount != 8*/) 00201 // for color display 00202 WD.writeDISP(100+20,190+20,TrBIT4); 00203 else 00204 // for color diaplay 00205 WD.writeDISP(100+20,190+20,TrBIT1); 00206 00207 if( j%2 == 0 && t==60) 00208 { 00209 // 60 < t => 80 yellow char 00210 WD.foreground(0x0C); 00211 }else 00212 if( j%2 == 0 && t==80) 00213 { 00214 // 80 < t => 99 rec char 00215 WD.foreground(0x08); 00216 } 00217 //wait(0.5); 00218 } 00219 } 00220 } 00221 } 00222 } 00223 00224 /** 00225 * @brief read a bitmap file in SD. 8color mode 00226 */ 00227 void SD2BUF(char *filepath){ 00228 char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; 00229 int RGB; 00230 FILE *fp ; 00231 00232 pc.printf("file=%s\n",filepath); 00233 fp = fopen(filepath, "rb"); 00234 if(fp != NULL) { 00235 //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes 00236 for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00237 fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes 00238 for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00239 bmp_bitcount = bc[0]+bc[1]*256; 00240 00241 for(int y=height-1; y>=0; y--) { 00242 for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit 00243 fscanf(fp, "%c",B8); 00244 fscanf(fp, "%c",G8); 00245 fscanf(fp, "%c",R8); 00246 00247 RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 00248 WD.pixel(x,y,RGB); 00249 } 00250 if( y!=0) // The last data column doesn't need padding 00251 for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) 00252 } 00253 } 00254 fclose(fp); 00255 } 00256 00257 /** 00258 * @brief read a text file in SD. 00259 */ 00260 void SDtex2BUF(char *filepath){ 00261 int x,y,font,color; 00262 char text[40]; 00263 int ifEOF; 00264 FILE *fp ; 00265 00266 fp = fopen(filepath, "r"); 00267 if(fp != NULL) { 00268 while(ifEOF != -1){ 00269 ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text); 00270 WD.locate(x,y); 00271 WD.foreground(color); 00272 if (font ==1) WD.set_font((unsigned char*) Arial12x12); 00273 else if (font ==2) WD.set_font((unsigned char*) Arial24x23); 00274 else if (font ==3) WD.set_font((unsigned char*) Arial28x28); 00275 else WD.set_font((unsigned char*) Neu42x35); 00276 00277 WD.printf("%s",text); 00278 } 00279 } 00280 fclose(fp); 00281 } 00282 00283 /* 00284 void DispAllDir(const char *fsrc) 00285 { 00286 DIR *d = opendir(fsrc); 00287 struct dirent *p; 00288 char filepath[40]; 00289 00290 while ((p = readdir(d)) != NULL) { 00291 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00292 SD2BUF(filepath); 00293 WD.writeDISP(); 00294 } 00295 closedir(d); 00296 } 00297 */ 00298 00299 /** 00300 * @brief read a bitmap file in SD by file number. 00301 */ 00302 void ReadBmp(const char *fsrc, uint32_t FileNum) 00303 { 00304 DIR *d = opendir(fsrc); 00305 struct dirent *p; 00306 char filepath[40]; 00307 00308 for(uint32_t i=0; i< FileNum; i++) readdir(d); 00309 if ((p = readdir(d)) != NULL) { 00310 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00311 SD2BUF(filepath); 00312 if(ifMargeTXT){ 00313 sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name); 00314 SDtex2BUF(filepath); 00315 } 00316 } 00317 closedir(d); 00318 } 00319 00320 uint32_t CntFile(const char *fsrc) 00321 { 00322 DIR *d = opendir(fsrc); 00323 uint32_t counter = 0; 00324 while (readdir(d)!= NULL) counter++; 00325 closedir(d); 00326 return counter; 00327 } 00328 00329 void OffSequence(void){ 00330 BK.write(0); //add 20160712 17:00 00331 WD.background(Black); 00332 WD.clsBUF(); 00333 WD.SwDisp(0); 00334 WD.writeDISP(); 00335 WD.writeDISP(); 00336 bloff = 1; 00337 } 00338 00339 void ifswPWM(void){ 00340 if(bloff == 0){ 00341 if(blduty >= 10){ //0 00342 blduty = 0; //10 00343 COMSEL.write(1); // 00344 }else{ 00345 blduty += 1; //-= 00346 COMSEL.write(1); // 00347 } 00348 }else{ 00349 blduty = 0; 00350 COMSEL.write(1); // 00351 } 00352 // BKduty = BKduty - 0.125; 00353 // BKduty -= 0.125; 00354 // if(BKduty <= 0) BKduty = 1; 00355 // BK.write(BKduty); 00356 BK.write(blduty*0.1); // 00357 if(blduty == 0){ 00358 bk_timer = 1.0; 00359 }else{ 00360 bk_timer = 0.008; //0.016 20160712 00361 } 00362 } 00363 00364 void ifOFFseq(void){ 00365 if(swPWMorOFF.IfAtTime()){ 00366 swPWMorOFF.IfCntClose(OFF); 00367 swPWMorOFF.IfCntState(OFF); 00368 OffSequence(); 00369 } 00370 } 00371
Generated on Wed Jul 13 2022 13:27:06 by
1.7.2