Ok for EveConnect
Dependents: FT800_RGB_demo-for_ConnectEve
FT_Hal_Utils.cpp@0:352efe1d072f, 2019-03-11 (annotated)
- Committer:
- schnf30
- Date:
- Mon Mar 11 19:14:19 2019 +0000
- Revision:
- 0:352efe1d072f
Programme demo FT800 for ConnectEve. It's Ok.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
schnf30 | 0:352efe1d072f | 1 | #include "FT_Platform.h" |
schnf30 | 0:352efe1d072f | 2 | #include "mbed.h" |
schnf30 | 0:352efe1d072f | 3 | |
schnf30 | 0:352efe1d072f | 4 | /* function to load jpg file from filesystem */ |
schnf30 | 0:352efe1d072f | 5 | /* return 0 if jpg is ok */ |
schnf30 | 0:352efe1d072f | 6 | /* return x_size and y_size of jpg */ |
schnf30 | 0:352efe1d072f | 7 | |
schnf30 | 0:352efe1d072f | 8 | int FT800::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) |
schnf30 | 0:352efe1d072f | 9 | { |
schnf30 | 0:352efe1d072f | 10 | unsigned char pbuff[8291]; |
schnf30 | 0:352efe1d072f | 11 | unsigned short marker; |
schnf30 | 0:352efe1d072f | 12 | unsigned short length; |
schnf30 | 0:352efe1d072f | 13 | unsigned char data[4]; |
schnf30 | 0:352efe1d072f | 14 | |
schnf30 | 0:352efe1d072f | 15 | ft_uint16_t blocklen; |
schnf30 | 0:352efe1d072f | 16 | |
schnf30 | 0:352efe1d072f | 17 | FILE *fp = fopen(filename, "r"); |
schnf30 | 0:352efe1d072f | 18 | if(fp == NULL) return (-1); // connot open file |
schnf30 | 0:352efe1d072f | 19 | |
schnf30 | 0:352efe1d072f | 20 | // search for 0xFFC0 marker |
schnf30 | 0:352efe1d072f | 21 | fseek(fp, 0, SEEK_END); |
schnf30 | 0:352efe1d072f | 22 | unsigned int Fsize = ftell(fp); |
schnf30 | 0:352efe1d072f | 23 | fseek(fp, 2, SEEK_SET); |
schnf30 | 0:352efe1d072f | 24 | fread(data,4,1,fp); |
schnf30 | 0:352efe1d072f | 25 | marker = data[0] << 8 | data[1]; |
schnf30 | 0:352efe1d072f | 26 | length = data[2] << 8 | data[3]; |
schnf30 | 0:352efe1d072f | 27 | do { |
schnf30 | 0:352efe1d072f | 28 | if(marker == 0xFFC0) break; |
schnf30 | 0:352efe1d072f | 29 | if(marker & 0xFF00 != 0xFF00) break; |
schnf30 | 0:352efe1d072f | 30 | if (fseek(fp, length - 2,SEEK_CUR) != 0) break; |
schnf30 | 0:352efe1d072f | 31 | fread(data,4,1,fp); |
schnf30 | 0:352efe1d072f | 32 | marker = data[0] << 8 | data[1]; |
schnf30 | 0:352efe1d072f | 33 | length = data[2] << 8 | data[3]; |
schnf30 | 0:352efe1d072f | 34 | } while(1); |
schnf30 | 0:352efe1d072f | 35 | if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG |
schnf30 | 0:352efe1d072f | 36 | fseek(fp, 1,SEEK_CUR); |
schnf30 | 0:352efe1d072f | 37 | fread(data,4,1,fp); |
schnf30 | 0:352efe1d072f | 38 | *y_size = (data[0] << 8 | data[1]); |
schnf30 | 0:352efe1d072f | 39 | *x_size = (data[2] << 8 | data[3]); |
schnf30 | 0:352efe1d072f | 40 | |
schnf30 | 0:352efe1d072f | 41 | //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen |
schnf30 | 0:352efe1d072f | 42 | |
schnf30 | 0:352efe1d072f | 43 | fseek(fp, 0, SEEK_SET); |
schnf30 | 0:352efe1d072f | 44 | WrCmd32(CMD_LOADIMAGE); // load a JPEG image |
schnf30 | 0:352efe1d072f | 45 | WrCmd32(0); //destination address of jpg decode |
schnf30 | 0:352efe1d072f | 46 | WrCmd32(0); //output format of the bitmap - default is rgb565 |
schnf30 | 0:352efe1d072f | 47 | while(Fsize > 0) { |
schnf30 | 0:352efe1d072f | 48 | /* download the data into the command buffer by 8kb one shot */ |
schnf30 | 0:352efe1d072f | 49 | blocklen = Fsize>8192?8192:Fsize; |
schnf30 | 0:352efe1d072f | 50 | /* copy the data into pbuff and then transfter it to command buffer */ |
schnf30 | 0:352efe1d072f | 51 | fread(pbuff,1,blocklen,fp); |
schnf30 | 0:352efe1d072f | 52 | Fsize -= blocklen; |
schnf30 | 0:352efe1d072f | 53 | /* copy data continuously into command memory */ |
schnf30 | 0:352efe1d072f | 54 | WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
schnf30 | 0:352efe1d072f | 55 | } |
schnf30 | 0:352efe1d072f | 56 | fclose(fp); |
schnf30 | 0:352efe1d072f | 57 | |
schnf30 | 0:352efe1d072f | 58 | return(0); |
schnf30 | 0:352efe1d072f | 59 | } |
schnf30 | 0:352efe1d072f | 60 | |
schnf30 | 0:352efe1d072f | 61 | |
schnf30 | 0:352efe1d072f | 62 | /* calibrate touch */ |
schnf30 | 0:352efe1d072f | 63 | ft_void_t FT800::Calibrate() |
schnf30 | 0:352efe1d072f | 64 | { |
schnf30 | 0:352efe1d072f | 65 | /*************************************************************************/ |
schnf30 | 0:352efe1d072f | 66 | /* Below code demonstrates the usage of calibrate function. Calibrate */ |
schnf30 | 0:352efe1d072f | 67 | /* function will wait untill user presses all the three dots. Only way to*/ |
schnf30 | 0:352efe1d072f | 68 | /* come out of this api is to reset the coprocessor bit. */ |
schnf30 | 0:352efe1d072f | 69 | /*************************************************************************/ |
schnf30 | 0:352efe1d072f | 70 | { |
schnf30 | 0:352efe1d072f | 71 | |
schnf30 | 0:352efe1d072f | 72 | DLstart(); // start a new display command list |
schnf30 | 0:352efe1d072f | 73 | DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B |
schnf30 | 0:352efe1d072f | 74 | DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
schnf30 | 0:352efe1d072f | 75 | DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B |
schnf30 | 0:352efe1d072f | 76 | Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Appuyez sur les points"); // draw Text at x,y, font 27, centered |
schnf30 | 0:352efe1d072f | 77 | Calibrate(0); // start the calibration of touch screen |
schnf30 | 0:352efe1d072f | 78 | Flush_Co_Buffer(); // download the commands into FT800 FIFO |
schnf30 | 0:352efe1d072f | 79 | WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
schnf30 | 0:352efe1d072f | 80 | } |
schnf30 | 0:352efe1d072f | 81 | } |
schnf30 | 0:352efe1d072f | 82 | |
schnf30 | 0:352efe1d072f | 83 |