configured for beyondtek displays
Fork of FT800_3 by
FT_Hal_Utils.cpp@10:39d32e09742d, 2016-08-15 (annotated)
- Committer:
- cpm219
- Date:
- Mon Aug 15 15:32:32 2016 +0000
- Revision:
- 10:39d32e09742d
- Parent:
- 8:4601ccd8a927
no change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 4:363ec27cdfaa | 1 | #include "FT_Platform.h" |
dreschpe | 4:363ec27cdfaa | 2 | #include "mbed.h" |
cpm219 | 10:39d32e09742d | 3 | #include "SDFileSystem.h" |
dreschpe | 4:363ec27cdfaa | 4 | |
dreschpe | 4:363ec27cdfaa | 5 | /* function to load jpg file from filesystem */ |
dreschpe | 4:363ec27cdfaa | 6 | /* return 0 if jpg is ok */ |
dreschpe | 4:363ec27cdfaa | 7 | /* return x_size and y_size of jpg */ |
dreschpe | 4:363ec27cdfaa | 8 | |
montgojj | 8:4601ccd8a927 | 9 | int FT800::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address) |
dreschpe | 4:363ec27cdfaa | 10 | { |
dreschpe | 4:363ec27cdfaa | 11 | unsigned char pbuff[8291]; |
dreschpe | 4:363ec27cdfaa | 12 | unsigned short marker; |
dreschpe | 4:363ec27cdfaa | 13 | unsigned short length; |
dreschpe | 4:363ec27cdfaa | 14 | unsigned char data[4]; |
dreschpe | 4:363ec27cdfaa | 15 | |
dreschpe | 4:363ec27cdfaa | 16 | ft_uint16_t blocklen; |
cpm219 | 10:39d32e09742d | 17 | // sd.mount(); |
dreschpe | 4:363ec27cdfaa | 18 | FILE *fp = fopen(filename, "r"); |
dreschpe | 4:363ec27cdfaa | 19 | if(fp == NULL) return (-1); // connot open file |
dreschpe | 4:363ec27cdfaa | 20 | |
dreschpe | 4:363ec27cdfaa | 21 | // search for 0xFFC0 marker |
dreschpe | 4:363ec27cdfaa | 22 | fseek(fp, 0, SEEK_END); |
dreschpe | 4:363ec27cdfaa | 23 | unsigned int Fsize = ftell(fp); |
dreschpe | 4:363ec27cdfaa | 24 | fseek(fp, 2, SEEK_SET); |
dreschpe | 4:363ec27cdfaa | 25 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 26 | marker = data[0] << 8 | data[1]; |
dreschpe | 4:363ec27cdfaa | 27 | length = data[2] << 8 | data[3]; |
dreschpe | 4:363ec27cdfaa | 28 | do { |
dreschpe | 4:363ec27cdfaa | 29 | if(marker == 0xFFC0) break; |
dreschpe | 4:363ec27cdfaa | 30 | if(marker & 0xFF00 != 0xFF00) break; |
dreschpe | 4:363ec27cdfaa | 31 | if (fseek(fp, length - 2,SEEK_CUR) != 0) break; |
dreschpe | 4:363ec27cdfaa | 32 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 33 | marker = data[0] << 8 | data[1]; |
dreschpe | 4:363ec27cdfaa | 34 | length = data[2] << 8 | data[3]; |
dreschpe | 4:363ec27cdfaa | 35 | } while(1); |
dreschpe | 4:363ec27cdfaa | 36 | if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG |
dreschpe | 4:363ec27cdfaa | 37 | fseek(fp, 1,SEEK_CUR); |
dreschpe | 4:363ec27cdfaa | 38 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 39 | *y_size = (data[0] << 8 | data[1]); |
dreschpe | 4:363ec27cdfaa | 40 | *x_size = (data[2] << 8 | data[3]); |
dreschpe | 4:363ec27cdfaa | 41 | |
dreschpe | 4:363ec27cdfaa | 42 | //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen |
dreschpe | 4:363ec27cdfaa | 43 | |
dreschpe | 4:363ec27cdfaa | 44 | fseek(fp, 0, SEEK_SET); |
dreschpe | 4:363ec27cdfaa | 45 | WrCmd32(CMD_LOADIMAGE); // load a JPEG image |
montgojj | 8:4601ccd8a927 | 46 | WrCmd32(address); //destination address of jpg decode |
dreschpe | 4:363ec27cdfaa | 47 | WrCmd32(0); //output format of the bitmap - default is rgb565 |
dreschpe | 4:363ec27cdfaa | 48 | while(Fsize > 0) { |
dreschpe | 4:363ec27cdfaa | 49 | /* download the data into the command buffer by 8kb one shot */ |
dreschpe | 4:363ec27cdfaa | 50 | blocklen = Fsize>8192?8192:Fsize; |
dreschpe | 4:363ec27cdfaa | 51 | /* copy the data into pbuff and then transfter it to command buffer */ |
dreschpe | 4:363ec27cdfaa | 52 | fread(pbuff,1,blocklen,fp); |
dreschpe | 4:363ec27cdfaa | 53 | Fsize -= blocklen; |
dreschpe | 4:363ec27cdfaa | 54 | /* copy data continuously into command memory */ |
dreschpe | 4:363ec27cdfaa | 55 | WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
dreschpe | 4:363ec27cdfaa | 56 | } |
dreschpe | 4:363ec27cdfaa | 57 | fclose(fp); |
cpm219 | 10:39d32e09742d | 58 | // sd.unmount(); |
dreschpe | 4:363ec27cdfaa | 59 | |
dreschpe | 4:363ec27cdfaa | 60 | return(0); |
dreschpe | 4:363ec27cdfaa | 61 | } |
dreschpe | 4:363ec27cdfaa | 62 | |
cpm219 | 10:39d32e09742d | 63 | //int FT800::Load_raw(char* filename) |
cpm219 | 10:39d32e09742d | 64 | //{ |
cpm219 | 10:39d32e09742d | 65 | // ft_uint8_t imbuff[8192]; |
cpm219 | 10:39d32e09742d | 66 | // ft_uint16_t filesize; |
cpm219 | 10:39d32e09742d | 67 | // ft_uint16_t blocklen; |
cpm219 | 10:39d32e09742d | 68 | //// ft_uint16_t ram_start = 0x00; |
cpm219 | 10:39d32e09742d | 69 | // |
cpm219 | 10:39d32e09742d | 70 | //// sd.mount(); |
cpm219 | 10:39d32e09742d | 71 | // FILE *fp = fopen(filename, "rb"); // open file |
cpm219 | 10:39d32e09742d | 72 | //// if(fp == NULL) return (-1); // connot open file |
cpm219 | 10:39d32e09742d | 73 | // fseek(fp, 0, SEEK_END); // set file position to end of file |
cpm219 | 10:39d32e09742d | 74 | // filesize= ftell(fp); // determine file size |
cpm219 | 10:39d32e09742d | 75 | // fseek(fp, 2, SEEK_SET); // return to beginning of file |
cpm219 | 10:39d32e09742d | 76 | // |
cpm219 | 10:39d32e09742d | 77 | // while(filesize > 0) |
cpm219 | 10:39d32e09742d | 78 | // { |
cpm219 | 10:39d32e09742d | 79 | // //copy the .raw file data to imbuff[8192] in 8k block |
cpm219 | 10:39d32e09742d | 80 | // blocklen = filesize>8192?8192:filesize; |
cpm219 | 10:39d32e09742d | 81 | // fread(imbuff,1,blocklen,fp); |
cpm219 | 10:39d32e09742d | 82 | // filesize-= blocklen; |
cpm219 | 10:39d32e09742d | 83 | // //write imbuff contents to graphics RAM at address ram_start = 0x00 |
cpm219 | 10:39d32e09742d | 84 | // WrCmdBuf(imbuff, blocklen); //alignment is already taken care by this api |
cpm219 | 10:39d32e09742d | 85 | //// ram_start += 8192; |
cpm219 | 10:39d32e09742d | 86 | // } |
cpm219 | 10:39d32e09742d | 87 | // fclose(fp); |
cpm219 | 10:39d32e09742d | 88 | //// sd.unmount(); |
cpm219 | 10:39d32e09742d | 89 | // |
cpm219 | 10:39d32e09742d | 90 | // return 0; |
cpm219 | 10:39d32e09742d | 91 | //} |
cpm219 | 10:39d32e09742d | 92 | |
cpm219 | 10:39d32e09742d | 93 | |
cpm219 | 10:39d32e09742d | 94 | |
cpm219 | 10:39d32e09742d | 95 | |
cpm219 | 10:39d32e09742d | 96 | |
dreschpe | 4:363ec27cdfaa | 97 | |
dreschpe | 4:363ec27cdfaa | 98 | /* calibrate touch */ |
dreschpe | 4:363ec27cdfaa | 99 | ft_void_t FT800::Calibrate() |
dreschpe | 4:363ec27cdfaa | 100 | { |
dreschpe | 4:363ec27cdfaa | 101 | /*************************************************************************/ |
dreschpe | 4:363ec27cdfaa | 102 | /* Below code demonstrates the usage of calibrate function. Calibrate */ |
dreschpe | 4:363ec27cdfaa | 103 | /* function will wait untill user presses all the three dots. Only way to*/ |
dreschpe | 4:363ec27cdfaa | 104 | /* come out of this api is to reset the coprocessor bit. */ |
dreschpe | 4:363ec27cdfaa | 105 | /*************************************************************************/ |
dreschpe | 4:363ec27cdfaa | 106 | { |
dreschpe | 4:363ec27cdfaa | 107 | |
dreschpe | 4:363ec27cdfaa | 108 | DLstart(); // start a new display command list |
dreschpe | 4:363ec27cdfaa | 109 | DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B |
dreschpe | 4:363ec27cdfaa | 110 | DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 4:363ec27cdfaa | 111 | DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B |
dreschpe | 4:363ec27cdfaa | 112 | Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please Tap on the dot"); // draw Text at x,y, font 27, centered |
dreschpe | 4:363ec27cdfaa | 113 | Calibrate(0); // start the calibration of touch screen |
dreschpe | 4:363ec27cdfaa | 114 | Flush_Co_Buffer(); // download the commands into FT800 FIFO |
dreschpe | 4:363ec27cdfaa | 115 | WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 4:363ec27cdfaa | 116 | } |
dreschpe | 4:363ec27cdfaa | 117 | } |
dreschpe | 4:363ec27cdfaa | 118 | |
dreschpe | 5:c0ffdb08b8a5 | 119 | |
dreschpe | 5:c0ffdb08b8a5 | 120 | /* API to give fadeout effect by changing the display PWM from 100 till 0 */ |
dreschpe | 5:c0ffdb08b8a5 | 121 | ft_void_t FT800::fadeout() |
dreschpe | 5:c0ffdb08b8a5 | 122 | { |
dreschpe | 5:c0ffdb08b8a5 | 123 | ft_int32_t i; |
dreschpe | 5:c0ffdb08b8a5 | 124 | |
dreschpe | 5:c0ffdb08b8a5 | 125 | for (i = 100; i >= 0; i -= 3) |
dreschpe | 5:c0ffdb08b8a5 | 126 | { |
dreschpe | 5:c0ffdb08b8a5 | 127 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 128 | Sleep(2);//sleep for 2 ms |
dreschpe | 5:c0ffdb08b8a5 | 129 | } |
dreschpe | 5:c0ffdb08b8a5 | 130 | } |
dreschpe | 5:c0ffdb08b8a5 | 131 | |
dreschpe | 5:c0ffdb08b8a5 | 132 | /* API to perform display fadein effect by changing the display PWM from 0 till 100 and finally 128 */ |
dreschpe | 5:c0ffdb08b8a5 | 133 | ft_void_t FT800::fadein() |
dreschpe | 5:c0ffdb08b8a5 | 134 | { |
dreschpe | 5:c0ffdb08b8a5 | 135 | ft_int32_t i; |
dreschpe | 5:c0ffdb08b8a5 | 136 | |
dreschpe | 5:c0ffdb08b8a5 | 137 | for (i = 0; i <=100 ; i += 3) |
dreschpe | 5:c0ffdb08b8a5 | 138 | { |
dreschpe | 5:c0ffdb08b8a5 | 139 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 140 | Sleep(2);//sleep for 2 ms |
dreschpe | 5:c0ffdb08b8a5 | 141 | } |
dreschpe | 5:c0ffdb08b8a5 | 142 | /* Finally make the PWM 100% */ |
dreschpe | 5:c0ffdb08b8a5 | 143 | i = 128; |
dreschpe | 5:c0ffdb08b8a5 | 144 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 145 | } |
dreschpe | 5:c0ffdb08b8a5 | 146 | |
dreschpe | 6:16e22c789f7d | 147 | ft_void_t FT800::read_calibrate(ft_uint8_t data[24]){ |
dreschpe | 6:16e22c789f7d | 148 | unsigned int i; |
dreschpe | 6:16e22c789f7d | 149 | for(i=0;i<24;i++){ |
dreschpe | 6:16e22c789f7d | 150 | data[i] = Rd8(REG_TOUCH_TRANSFORM_A + i); |
dreschpe | 6:16e22c789f7d | 151 | } |
dreschpe | 6:16e22c789f7d | 152 | } |
dreschpe | 6:16e22c789f7d | 153 | |
dreschpe | 6:16e22c789f7d | 154 | ft_void_t FT800::write_calibrate(ft_uint8_t data[24]){ |
dreschpe | 6:16e22c789f7d | 155 | unsigned int i; |
dreschpe | 6:16e22c789f7d | 156 | for(i=0;i<24;i++) { |
dreschpe | 6:16e22c789f7d | 157 | Wr8(REG_TOUCH_TRANSFORM_A + i,data[i]); |
dreschpe | 6:16e22c789f7d | 158 | } |
dreschpe | 6:16e22c789f7d | 159 | } |
dreschpe | 6:16e22c789f7d | 160 | |
dreschpe | 6:16e22c789f7d | 161 | ft_uint32_t FT800::color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ |
dreschpe | 6:16e22c789f7d | 162 | return ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); |
dreschpe | 6:16e22c789f7d | 163 | } |
dreschpe | 6:16e22c789f7d | 164 | |
dreschpe | 6:16e22c789f7d | 165 | ft_uint32_t FT800::clear_color_rgb(ft_uint8_t red,ft_uint8_t green, ft_uint8_t blue){ |
dreschpe | 6:16e22c789f7d | 166 | return ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); |
dreschpe | 6:16e22c789f7d | 167 | } |
dreschpe | 6:16e22c789f7d | 168 |