Library for FT810 EVE chip
Dependents: PANEL_GUI_hello_world
FT_Hal_Utils.cpp
00001 #include "FT_Platform.h" 00002 #include "mbed.h" 00003 //#include "SDFileSystem.h" 00004 00005 /* function to load jpg file from filesystem */ 00006 /* return 0 if jpg is ok */ 00007 /* return x_size and y_size of jpg */ 00008 00009 int FT800::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address) 00010 { 00011 unsigned char pbuff[8291]; 00012 unsigned short marker; 00013 unsigned short length; 00014 unsigned char data[4]; 00015 00016 ft_uint16_t blocklen; 00017 // sd.mount(); 00018 FILE *fp = fopen(filename, "r"); 00019 if(fp == NULL) return (-1); // connot open file 00020 00021 // search for 0xFFC0 marker 00022 fseek(fp, 0, SEEK_END); 00023 unsigned int Fsize = ftell(fp); 00024 fseek(fp, 2, SEEK_SET); 00025 fread(data,4,1,fp); 00026 marker = data[0] << 8 | data[1]; 00027 length = data[2] << 8 | data[3]; 00028 do { 00029 if(marker == 0xFFC0) break; 00030 if(marker & 0xFF00 != 0xFF00) break; 00031 if (fseek(fp, length - 2,SEEK_CUR) != 0) break; 00032 fread(data,4,1,fp); 00033 marker = data[0] << 8 | data[1]; 00034 length = data[2] << 8 | data[3]; 00035 } while(1); 00036 if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG 00037 fseek(fp, 1,SEEK_CUR); 00038 fread(data,4,1,fp); 00039 *y_size = (data[0] << 8 | data[1]); 00040 *x_size = (data[2] << 8 | data[3]); 00041 00042 //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen 00043 00044 fseek(fp, 0, SEEK_SET); 00045 WrCmd32(CMD_LOADIMAGE); // load a JPEG image 00046 WrCmd32(address); //destination address of jpg decode 00047 WrCmd32(0); //output format of the bitmap - default is rgb565 00048 while(Fsize > 0) { 00049 /* download the data into the command buffer by 8kb one shot */ 00050 blocklen = Fsize>8192?8192:Fsize; 00051 /* copy the data into pbuff and then transfter it to command buffer */ 00052 fread(pbuff,1,blocklen,fp); 00053 Fsize -= blocklen; 00054 /* copy data continuously into command memory */ 00055 WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api 00056 } 00057 fclose(fp); 00058 // sd.unmount(); 00059 00060 return(0); 00061 } 00062 00063 //int FT800::Load_raw(char* filename) 00064 //{ 00065 // ft_uint8_t imbuff[8192]; 00066 // ft_uint16_t filesize; 00067 // ft_uint16_t blocklen; 00068 //// ft_uint16_t ram_start = 0x00; 00069 // 00070 //// sd.mount(); 00071 // FILE *fp = fopen(filename, "rb"); // open file 00072 //// if(fp == NULL) return (-1); // connot open file 00073 // fseek(fp, 0, SEEK_END); // set file position to end of file 00074 // filesize= ftell(fp); // determine file size 00075 // fseek(fp, 2, SEEK_SET); // return to beginning of file 00076 // 00077 // while(filesize > 0) 00078 // { 00079 // //copy the .raw file data to imbuff[8192] in 8k block 00080 // blocklen = filesize>8192?8192:filesize; 00081 // fread(imbuff,1,blocklen,fp); 00082 // filesize-= blocklen; 00083 // //write imbuff contents to graphics RAM at address ram_start = 0x00 00084 // WrCmdBuf(imbuff, blocklen); //alignment is already taken care by this api 00085 //// ram_start += 8192; 00086 // } 00087 // fclose(fp); 00088 //// sd.unmount(); 00089 // 00090 // return 0; 00091 //} 00092 00093 00094 00095 00096 00097 00098 /* calibrate touch */ 00099 ft_void_t FT800::Calibrate() 00100 { 00101 /*************************************************************************/ 00102 /* Below code demonstrates the usage of calibrate function. Calibrate */ 00103 /* function will wait untill user presses all the three dots. Only way to*/ 00104 /* come out of this api is to reset the coprocessor bit. */ 00105 /*************************************************************************/ 00106 { 00107 00108 DLstart(); // start a new display command list 00109 DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B 00110 DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer 00111 DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B 00112 Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please Tap on the dot"); // draw Text at x,y, font 27, centered 00113 Calibrate(0); // start the calibration of touch screen 00114 Flush_Co_Buffer(); // download the commands into FT800 FIFO 00115 WaitCmdfifo_empty(); // Wait till coprocessor completes the operation 00116 } 00117 } 00118 00119 00120 /* API to give fadeout effect by changing the display PWM from 100 till 0 */ 00121 ft_void_t FT800::fadeout() 00122 { 00123 ft_int32_t i; 00124 00125 for (i = 100; i >= 0; i -= 3) 00126 { 00127 Wr8(REG_PWM_DUTY,i); 00128 Sleep(2);//sleep for 2 ms 00129 } 00130 } 00131 00132 /* API to perform display fadein effect by changing the display PWM from 0 till 100 and finally 128 */ 00133 ft_void_t FT800::fadein() 00134 { 00135 ft_int32_t i; 00136 00137 for (i = 0; i <=100 ; i += 3) 00138 { 00139 Wr8(REG_PWM_DUTY,i); 00140 Sleep(2);//sleep for 2 ms 00141 } 00142 /* Finally make the PWM 100% */ 00143 i = 128; 00144 Wr8(REG_PWM_DUTY,i); 00145 } 00146 00147 ft_void_t FT800::read_calibrate(ft_uint8_t data[24]){ 00148 unsigned int i; 00149 for(i=0;i<24;i++){ 00150 data[i] = Rd8(REG_TOUCH_TRANSFORM_A + i); 00151 } 00152 } 00153 00154 ft_void_t FT800::write_calibrate(ft_uint8_t data[24]){ 00155 unsigned int i; 00156 for(i=0;i<24;i++) { 00157 Wr8(REG_TOUCH_TRANSFORM_A + i,data[i]); 00158 } 00159 } 00160 00161 ft_uint32_t FT800::color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ 00162 return ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); 00163 } 00164 00165 ft_uint32_t FT800::clear_color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ 00166 return ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); 00167 } 00168
Generated on Sat Jul 16 2022 17:49:00 by
