808

Dependents:   Chromatograph_Mobile

Committer:
cpm219
Date:
Sun Oct 02 04:53:42 2016 +0000
Revision:
5:506e2de9a9e6
Parent:
0:2d0ef4830603
Child:
10:6a81aeca25e3
latest

Who changed what in which revision?

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