Lib FT800 Modifiee

Dependents:   FT800_Lib_perso

Committer:
schnf30
Date:
Tue Feb 08 08:17:31 2022 +0000
Revision:
0:7ea2f058a713
Librairie FT800 adaptee avec drawline, Brigntness etc...

Who changed what in which revision?

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