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_Ver40 mbed
Dependents: MIP8f_FRDM_TransferMode_sample MIP8f_FRDM_Animation_sample
main.cpp
00001 /** 00002 * @file main.cpp 00003 * @brief Ver4.0 Sample source code for MIP8 diplay. 00004 * @details 00005 * Ver4.0 Addtional function is Line buffer version.the Sample bitmap display color and monochrome by line buffer. 00006 * Ver3.0 Addtional function is font display. this demo code is the nunber 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 00069 //function prototype 00070 #if FRAMEBUFF_MODE 00071 void SD2BUF(char *filepath); 00072 void SDtex2BUF(char *filepath); 00073 void ReadBmp(const char *fsrc, uint32_t FileNum); 00074 #endif 00075 00076 #if LINEBUFF_MODE 00077 void SD2LINEBUF(char *filepath,int transfermode); 00078 void ReadBmp2LineBuffer(const char *fsrc, uint32_t FileNum,int transfermode); 00079 #endif 00080 00081 void ifOFFseq(void); 00082 void ifswPWM(void); 00083 void OffSequence(void); 00084 void DispAllDir(const char *fsrc); 00085 uint32_t CntFile(const char *fsrc); 00086 //Grobal value 00087 int ifMargeTXT = 0; 00088 int width = 400; 00089 int height= 240; 00090 00091 float BKduty = 0; 00092 float BKjudge = 0; 00093 //double BKduty = 0; 00094 float bk_timer = 1.0; 00095 int blduty = 0; 00096 int bloff = 0; 00097 int blctrl_sel = 0; //0:40mA, 1:160mA //Y.S 00098 // Readed bitmap format, Color bit size = 1,4,8,(16),24,32 00099 uint16_t bmp_bitcount; 00100 00101 int main() { 00102 00103 uint32_t filenum=0; 00104 char filepath[40]; 00105 //char countup[3+1]; 00106 //char KMPH[4+1]; 00107 00108 00109 sd.disk_initialize(); 00110 HaltSW.Enable(1); 00111 00112 FILE *fp = fopen("/sd/settings2.txt", "rb"); //read binary 00113 if(fp != NULL) { 00114 fscanf(fp, "%d",&width); //width read 00115 fscanf(fp, "%d",&height); //height read 00116 fscanf(fp, "%d",&blctrl_sel);//blct_sel read //0:40mA, 1:160mA 00117 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00118 fclose(fp); 00119 } else { 00120 FILE *fp = fopen("/sd/settings.txt", "rb"); //read binary 00121 if(fp != NULL) { 00122 fscanf(fp, "%d",&width); //width read 00123 fscanf(fp, "%d",&height); //height read 00124 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00125 fclose(fp); 00126 } else{ 00127 width =180; 00128 height=180; 00129 sprintf(filepath,"/sd/180x180"); //DispAllDir("/sd/180x180") 00130 } 00131 } 00132 00133 COMSEL.write(1); // 00134 00135 BLCTRL.write(blctrl_sel); // 00136 00137 WD.setWH(width,height); //input -> width, height 00138 WD.background(Black); //background = black 00139 #if FRAMEBUFF_MODE 00140 WD.clsBUF(); //data initialize 00141 WD.writeDISP(); //picture write(black) 00142 #endif 00143 #if LINEBUFF_MODE 00144 WD.clsLINEBUF(); //data initialize 00145 WD.writeDISPLinebuffer(); //picture write(black) 00146 #endif 00147 WD.SwDisp(1); //disp on 00148 00149 //OffSW.fall(&OffSequence); // Renamed "OffSW" as "PWMorOFF" for BK PWM setting 00150 //SW settings for PWM or OFF 00151 PWMorOFF.fall(&ifswPWM); // Backlight //sw2 fall edge 00152 PWMorOFF.rise(&ifOFFseq); // OFF Sequence //sw2 rise edge 00153 00154 swPWMorOFF.Enable(8, 2, 1); //int ModeNum, int NoiseCancel, int OpenTime //???? 00155 swPWMorOFF.IfCntClose(ON); 00156 swPWMorOFF.IfCntState(ON); 00157 00158 COM60HZ.period_ms(8); //add 20161108 00159 COM60HZ.write(0.5); //add 20161108 00160 00161 BK.period_ms(1); //1ms cycle 20161012 00162 BK.write(1); //low output 20160725 <- high output 00163 00164 //DIR *d; 00165 00166 while(1) 00167 { //BITMAPS 00168 filenum = CntFile(filepath); //file number read 00169 for(uint32_t i=0; i<filenum; i++) 00170 { 00171 for( int j = 0; j < 2; j++) 00172 { 00173 #if LINEBUFF_MODE 00174 if( j%2 == 0 ) //&& bmp_bitcount != 8) 00175 ReadBmp2LineBuffer(filepath,i,TrBIT4); 00176 else 00177 ReadBmp2LineBuffer(filepath,i,TrBIT1); 00178 #endif 00179 while(HaltSW.State()); 00180 HaltSW.Clear(); 00181 00182 } 00183 } 00184 } 00185 } 00186 00187 uint32_t CntFile(const char *fsrc) 00188 { 00189 DIR *d = opendir(fsrc); 00190 uint32_t counter = 0; 00191 while (readdir(d)!= NULL) counter++; 00192 closedir(d); 00193 return counter; 00194 } 00195 00196 void OffSequence(void){ 00197 BK.write(0); //add 20160712 17:00 00198 WD.background(Black); 00199 #if LINEBUFF_MODE 00200 WD.clsLINEBUF(); 00201 WD.SwDisp(0); 00202 WD.writeDISPLinebuffer(); 00203 #endif 00204 #if FRAMEBUFF_MODE 00205 WD.clsBUF(); 00206 WD.SwDisp(0); 00207 WD.writeDISP(); 00208 #endif 00209 WD.SwDisp(0); 00210 bloff = 1; 00211 } 00212 00213 void ifswPWM(void){ 00214 if(bloff == 0){ 00215 if(blduty >= 10){ //0 00216 blduty = 0; //10 00217 COMSEL.write(1); // 00218 }else{ 00219 blduty += 1; //-= 00220 COMSEL.write(1); // 00221 } 00222 }else{ 00223 blduty = 0; 00224 COMSEL.write(1); // 00225 } 00226 // BKduty = BKduty - 0.125; 00227 // BKduty -= 0.125; 00228 // if(BKduty <= 0) BKduty = 1; 00229 // BK.write(BKduty); 00230 BK.write(blduty*0.1); // 00231 if(blduty == 0){ 00232 bk_timer = 1.0; 00233 }else{ 00234 bk_timer = 0.008; //0.016 20160712 00235 } 00236 } 00237 00238 void ifOFFseq(void){ 00239 if(swPWMorOFF.IfAtTime()){ 00240 swPWMorOFF.IfCntClose(OFF); 00241 swPWMorOFF.IfCntState(OFF); 00242 OffSequence(); 00243 } 00244 } 00245 #if FRAMEBUFF_MODE 00246 /** 00247 * @brief read a bitmap file in SD. 8color mode 00248 */ 00249 void SD2BUF(char *filepath){ 00250 char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; 00251 int RGB; 00252 FILE *fp ; 00253 00254 //pc.printf("file=%s\n",filepath); 00255 fp = fopen(filepath, "rb"); 00256 if(fp != NULL) { 00257 //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes 00258 for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00259 fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes 00260 for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00261 bmp_bitcount = bc[0]+bc[1]*256; 00262 00263 for(int y=height-1; y>=0; y--) { 00264 for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit 00265 fscanf(fp, "%c",B8); 00266 fscanf(fp, "%c",G8); 00267 fscanf(fp, "%c",R8); 00268 00269 RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 00270 WD.pixel(x,y,RGB); 00271 } 00272 if( y!=0) // The last data column doesn't need padding 00273 for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) 00274 } 00275 } 00276 fclose(fp); 00277 } 00278 /** 00279 * @brief read a text file in SD. 00280 */ 00281 void SDtex2BUF(char *filepath){ 00282 int x,y,font,color; 00283 char text[40]; 00284 int ifEOF; 00285 FILE *fp ; 00286 00287 fp = fopen(filepath, "r"); 00288 if(fp != NULL) { 00289 while(ifEOF != -1){ 00290 ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text); 00291 WD.locate(x,y); 00292 WD.foreground(color); 00293 if (font ==1) WD.set_font((unsigned char*) Arial12x12); 00294 else if (font ==2) WD.set_font((unsigned char*) Arial24x23); 00295 else if (font ==3) WD.set_font((unsigned char*) Arial28x28); 00296 else WD.set_font((unsigned char*) Neu42x35); 00297 00298 WD.printf("%s",text); 00299 } 00300 } 00301 fclose(fp); 00302 } 00303 //** 00304 /* @brief read a bitmap file in SD by file number. 00305 */ 00306 void ReadBmp(const char *fsrc, uint32_t FileNum) 00307 { 00308 DIR *d = opendir(fsrc); 00309 struct dirent *p; 00310 char filepath[40]; 00311 00312 for(uint32_t i=0; i< FileNum; i++) readdir(d); 00313 if ((p = readdir(d)) != NULL) { 00314 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00315 pc.printf( "%s/%s[%u]\n",fsrc,p->d_name,p->d_type); 00316 SD2BUF(filepath); 00317 if(ifMargeTXT){ 00318 sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name); 00319 //SDtex2BUF(filepath); 00320 } 00321 } 00322 closedir(d); 00323 } 00324 #endif 00325 00326 #if LINEBUFF_MODE 00327 /** 00328 * @brief read a bitmap file in SD. 8color mode 00329 */ 00330 void SD2LINEBUF(char *filepath,int transfermode){ 00331 char R8[1],G8[1],B8[1] ,DUMMY[1],bc[2]; 00332 int RGB; 00333 FILE *fp ; 00334 00335 //pc.printf("file=%s\n",filepath); 00336 fp = fopen(filepath, "rb"); 00337 if(fp != NULL) { 00338 //for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes 00339 for(int i=0; i< 28 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00340 fscanf(fp,"%c",&(bc[0]));fscanf(fp,"%c",&(bc[1]));// color bit size 2bytes 00341 for(int i=0; i< 24 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 26bytes 00342 bmp_bitcount = bc[0]+bc[1]*256; 00343 for(int y=height-1; y>=0; y--) { 00344 for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit 00345 fscanf(fp, "%c",B8); 00346 fscanf(fp, "%c",G8); 00347 fscanf(fp, "%c",R8); 00348 00349 RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 00350 WD.pixel(x,RGB); 00351 } 00352 if( y!=0) // The last data column doesn't need padding 00353 for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column(only windows bitmap format) 00354 00355 //Pixel Data Transfer by SPI 00356 WD.writeDISP(y,transfermode); 00357 } 00358 00359 } 00360 fclose(fp); 00361 } 00362 00363 //** 00364 /* @brief read a bitmap file in SD by file number. 00365 */ 00366 void ReadBmp2LineBuffer(const char *fsrc,uint32_t FileNum,int transfermode) 00367 { 00368 DIR *d = opendir(fsrc); 00369 struct dirent *p; 00370 char filepath[40]; 00371 00372 for(uint32_t i=0; i< FileNum; i++) readdir(d); 00373 if ((p = readdir(d)) != NULL) { 00374 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00375 //pc.printf( "%s/%s[%u]\n",fsrc,p->d_name,p->d_type); 00376 SD2LINEBUF(filepath,transfermode); 00377 } 00378 closedir(d); 00379 } 00380 #endif
Generated on Wed Jul 13 2022 14:14:08 by
1.7.2