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_MonochromeDisplay_sample by
main.cpp
00001 /** 00002 * @file main.cpp 00003 * @brief Sample source code for MIP8 diplay. 00004 * @details 00005 * 00006 * Addtional function is Monochome display by 1bit mode of SPI transfer. 00007 * 00008 * spi-transfer to Display has 3 mode. 00009 * 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. 00010 * 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.) 00011 * 1bit mode is monocrome display,high speed refresh mode. a only Green subpixel of bitmap data is transfered. 00012 * <License> 00013 * Copyright 2018 Japan Display Inc. 00014 * Licensed under the Apache License, Version 2.0 (the "License"); 00015 * you may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at 00017 * 00018 * http://www.apache.org/licenses/LICENSE-2.0 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 */ 00026 #include "stdio.h" 00027 #include "string" 00028 #include "mbed.h" 00029 #include "MIP8F_SPI.h" 00030 #include "SDFileSystem.h" 00031 #include "StateSW.h" 00032 #include "TglSW.h" 00033 00034 #include "Arial12x12.h" 00035 #include "Arial24x23.h" 00036 #include "Arial28x28.h" 00037 #include "font_big.h" 00038 //#include "Prototype29x28.h" 00039 //#include "Prototype70x86.h" 00040 //#include "HGP23x29.h" 00041 //#include "HGP15x19.h" 00042 //#include "symbol.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 //function prototype 00065 void SD2BUF(char *filepath); 00066 void ifOFFseq(void); 00067 void ifswPWM(void); 00068 void OffSequence(void); 00069 void DispAllDir(const char *fsrc); 00070 void ReadBmp(const char *fsrc, uint32_t FileNum); 00071 uint32_t CntFile(const char *fsrc); 00072 //Grobal value 00073 int ifMargeTXT = 0; 00074 int width = 400; 00075 int height= 240; 00076 00077 float BKduty = 0; 00078 float BKjudge = 0; 00079 //double BKduty = 0; 00080 float bk_timer = 1.0; 00081 int blduty = 0; 00082 int bloff = 0; 00083 int blctrl_sel = 0; //0:40mA, 1:160mA //Y.S 00084 00085 int main() { 00086 00087 uint32_t filenum=0; 00088 char filepath[40]; 00089 00090 sd.disk_initialize(); 00091 HaltSW.Enable(1); 00092 00093 00094 FILE *fp = fopen("/sd/settings2.txt", "rb"); //read binary 00095 if(fp != NULL) { 00096 fscanf(fp, "%d",&width); //width read 00097 fscanf(fp, "%d",&height); //height read 00098 fscanf(fp, "%d",&blctrl_sel);//blct_sel read //0:40mA, 1:160mA 00099 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00100 fclose(fp); 00101 } else { 00102 FILE *fp = fopen("/sd/settings.txt", "rb"); //read binary 00103 if(fp != NULL) { 00104 fscanf(fp, "%d",&width); //width read 00105 fscanf(fp, "%d",&height); //height read 00106 sprintf(filepath,"/sd/%dx%d",width,height); //DispAllDir("/sd/180x180") //file name write to filepath 00107 fclose(fp); 00108 } else{ 00109 width =180; 00110 height=180; 00111 sprintf(filepath,"/sd/180x180"); //DispAllDir("/sd/180x180") 00112 } 00113 } 00114 00115 COMSEL.write(1); // 00116 00117 BLCTRL.write(blctrl_sel); // 00118 00119 WD.setWH(width,height); //input -> width, height 00120 WD.background(Black); //background = black 00121 WD.clsBUF(); //data initialize 00122 WD.writeDISP(); //picture write(black) 00123 WD.SwDisp(1); //disp on 00124 00125 // OffSW.fall(&OffSequence); // Renamed "OffSW" as "PWMorOFF" for BK PWM setting 00126 // SW settings for PWM or OFF 00127 PWMorOFF.fall(&ifswPWM); // Backlight //sw2 fall edge 00128 PWMorOFF.rise(&ifOFFseq); // OFF Sequence //sw2 rise edge 00129 00130 swPWMorOFF.Enable(8, 2, 1); //int ModeNum, int NoiseCancel, int OpenTime //???? 00131 swPWMorOFF.IfCntClose(ON); 00132 swPWMorOFF.IfCntState(ON); 00133 00134 COM60HZ.period_ms(8); //add 20161108 00135 COM60HZ.write(0.5); //add 20161108 00136 00137 BK.period_ms(1); //1ms cycle 20161012 00138 BK.write(0); //low output 20160725 <- high output 00139 00140 while(1) 00141 { //BITMAPS 00142 filenum = CntFile(filepath); //file number read 00143 for(uint32_t i=0; i<filenum; i++) 00144 { 00145 ReadBmp(filepath,i); 00146 while(HaltSW.State()) { // VCOM invert when image is still 00147 // pol++; 00148 // WD.command( (pol << 6) & 0x40 ); 00149 // wait(bk_timer); //1Hz 00150 } 00151 HaltSW.Clear(); 00152 //1bit trasfer mode = monochro diplay 00153 WD.writeDISP(TrBIT1); 00154 wait(2); 00155 } 00156 } 00157 } 00158 00159 //4bit mode 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(only windows bitmap format) 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 Tue Jul 12 2022 22:26:42 by
1.7.2
