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.
Fork of MIP8f_FRDM_sample by
main.cpp
00001 /** 00002 * Copyright 2018 Japan Display Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "stdio.h" 00017 #include "string" 00018 #include "mbed.h" 00019 #include "MIP8F_SPI.h" 00020 #include "SDFileSystem.h" 00021 #include "StateSW.h" 00022 #include "TglSW.h" 00023 00024 00025 #include "Arial12x12.h" 00026 #include "Arial24x23.h" 00027 #include "Arial28x28.h" 00028 #include "font_big.h" 00029 //#include "Prototype29x28.h" 00030 //#include "Prototype70x86.h" 00031 //#include "HGP23x29.h" 00032 //#include "HGP15x19.h" 00033 //#include "symbol.h" 00034 00035 #define ON 1 00036 #define OFF 0 00037 00038 00039 //K64F 00040 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // mosi,miso,sck,cs 00041 memLCD8 WD(PTD2,PTD3,PTD1,PTD0,PTC4,PTD3); //PTC12); // mosi,miso,clk,cs,disp,power 00042 PwmOut BK(PTC3); 00043 PwmOut COM60HZ(PTC10); //add 20161108 00044 DigitalOut COMSEL(PTA2,0); //add 20161108 00045 00046 DigitalOut BLCTRL(PTB10,0); //add 20171115 00047 00048 // SW2 00049 StateSW swPWMorOFF(SW2); //PTC6); 00050 InterruptIn PWMorOFF(SW2); 00051 00052 // SW3 00053 TglSW HaltSW(SW3); //PTA4); 00054 DigitalIn TexSW(SW3); 00055 00056 00057 00058 void SD2BUF(char *filepath); 00059 void ifOFFseq(void); 00060 void ifswPWM(void); 00061 void OffSequence(void); 00062 void DispAllDir(const char *fsrc); 00063 void ReadBmp(const char *fsrc, uint32_t FileNum); 00064 uint32_t CntFile(const char *fsrc); 00065 int ifMargeTXT = 0; 00066 int width = 400; 00067 int height= 240; 00068 00069 float BKduty = 0; 00070 float BKjudge = 0; 00071 //double BKduty = 0; 00072 float bk_timer = 1.0; 00073 int blduty = 0; 00074 int bloff = 0; 00075 int blctrl_sel = 1; //0:40mA, 1:160mA 00076 00077 int main() { 00078 00079 uint32_t filenum=0; 00080 char filepath[40]; 00081 00082 00083 sd.disk_initialize(); 00084 HaltSW.Enable(1); 00085 00086 00087 FILE *fp = fopen("/sd/settings2.txt", "rb"); //read binary 00088 if(fp != NULL) { 00089 fscanf(fp, "%d",&width); //width read 00090 fscanf(fp, "%d",&height); //height read 00091 fscanf(fp, "%d",&blctrl_sel);//blct_sel read //0:40mA, 1:160mA 00092 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00093 fclose(fp); 00094 } else { 00095 FILE *fp = fopen("/sd/settings.txt", "rb"); //read binary 00096 if(fp != NULL) { 00097 fscanf(fp, "%d",&width); //width read 00098 fscanf(fp, "%d",&height); //height read 00099 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00100 fclose(fp); 00101 } else{ 00102 width =180; 00103 height=180; 00104 sprintf(filepath,"/sd/180x180"); //DispAllDir("/sd/180x180") 00105 } 00106 } 00107 00108 COMSEL.write(1); // 00109 00110 BLCTRL.write(blctrl_sel); // 00111 00112 WD.setWH(width,height); //input -> width, height 00113 WD.background(Black); //background = black 00114 WD.clsBUF(); //data initialize 00115 WD.writeDISP(); //picture write(black) 00116 WD.SwDisp(1); //disp on 00117 00118 // OffSW.fall(&OffSequence); // Renamed "OffSW" as "PWMorOFF" for BK PWM setting 00119 // SW settings for PWM or OFF 00120 PWMorOFF.fall(&ifswPWM); // Backlight //sw2 fall edge 00121 PWMorOFF.rise(&ifOFFseq); // OFF Sequence //sw2 rise edge 00122 00123 swPWMorOFF.Enable(8, 2, 1); //int ModeNum, int NoiseCancel, int OpenTime //???? 00124 swPWMorOFF.IfCntClose(ON); 00125 swPWMorOFF.IfCntState(ON); 00126 00127 COM60HZ.period_ms(8); //add 20161108 00128 COM60HZ.write(0.5); //add 20161108 00129 00130 BK.period_ms(1); //1ms cycle 20161012 00131 BK.write(0); //low output 20160725 <- high output 00132 00133 while(1){ //BITMAPS 00134 filenum = CntFile(filepath); //file number read 00135 for(uint32_t i=0; i<filenum; i++){ 00136 ReadBmp(filepath,i); 00137 00138 while(HaltSW.State()){ // VCOM invert when image is still 00139 // pol++; 00140 // WD.command( (pol << 6) & 0x40 ); 00141 // wait(bk_timer); //1Hz 00142 } 00143 /* 00144 // Brink 00145 for(char j = 0; j < 8; j++){ 00146 pol = j&0x01; 00147 EnterOrLeave = (j+1)&0x01; 00148 WD.command( (pol << 6) | (EnterOrLeave << 3) ); 00149 wait(0.2); 00150 } 00151 */ 00152 HaltSW.Clear(); 00153 WD.writeDISP(); 00154 wait(2); 00155 } 00156 } 00157 } 00158 00159 00160 void SD2BUF(char *filepath){ 00161 char R8[1],G8[1],B8[1] ,DUMMY[1]; 00162 int RGB; 00163 FILE *fp ; 00164 00165 fp = fopen(filepath, "rb"); 00166 if(fp != NULL) { 00167 for(int i=0; i< 54 ; i++) fscanf(fp,"%c",DUMMY); // Discard Header 54bytes 00168 for(int y=height-1; y>=0; y--) { 00169 for(int x=0; x< width; x++) { //24bit color B 8bit -> G 8bit -> R 8bit 00170 fscanf(fp, "%c",B8); 00171 fscanf(fp, "%c",G8); 00172 fscanf(fp, "%c",R8); 00173 00174 RGB = RGB8(*R8,*G8,*B8); //6bit(8bit) MIP MASK 0000 1110 00175 WD.pixel(x,y,RGB); 00176 } 00177 if( y!=0) // The last data column doesn't need padding 00178 for(int x=(width*3)%4; (x%4 !=0); x++) fscanf(fp, "%c",DUMMY); // 4byte boundery for every column 00179 } 00180 } 00181 fclose(fp); 00182 } 00183 00184 void SDtex2BUF(char *filepath){ 00185 int x,y,font,color; 00186 char text[40]; 00187 int ifEOF; 00188 FILE *fp ; 00189 00190 fp = fopen(filepath, "r"); 00191 if(fp != NULL) { 00192 // for(int i=0; i<3; i++){ 00193 while(ifEOF != -1){ 00194 ifEOF = fscanf(fp,"%d,%d,%d,%d,%[^,],",&x,&y,&font,&color,text); 00195 WD.locate(x,y); 00196 WD.foreground(color); 00197 if (font ==1) WD.set_font((unsigned char*) Arial12x12); 00198 else if (font ==2) WD.set_font((unsigned char*) Arial24x23); 00199 else if (font ==3) WD.set_font((unsigned char*) Arial28x28); 00200 else WD.set_font((unsigned char*) Neu42x35); 00201 00202 WD.printf("%s",text); 00203 } 00204 } 00205 fclose(fp); 00206 } 00207 00208 void DispAllDir(const char *fsrc) 00209 { 00210 DIR *d = opendir(fsrc); 00211 struct dirent *p; 00212 char filepath[40]; 00213 00214 while ((p = readdir(d)) != NULL) { 00215 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00216 SD2BUF(filepath); 00217 WD.writeDISP(); 00218 } 00219 closedir(d); 00220 } 00221 00222 void ReadBmp(const char *fsrc, uint32_t FileNum) 00223 { 00224 DIR *d = opendir(fsrc); 00225 struct dirent *p; 00226 char filepath[40]; 00227 00228 for(uint32_t i=0; i< FileNum; i++) readdir(d); 00229 if ((p = readdir(d)) != NULL) { 00230 sprintf(filepath, "%s/%s",fsrc,p->d_name); 00231 SD2BUF(filepath); 00232 if(ifMargeTXT){ 00233 sprintf(filepath, "%s_txt/%s.txt",fsrc,p->d_name); 00234 SDtex2BUF(filepath); 00235 } 00236 } 00237 closedir(d); 00238 } 00239 00240 uint32_t CntFile(const char *fsrc) 00241 { 00242 DIR *d = opendir(fsrc); 00243 uint32_t counter = 0; 00244 while (readdir(d)!= NULL) counter++; 00245 closedir(d); 00246 return counter; 00247 } 00248 00249 00250 void OffSequence(void){ 00251 BK.write(0); //add 20160712 17:00 00252 WD.background(Black); 00253 WD.clsBUF(); 00254 WD.SwDisp(0); 00255 WD.writeDISP(); 00256 WD.writeDISP(); 00257 bloff = 1; 00258 } 00259 00260 void ifswPWM(void){ 00261 if(bloff == 0){ 00262 if(blduty >= 10){ //0 00263 blduty = 0; //10 00264 COMSEL.write(1); // 00265 }else{ 00266 blduty += 1; //-= 00267 COMSEL.write(1); // 00268 } 00269 }else{ 00270 blduty = 0; 00271 COMSEL.write(1); // 00272 } 00273 // BKduty = BKduty - 0.125; 00274 // BKduty -= 0.125; 00275 // if(BKduty <= 0) BKduty = 1; 00276 // BK.write(BKduty); 00277 BK.write(blduty*0.1); // 00278 if(blduty == 0){ 00279 bk_timer = 1.0; 00280 }else{ 00281 bk_timer = 0.008; //0.016 20160712 00282 } 00283 } 00284 00285 void ifOFFseq(void){ 00286 if(swPWMorOFF.IfAtTime()){ 00287 swPWMorOFF.IfCntClose(OFF); 00288 swPWMorOFF.IfCntState(OFF); 00289 OffSequence(); 00290 } 00291 } 00292
Generated on Wed Jul 13 2022 02:52:47 by
1.7.2
