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 FT800_3 by
FT_Hal_Utils.cpp@5:c0ffdb08b8a5, 2014-09-25 (annotated)
- Committer:
- dreschpe
- Date:
- Thu Sep 25 20:32:21 2014 +0000
- Revision:
- 5:c0ffdb08b8a5
- Parent:
- 4:363ec27cdfaa
- Child:
- 6:16e22c789f7d
add fadein fadeout backlite
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" |
dreschpe | 4:363ec27cdfaa | 3 | |
dreschpe | 4:363ec27cdfaa | 4 | /* function to load jpg file from filesystem */ |
dreschpe | 4:363ec27cdfaa | 5 | /* return 0 if jpg is ok */ |
dreschpe | 4:363ec27cdfaa | 6 | /* return x_size and y_size of jpg */ |
dreschpe | 4:363ec27cdfaa | 7 | |
dreschpe | 4:363ec27cdfaa | 8 | int FT800::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) |
dreschpe | 4:363ec27cdfaa | 9 | { |
dreschpe | 4:363ec27cdfaa | 10 | unsigned char pbuff[8291]; |
dreschpe | 4:363ec27cdfaa | 11 | unsigned short marker; |
dreschpe | 4:363ec27cdfaa | 12 | unsigned short length; |
dreschpe | 4:363ec27cdfaa | 13 | unsigned char data[4]; |
dreschpe | 4:363ec27cdfaa | 14 | |
dreschpe | 4:363ec27cdfaa | 15 | ft_uint16_t blocklen; |
dreschpe | 4:363ec27cdfaa | 16 | |
dreschpe | 4:363ec27cdfaa | 17 | FILE *fp = fopen(filename, "r"); |
dreschpe | 4:363ec27cdfaa | 18 | if(fp == NULL) return (-1); // connot open file |
dreschpe | 4:363ec27cdfaa | 19 | |
dreschpe | 4:363ec27cdfaa | 20 | // search for 0xFFC0 marker |
dreschpe | 4:363ec27cdfaa | 21 | fseek(fp, 0, SEEK_END); |
dreschpe | 4:363ec27cdfaa | 22 | unsigned int Fsize = ftell(fp); |
dreschpe | 4:363ec27cdfaa | 23 | fseek(fp, 2, SEEK_SET); |
dreschpe | 4:363ec27cdfaa | 24 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 25 | marker = data[0] << 8 | data[1]; |
dreschpe | 4:363ec27cdfaa | 26 | length = data[2] << 8 | data[3]; |
dreschpe | 4:363ec27cdfaa | 27 | do { |
dreschpe | 4:363ec27cdfaa | 28 | if(marker == 0xFFC0) break; |
dreschpe | 4:363ec27cdfaa | 29 | if(marker & 0xFF00 != 0xFF00) break; |
dreschpe | 4:363ec27cdfaa | 30 | if (fseek(fp, length - 2,SEEK_CUR) != 0) break; |
dreschpe | 4:363ec27cdfaa | 31 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 32 | marker = data[0] << 8 | data[1]; |
dreschpe | 4:363ec27cdfaa | 33 | length = data[2] << 8 | data[3]; |
dreschpe | 4:363ec27cdfaa | 34 | } while(1); |
dreschpe | 4:363ec27cdfaa | 35 | if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG |
dreschpe | 4:363ec27cdfaa | 36 | fseek(fp, 1,SEEK_CUR); |
dreschpe | 4:363ec27cdfaa | 37 | fread(data,4,1,fp); |
dreschpe | 4:363ec27cdfaa | 38 | *y_size = (data[0] << 8 | data[1]); |
dreschpe | 4:363ec27cdfaa | 39 | *x_size = (data[2] << 8 | data[3]); |
dreschpe | 4:363ec27cdfaa | 40 | |
dreschpe | 4:363ec27cdfaa | 41 | //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen |
dreschpe | 4:363ec27cdfaa | 42 | |
dreschpe | 4:363ec27cdfaa | 43 | fseek(fp, 0, SEEK_SET); |
dreschpe | 4:363ec27cdfaa | 44 | WrCmd32(CMD_LOADIMAGE); // load a JPEG image |
dreschpe | 4:363ec27cdfaa | 45 | WrCmd32(0); //destination address of jpg decode |
dreschpe | 4:363ec27cdfaa | 46 | WrCmd32(0); //output format of the bitmap - default is rgb565 |
dreschpe | 4:363ec27cdfaa | 47 | while(Fsize > 0) { |
dreschpe | 4:363ec27cdfaa | 48 | /* download the data into the command buffer by 8kb one shot */ |
dreschpe | 4:363ec27cdfaa | 49 | blocklen = Fsize>8192?8192:Fsize; |
dreschpe | 4:363ec27cdfaa | 50 | /* copy the data into pbuff and then transfter it to command buffer */ |
dreschpe | 4:363ec27cdfaa | 51 | fread(pbuff,1,blocklen,fp); |
dreschpe | 4:363ec27cdfaa | 52 | Fsize -= blocklen; |
dreschpe | 4:363ec27cdfaa | 53 | /* copy data continuously into command memory */ |
dreschpe | 4:363ec27cdfaa | 54 | WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
dreschpe | 4:363ec27cdfaa | 55 | } |
dreschpe | 4:363ec27cdfaa | 56 | fclose(fp); |
dreschpe | 4:363ec27cdfaa | 57 | |
dreschpe | 4:363ec27cdfaa | 58 | return(0); |
dreschpe | 4:363ec27cdfaa | 59 | } |
dreschpe | 4:363ec27cdfaa | 60 | |
dreschpe | 4:363ec27cdfaa | 61 | |
dreschpe | 4:363ec27cdfaa | 62 | /* calibrate touch */ |
dreschpe | 4:363ec27cdfaa | 63 | ft_void_t FT800::Calibrate() |
dreschpe | 4:363ec27cdfaa | 64 | { |
dreschpe | 4:363ec27cdfaa | 65 | /*************************************************************************/ |
dreschpe | 4:363ec27cdfaa | 66 | /* Below code demonstrates the usage of calibrate function. Calibrate */ |
dreschpe | 4:363ec27cdfaa | 67 | /* function will wait untill user presses all the three dots. Only way to*/ |
dreschpe | 4:363ec27cdfaa | 68 | /* come out of this api is to reset the coprocessor bit. */ |
dreschpe | 4:363ec27cdfaa | 69 | /*************************************************************************/ |
dreschpe | 4:363ec27cdfaa | 70 | { |
dreschpe | 4:363ec27cdfaa | 71 | |
dreschpe | 4:363ec27cdfaa | 72 | DLstart(); // start a new display command list |
dreschpe | 4:363ec27cdfaa | 73 | DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B |
dreschpe | 4:363ec27cdfaa | 74 | DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 4:363ec27cdfaa | 75 | DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B |
dreschpe | 4:363ec27cdfaa | 76 | Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please Tap on the dot"); // draw Text at x,y, font 27, centered |
dreschpe | 4:363ec27cdfaa | 77 | Calibrate(0); // start the calibration of touch screen |
dreschpe | 4:363ec27cdfaa | 78 | Flush_Co_Buffer(); // download the commands into FT800 FIFO |
dreschpe | 4:363ec27cdfaa | 79 | WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 4:363ec27cdfaa | 80 | } |
dreschpe | 4:363ec27cdfaa | 81 | } |
dreschpe | 4:363ec27cdfaa | 82 | |
dreschpe | 5:c0ffdb08b8a5 | 83 | |
dreschpe | 5:c0ffdb08b8a5 | 84 | /* API to give fadeout effect by changing the display PWM from 100 till 0 */ |
dreschpe | 5:c0ffdb08b8a5 | 85 | ft_void_t FT800::fadeout() |
dreschpe | 5:c0ffdb08b8a5 | 86 | { |
dreschpe | 5:c0ffdb08b8a5 | 87 | ft_int32_t i; |
dreschpe | 5:c0ffdb08b8a5 | 88 | |
dreschpe | 5:c0ffdb08b8a5 | 89 | for (i = 100; i >= 0; i -= 3) |
dreschpe | 5:c0ffdb08b8a5 | 90 | { |
dreschpe | 5:c0ffdb08b8a5 | 91 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 92 | Sleep(2);//sleep for 2 ms |
dreschpe | 5:c0ffdb08b8a5 | 93 | } |
dreschpe | 5:c0ffdb08b8a5 | 94 | } |
dreschpe | 5:c0ffdb08b8a5 | 95 | |
dreschpe | 5:c0ffdb08b8a5 | 96 | /* API to perform display fadein effect by changing the display PWM from 0 till 100 and finally 128 */ |
dreschpe | 5:c0ffdb08b8a5 | 97 | ft_void_t FT800::fadein() |
dreschpe | 5:c0ffdb08b8a5 | 98 | { |
dreschpe | 5:c0ffdb08b8a5 | 99 | ft_int32_t i; |
dreschpe | 5:c0ffdb08b8a5 | 100 | |
dreschpe | 5:c0ffdb08b8a5 | 101 | for (i = 0; i <=100 ; i += 3) |
dreschpe | 5:c0ffdb08b8a5 | 102 | { |
dreschpe | 5:c0ffdb08b8a5 | 103 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 104 | Sleep(2);//sleep for 2 ms |
dreschpe | 5:c0ffdb08b8a5 | 105 | } |
dreschpe | 5:c0ffdb08b8a5 | 106 | /* Finally make the PWM 100% */ |
dreschpe | 5:c0ffdb08b8a5 | 107 | i = 128; |
dreschpe | 5:c0ffdb08b8a5 | 108 | Wr8(REG_PWM_DUTY,i); |
dreschpe | 5:c0ffdb08b8a5 | 109 | } |
dreschpe | 5:c0ffdb08b8a5 | 110 |