808
Dependents: Chromatograph_Mobile
src/FT_Hal_Utils.cpp@13:5959af2ac87a, 2020-09-01 (annotated)
- Committer:
- nikmaos
- Date:
- Tue Sep 01 10:52:05 2020 +0000
- Revision:
- 13:5959af2ac87a
- Parent:
- 10:6a81aeca25e3
1.09.2020
Who changed what in which revision?
User | Revision | Line number | New 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 | |
JackB | 10:6a81aeca25e3 | 5 | #define DEBUG |
JackB | 10:6a81aeca25e3 | 6 | |
JackB | 10:6a81aeca25e3 | 7 | /* meta-commands, sequences of several display-list entries condensed into simpler to use functions at the price of some overhead */ |
JackB | 10:6a81aeca25e3 | 8 | |
JackB | 10:6a81aeca25e3 | 9 | ft_void_t FT813::Point(ft_int16_t x, ft_int16_t y, ft_uint16_t size) |
JackB | 10:6a81aeca25e3 | 10 | { |
JackB | 10:6a81aeca25e3 | 11 | ft_uint32_t calc; |
JackB | 10:6a81aeca25e3 | 12 | |
JackB | 10:6a81aeca25e3 | 13 | StartFunc(FT_CMD_SIZE*4); |
JackB | 10:6a81aeca25e3 | 14 | SendCmd(DL_BEGIN | FT8_POINTS); |
JackB | 10:6a81aeca25e3 | 15 | calc = POINT_SIZE(size*16); |
JackB | 10:6a81aeca25e3 | 16 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 17 | calc = VERTEX2F(x * 16, y * 16); |
JackB | 10:6a81aeca25e3 | 18 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 19 | SendCmd(DL_END); |
JackB | 10:6a81aeca25e3 | 20 | EndFunc(); |
JackB | 10:6a81aeca25e3 | 21 | } |
JackB | 10:6a81aeca25e3 | 22 | |
JackB | 10:6a81aeca25e3 | 23 | ft_void_t FT813::Line(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t width) |
JackB | 10:6a81aeca25e3 | 24 | { |
JackB | 10:6a81aeca25e3 | 25 | ft_uint32_t calc; |
JackB | 10:6a81aeca25e3 | 26 | |
JackB | 10:6a81aeca25e3 | 27 | StartFunc(FT_CMD_SIZE*5); |
JackB | 10:6a81aeca25e3 | 28 | SendCmd(DL_BEGIN | FT8_LINES); |
JackB | 10:6a81aeca25e3 | 29 | calc = LINE_WIDTH(width * 16); |
JackB | 10:6a81aeca25e3 | 30 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 31 | calc = VERTEX2F(x0 * 16, y0 * 16); |
JackB | 10:6a81aeca25e3 | 32 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 33 | calc = VERTEX2F(x1 * 16, y1 * 16); |
JackB | 10:6a81aeca25e3 | 34 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 35 | SendCmd(DL_END); |
JackB | 10:6a81aeca25e3 | 36 | EndFunc(); |
JackB | 10:6a81aeca25e3 | 37 | } |
JackB | 10:6a81aeca25e3 | 38 | |
JackB | 10:6a81aeca25e3 | 39 | ft_void_t FT813::Rect(ft_int16_t x0, ft_int16_t y0, ft_int16_t x1, ft_int16_t y1, ft_int16_t corner) |
JackB | 10:6a81aeca25e3 | 40 | { |
JackB | 10:6a81aeca25e3 | 41 | ft_uint32_t calc; |
JackB | 10:6a81aeca25e3 | 42 | |
JackB | 10:6a81aeca25e3 | 43 | StartFunc(FT_CMD_SIZE*5); |
JackB | 10:6a81aeca25e3 | 44 | SendCmd(DL_BEGIN | FT8_RECTS); |
JackB | 10:6a81aeca25e3 | 45 | calc = LINE_WIDTH(corner * 16); |
JackB | 10:6a81aeca25e3 | 46 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 47 | calc = VERTEX2F(x0 * 16, y0 * 16); |
JackB | 10:6a81aeca25e3 | 48 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 49 | calc = VERTEX2F(x1 * 16, y1 * 16); |
JackB | 10:6a81aeca25e3 | 50 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 51 | SendCmd(DL_END); |
JackB | 10:6a81aeca25e3 | 52 | EndFunc(); |
JackB | 10:6a81aeca25e3 | 53 | } |
JackB | 10:6a81aeca25e3 | 54 | |
JackB | 10:6a81aeca25e3 | 55 | ft_void_t FT813::RectWH(ft_int16_t x0, ft_int16_t y0, ft_int16_t w, ft_int16_t h, ft_int16_t corner) |
JackB | 10:6a81aeca25e3 | 56 | { |
JackB | 10:6a81aeca25e3 | 57 | ft_uint32_t calc; |
JackB | 10:6a81aeca25e3 | 58 | x0 += corner; |
JackB | 10:6a81aeca25e3 | 59 | y0 += corner; |
JackB | 10:6a81aeca25e3 | 60 | w -= corner*2; |
JackB | 10:6a81aeca25e3 | 61 | h -= corner*2; |
JackB | 10:6a81aeca25e3 | 62 | ft_int16_t x1 = x0 + w; |
JackB | 10:6a81aeca25e3 | 63 | ft_int16_t y1 = y0 + h; |
JackB | 10:6a81aeca25e3 | 64 | StartFunc(FT_CMD_SIZE*5); |
JackB | 10:6a81aeca25e3 | 65 | SendCmd(DL_BEGIN | FT8_RECTS); |
JackB | 10:6a81aeca25e3 | 66 | calc = LINE_WIDTH(corner * 16); |
JackB | 10:6a81aeca25e3 | 67 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 68 | calc = VERTEX2F(x0 * 16, y0 * 16); |
JackB | 10:6a81aeca25e3 | 69 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 70 | calc = VERTEX2F(x1 * 16, y1 * 16); |
JackB | 10:6a81aeca25e3 | 71 | SendCmd(calc); |
JackB | 10:6a81aeca25e3 | 72 | SendCmd(DL_END); |
JackB | 10:6a81aeca25e3 | 73 | EndFunc(); |
JackB | 10:6a81aeca25e3 | 74 | } |
JackB | 10:6a81aeca25e3 | 75 | |
JackB | 10:6a81aeca25e3 | 76 | /* Function to load JPG file from the filesystem into the FT800 buffer. */ |
JackB | 10:6a81aeca25e3 | 77 | /* First the graphics data have to be load into the FT800 buffer. */ |
JackB | 10:6a81aeca25e3 | 78 | /* The FT800 will decode the JPG data into a bitmap. */ |
JackB | 10:6a81aeca25e3 | 79 | /* In the second step this bitmap will displayed on the LCD. */ |
JackB | 10:6a81aeca25e3 | 80 | /* return 0 if jpg is ok */ |
JackB | 10:6a81aeca25e3 | 81 | /* return x_size and y_size of jpg */ |
JackB | 10:6a81aeca25e3 | 82 | ft_uint8_t FT813::LoadJpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) |
JackB | 10:6a81aeca25e3 | 83 | { |
JackB | 10:6a81aeca25e3 | 84 | // unsigned char pbuff[8192]; |
JackB | 10:6a81aeca25e3 | 85 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 86 | // void* pbuff; |
JackB | 10:6a81aeca25e3 | 87 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 88 | // char pbuff[BUFFER_SIZE] = {0}; |
JackB | 10:6a81aeca25e3 | 89 | unsigned short marker; |
JackB | 10:6a81aeca25e3 | 90 | unsigned short length; |
JackB | 10:6a81aeca25e3 | 91 | unsigned char data[4]; |
JackB | 10:6a81aeca25e3 | 92 | |
JackB | 10:6a81aeca25e3 | 93 | ft_uint16_t blocklen; |
JackB | 10:6a81aeca25e3 | 94 | |
JackB | 10:6a81aeca25e3 | 95 | // printf("LoadJpg: Open filename \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 96 | |
JackB | 10:6a81aeca25e3 | 97 | FILE *fp = fopen(filename, "rb"); |
JackB | 10:6a81aeca25e3 | 98 | if(fp == NULL) { |
JackB | 10:6a81aeca25e3 | 99 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 100 | printf("LoadJpg: Cannot open file \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 101 | return (-1); // cannot open file |
JackB | 10:6a81aeca25e3 | 102 | } |
JackB | 10:6a81aeca25e3 | 103 | |
JackB | 10:6a81aeca25e3 | 104 | // https://en.wikipedia.org/wiki/JPEG |
JackB | 10:6a81aeca25e3 | 105 | // search for 0xFFC0 marker |
JackB | 10:6a81aeca25e3 | 106 | fseek(fp, 0, SEEK_END); |
JackB | 10:6a81aeca25e3 | 107 | unsigned int filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 108 | printf("LoadJpg: Size: %d.\n", filesize); |
JackB | 10:6a81aeca25e3 | 109 | |
JackB | 10:6a81aeca25e3 | 110 | fseek(fp, 2, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 111 | fread(data, 4, 1, fp); // Read first 4 bytes |
JackB | 10:6a81aeca25e3 | 112 | marker = data[0] << 8 | data[1]; |
JackB | 10:6a81aeca25e3 | 113 | length = data[2] << 8 | data[3]; |
JackB | 10:6a81aeca25e3 | 114 | do { |
JackB | 10:6a81aeca25e3 | 115 | if(marker == 0xFFC0) |
JackB | 10:6a81aeca25e3 | 116 | break; |
JackB | 10:6a81aeca25e3 | 117 | if(marker & 0xFF00 != 0xFF00) |
JackB | 10:6a81aeca25e3 | 118 | break; |
JackB | 10:6a81aeca25e3 | 119 | if (fseek(fp, length - 2,SEEK_CUR) != 0) // Skip marker |
JackB | 10:6a81aeca25e3 | 120 | break; |
JackB | 10:6a81aeca25e3 | 121 | fread(data, 4, 1, fp); |
JackB | 10:6a81aeca25e3 | 122 | marker = data[0] << 8 | data[1]; |
JackB | 10:6a81aeca25e3 | 123 | length = data[2] << 8 | data[3]; |
JackB | 10:6a81aeca25e3 | 124 | } while(1); |
JackB | 10:6a81aeca25e3 | 125 | |
JackB | 10:6a81aeca25e3 | 126 | if(marker != 0xFFC0) { |
JackB | 10:6a81aeca25e3 | 127 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 128 | printf("LoadJpg: marker != 0xFFC0\n"); |
JackB | 10:6a81aeca25e3 | 129 | return (-2); // No FFC0 Marker, wrong format no baseline DCT-based JPEG |
JackB | 10:6a81aeca25e3 | 130 | } |
JackB | 10:6a81aeca25e3 | 131 | |
JackB | 10:6a81aeca25e3 | 132 | fseek(fp, 1, SEEK_CUR); // Skip marker |
JackB | 10:6a81aeca25e3 | 133 | fread(data, 8, 1, fp); // Read next 8 bytes & extract height & width |
JackB | 10:6a81aeca25e3 | 134 | *y_size = (data[0] << 8 | data[1]); |
JackB | 10:6a81aeca25e3 | 135 | *x_size = (data[2] << 8 | data[3]); |
JackB | 10:6a81aeca25e3 | 136 | uint16_t size_y = (data[0] << 8 | data[1]); |
JackB | 10:6a81aeca25e3 | 137 | uint16_t size_x = (data[2] << 8 | data[3]); |
JackB | 10:6a81aeca25e3 | 138 | |
JackB | 10:6a81aeca25e3 | 139 | uint16_t disp_x = DispWidth; |
JackB | 10:6a81aeca25e3 | 140 | uint16_t disp_y = DispHeight; |
JackB | 10:6a81aeca25e3 | 141 | if ((_orientation == FT8_DISPLAY_PORTRAIT_90CW) || (_orientation == FT8_DISPLAY_PORTRAIT_90CCW)) { |
JackB | 10:6a81aeca25e3 | 142 | disp_x = DispHeight; |
JackB | 10:6a81aeca25e3 | 143 | disp_y = DispWidth; |
JackB | 10:6a81aeca25e3 | 144 | } |
JackB | 10:6a81aeca25e3 | 145 | |
JackB | 10:6a81aeca25e3 | 146 | // http://www.ftdichip.com/Support/Documents/AppNotes/AN_339%20Using%20JPEGs%20with%20the%20FT800%20series.pdf, page 11 |
JackB | 10:6a81aeca25e3 | 147 | // if (marker_next_byte[0] == 0xC2){ //check if progressive JPEG |
JackB | 10:6a81aeca25e3 | 148 | // error_code = 3; |
JackB | 10:6a81aeca25e3 | 149 | // } |
JackB | 10:6a81aeca25e3 | 150 | |
JackB | 10:6a81aeca25e3 | 151 | // if(*x_size > TFT.FT_DispWidth || *y_size > TFT.FT_DispHeight) return (-3); // to big to fit on screen |
JackB | 10:6a81aeca25e3 | 152 | if(*x_size > disp_x || *y_size > disp_y) |
JackB | 10:6a81aeca25e3 | 153 | { |
JackB | 10:6a81aeca25e3 | 154 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 155 | printf("LoadJpg: Too big to fit on screen\n"); |
JackB | 10:6a81aeca25e3 | 156 | printf("LoadJpg: JPG (%dx%d) does not fit on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); |
JackB | 10:6a81aeca25e3 | 157 | return (-3); // Too big to fit on screen |
JackB | 10:6a81aeca25e3 | 158 | } |
JackB | 10:6a81aeca25e3 | 159 | |
JackB | 10:6a81aeca25e3 | 160 | // printf("LoadJpg: JPG (%dx%d) fits on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); |
JackB | 10:6a81aeca25e3 | 161 | |
JackB | 10:6a81aeca25e3 | 162 | fseek(fp, 0, SEEK_SET); |
JackB | 10:6a81aeca25e3 | 163 | |
JackB | 10:6a81aeca25e3 | 164 | |
JackB | 10:6a81aeca25e3 | 165 | WrCmd32(CMD_LOADIMAGE); |
JackB | 10:6a81aeca25e3 | 166 | WrCmd32(_address); //destination address of jpg decode |
JackB | 10:6a81aeca25e3 | 167 | |
JackB | 10:6a81aeca25e3 | 168 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 169 | // Increment _address |
JackB | 10:6a81aeca25e3 | 170 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 171 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 172 | _address += (uint32_t) (size_x * size_y * 2); |
JackB | 10:6a81aeca25e3 | 173 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 174 | // 0 OPT_RGB565 |
JackB | 10:6a81aeca25e3 | 175 | // 1 OPT_MONO |
JackB | 10:6a81aeca25e3 | 176 | // 2 OPT_NODL |
JackB | 10:6a81aeca25e3 | 177 | // 256 OPT_FLAT |
JackB | 10:6a81aeca25e3 | 178 | // 256 OPT_SIGNED |
JackB | 10:6a81aeca25e3 | 179 | // 512 OPT_CENTERX |
JackB | 10:6a81aeca25e3 | 180 | // 1024 OPT_CENTERY |
JackB | 10:6a81aeca25e3 | 181 | // 1536 OPT_CENTER |
JackB | 10:6a81aeca25e3 | 182 | // 2048 OPT_RIGHTX |
JackB | 10:6a81aeca25e3 | 183 | // 4096 OPT_NOBACK |
JackB | 10:6a81aeca25e3 | 184 | // 8192 OPT_NOTICKS |
JackB | 10:6a81aeca25e3 | 185 | WrCmd32(0); //output format of the bitmap - default is rgb565 |
JackB | 10:6a81aeca25e3 | 186 | while(filesize > 0) { |
JackB | 10:6a81aeca25e3 | 187 | /* download the data into the command buffer by 8kb one shot */ |
JackB | 10:6a81aeca25e3 | 188 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 189 | // printf("LoadJpg: blocklen: %d\n", blocklen); |
JackB | 10:6a81aeca25e3 | 190 | // printf("LoadJpg: filesize: %d\n", filesize); |
JackB | 10:6a81aeca25e3 | 191 | |
JackB | 10:6a81aeca25e3 | 192 | /* copy the data into pbuff and then transfter it to command buffer */ |
JackB | 10:6a81aeca25e3 | 193 | // int size = fread(&pbuff[0], 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 194 | int size = fread(pbuff, 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 195 | // printf("LoadJpg: fread: %d, %d\n", blocklen, size); |
JackB | 10:6a81aeca25e3 | 196 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 197 | /* copy data continuously into command memory */ |
JackB | 10:6a81aeca25e3 | 198 | // TFT.Ft_Gpu_Hal_WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 199 | WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 200 | } |
JackB | 10:6a81aeca25e3 | 201 | fclose(fp); |
JackB | 10:6a81aeca25e3 | 202 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 203 | |
JackB | 10:6a81aeca25e3 | 204 | return(0); |
JackB | 10:6a81aeca25e3 | 205 | } |
JackB | 10:6a81aeca25e3 | 206 | |
JackB | 10:6a81aeca25e3 | 207 | ft_uint8_t FT813::LoadPng(char* filename, ft_int16_t* x_size, ft_int16_t* y_size) |
JackB | 10:6a81aeca25e3 | 208 | { |
JackB | 10:6a81aeca25e3 | 209 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 210 | ft_uint32_t filesize = 0; |
JackB | 10:6a81aeca25e3 | 211 | ft_uint16_t blocklen = 0; |
JackB | 10:6a81aeca25e3 | 212 | uint32_t marker1; |
JackB | 10:6a81aeca25e3 | 213 | uint32_t marker2; |
JackB | 10:6a81aeca25e3 | 214 | unsigned short length; |
JackB | 10:6a81aeca25e3 | 215 | unsigned char data[32]; |
JackB | 10:6a81aeca25e3 | 216 | |
JackB | 10:6a81aeca25e3 | 217 | // printf("------------------------------\n"); |
JackB | 10:6a81aeca25e3 | 218 | printf("LoadPng: Filename \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 219 | |
JackB | 10:6a81aeca25e3 | 220 | FILE *fp = fopen(filename, "rb"); |
JackB | 10:6a81aeca25e3 | 221 | if(fp == NULL) { |
JackB | 10:6a81aeca25e3 | 222 | printf("LoadPng: Cannot open file \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 223 | return (-1); // cannot open file |
JackB | 10:6a81aeca25e3 | 224 | } |
JackB | 10:6a81aeca25e3 | 225 | |
JackB | 10:6a81aeca25e3 | 226 | // Get file size |
JackB | 10:6a81aeca25e3 | 227 | fseek(fp, 0, SEEK_END); // End of file |
JackB | 10:6a81aeca25e3 | 228 | filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 229 | fseek(fp, 0, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 230 | printf("LoadPng: Filesize %d\n", filesize); |
JackB | 10:6a81aeca25e3 | 231 | |
JackB | 10:6a81aeca25e3 | 232 | // search for 0x89504E47 and 0x0D0A1A0A markers "‰PNG...." |
JackB | 10:6a81aeca25e3 | 233 | fread(data, 1, 32, fp); // Read first 32 bytes |
JackB | 10:6a81aeca25e3 | 234 | // rewind(fp); // Beginning of file |
JackB | 10:6a81aeca25e3 | 235 | fseek(fp, 0, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 236 | |
JackB | 10:6a81aeca25e3 | 237 | // Check that this is indeed a PNG file |
JackB | 10:6a81aeca25e3 | 238 | unsigned char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; |
JackB | 10:6a81aeca25e3 | 239 | // Make sure you have an IHDR |
JackB | 10:6a81aeca25e3 | 240 | unsigned char ihdr_name[] = "IHDR"; |
JackB | 10:6a81aeca25e3 | 241 | if ((memcmp(data, png_header, 8)) || (memcmp(data+8+4, ihdr_name, 4))) { |
JackB | 10:6a81aeca25e3 | 242 | printf("LoadPng: Invalid PNG file.\n"); |
JackB | 10:6a81aeca25e3 | 243 | return (-2); // No FFC0 Marker, wrong format no baseline DCT-based JPEG |
JackB | 10:6a81aeca25e3 | 244 | } |
JackB | 10:6a81aeca25e3 | 245 | |
JackB | 10:6a81aeca25e3 | 246 | // PNG actually stores integers in big-endian. |
JackB | 10:6a81aeca25e3 | 247 | *x_size = ReadBigInt32(data, 24 - 8); |
JackB | 10:6a81aeca25e3 | 248 | *y_size = ReadBigInt32(data, 24 - 4); |
JackB | 10:6a81aeca25e3 | 249 | uint16_t size_x = ReadBigInt32(data, 24 - 8); |
JackB | 10:6a81aeca25e3 | 250 | uint16_t size_y = ReadBigInt32(data, 24 - 4); |
JackB | 10:6a81aeca25e3 | 251 | |
JackB | 10:6a81aeca25e3 | 252 | uint16_t disp_x = DispWidth; |
JackB | 10:6a81aeca25e3 | 253 | uint16_t disp_y = DispHeight; |
JackB | 10:6a81aeca25e3 | 254 | if ((_orientation == FT8_DISPLAY_PORTRAIT_90CW) || (_orientation == FT8_DISPLAY_PORTRAIT_90CCW)) { |
JackB | 10:6a81aeca25e3 | 255 | disp_x = DispHeight; |
JackB | 10:6a81aeca25e3 | 256 | disp_y = DispWidth; |
JackB | 10:6a81aeca25e3 | 257 | } |
JackB | 10:6a81aeca25e3 | 258 | |
JackB | 10:6a81aeca25e3 | 259 | if(*x_size > disp_x || *y_size > disp_y) |
JackB | 10:6a81aeca25e3 | 260 | { |
JackB | 10:6a81aeca25e3 | 261 | printf("LoadPng: Too big to fit on screen\n"); |
JackB | 10:6a81aeca25e3 | 262 | printf("LoadPng: PNG (%dx%d) does not fit on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); |
JackB | 10:6a81aeca25e3 | 263 | return (-3); // Too big to fit on screen |
JackB | 10:6a81aeca25e3 | 264 | } |
JackB | 10:6a81aeca25e3 | 265 | |
JackB | 10:6a81aeca25e3 | 266 | // printf("LoadPng: PNG (%dx%d) fits on TFT (%dx%d)\n", *x_size, *y_size, DispWidth, DispHeight); |
JackB | 10:6a81aeca25e3 | 267 | |
JackB | 10:6a81aeca25e3 | 268 | // http://www.ftdichip.com/Support/Documents/AppNotes/AN_339%20Using%20JPEGs%20with%20the%20FT800%20series.pdf |
JackB | 10:6a81aeca25e3 | 269 | // CMD_LOADIMAGE: This function will decode the JPEG file, produce |
JackB | 10:6a81aeca25e3 | 270 | // either RGB565 or L8 bitmap data and store this in graphics RAM. |
JackB | 10:6a81aeca25e3 | 271 | // It also writes commands to the display list to set the source, layout and size of the |
JackB | 10:6a81aeca25e3 | 272 | // image (BITMAP_SOURCE, BITMAP_LAYOUT and BITMAP_SIZE). |
JackB | 10:6a81aeca25e3 | 273 | // Note that only a BEGIN and VERTEX2F (or VERTEX2II) display list commands are then |
JackB | 10:6a81aeca25e3 | 274 | // required to complete the display list needed to render the image. |
JackB | 10:6a81aeca25e3 | 275 | WrCmd32(CMD_LOADIMAGE); |
JackB | 10:6a81aeca25e3 | 276 | WrCmd32(_address); //destination address of png decode |
JackB | 10:6a81aeca25e3 | 277 | // 0 OPT_RGB565 |
JackB | 10:6a81aeca25e3 | 278 | // 1 OPT_MONO |
JackB | 10:6a81aeca25e3 | 279 | // 2 OPT_NODL |
JackB | 10:6a81aeca25e3 | 280 | // 256 OPT_FLAT |
JackB | 10:6a81aeca25e3 | 281 | // 256 OPT_SIGNED |
JackB | 10:6a81aeca25e3 | 282 | // 512 OPT_CENTERX |
JackB | 10:6a81aeca25e3 | 283 | // 1024 OPT_CENTERY |
JackB | 10:6a81aeca25e3 | 284 | // 1536 OPT_CENTER |
JackB | 10:6a81aeca25e3 | 285 | // 2048 OPT_RIGHTX |
JackB | 10:6a81aeca25e3 | 286 | // 4096 OPT_NOBACK |
JackB | 10:6a81aeca25e3 | 287 | // 8192 OPT_NOTICKS |
JackB | 10:6a81aeca25e3 | 288 | // By default, option OPT_RGB565 means the loaded bitmap is in RGB565 format. |
JackB | 10:6a81aeca25e3 | 289 | |
JackB | 10:6a81aeca25e3 | 290 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 291 | // Increment _address |
JackB | 10:6a81aeca25e3 | 292 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 293 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 294 | _address += (uint32_t) (size_x * size_y * 2); |
JackB | 10:6a81aeca25e3 | 295 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 296 | printf("LoadPng: Bitmap# %d, Res. %dx%d, Address %d-%d\n", _bitmap_count - 1, *x_size, *y_size, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); |
JackB | 10:6a81aeca25e3 | 297 | |
JackB | 10:6a81aeca25e3 | 298 | WrCmd32(OPT_RGB565); // Output format of the bitmap OPT_RGB565 |
JackB | 10:6a81aeca25e3 | 299 | // unsigned int filesizeCounter = filesize; |
JackB | 10:6a81aeca25e3 | 300 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 301 | while(filesize > 0) { |
JackB | 10:6a81aeca25e3 | 302 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 303 | int size = fread(pbuff, 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 304 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 305 | |
JackB | 10:6a81aeca25e3 | 306 | WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 307 | } |
JackB | 10:6a81aeca25e3 | 308 | fclose(fp); |
JackB | 10:6a81aeca25e3 | 309 | // If the number of bytes in the JPEG file to be written to the command buffer is not a multiple of |
JackB | 10:6a81aeca25e3 | 310 | // four, then one, two or three bytes (of any value) should be added to ensure four-byte alignment of |
JackB | 10:6a81aeca25e3 | 311 | // the next command. |
JackB | 10:6a81aeca25e3 | 312 | // blocklen = filesize % 4; |
JackB | 10:6a81aeca25e3 | 313 | // memset(pbuff, 0, blocklen); |
JackB | 10:6a81aeca25e3 | 314 | // WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 315 | |
JackB | 10:6a81aeca25e3 | 316 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 317 | |
JackB | 10:6a81aeca25e3 | 318 | printf("LoadPng: Done.\n"); |
JackB | 10:6a81aeca25e3 | 319 | |
JackB | 10:6a81aeca25e3 | 320 | return(0); |
JackB | 10:6a81aeca25e3 | 321 | } |
JackB | 10:6a81aeca25e3 | 322 | |
JackB | 10:6a81aeca25e3 | 323 | int FT813::LoadRaw(char* filename) |
JackB | 10:6a81aeca25e3 | 324 | { |
JackB | 10:6a81aeca25e3 | 325 | ft_uint16_t filesize = 0; |
JackB | 10:6a81aeca25e3 | 326 | ft_uint16_t blocklen; |
JackB | 10:6a81aeca25e3 | 327 | ft_uint16_t ram_start = _address; |
JackB | 10:6a81aeca25e3 | 328 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 329 | |
JackB | 10:6a81aeca25e3 | 330 | FILE *fp = fopen(filename, "rb"); // open file |
JackB | 10:6a81aeca25e3 | 331 | if (fp == NULL) |
JackB | 10:6a81aeca25e3 | 332 | { |
JackB | 10:6a81aeca25e3 | 333 | // Cannot open file |
JackB | 10:6a81aeca25e3 | 334 | printf("Unable to open: %s\n", filename); |
JackB | 10:6a81aeca25e3 | 335 | return -1; |
JackB | 10:6a81aeca25e3 | 336 | } |
JackB | 10:6a81aeca25e3 | 337 | fseek(fp, 0, SEEK_END); // set file position to end of file |
JackB | 10:6a81aeca25e3 | 338 | filesize = ftell(fp); // determine file size |
JackB | 10:6a81aeca25e3 | 339 | fseek(fp, 0, SEEK_SET); // return to beginning of file |
JackB | 10:6a81aeca25e3 | 340 | |
JackB | 10:6a81aeca25e3 | 341 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 342 | // Increment _address |
JackB | 10:6a81aeca25e3 | 343 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 344 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 345 | _address += (uint32_t) filesize; |
JackB | 10:6a81aeca25e3 | 346 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 347 | printf("LoadRaw: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); |
JackB | 10:6a81aeca25e3 | 348 | |
JackB | 10:6a81aeca25e3 | 349 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 350 | while(filesize > 0) |
JackB | 10:6a81aeca25e3 | 351 | { |
JackB | 10:6a81aeca25e3 | 352 | //copy the .raw file data to pbuff[8192] in 8k block |
JackB | 10:6a81aeca25e3 | 353 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 354 | fread(pbuff, 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 355 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 356 | //write pbuff contents to graphics RAM at address ram_start = 0x00 |
JackB | 10:6a81aeca25e3 | 357 | Wr8s(ram_start, (uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 358 | ram_start += blocklen; |
JackB | 10:6a81aeca25e3 | 359 | } |
JackB | 10:6a81aeca25e3 | 360 | fclose(fp); |
JackB | 10:6a81aeca25e3 | 361 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 362 | return 0; |
JackB | 10:6a81aeca25e3 | 363 | } |
JackB | 10:6a81aeca25e3 | 364 | |
JackB | 10:6a81aeca25e3 | 365 | int FT813::LoadRawFile(ft_uint32_t address, const char *filename) |
JackB | 10:6a81aeca25e3 | 366 | { |
JackB | 10:6a81aeca25e3 | 367 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 368 | ft_uint32_t filesize = 0; |
JackB | 10:6a81aeca25e3 | 369 | ft_uint16_t blocklen = 0; |
JackB | 10:6a81aeca25e3 | 370 | |
JackB | 10:6a81aeca25e3 | 371 | _address = address; |
JackB | 10:6a81aeca25e3 | 372 | ft_uint32_t addr = address; |
JackB | 10:6a81aeca25e3 | 373 | |
JackB | 10:6a81aeca25e3 | 374 | FILE *fp = fopen(filename, "rb"); |
JackB | 10:6a81aeca25e3 | 375 | if (fp == NULL) |
JackB | 10:6a81aeca25e3 | 376 | { |
JackB | 10:6a81aeca25e3 | 377 | printf("LoadRawFile: Cannot open file \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 378 | return 0; |
JackB | 10:6a81aeca25e3 | 379 | } |
JackB | 10:6a81aeca25e3 | 380 | fseek(fp, 0, SEEK_END); // End of file |
JackB | 10:6a81aeca25e3 | 381 | filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 382 | fseek(fp, 0, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 383 | |
JackB | 10:6a81aeca25e3 | 384 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 385 | // Increment _address |
JackB | 10:6a81aeca25e3 | 386 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 387 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 388 | _address += (uint32_t) filesize; |
JackB | 10:6a81aeca25e3 | 389 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 390 | printf("LoadRawFile: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); |
JackB | 10:6a81aeca25e3 | 391 | |
JackB | 10:6a81aeca25e3 | 392 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 393 | while (filesize > 0) |
JackB | 10:6a81aeca25e3 | 394 | { |
JackB | 10:6a81aeca25e3 | 395 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 396 | fread(pbuff, 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 397 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 398 | WrMem(addr, (ft_uint8_t *)pbuff, blocklen); |
JackB | 10:6a81aeca25e3 | 399 | addr += blocklen; |
JackB | 10:6a81aeca25e3 | 400 | // WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 401 | } |
JackB | 10:6a81aeca25e3 | 402 | fclose(fp); |
JackB | 10:6a81aeca25e3 | 403 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 404 | |
JackB | 10:6a81aeca25e3 | 405 | printf("LoadRawFile: Done.\n"); |
JackB | 10:6a81aeca25e3 | 406 | return 1; |
JackB | 10:6a81aeca25e3 | 407 | } |
JackB | 10:6a81aeca25e3 | 408 | |
JackB | 10:6a81aeca25e3 | 409 | int FT813::LoadInflateFile(ft_uint32_t address, const char *filename) |
JackB | 10:6a81aeca25e3 | 410 | { |
JackB | 10:6a81aeca25e3 | 411 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 412 | ft_uint32_t filesize = 0; |
JackB | 10:6a81aeca25e3 | 413 | ft_uint16_t blocklen = 0; |
JackB | 10:6a81aeca25e3 | 414 | ft_uint32_t addr = address; |
JackB | 10:6a81aeca25e3 | 415 | ft_uint32_t filesize_org = address; |
JackB | 10:6a81aeca25e3 | 416 | |
JackB | 10:6a81aeca25e3 | 417 | _address = address; |
JackB | 10:6a81aeca25e3 | 418 | |
JackB | 10:6a81aeca25e3 | 419 | FILE *fp = fopen(filename, "rb"); // read Binary (rb) |
JackB | 10:6a81aeca25e3 | 420 | if (fp == NULL) |
JackB | 10:6a81aeca25e3 | 421 | { |
JackB | 10:6a81aeca25e3 | 422 | printf("LoadInflateFile: Cannot open file \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 423 | return 0; |
JackB | 10:6a81aeca25e3 | 424 | } |
JackB | 10:6a81aeca25e3 | 425 | fseek(fp, 0, SEEK_END); // End of file |
JackB | 10:6a81aeca25e3 | 426 | filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 427 | fseek(fp, 0, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 428 | |
JackB | 10:6a81aeca25e3 | 429 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 430 | // Increment _address |
JackB | 10:6a81aeca25e3 | 431 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 432 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 433 | // _address += (uint32_t) 0; |
JackB | 10:6a81aeca25e3 | 434 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 435 | // printf("# %d, Addr %d\n", _bitmap_count - 1, _addresses[_bitmap_count-1]); |
JackB | 10:6a81aeca25e3 | 436 | |
JackB | 10:6a81aeca25e3 | 437 | WrCmd32(CMD_INFLATE); |
JackB | 10:6a81aeca25e3 | 438 | WrCmd32(address); //destination address of bin decode |
JackB | 10:6a81aeca25e3 | 439 | |
JackB | 10:6a81aeca25e3 | 440 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 441 | while (filesize > 0) |
JackB | 10:6a81aeca25e3 | 442 | { |
JackB | 10:6a81aeca25e3 | 443 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 444 | int size = fread(pbuff, 1, blocklen, fp); /* copy the data into pbuff and then transfter it to command buffer */ |
JackB | 10:6a81aeca25e3 | 445 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 446 | |
JackB | 10:6a81aeca25e3 | 447 | // WrMem(addr, (ft_uint8_t *)pbuff, blocklen); |
JackB | 10:6a81aeca25e3 | 448 | // addr += blocklen; |
JackB | 10:6a81aeca25e3 | 449 | |
JackB | 10:6a81aeca25e3 | 450 | //Do not call "Ft_Gpu_Hal_WrCmdBuf_nowait" because it may cause emulator process hang. |
JackB | 10:6a81aeca25e3 | 451 | WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 452 | // WaitCmdfifo_empty(); |
JackB | 10:6a81aeca25e3 | 453 | } |
JackB | 10:6a81aeca25e3 | 454 | // If the number of bytes in the JPEG file to be written to the command buffer is not a multiple of |
JackB | 10:6a81aeca25e3 | 455 | // four, then one, two or three bytes (of any value) should be added to ensure four-byte alignment of |
JackB | 10:6a81aeca25e3 | 456 | // the next command. |
JackB | 10:6a81aeca25e3 | 457 | // blocklen = filesize_org % 4; |
JackB | 10:6a81aeca25e3 | 458 | // memset(pbuff, 0, blocklen); |
JackB | 10:6a81aeca25e3 | 459 | // WrMem(addr, (ft_uint8_t *)pbuff, blocklen); |
JackB | 10:6a81aeca25e3 | 460 | // WrCmdBuf((uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 461 | |
JackB | 10:6a81aeca25e3 | 462 | // WaitCmdfifo_empty(); |
JackB | 10:6a81aeca25e3 | 463 | |
JackB | 10:6a81aeca25e3 | 464 | fclose(fp); /* close the opened jpg file */ |
JackB | 10:6a81aeca25e3 | 465 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 466 | return 1; |
JackB | 10:6a81aeca25e3 | 467 | } |
JackB | 10:6a81aeca25e3 | 468 | |
JackB | 10:6a81aeca25e3 | 469 | int FT813::LoadImageFile(ft_uint32_t address, const char *filename) |
JackB | 10:6a81aeca25e3 | 470 | { |
JackB | 10:6a81aeca25e3 | 471 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 472 | ft_uint32_t filesize = 0; |
JackB | 10:6a81aeca25e3 | 473 | ft_uint16_t blocklen = 0; |
JackB | 10:6a81aeca25e3 | 474 | |
JackB | 10:6a81aeca25e3 | 475 | _address = address; |
JackB | 10:6a81aeca25e3 | 476 | |
JackB | 10:6a81aeca25e3 | 477 | FILE *fp = fopen(filename, "rb"); // read Binary (rb) |
JackB | 10:6a81aeca25e3 | 478 | if (fp == NULL) |
JackB | 10:6a81aeca25e3 | 479 | { |
JackB | 10:6a81aeca25e3 | 480 | printf("LoadImageFile: Cannot open file \"%s\".\n", filename); |
JackB | 10:6a81aeca25e3 | 481 | return 0; |
JackB | 10:6a81aeca25e3 | 482 | } |
JackB | 10:6a81aeca25e3 | 483 | // TODO: Let it write into the scratch display list handle, |
JackB | 10:6a81aeca25e3 | 484 | // and read it out and write into the bitmapInfo the proper |
JackB | 10:6a81aeca25e3 | 485 | // values to use. Replace compressed bool with uint8 enum to |
JackB | 10:6a81aeca25e3 | 486 | // specify the loading mechanism |
JackB | 10:6a81aeca25e3 | 487 | fseek(fp, 0, SEEK_END); // End of file |
JackB | 10:6a81aeca25e3 | 488 | filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 489 | fseek(fp, 0, SEEK_SET); // Beginning of file |
JackB | 10:6a81aeca25e3 | 490 | |
JackB | 10:6a81aeca25e3 | 491 | // Keep track of of the start addresses of loaded images |
JackB | 10:6a81aeca25e3 | 492 | // Increment _address |
JackB | 10:6a81aeca25e3 | 493 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 494 | _bitmap_count++; |
JackB | 10:6a81aeca25e3 | 495 | _address += (uint32_t) filesize; |
JackB | 10:6a81aeca25e3 | 496 | _addresses[_bitmap_count] = _address; |
JackB | 10:6a81aeca25e3 | 497 | printf("LoadImageFile: Bitmap# %d, Address %d-%d\n", _bitmap_count - 1, _addresses[_bitmap_count-1], _addresses[_bitmap_count]); |
JackB | 10:6a81aeca25e3 | 498 | |
JackB | 10:6a81aeca25e3 | 499 | WrCmd32(CMD_LOADIMAGE); |
JackB | 10:6a81aeca25e3 | 500 | WrCmd32(address); //destination address of png decode |
JackB | 10:6a81aeca25e3 | 501 | // 0 OPT_RGB565 |
JackB | 10:6a81aeca25e3 | 502 | // 1 OPT_MONO |
JackB | 10:6a81aeca25e3 | 503 | // 2 OPT_NODL |
JackB | 10:6a81aeca25e3 | 504 | // 256 OPT_FLAT |
JackB | 10:6a81aeca25e3 | 505 | // 256 OPT_SIGNED |
JackB | 10:6a81aeca25e3 | 506 | // 512 OPT_CENTERX |
JackB | 10:6a81aeca25e3 | 507 | // 1024 OPT_CENTERY |
JackB | 10:6a81aeca25e3 | 508 | // 1536 OPT_CENTER |
JackB | 10:6a81aeca25e3 | 509 | // 2048 OPT_RIGHTX |
JackB | 10:6a81aeca25e3 | 510 | // 4096 OPT_NOBACK |
JackB | 10:6a81aeca25e3 | 511 | // 8192 OPT_NOTICKS |
JackB | 10:6a81aeca25e3 | 512 | // By default, option OPT_RGB565 means the loaded bitmap is in RGB565 format. |
JackB | 10:6a81aeca25e3 | 513 | WrCmd32(OPT_RGB565); // Output format of the bitmap OPT_RGB565 |
JackB | 10:6a81aeca25e3 | 514 | // WrCmd32(OPT_NODL); |
JackB | 10:6a81aeca25e3 | 515 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 516 | while (filesize > 0) |
JackB | 10:6a81aeca25e3 | 517 | { |
JackB | 10:6a81aeca25e3 | 518 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 519 | int size = fread(pbuff, 1, blocklen, fp); /* copy the data into pbuff and then transfter it to command buffer */ |
JackB | 10:6a81aeca25e3 | 520 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 521 | // blocklen += 3; |
JackB | 10:6a81aeca25e3 | 522 | // blocklen -= blocklen % 4; |
JackB | 10:6a81aeca25e3 | 523 | |
JackB | 10:6a81aeca25e3 | 524 | //Do not call "Ft_Gpu_Hal_WrCmdBuf_nowait" because it may cause emulator process hang. |
JackB | 10:6a81aeca25e3 | 525 | WrCmdBuf((ft_uint8_t *)pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 526 | } |
JackB | 10:6a81aeca25e3 | 527 | // WaitCmdfifo_empty(); |
JackB | 10:6a81aeca25e3 | 528 | |
JackB | 10:6a81aeca25e3 | 529 | fclose(fp); /* close the opened jpg file */ |
JackB | 10:6a81aeca25e3 | 530 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 531 | return 1; |
JackB | 10:6a81aeca25e3 | 532 | } |
JackB | 10:6a81aeca25e3 | 533 | |
JackB | 10:6a81aeca25e3 | 534 | ft_void_t FT813::SetEndAddressForSize(ft_uint32_t addr) |
JackB | 10:6a81aeca25e3 | 535 | { |
JackB | 10:6a81aeca25e3 | 536 | _addresses[_bitmap_count] = _addresses[_bitmap_count - 1] + addr; |
JackB | 10:6a81aeca25e3 | 537 | } |
JackB | 10:6a81aeca25e3 | 538 | |
JackB | 10:6a81aeca25e3 | 539 | ft_void_t FT813::Wr8s(ft_uint32_t addr, ft_uint8_t *buffer, ft_uint8_t length) |
JackB | 10:6a81aeca25e3 | 540 | { |
JackB | 10:6a81aeca25e3 | 541 | // StartTransfer(FT_GPU_WRITE, addr); |
JackB | 10:6a81aeca25e3 | 542 | // if (FT_GPU_READ == rw) { // if (FT_GPU_READ == FT_GPU_WRITE) |
JackB | 10:6a81aeca25e3 | 543 | // _ss = 0; // cs low |
JackB | 10:6a81aeca25e3 | 544 | // _spi.write(addr >> 16); |
JackB | 10:6a81aeca25e3 | 545 | // _spi.write(addr >> 8); |
JackB | 10:6a81aeca25e3 | 546 | // _spi.write(addr & 0xff); |
JackB | 10:6a81aeca25e3 | 547 | // _spi.write(0); //Dummy Read Byte |
JackB | 10:6a81aeca25e3 | 548 | // status = READING; |
JackB | 10:6a81aeca25e3 | 549 | // } else { |
JackB | 10:6a81aeca25e3 | 550 | _ss = 0; // cs low |
JackB | 10:6a81aeca25e3 | 551 | _spi.write(0x80 | (addr >> 16)); |
JackB | 10:6a81aeca25e3 | 552 | _spi.write(addr >> 8); |
JackB | 10:6a81aeca25e3 | 553 | _spi.write(addr & 0xff); |
JackB | 10:6a81aeca25e3 | 554 | status = WRITING; |
JackB | 10:6a81aeca25e3 | 555 | // } |
JackB | 10:6a81aeca25e3 | 556 | |
JackB | 10:6a81aeca25e3 | 557 | // Transfer8(v); |
JackB | 10:6a81aeca25e3 | 558 | // _spi.write(v); |
JackB | 10:6a81aeca25e3 | 559 | |
JackB | 10:6a81aeca25e3 | 560 | while (length--) { |
JackB | 10:6a81aeca25e3 | 561 | // Transfer8(*buffer); |
JackB | 10:6a81aeca25e3 | 562 | _spi.write(*buffer); |
JackB | 10:6a81aeca25e3 | 563 | buffer++; |
JackB | 10:6a81aeca25e3 | 564 | // SizeTransfered++; |
JackB | 10:6a81aeca25e3 | 565 | } |
JackB | 10:6a81aeca25e3 | 566 | |
JackB | 10:6a81aeca25e3 | 567 | // EndTransfer(); |
JackB | 10:6a81aeca25e3 | 568 | _ss = 1; |
JackB | 10:6a81aeca25e3 | 569 | status = OPENED; |
JackB | 10:6a81aeca25e3 | 570 | } |
JackB | 10:6a81aeca25e3 | 571 | |
JackB | 10:6a81aeca25e3 | 572 | //{ |
JackB | 10:6a81aeca25e3 | 573 | //ft_uint8_t imbuff[8192]; |
JackB | 10:6a81aeca25e3 | 574 | //ft_uint16_t blocklen; |
JackB | 10:6a81aeca25e3 | 575 | ////decompress the .bin file using CMD_INFLATE |
JackB | 10:6a81aeca25e3 | 576 | //WrCmd32(phost,CMD_INFLATE); |
JackB | 10:6a81aeca25e3 | 577 | ////specify starting address in graphics RAM |
JackB | 10:6a81aeca25e3 | 578 | //WrCmd32(phost,0L); |
JackB | 10:6a81aeca25e3 | 579 | ////check filesize and adjust number of bytes to multiple of 4 |
JackB | 10:6a81aeca25e3 | 580 | //chdir("..\\..\\..\\Test"); //change directory to location (Test) of .bin file |
JackB | 10:6a81aeca25e3 | 581 | //pfile = fopen("lenaface40.bin","rb"); |
JackB | 10:6a81aeca25e3 | 582 | //fseek(pfile,0,SEEK_END); //set file position to end of file |
JackB | 10:6a81aeca25e3 | 583 | //filesize = ftell(pfile); // determine file size |
JackB | 10:6a81aeca25e3 | 584 | //fseek(pfile,0,SEEK_SET); // return to beginning of file |
JackB | 10:6a81aeca25e3 | 585 | //while(filesize > 0) |
JackB | 10:6a81aeca25e3 | 586 | //{ |
JackB | 10:6a81aeca25e3 | 587 | // //copy the .raw file data to imbuff[8192] in 8k blocks |
JackB | 10:6a81aeca25e3 | 588 | //blocklen = filesize>8192?8192:filesize; |
JackB | 10:6a81aeca25e3 | 589 | //fread(imbuff,1,blocklen,pfile); |
JackB | 10:6a81aeca25e3 | 590 | //filesize -= blocklen; //reduce filesize by blocklen |
JackB | 10:6a81aeca25e3 | 591 | ////write imbuff contents to the FT800 FIFO command buffer |
JackB | 10:6a81aeca25e3 | 592 | //Ft_Gpu_Hal_WrCmdBuf(phost,imbuff,blocklen); |
JackB | 10:6a81aeca25e3 | 593 | //} |
JackB | 10:6a81aeca25e3 | 594 | //fclose(pfile); /* close the opened .bin file */ |
JackB | 10:6a81aeca25e3 | 595 | //} |
JackB | 10:6a81aeca25e3 | 596 | |
JackB | 10:6a81aeca25e3 | 597 | int FT813::LoadRawFile(ft_uint32_t address, char* filename) |
JackB | 10:6a81aeca25e3 | 598 | { |
JackB | 10:6a81aeca25e3 | 599 | ft_uint16_t filesize; |
JackB | 10:6a81aeca25e3 | 600 | ft_uint16_t blocklen; |
JackB | 10:6a81aeca25e3 | 601 | ft_uint32_t addr = address; |
JackB | 10:6a81aeca25e3 | 602 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 603 | |
JackB | 10:6a81aeca25e3 | 604 | FILE *fp = fopen(filename, "rb"); // open file |
JackB | 10:6a81aeca25e3 | 605 | if (fp == NULL) |
JackB | 10:6a81aeca25e3 | 606 | { |
JackB | 10:6a81aeca25e3 | 607 | // Cannot open file |
JackB | 10:6a81aeca25e3 | 608 | printf("Unable to open: %s\n", filename); |
JackB | 10:6a81aeca25e3 | 609 | return -1; |
JackB | 10:6a81aeca25e3 | 610 | } |
JackB | 10:6a81aeca25e3 | 611 | fseek(fp, 0, SEEK_END); // set file position to end of file |
JackB | 10:6a81aeca25e3 | 612 | filesize = ftell(fp); // determine file size |
JackB | 10:6a81aeca25e3 | 613 | fseek(fp, 0, SEEK_SET); // return to beginning of file |
JackB | 10:6a81aeca25e3 | 614 | #ifdef DEBUG |
JackB | 10:6a81aeca25e3 | 615 | printf("LoadRawFile: %s %d @ %d\n", filename, filesize, address); |
JackB | 10:6a81aeca25e3 | 616 | #endif |
JackB | 10:6a81aeca25e3 | 617 | |
JackB | 10:6a81aeca25e3 | 618 | char* pbuff = (char*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 619 | while(filesize > 0) |
JackB | 10:6a81aeca25e3 | 620 | { |
JackB | 10:6a81aeca25e3 | 621 | //copy the .raw file data to pbuff[8192] in 8k block |
JackB | 10:6a81aeca25e3 | 622 | blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 623 | fread(pbuff, 1, blocklen, fp); |
JackB | 10:6a81aeca25e3 | 624 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 625 | //write pbuff contents to graphics RAM at addr |
JackB | 10:6a81aeca25e3 | 626 | WrMem(addr, (ft_uint8_t *)pbuff, blocklen); |
JackB | 10:6a81aeca25e3 | 627 | addr += blocklen; |
JackB | 10:6a81aeca25e3 | 628 | } |
JackB | 10:6a81aeca25e3 | 629 | fclose(fp); |
JackB | 10:6a81aeca25e3 | 630 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 631 | return 0; |
JackB | 10:6a81aeca25e3 | 632 | } |
JackB | 10:6a81aeca25e3 | 633 | |
JackB | 10:6a81aeca25e3 | 634 | void FT813::FillBitmap(ft_int16_t bitmap_number) |
JackB | 10:6a81aeca25e3 | 635 | { |
JackB | 10:6a81aeca25e3 | 636 | int bufferSize = 8192; |
JackB | 10:6a81aeca25e3 | 637 | uint8_t* pbuff = (uint8_t*)malloc(bufferSize); |
JackB | 10:6a81aeca25e3 | 638 | // Clear buffer |
JackB | 10:6a81aeca25e3 | 639 | memset(pbuff, 0, bufferSize); |
JackB | 10:6a81aeca25e3 | 640 | |
JackB | 10:6a81aeca25e3 | 641 | ft_int32_t addr_start = _addresses[bitmap_number]; |
JackB | 10:6a81aeca25e3 | 642 | ft_int32_t addr_end = _addresses[bitmap_number+1]; |
JackB | 10:6a81aeca25e3 | 643 | printf("FillBitmap %d (%d - %d).\n", bitmap_number, addr_start, addr_end); |
JackB | 10:6a81aeca25e3 | 644 | // ft_int32_t bufferSize = addr_end - addr_start; |
JackB | 10:6a81aeca25e3 | 645 | ft_int32_t filesize = addr_end - addr_start; |
JackB | 10:6a81aeca25e3 | 646 | // ft_int32_t addr = addr_start; |
JackB | 10:6a81aeca25e3 | 647 | |
JackB | 10:6a81aeca25e3 | 648 | WrCmd32(CMD_LOADIMAGE); |
JackB | 10:6a81aeca25e3 | 649 | WrCmd32(addr_start); //destination address of png decode |
JackB | 10:6a81aeca25e3 | 650 | WrCmd32(0); //output format of the bitmap - default is rgb565 |
JackB | 10:6a81aeca25e3 | 651 | printf("filesize = %d\n", filesize); |
JackB | 10:6a81aeca25e3 | 652 | printf("while(filesize > 0)...\n"); |
JackB | 10:6a81aeca25e3 | 653 | while(filesize > 0) { |
JackB | 10:6a81aeca25e3 | 654 | ft_uint16_t blocklen = filesize > bufferSize ? bufferSize : filesize; |
JackB | 10:6a81aeca25e3 | 655 | // printf("WrCmdBuf %d.\n", bufferSize); |
JackB | 10:6a81aeca25e3 | 656 | filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 657 | printf("blocklen = %d\n", blocklen); |
JackB | 10:6a81aeca25e3 | 658 | printf("WrCmdBuf...\n"); |
JackB | 10:6a81aeca25e3 | 659 | WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 660 | printf("Done.\n"); |
JackB | 10:6a81aeca25e3 | 661 | } |
JackB | 10:6a81aeca25e3 | 662 | printf("free(pbuff)...\n"); |
JackB | 10:6a81aeca25e3 | 663 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 664 | printf("Done.\n"); |
JackB | 10:6a81aeca25e3 | 665 | } |
JackB | 10:6a81aeca25e3 | 666 | |
JackB | 10:6a81aeca25e3 | 667 | void FT813::ClearBitmapCount(void) |
JackB | 10:6a81aeca25e3 | 668 | { |
JackB | 10:6a81aeca25e3 | 669 | _bitmap_count = 0; |
JackB | 10:6a81aeca25e3 | 670 | } |
JackB | 10:6a81aeca25e3 | 671 | |
JackB | 10:6a81aeca25e3 | 672 | ft_uint32_t FT813::ReadBigInt32(unsigned char* data, ft_uint32_t offset) |
JackB | 10:6a81aeca25e3 | 673 | { |
JackB | 10:6a81aeca25e3 | 674 | return (data[offset + 0] << 24 | data[24 - 4 + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]); |
JackB | 10:6a81aeca25e3 | 675 | } |
JackB | 10:6a81aeca25e3 | 676 | |
JackB | 10:6a81aeca25e3 | 677 | // Loads JPG at x, y on the screen |
JackB | 10:6a81aeca25e3 | 678 | ft_uint8_t FT813::Jpg(char *jpg_filename, int x, int y) |
JackB | 10:6a81aeca25e3 | 679 | { |
JackB | 10:6a81aeca25e3 | 680 | ft_int16_t x_size,y_size; |
JackB | 10:6a81aeca25e3 | 681 | int err; |
JackB | 10:6a81aeca25e3 | 682 | |
JackB | 10:6a81aeca25e3 | 683 | err = LoadJpg(jpg_filename, & x_size, & y_size); // load graphic data into buffer and decode jpg to bitmap |
JackB | 10:6a81aeca25e3 | 684 | if(err != 0) { // something is wrong - display error |
JackB | 10:6a81aeca25e3 | 685 | printf("LoadJpg: Error.\n"); |
JackB | 10:6a81aeca25e3 | 686 | return(-1); |
JackB | 10:6a81aeca25e3 | 687 | } |
JackB | 10:6a81aeca25e3 | 688 | DL(BEGIN(BITMAPS)); |
JackB | 10:6a81aeca25e3 | 689 | // LoadIdentity(); |
JackB | 10:6a81aeca25e3 | 690 | // SetMatrix(); |
JackB | 10:6a81aeca25e3 | 691 | DL(VERTEX2F(x * 16, y * 16)); |
JackB | 10:6a81aeca25e3 | 692 | |
JackB | 10:6a81aeca25e3 | 693 | // jpg is loaded and decoded into bitmap |
JackB | 10:6a81aeca25e3 | 694 | // printf("jpg %s is loaded and decoded into bitmap (%dx%d)\n", jpg_filename, x_size, y_size); |
JackB | 10:6a81aeca25e3 | 695 | |
JackB | 10:6a81aeca25e3 | 696 | return(0); |
JackB | 10:6a81aeca25e3 | 697 | } |
JackB | 10:6a81aeca25e3 | 698 | |
JackB | 10:6a81aeca25e3 | 699 | // Loads PNG at x, y on the screen |
JackB | 10:6a81aeca25e3 | 700 | ft_uint8_t FT813::Png(char *png_filename, int x, int y) |
JackB | 10:6a81aeca25e3 | 701 | { |
JackB | 10:6a81aeca25e3 | 702 | ft_int16_t x_size,y_size; |
JackB | 10:6a81aeca25e3 | 703 | int err; |
JackB | 10:6a81aeca25e3 | 704 | |
JackB | 10:6a81aeca25e3 | 705 | err = LoadPng(png_filename, & x_size, & y_size); // load graphic data into buffer and decode png to bitmap |
JackB | 10:6a81aeca25e3 | 706 | if(err != 0) { // something is wrong - display error |
JackB | 10:6a81aeca25e3 | 707 | printf("LoadPng: Error.\n"); |
JackB | 10:6a81aeca25e3 | 708 | return(-1); |
JackB | 10:6a81aeca25e3 | 709 | } |
JackB | 10:6a81aeca25e3 | 710 | DL(BEGIN(BITMAPS)); |
JackB | 10:6a81aeca25e3 | 711 | // LoadIdentity(); |
JackB | 10:6a81aeca25e3 | 712 | // SetMatrix(); |
JackB | 10:6a81aeca25e3 | 713 | DL(VERTEX2F(x * 16, y * 16)); |
JackB | 10:6a81aeca25e3 | 714 | |
JackB | 10:6a81aeca25e3 | 715 | // png is loaded and decoded into bitmap |
JackB | 10:6a81aeca25e3 | 716 | // printf("png %s is loaded and decoded into bitmap (%dx%d)\n", png_filename, x_size, y_size); |
JackB | 10:6a81aeca25e3 | 717 | |
JackB | 10:6a81aeca25e3 | 718 | return(0); |
JackB | 10:6a81aeca25e3 | 719 | } |
JackB | 10:6a81aeca25e3 | 720 | |
JackB | 10:6a81aeca25e3 | 721 | // Loads PNG at x, y on the screen at given address |
JackB | 10:6a81aeca25e3 | 722 | ft_uint8_t FT813::Png(char *png_filename, int x, int y, ft_int32_t address) |
JackB | 10:6a81aeca25e3 | 723 | { |
JackB | 10:6a81aeca25e3 | 724 | ft_int16_t x_size,y_size; |
JackB | 10:6a81aeca25e3 | 725 | int err; |
JackB | 10:6a81aeca25e3 | 726 | _address = address; |
JackB | 10:6a81aeca25e3 | 727 | err = LoadPng(png_filename, & x_size, & y_size); // load graphic data into buffer and decode png to bitmap |
JackB | 10:6a81aeca25e3 | 728 | if(err != 0) { // something is wrong - display error |
JackB | 10:6a81aeca25e3 | 729 | printf("LoadPng: Error.\n"); |
JackB | 10:6a81aeca25e3 | 730 | return(-1); |
JackB | 10:6a81aeca25e3 | 731 | } |
JackB | 10:6a81aeca25e3 | 732 | DL(BEGIN(BITMAPS)); |
JackB | 10:6a81aeca25e3 | 733 | // LoadIdentity(); |
JackB | 10:6a81aeca25e3 | 734 | // SetMatrix(); |
JackB | 10:6a81aeca25e3 | 735 | DL(VERTEX2F(x * 16, y * 16)); |
JackB | 10:6a81aeca25e3 | 736 | |
JackB | 10:6a81aeca25e3 | 737 | // DL(DISPLAY()); //ends the display,commands after this ignored |
JackB | 10:6a81aeca25e3 | 738 | |
JackB | 10:6a81aeca25e3 | 739 | // png is loaded and decoded into bitmap |
JackB | 10:6a81aeca25e3 | 740 | printf("png %s is loaded and decoded into bitmap (%dx%d)\n", png_filename, x_size, y_size); |
JackB | 10:6a81aeca25e3 | 741 | |
JackB | 10:6a81aeca25e3 | 742 | return(0); |
JackB | 10:6a81aeca25e3 | 743 | } |
JackB | 10:6a81aeca25e3 | 744 | |
JackB | 10:6a81aeca25e3 | 745 | // Loads JPG at the center of the screen (splash screen) |
JackB | 10:6a81aeca25e3 | 746 | // Background color specified |
JackB | 10:6a81aeca25e3 | 747 | ft_uint8_t FT813::JpgSplash(char *jpg_filename, ft_uint8_t r, ft_uint8_t g, ft_uint8_t b) |
JackB | 10:6a81aeca25e3 | 748 | { |
JackB | 10:6a81aeca25e3 | 749 | ft_int16_t x_size,y_size; |
JackB | 10:6a81aeca25e3 | 750 | int err; |
JackB | 10:6a81aeca25e3 | 751 | |
JackB | 10:6a81aeca25e3 | 752 | DLstart(); // start a new display command list |
JackB | 10:6a81aeca25e3 | 753 | DL(CLEAR_COLOR_RGB(r, g, b)); // set the clear color to white |
JackB | 10:6a81aeca25e3 | 754 | DL(CLEAR(1, 1, 1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
JackB | 10:6a81aeca25e3 | 755 | |
JackB | 10:6a81aeca25e3 | 756 | err = LoadJpg(jpg_filename, & x_size, & y_size); // load graphic data into buffer and decode jpg to bitmap |
JackB | 10:6a81aeca25e3 | 757 | if(err != 0) { // something is wrong - display error |
JackB | 10:6a81aeca25e3 | 758 | printf("LoadJpg: Error.\n"); |
JackB | 10:6a81aeca25e3 | 759 | return(-1); |
JackB | 10:6a81aeca25e3 | 760 | } |
JackB | 10:6a81aeca25e3 | 761 | |
JackB | 10:6a81aeca25e3 | 762 | DL(BEGIN(BITMAPS)); |
JackB | 10:6a81aeca25e3 | 763 | LoadIdentity(); |
JackB | 10:6a81aeca25e3 | 764 | SetMatrix(); |
JackB | 10:6a81aeca25e3 | 765 | int x = (DispWidth - x_size) / 2; |
JackB | 10:6a81aeca25e3 | 766 | int y = (DispHeight - y_size) / 2; |
JackB | 10:6a81aeca25e3 | 767 | DL(VERTEX2F(x * 16, y * 16)); |
JackB | 10:6a81aeca25e3 | 768 | |
JackB | 10:6a81aeca25e3 | 769 | DL(DISPLAY()); // Display the image |
JackB | 10:6a81aeca25e3 | 770 | Swap(); // Swap the current display list |
JackB | 10:6a81aeca25e3 | 771 | Flush_Co_Buffer(); // Download the command list into fifo |
JackB | 10:6a81aeca25e3 | 772 | WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
JackB | 10:6a81aeca25e3 | 773 | |
JackB | 10:6a81aeca25e3 | 774 | return(0); |
JackB | 10:6a81aeca25e3 | 775 | } |
JackB | 10:6a81aeca25e3 | 776 | |
JackB | 10:6a81aeca25e3 | 777 | // *************************************************************************************************************** |
JackB | 10:6a81aeca25e3 | 778 | // *** Utility and helper functions ****************************************************************************** |
JackB | 10:6a81aeca25e3 | 779 | // *************************************************************************************************************** |
JackB | 10:6a81aeca25e3 | 780 | |
JackB | 10:6a81aeca25e3 | 781 | // Find the space available in the GPU AKA CoProcessor AKA command buffer AKA FIFO |
JackB | 10:6a81aeca25e3 | 782 | ft_uint16_t FT813::CoProFIFO_FreeSpace(void) |
JackB | 10:6a81aeca25e3 | 783 | { |
JackB | 10:6a81aeca25e3 | 784 | ft_uint16_t cmdBufferDiff, cmdBufferRd, cmdBufferWr, retval; |
JackB | 10:6a81aeca25e3 | 785 | |
JackB | 10:6a81aeca25e3 | 786 | cmdBufferRd = Rd16(REG_CMD_READ + RAM_REG); |
JackB | 10:6a81aeca25e3 | 787 | cmdBufferWr = Rd16(REG_CMD_WRITE + RAM_REG); |
JackB | 10:6a81aeca25e3 | 788 | |
JackB | 10:6a81aeca25e3 | 789 | cmdBufferDiff = (cmdBufferWr-cmdBufferRd) % FT_CMD_FIFO_SIZE; // FT81x Programmers Guide 5.1.1 |
JackB | 10:6a81aeca25e3 | 790 | retval = (FT_CMD_FIFO_SIZE - 4) - cmdBufferDiff; |
JackB | 10:6a81aeca25e3 | 791 | return (retval); |
JackB | 10:6a81aeca25e3 | 792 | } |
JackB | 10:6a81aeca25e3 | 793 | |
JackB | 10:6a81aeca25e3 | 794 | // Sit and wait until there are the specified number of bytes free in the <GPU/CoProcessor> incoming FIFO |
JackB | 10:6a81aeca25e3 | 795 | void FT813::Wait4CoProFIFO(ft_uint32_t room) |
JackB | 10:6a81aeca25e3 | 796 | { |
JackB | 10:6a81aeca25e3 | 797 | ft_uint16_t getfreespace; |
JackB | 10:6a81aeca25e3 | 798 | |
JackB | 10:6a81aeca25e3 | 799 | do { |
JackB | 10:6a81aeca25e3 | 800 | getfreespace = CoProFIFO_FreeSpace(); |
JackB | 10:6a81aeca25e3 | 801 | } while(getfreespace < room); |
JackB | 10:6a81aeca25e3 | 802 | } |
JackB | 10:6a81aeca25e3 | 803 | |
JackB | 10:6a81aeca25e3 | 804 | // Sit and wait until the CoPro FIFO is empty |
JackB | 10:6a81aeca25e3 | 805 | void FT813::Wait4CoProFIFOEmpty(void) |
JackB | 10:6a81aeca25e3 | 806 | { |
JackB | 10:6a81aeca25e3 | 807 | while(Rd16(REG_CMD_READ + RAM_REG) != Rd16(REG_CMD_WRITE + RAM_REG)); |
JackB | 10:6a81aeca25e3 | 808 | } |
JackB | 10:6a81aeca25e3 | 809 | |
JackB | 10:6a81aeca25e3 | 810 | // Check if the CoPro FIFO is empty |
JackB | 10:6a81aeca25e3 | 811 | // returns 1 if the CoPro FIFO is empty |
JackB | 10:6a81aeca25e3 | 812 | // returns 0 if the CoPro FIFO is not empty |
JackB | 10:6a81aeca25e3 | 813 | ft_uint8_t FT813::CheckIfCoProFIFOEmpty(void) |
JackB | 10:6a81aeca25e3 | 814 | { |
JackB | 10:6a81aeca25e3 | 815 | return (Rd16(REG_CMD_READ + RAM_REG) == Rd16(REG_CMD_WRITE + RAM_REG)) ? 1 : 0; |
JackB | 10:6a81aeca25e3 | 816 | } |
JackB | 10:6a81aeca25e3 | 817 | |
JackB | 10:6a81aeca25e3 | 818 | // Write a block of data into Eve RAM space a byte at a time. |
JackB | 10:6a81aeca25e3 | 819 | // Return the last written address + 1 (The next available RAM address) |
JackB | 10:6a81aeca25e3 | 820 | ft_uint32_t FT813::WriteBlockRAM(ft_uint32_t Add, const ft_uint8_t *buff, ft_uint32_t count) |
JackB | 10:6a81aeca25e3 | 821 | { |
JackB | 10:6a81aeca25e3 | 822 | ft_uint32_t index; |
JackB | 10:6a81aeca25e3 | 823 | ft_uint32_t WriteAddress = Add; // I want to return the value instead of modifying the variable in place |
JackB | 10:6a81aeca25e3 | 824 | |
JackB | 10:6a81aeca25e3 | 825 | for (index = 0; index < count; index++) { |
JackB | 10:6a81aeca25e3 | 826 | Wr8(WriteAddress++, buff[index]); |
JackB | 10:6a81aeca25e3 | 827 | } |
JackB | 10:6a81aeca25e3 | 828 | return (WriteAddress); |
JackB | 10:6a81aeca25e3 | 829 | } |
JackB | 10:6a81aeca25e3 | 830 | |
cpm219 | 0:2d0ef4830603 | 831 | /* function to load jpg file from filesystem */ |
cpm219 | 0:2d0ef4830603 | 832 | /* return 0 if jpg is ok */ |
cpm219 | 0:2d0ef4830603 | 833 | /* return x_size and y_size of jpg */ |
cpm219 | 0:2d0ef4830603 | 834 | |
JackB | 10:6a81aeca25e3 | 835 | //int FT813::Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address) |
JackB | 10:6a81aeca25e3 | 836 | //{ |
JackB | 10:6a81aeca25e3 | 837 | // unsigned char pbuff[8192]; |
JackB | 10:6a81aeca25e3 | 838 | // unsigned short marker; |
JackB | 10:6a81aeca25e3 | 839 | // unsigned short length; |
JackB | 10:6a81aeca25e3 | 840 | // unsigned char data[4]; |
JackB | 10:6a81aeca25e3 | 841 | // |
JackB | 10:6a81aeca25e3 | 842 | // ft_uint16_t blocklen; |
JackB | 10:6a81aeca25e3 | 843 | //// sd.mount(); |
JackB | 10:6a81aeca25e3 | 844 | // FILE *fp = fopen(filename, "r"); |
JackB | 10:6a81aeca25e3 | 845 | // if(fp == NULL) return (-1); // connot open file |
JackB | 10:6a81aeca25e3 | 846 | // |
JackB | 10:6a81aeca25e3 | 847 | // // search for 0xFFC0 marker |
JackB | 10:6a81aeca25e3 | 848 | // fseek(fp, 0, SEEK_END); |
JackB | 10:6a81aeca25e3 | 849 | // unsigned int filesize = ftell(fp); |
JackB | 10:6a81aeca25e3 | 850 | // fseek(fp, 2, SEEK_SET); |
JackB | 10:6a81aeca25e3 | 851 | // fread(data,4,1,fp); |
JackB | 10:6a81aeca25e3 | 852 | // marker = data[0] << 8 | data[1]; |
JackB | 10:6a81aeca25e3 | 853 | // length = data[2] << 8 | data[3]; |
JackB | 10:6a81aeca25e3 | 854 | // do { |
JackB | 10:6a81aeca25e3 | 855 | // if(marker == 0xFFC0) break; |
JackB | 10:6a81aeca25e3 | 856 | // if(marker & 0xFF00 != 0xFF00) break; |
JackB | 10:6a81aeca25e3 | 857 | // if (fseek(fp, length - 2,SEEK_CUR) != 0) break; |
JackB | 10:6a81aeca25e3 | 858 | // fread(data,4,1,fp); |
JackB | 10:6a81aeca25e3 | 859 | // marker = data[0] << 8 | data[1]; |
JackB | 10:6a81aeca25e3 | 860 | // length = data[2] << 8 | data[3]; |
JackB | 10:6a81aeca25e3 | 861 | // } while(1); |
JackB | 10:6a81aeca25e3 | 862 | // if(marker != 0xFFC0) return (-2); // no FFC0 Marker, wrong format no baseline DCT-based JPEG |
JackB | 10:6a81aeca25e3 | 863 | // fseek(fp, 1,SEEK_CUR); |
JackB | 10:6a81aeca25e3 | 864 | // fread(data,4,1,fp); |
JackB | 10:6a81aeca25e3 | 865 | // *y_size = (data[0] << 8 | data[1]); |
JackB | 10:6a81aeca25e3 | 866 | // *x_size = (data[2] << 8 | data[3]); |
JackB | 10:6a81aeca25e3 | 867 | // |
JackB | 10:6a81aeca25e3 | 868 | // //if(*x_size > DispWidth || *y_size > DispHeight) return (-3); // to big to fit on screen |
JackB | 10:6a81aeca25e3 | 869 | // |
JackB | 10:6a81aeca25e3 | 870 | // fseek(fp, 0, SEEK_SET); |
JackB | 10:6a81aeca25e3 | 871 | // WrCmd32(CMD_LOADIMAGE); // load a JPEG image |
JackB | 10:6a81aeca25e3 | 872 | // WrCmd32(address); //destination address of jpg decode |
JackB | 10:6a81aeca25e3 | 873 | // WrCmd32(0); //output format of the bitmap - default is rgb565 |
JackB | 10:6a81aeca25e3 | 874 | // while(filesize > 0) { |
JackB | 10:6a81aeca25e3 | 875 | // /* download the data into the command buffer by 8kb one shot */ |
JackB | 10:6a81aeca25e3 | 876 | // blocklen = filesize>8192?8192:filesize; |
JackB | 10:6a81aeca25e3 | 877 | // /* copy the data into pbuff and then transfter it to command buffer */ |
JackB | 10:6a81aeca25e3 | 878 | // fread(pbuff,1,blocklen,fp); |
JackB | 10:6a81aeca25e3 | 879 | // filesize -= blocklen; |
JackB | 10:6a81aeca25e3 | 880 | // /* copy data continuously into command memory */ |
JackB | 10:6a81aeca25e3 | 881 | // WrCmdBuf(pbuff, blocklen); //alignment is already taken care by this api |
JackB | 10:6a81aeca25e3 | 882 | // } |
JackB | 10:6a81aeca25e3 | 883 | // fclose(fp); |
JackB | 10:6a81aeca25e3 | 884 | //// sd.unmount(); |
JackB | 10:6a81aeca25e3 | 885 | // |
JackB | 10:6a81aeca25e3 | 886 | // return(0); |
JackB | 10:6a81aeca25e3 | 887 | //} |
cpm219 | 0:2d0ef4830603 | 888 | |
JackB | 10:6a81aeca25e3 | 889 | //int FT813::Load_raw(char* filename) |
cpm219 | 0:2d0ef4830603 | 890 | //{ |
cpm219 | 0:2d0ef4830603 | 891 | // ft_uint8_t imbuff[8192]; |
cpm219 | 0:2d0ef4830603 | 892 | // ft_uint16_t filesize; |
cpm219 | 0:2d0ef4830603 | 893 | // ft_uint16_t blocklen; |
cpm219 | 0:2d0ef4830603 | 894 | //// ft_uint16_t ram_start = 0x00; |
cpm219 | 0:2d0ef4830603 | 895 | // |
cpm219 | 0:2d0ef4830603 | 896 | //// sd.mount(); |
cpm219 | 0:2d0ef4830603 | 897 | // FILE *fp = fopen(filename, "rb"); // open file |
cpm219 | 0:2d0ef4830603 | 898 | //// if(fp == NULL) return (-1); // connot open file |
cpm219 | 0:2d0ef4830603 | 899 | // fseek(fp, 0, SEEK_END); // set file position to end of file |
cpm219 | 0:2d0ef4830603 | 900 | // filesize= ftell(fp); // determine file size |
cpm219 | 0:2d0ef4830603 | 901 | // fseek(fp, 2, SEEK_SET); // return to beginning of file |
cpm219 | 0:2d0ef4830603 | 902 | // |
cpm219 | 0:2d0ef4830603 | 903 | // while(filesize > 0) |
cpm219 | 0:2d0ef4830603 | 904 | // { |
cpm219 | 0:2d0ef4830603 | 905 | // //copy the .raw file data to imbuff[8192] in 8k block |
cpm219 | 0:2d0ef4830603 | 906 | // blocklen = filesize>8192?8192:filesize; |
cpm219 | 0:2d0ef4830603 | 907 | // fread(imbuff,1,blocklen,fp); |
cpm219 | 0:2d0ef4830603 | 908 | // filesize-= blocklen; |
cpm219 | 0:2d0ef4830603 | 909 | // //write imbuff contents to graphics RAM at address ram_start = 0x00 |
cpm219 | 0:2d0ef4830603 | 910 | // WrCmdBuf(imbuff, blocklen); //alignment is already taken care by this api |
cpm219 | 0:2d0ef4830603 | 911 | //// ram_start += 8192; |
cpm219 | 0:2d0ef4830603 | 912 | // } |
cpm219 | 0:2d0ef4830603 | 913 | // fclose(fp); |
cpm219 | 0:2d0ef4830603 | 914 | //// sd.unmount(); |
cpm219 | 0:2d0ef4830603 | 915 | // |
cpm219 | 0:2d0ef4830603 | 916 | // return 0; |
cpm219 | 0:2d0ef4830603 | 917 | //} |
cpm219 | 0:2d0ef4830603 | 918 | |
cpm219 | 0:2d0ef4830603 | 919 | /* calibrate touch */ |
JackB | 10:6a81aeca25e3 | 920 | ft_void_t FT813::Calibrate() |
cpm219 | 0:2d0ef4830603 | 921 | { |
cpm219 | 0:2d0ef4830603 | 922 | /*************************************************************************/ |
cpm219 | 0:2d0ef4830603 | 923 | /* Below code demonstrates the usage of calibrate function. Calibrate */ |
cpm219 | 0:2d0ef4830603 | 924 | /* function will wait untill user presses all the three dots. Only way to*/ |
cpm219 | 0:2d0ef4830603 | 925 | /* come out of this api is to reset the coprocessor bit. */ |
cpm219 | 0:2d0ef4830603 | 926 | /*************************************************************************/ |
JackB | 10:6a81aeca25e3 | 927 | DLstart(); // start a new display command list |
JackB | 10:6a81aeca25e3 | 928 | DL(CLEAR_COLOR_RGB(64,64,64)); // set the clear color R, G, B |
JackB | 10:6a81aeca25e3 | 929 | DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
JackB | 10:6a81aeca25e3 | 930 | DL(COLOR_RGB(0xff,0xff,0xff)); // set the current color R, G, B |
JackB | 10:6a81aeca25e3 | 931 | Text((DispWidth/2), (DispHeight/2), 27, OPT_CENTER, "Please tap on the dot"); // draw Text at x,y, font 27, centered |
JackB | 10:6a81aeca25e3 | 932 | Calibrate(0); // start the calibration of touch screen |
JackB | 10:6a81aeca25e3 | 933 | Flush_Co_Buffer(); // download the commands into FT813 FIFO |
JackB | 10:6a81aeca25e3 | 934 | WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
cpm219 | 0:2d0ef4830603 | 935 | } |
cpm219 | 0:2d0ef4830603 | 936 | |
cpm219 | 0:2d0ef4830603 | 937 | |
cpm219 | 0:2d0ef4830603 | 938 | /* API to give fadeout effect by changing the display PWM from 100 till 0 */ |
JackB | 10:6a81aeca25e3 | 939 | ft_void_t FT813::fadeout() |
cpm219 | 0:2d0ef4830603 | 940 | { |
JackB | 10:6a81aeca25e3 | 941 | ft_int32_t i; |
cpm219 | 0:2d0ef4830603 | 942 | |
cpm219 | 0:2d0ef4830603 | 943 | for (i = 100; i >= 0; i -= 3) |
cpm219 | 0:2d0ef4830603 | 944 | { |
JackB | 10:6a81aeca25e3 | 945 | Wr8(REG_PWM_DUTY, i); |
cpm219 | 0:2d0ef4830603 | 946 | Sleep(2);//sleep for 2 ms |
cpm219 | 0:2d0ef4830603 | 947 | } |
cpm219 | 0:2d0ef4830603 | 948 | } |
cpm219 | 0:2d0ef4830603 | 949 | |
cpm219 | 0:2d0ef4830603 | 950 | /* API to perform display fadein effect by changing the display PWM from 0 till 100 and finally 128 */ |
JackB | 10:6a81aeca25e3 | 951 | ft_void_t FT813::fadein() |
cpm219 | 0:2d0ef4830603 | 952 | { |
cpm219 | 0:2d0ef4830603 | 953 | ft_int32_t i; |
cpm219 | 0:2d0ef4830603 | 954 | |
cpm219 | 0:2d0ef4830603 | 955 | for (i = 0; i <=100 ; i += 3) |
cpm219 | 0:2d0ef4830603 | 956 | { |
cpm219 | 0:2d0ef4830603 | 957 | Wr8(REG_PWM_DUTY,i); |
cpm219 | 0:2d0ef4830603 | 958 | Sleep(2);//sleep for 2 ms |
cpm219 | 0:2d0ef4830603 | 959 | } |
cpm219 | 0:2d0ef4830603 | 960 | /* Finally make the PWM 100% */ |
cpm219 | 0:2d0ef4830603 | 961 | i = 128; |
cpm219 | 0:2d0ef4830603 | 962 | Wr8(REG_PWM_DUTY,i); |
cpm219 | 0:2d0ef4830603 | 963 | } |
cpm219 | 0:2d0ef4830603 | 964 | |
JackB | 10:6a81aeca25e3 | 965 | ft_uint8_t FT813::read_calibrate_reg(ft_uint8_t i) { |
JackB | 10:6a81aeca25e3 | 966 | return Rd8(REG_TOUCH_TRANSFORM_A + i); |
JackB | 10:6a81aeca25e3 | 967 | } |
JackB | 10:6a81aeca25e3 | 968 | |
JackB | 10:6a81aeca25e3 | 969 | ft_uint32_t FT813::read_calibrate_reg32(ft_uint8_t i) { |
JackB | 10:6a81aeca25e3 | 970 | return (Rd8(REG_TOUCH_TRANSFORM_A + i)) + // lsb |
JackB | 10:6a81aeca25e3 | 971 | (Rd8(REG_TOUCH_TRANSFORM_A + i+1) << 8) + |
JackB | 10:6a81aeca25e3 | 972 | (Rd8(REG_TOUCH_TRANSFORM_A + i+2) << 16) + |
JackB | 10:6a81aeca25e3 | 973 | (Rd8(REG_TOUCH_TRANSFORM_A + i+3) << 24); // msb |
JackB | 10:6a81aeca25e3 | 974 | } |
JackB | 10:6a81aeca25e3 | 975 | |
JackB | 10:6a81aeca25e3 | 976 | ft_void_t FT813::read_calibrate(ft_uint8_t data[24]) { |
JackB | 10:6a81aeca25e3 | 977 | unsigned int i; |
JackB | 10:6a81aeca25e3 | 978 | for(i = 0; i < 24; i++) { |
JackB | 10:6a81aeca25e3 | 979 | data[i] = Rd8(REG_TOUCH_TRANSFORM_A + i); |
JackB | 10:6a81aeca25e3 | 980 | } |
JackB | 10:6a81aeca25e3 | 981 | } |
JackB | 10:6a81aeca25e3 | 982 | |
JackB | 10:6a81aeca25e3 | 983 | ft_void_t FT813::write_calibrate(ft_uint8_t data[24]) { |
JackB | 10:6a81aeca25e3 | 984 | unsigned int i; |
JackB | 10:6a81aeca25e3 | 985 | for(i = 0; i < 24; i++) { |
JackB | 10:6a81aeca25e3 | 986 | Wr8(REG_TOUCH_TRANSFORM_A + i, data[i]); |
JackB | 10:6a81aeca25e3 | 987 | } |
JackB | 10:6a81aeca25e3 | 988 | } |
JackB | 10:6a81aeca25e3 | 989 | |
JackB | 10:6a81aeca25e3 | 990 | ft_void_t FT813::write_calibrate32(ft_uint32_t data[6]) { |
cpm219 | 0:2d0ef4830603 | 991 | unsigned int i; |
JackB | 10:6a81aeca25e3 | 992 | for(i = 0; i < 6; i++) { |
JackB | 10:6a81aeca25e3 | 993 | Wr8(REG_TOUCH_TRANSFORM_A + i*4, (data[i]) & 0xff); // lsb |
JackB | 10:6a81aeca25e3 | 994 | Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 1, (data[i] >> 8) & 0xff); |
JackB | 10:6a81aeca25e3 | 995 | Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 2, (data[i] >> 16) & 0xff); |
JackB | 10:6a81aeca25e3 | 996 | Wr8(REG_TOUCH_TRANSFORM_A + i*4 + 3, (data[i] >> 24) & 0xff); // msb |
JackB | 10:6a81aeca25e3 | 997 | } |
JackB | 10:6a81aeca25e3 | 998 | } |
JackB | 10:6a81aeca25e3 | 999 | |
JackB | 10:6a81aeca25e3 | 1000 | ft_uint32_t FT813::color_rgb(ft_uint8_t red, ft_uint8_t green, ft_uint8_t blue){ |
JackB | 10:6a81aeca25e3 | 1001 | return ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); |
JackB | 10:6a81aeca25e3 | 1002 | } |
JackB | 10:6a81aeca25e3 | 1003 | |
JackB | 10:6a81aeca25e3 | 1004 | ft_uint32_t FT813::clear_color_rgb(ft_uint8_t red, ft_uint8_t green, ft_uint8_t blue){ |
JackB | 10:6a81aeca25e3 | 1005 | return ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)); |
JackB | 10:6a81aeca25e3 | 1006 | } |
JackB | 10:6a81aeca25e3 | 1007 | |
JackB | 10:6a81aeca25e3 | 1008 | // Define the backlight PWM output duty cycle. |
JackB | 10:6a81aeca25e3 | 1009 | void FT813::SetBacklight(ft_uint16_t brightness) |
JackB | 10:6a81aeca25e3 | 1010 | { |
JackB | 10:6a81aeca25e3 | 1011 | brightness = brightness * brightness / 255; |
JackB | 10:6a81aeca25e3 | 1012 | if (brightness > 256) |
JackB | 10:6a81aeca25e3 | 1013 | brightness = 256; |
JackB | 10:6a81aeca25e3 | 1014 | if (brightness < 16) |
JackB | 10:6a81aeca25e3 | 1015 | brightness = 16; |
JackB | 10:6a81aeca25e3 | 1016 | Wr16(REG_PWM_DUTY, brightness); // Brightness |
JackB | 10:6a81aeca25e3 | 1017 | } |
JackB | 10:6a81aeca25e3 | 1018 | |
JackB | 10:6a81aeca25e3 | 1019 | void FT813::Tag(ft_uint8_t tag) |
JackB | 10:6a81aeca25e3 | 1020 | { |
JackB | 10:6a81aeca25e3 | 1021 | DL(TAG(tag)); |
JackB | 10:6a81aeca25e3 | 1022 | } |
JackB | 10:6a81aeca25e3 | 1023 | |
JackB | 10:6a81aeca25e3 | 1024 | void FT813::ClearTag(ft_uint8_t tag) |
JackB | 10:6a81aeca25e3 | 1025 | { |
JackB | 10:6a81aeca25e3 | 1026 | DL(CLEAR_TAG(tag)); |
JackB | 10:6a81aeca25e3 | 1027 | } |
JackB | 10:6a81aeca25e3 | 1028 | |
JackB | 10:6a81aeca25e3 | 1029 | void FT813::TagMask(ft_uint8_t mask) |
JackB | 10:6a81aeca25e3 | 1030 | { |
JackB | 10:6a81aeca25e3 | 1031 | DL(TAG_MASK(mask)); |
JackB | 10:6a81aeca25e3 | 1032 | } |
JackB | 10:6a81aeca25e3 | 1033 | |
JackB | 10:6a81aeca25e3 | 1034 | void FT813::BitmapLayoutH(ft_uint8_t linestride, ft_uint8_t height) |
JackB | 10:6a81aeca25e3 | 1035 | { |
JackB | 10:6a81aeca25e3 | 1036 | DL((40 << 24) | (((linestride) & 3) << 2) | (((height) & 3) << 0)); |
JackB | 10:6a81aeca25e3 | 1037 | } |
JackB | 10:6a81aeca25e3 | 1038 | |
JackB | 10:6a81aeca25e3 | 1039 | void FT813::BitmapSizeH(ft_uint8_t width, ft_uint8_t height) |
JackB | 10:6a81aeca25e3 | 1040 | { |
JackB | 10:6a81aeca25e3 | 1041 | DL((41UL << 24) | (((width) & 3) << 2) | (((height) & 3) << 0)); |
JackB | 10:6a81aeca25e3 | 1042 | } |
JackB | 10:6a81aeca25e3 | 1043 | |
JackB | 10:6a81aeca25e3 | 1044 | ft_void_t FT813::SetLoadAddress(ft_uint32_t address) |
JackB | 10:6a81aeca25e3 | 1045 | { |
JackB | 10:6a81aeca25e3 | 1046 | _address = address; // Old, try to get rid of this |
JackB | 10:6a81aeca25e3 | 1047 | _bitmapAddress = address; |
JackB | 10:6a81aeca25e3 | 1048 | } |
JackB | 10:6a81aeca25e3 | 1049 | |
JackB | 10:6a81aeca25e3 | 1050 | ft_void_t FT813::SetBitmapCount(ft_uint8_t count) |
JackB | 10:6a81aeca25e3 | 1051 | { |
JackB | 10:6a81aeca25e3 | 1052 | _bitmap_count = count; // Old, try to get rid of this |
JackB | 10:6a81aeca25e3 | 1053 | _bitmapCount = count; |
JackB | 10:6a81aeca25e3 | 1054 | } |
JackB | 10:6a81aeca25e3 | 1055 | |
JackB | 10:6a81aeca25e3 | 1056 | ft_uint32_t FT813::GetBitmapAddress(ft_uint8_t bitmap_number) |
JackB | 10:6a81aeca25e3 | 1057 | { |
JackB | 10:6a81aeca25e3 | 1058 | return _addresses[bitmap_number]; |
JackB | 10:6a81aeca25e3 | 1059 | } |
JackB | 10:6a81aeca25e3 | 1060 | |
JackB | 10:6a81aeca25e3 | 1061 | void FT813::SetThemeDefaultColor(void) |
JackB | 10:6a81aeca25e3 | 1062 | { |
JackB | 10:6a81aeca25e3 | 1063 | // Default |
JackB | 10:6a81aeca25e3 | 1064 | GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff |
JackB | 10:6a81aeca25e3 | 1065 | FgColor(COLOR_RGB(0x00, 0x38, 0x70)); // Default 0x003870 (0, 56, 112) |
JackB | 10:6a81aeca25e3 | 1066 | BgColor(COLOR_RGB(0x00, 0x20, 0x40)); // Default 0x002040 (0, 32, 64) |
JackB | 10:6a81aeca25e3 | 1067 | } |
JackB | 10:6a81aeca25e3 | 1068 | |
JackB | 10:6a81aeca25e3 | 1069 | void FT813::SetThemeColor(ft_uint32_t c) |
JackB | 10:6a81aeca25e3 | 1070 | { |
JackB | 10:6a81aeca25e3 | 1071 | GradColor(COLOR_RGB(0xff, 0xff, 0xff)); // Default 0xffffff |
JackB | 10:6a81aeca25e3 | 1072 | ft_uint8_t r = (c >> 16) & 0xff; |
JackB | 10:6a81aeca25e3 | 1073 | ft_uint8_t g = (c >> 8) & 0xff; |
JackB | 10:6a81aeca25e3 | 1074 | ft_uint8_t b = c & 0xff; |
JackB | 10:6a81aeca25e3 | 1075 | ft_uint8_t rfg = r * 112 / 255; |
JackB | 10:6a81aeca25e3 | 1076 | ft_uint8_t gfg = g * 112 / 255; |
JackB | 10:6a81aeca25e3 | 1077 | ft_uint8_t bfg = b * 112 / 255; |
JackB | 10:6a81aeca25e3 | 1078 | ft_uint8_t rbg = r * 64 / 255; |
JackB | 10:6a81aeca25e3 | 1079 | ft_uint8_t gbg = g * 64 / 255; |
JackB | 10:6a81aeca25e3 | 1080 | ft_uint8_t bbg = b * 64 / 255; |
JackB | 10:6a81aeca25e3 | 1081 | FgColor(COLOR_RGB(rfg, gfg, bfg)); // Default 0x003870 |
JackB | 10:6a81aeca25e3 | 1082 | BgColor(COLOR_RGB(rbg, gbg, bbg)); // Default 0x002040 |
JackB | 10:6a81aeca25e3 | 1083 | } |
JackB | 10:6a81aeca25e3 | 1084 | |
JackB | 10:6a81aeca25e3 | 1085 | // ShowCalibration |
JackB | 10:6a81aeca25e3 | 1086 | void FT813::ShowCalibrationInCode(void) |
JackB | 10:6a81aeca25e3 | 1087 | { |
JackB | 10:6a81aeca25e3 | 1088 | // Read calibrate registers |
JackB | 10:6a81aeca25e3 | 1089 | printf("// Calibration values:\n"); |
JackB | 10:6a81aeca25e3 | 1090 | printf(" ft_uint32_t canned_calibration_data[] = {\n"); |
JackB | 10:6a81aeca25e3 | 1091 | for(int i = 0; i < 24; i+=4) { |
JackB | 10:6a81aeca25e3 | 1092 | printf(" "); |
JackB | 10:6a81aeca25e3 | 1093 | printf("0x%08x", read_calibrate_reg32(i)); |
JackB | 10:6a81aeca25e3 | 1094 | if (i < 20) |
JackB | 10:6a81aeca25e3 | 1095 | printf(","); |
JackB | 10:6a81aeca25e3 | 1096 | printf("\n"); |
JackB | 10:6a81aeca25e3 | 1097 | } |
JackB | 10:6a81aeca25e3 | 1098 | printf(" };\n"); |
JackB | 10:6a81aeca25e3 | 1099 | printf(" write_calibrate32(canned_calibration_data);\n"); |
JackB | 10:6a81aeca25e3 | 1100 | } |
JackB | 10:6a81aeca25e3 | 1101 | |
JackB | 10:6a81aeca25e3 | 1102 | // Set screen orientation and preload canned touch screen calibration values |
JackB | 10:6a81aeca25e3 | 1103 | void FT813::SetOrientation(ft_uint8_t orientation) |
JackB | 10:6a81aeca25e3 | 1104 | { |
JackB | 10:6a81aeca25e3 | 1105 | // TFT.SetRotate(0); // Standard landscape |
JackB | 10:6a81aeca25e3 | 1106 | // TFT.SetRotate(1); // Rotate 180 to landscape (upside down) |
JackB | 10:6a81aeca25e3 | 1107 | // TFT.SetRotate(2); // Rotate 90 CCW to portrait |
JackB | 10:6a81aeca25e3 | 1108 | // TFT.SetRotate(3); // Rotate 90 CW to portrait |
JackB | 10:6a81aeca25e3 | 1109 | // TFT.SetRotate(4); // Mirror over landscape X |
JackB | 10:6a81aeca25e3 | 1110 | // TFT.SetRotate(5); // Mirror over landscape Y |
JackB | 10:6a81aeca25e3 | 1111 | // TFT.SetRotate(6); // Rotate 90 CCW to portrait and mirror over portrait X |
JackB | 10:6a81aeca25e3 | 1112 | // TFT.SetRotate(7); // Rotate 90 CW to portrait and mirror over portrait X |
JackB | 10:6a81aeca25e3 | 1113 | |
JackB | 10:6a81aeca25e3 | 1114 | _orientation = orientation; |
JackB | 10:6a81aeca25e3 | 1115 | |
JackB | 10:6a81aeca25e3 | 1116 | SetRotate(orientation); // Standard landscape |
JackB | 10:6a81aeca25e3 | 1117 | // Canned calibration for the orientation |
JackB | 10:6a81aeca25e3 | 1118 | |
JackB | 10:6a81aeca25e3 | 1119 | if (orientation == FT8_DISPLAY_LANDSCAPE_0) |
JackB | 10:6a81aeca25e3 | 1120 | { |
JackB | 10:6a81aeca25e3 | 1121 | // Landscape 0 |
JackB | 10:6a81aeca25e3 | 1122 | ft_uint32_t canned_calibration_data[] = { |
JackB | 10:6a81aeca25e3 | 1123 | 0x000109b0, // 68016 |
JackB | 10:6a81aeca25e3 | 1124 | 0x0000023d, // 573 |
JackB | 10:6a81aeca25e3 | 1125 | 0x0000fa64, // 64100 |
JackB | 10:6a81aeca25e3 | 1126 | 0xffffffcf, // -49 |
JackB | 10:6a81aeca25e3 | 1127 | 0xfffefc9a, // -66406 |
JackB | 10:6a81aeca25e3 | 1128 | 0x01ee8754 // 32409428 |
JackB | 10:6a81aeca25e3 | 1129 | }; |
JackB | 10:6a81aeca25e3 | 1130 | write_calibrate32(canned_calibration_data); |
JackB | 10:6a81aeca25e3 | 1131 | } |
JackB | 10:6a81aeca25e3 | 1132 | |
JackB | 10:6a81aeca25e3 | 1133 | if (orientation == FT8_DISPLAY_PORTRAIT_90CW) |
JackB | 10:6a81aeca25e3 | 1134 | { |
JackB | 10:6a81aeca25e3 | 1135 | ft_uint32_t canned_calibration_data[] = { |
JackB | 10:6a81aeca25e3 | 1136 | 0xfffff994, |
JackB | 10:6a81aeca25e3 | 1137 | 0xffff07d3, |
JackB | 10:6a81aeca25e3 | 1138 | 0x01e4b85c, |
JackB | 10:6a81aeca25e3 | 1139 | 0xfffef6f5, |
JackB | 10:6a81aeca25e3 | 1140 | 0x000002ad, |
JackB | 10:6a81aeca25e3 | 1141 | 0x032eb4d4 |
JackB | 10:6a81aeca25e3 | 1142 | }; |
JackB | 10:6a81aeca25e3 | 1143 | write_calibrate32(canned_calibration_data); |
JackB | 10:6a81aeca25e3 | 1144 | } |
JackB | 10:6a81aeca25e3 | 1145 | |
JackB | 10:6a81aeca25e3 | 1146 | if (orientation == FT8_DISPLAY_PORTRAIT_90CCW) |
JackB | 10:6a81aeca25e3 | 1147 | { |
JackB | 10:6a81aeca25e3 | 1148 | // Calibration rotate 90 CCW to portrait |
JackB | 10:6a81aeca25e3 | 1149 | ft_uint32_t canned_calibration_data[] = { |
JackB | 10:6a81aeca25e3 | 1150 | 0x00000491, |
JackB | 10:6a81aeca25e3 | 1151 | 0x0000fd0b, |
JackB | 10:6a81aeca25e3 | 1152 | 0xfff6f84b, |
JackB | 10:6a81aeca25e3 | 1153 | 0x00010503, |
JackB | 10:6a81aeca25e3 | 1154 | 0x000006b7, |
JackB | 10:6a81aeca25e3 | 1155 | 0xffeeb0b7 |
JackB | 10:6a81aeca25e3 | 1156 | }; |
JackB | 10:6a81aeca25e3 | 1157 | write_calibrate32(canned_calibration_data); |
JackB | 10:6a81aeca25e3 | 1158 | } |
JackB | 10:6a81aeca25e3 | 1159 | } |
JackB | 10:6a81aeca25e3 | 1160 | |
JackB | 10:6a81aeca25e3 | 1161 | void FT813::ShowBitmap(ft_uint8_t bitmap, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height) |
JackB | 10:6a81aeca25e3 | 1162 | { |
JackB | 10:6a81aeca25e3 | 1163 | ft_int32_t addr = GetBitmapAddress(bitmap); |
JackB | 10:6a81aeca25e3 | 1164 | DL(BITMAP_SOURCE(addr)); |
JackB | 10:6a81aeca25e3 | 1165 | // ft_int16_t stride = width * 2; |
JackB | 10:6a81aeca25e3 | 1166 | // 1-bits/p L1 |
JackB | 10:6a81aeca25e3 | 1167 | // if (fmt == L1) { |
JackB | 10:6a81aeca25e3 | 1168 | // stride = width / 8; |
JackB | 10:6a81aeca25e3 | 1169 | // } |
JackB | 10:6a81aeca25e3 | 1170 | // 2-bits/p L2 |
JackB | 10:6a81aeca25e3 | 1171 | // if (fmt == L2) { |
JackB | 10:6a81aeca25e3 | 1172 | // stride = width / 4; |
JackB | 10:6a81aeca25e3 | 1173 | // } |
JackB | 10:6a81aeca25e3 | 1174 | // 4-bits/p L4 |
JackB | 10:6a81aeca25e3 | 1175 | // if (fmt == L4) { |
JackB | 10:6a81aeca25e3 | 1176 | // stride = width / 2; |
JackB | 10:6a81aeca25e3 | 1177 | // } |
JackB | 10:6a81aeca25e3 | 1178 | // 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 |
JackB | 10:6a81aeca25e3 | 1179 | // if ((fmt == L8) || |
JackB | 10:6a81aeca25e3 | 1180 | // (fmt == RGB332) || |
JackB | 10:6a81aeca25e3 | 1181 | // (fmt == ARGB2) || |
JackB | 10:6a81aeca25e3 | 1182 | // (fmt == PALETTED565) || |
JackB | 10:6a81aeca25e3 | 1183 | // (fmt == PALETTED4444) || |
JackB | 10:6a81aeca25e3 | 1184 | // (fmt == PALETTED8)) { |
JackB | 10:6a81aeca25e3 | 1185 | // stride = width; |
JackB | 10:6a81aeca25e3 | 1186 | // } |
JackB | 10:6a81aeca25e3 | 1187 | // 16-bits/p ARGB1555 ARGB4 RGB565 |
JackB | 10:6a81aeca25e3 | 1188 | // if ((fmt == ARGB1555) || |
JackB | 10:6a81aeca25e3 | 1189 | // (fmt == ARGB4) || |
JackB | 10:6a81aeca25e3 | 1190 | // (fmt == RGB565)) { |
JackB | 10:6a81aeca25e3 | 1191 | // stride = width * 2; |
JackB | 10:6a81aeca25e3 | 1192 | // } |
JackB | 10:6a81aeca25e3 | 1193 | // DL(BITMAP_LAYOUT(fmt, stride, h)); // 10-bit linestride, 9-bit height |
JackB | 10:6a81aeca25e3 | 1194 | // DL(BITMAP_LAYOUT_H(stride >> 10, h >> 9)); // msb bits |
JackB | 10:6a81aeca25e3 | 1195 | // DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, w, h)); // 9-bit width, 9-bit height |
JackB | 10:6a81aeca25e3 | 1196 | // DL(BITMAP_SIZE_H(w >> 9, h >> 9)); // msb bits |
JackB | 10:6a81aeca25e3 | 1197 | |
JackB | 10:6a81aeca25e3 | 1198 | SetBitmap(addr, fmt, width, height); |
JackB | 10:6a81aeca25e3 | 1199 | |
JackB | 10:6a81aeca25e3 | 1200 | // DL(VERTEX2II(x, y, 0, 0)); |
JackB | 10:6a81aeca25e3 | 1201 | DL(VERTEX2F(x * 16, y * 16)); |
cpm219 | 0:2d0ef4830603 | 1202 | } |
cpm219 | 0:2d0ef4830603 | 1203 | |
JackB | 10:6a81aeca25e3 | 1204 | void FT813::ShowBitmapAtAddress(ft_uint32_t addr, ft_int16_t fmt, ft_uint16_t x, ft_uint16_t y, ft_uint16_t width, ft_uint16_t height) |
JackB | 10:6a81aeca25e3 | 1205 | { |
JackB | 10:6a81aeca25e3 | 1206 | DL(BITMAP_SOURCE(addr)); |
JackB | 10:6a81aeca25e3 | 1207 | // ft_int16_t stride = width * 2; |
JackB | 10:6a81aeca25e3 | 1208 | // 1-bits/p L1 |
JackB | 10:6a81aeca25e3 | 1209 | // if (fmt == L1) { |
JackB | 10:6a81aeca25e3 | 1210 | // stride = width / 8; |
JackB | 10:6a81aeca25e3 | 1211 | // } |
JackB | 10:6a81aeca25e3 | 1212 | // 2-bits/p L2 |
JackB | 10:6a81aeca25e3 | 1213 | // if (fmt == L2) { |
JackB | 10:6a81aeca25e3 | 1214 | // stride = width / 4; |
JackB | 10:6a81aeca25e3 | 1215 | // } |
JackB | 10:6a81aeca25e3 | 1216 | // 4-bits/p L4 |
JackB | 10:6a81aeca25e3 | 1217 | // if (fmt == L4) { |
JackB | 10:6a81aeca25e3 | 1218 | // stride = width / 2; |
JackB | 10:6a81aeca25e3 | 1219 | // } |
JackB | 10:6a81aeca25e3 | 1220 | // 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 |
JackB | 10:6a81aeca25e3 | 1221 | // if ((fmt == L8) || |
JackB | 10:6a81aeca25e3 | 1222 | // (fmt == RGB332) || |
JackB | 10:6a81aeca25e3 | 1223 | // (fmt == ARGB2) || |
JackB | 10:6a81aeca25e3 | 1224 | // (fmt == PALETTED565) || |
JackB | 10:6a81aeca25e3 | 1225 | // (fmt == PALETTED4444) || |
JackB | 10:6a81aeca25e3 | 1226 | // (fmt == PALETTED8)) { |
JackB | 10:6a81aeca25e3 | 1227 | // stride = width; |
JackB | 10:6a81aeca25e3 | 1228 | // } |
JackB | 10:6a81aeca25e3 | 1229 | // 16-bits/p ARGB1555 ARGB4 RGB565 |
JackB | 10:6a81aeca25e3 | 1230 | // if ((fmt == ARGB1555) || |
JackB | 10:6a81aeca25e3 | 1231 | // (fmt == ARGB4) || |
JackB | 10:6a81aeca25e3 | 1232 | // (fmt == RGB565)) { |
JackB | 10:6a81aeca25e3 | 1233 | // stride = width * 2; |
JackB | 10:6a81aeca25e3 | 1234 | // } |
JackB | 10:6a81aeca25e3 | 1235 | // DL(BITMAP_LAYOUT(fmt, stride, h)); // 10-bit linestride, 9-bit height |
JackB | 10:6a81aeca25e3 | 1236 | // DL(BITMAP_LAYOUT_H(stride >> 10, h >> 9)); // msb bits |
JackB | 10:6a81aeca25e3 | 1237 | // DL(BITMAP_SIZE(NEAREST, BORDER, BORDER, w, h)); // 9-bit width, 9-bit height |
JackB | 10:6a81aeca25e3 | 1238 | // DL(BITMAP_SIZE_H(w >> 9, h >> 9)); // msb bits |
JackB | 10:6a81aeca25e3 | 1239 | |
JackB | 10:6a81aeca25e3 | 1240 | SetBitmap(addr, fmt, width, height); |
JackB | 10:6a81aeca25e3 | 1241 | |
JackB | 10:6a81aeca25e3 | 1242 | // DL(VERTEX2II(x, y, 0, 0)); |
JackB | 10:6a81aeca25e3 | 1243 | DL(VERTEX2F(x * 16, y * 16)); |
JackB | 10:6a81aeca25e3 | 1244 | } |
JackB | 10:6a81aeca25e3 | 1245 | |
JackB | 10:6a81aeca25e3 | 1246 | int FT813::GetImageIndexFromName(char *name) |
JackB | 10:6a81aeca25e3 | 1247 | { |
JackB | 10:6a81aeca25e3 | 1248 | for (int i = 0; i < _bitmapCount; i++) { |
JackB | 10:6a81aeca25e3 | 1249 | if(strstr(_bitmaps[i].name, name) != NULL) { |
JackB | 10:6a81aeca25e3 | 1250 | return i; |
cpm219 | 0:2d0ef4830603 | 1251 | } |
JackB | 10:6a81aeca25e3 | 1252 | } |
JackB | 10:6a81aeca25e3 | 1253 | return -1; |
JackB | 10:6a81aeca25e3 | 1254 | } |
JackB | 10:6a81aeca25e3 | 1255 | |
JackB | 10:6a81aeca25e3 | 1256 | int FT813::ResetInflateFileBitmap(void) |
JackB | 10:6a81aeca25e3 | 1257 | { |
JackB | 10:6a81aeca25e3 | 1258 | _bitmapAddress = 0; |
JackB | 10:6a81aeca25e3 | 1259 | _bitmapCount = 0; |
JackB | 10:6a81aeca25e3 | 1260 | } |
JackB | 10:6a81aeca25e3 | 1261 | |
JackB | 10:6a81aeca25e3 | 1262 | uint32_t FT813::GetRamUsage(void) |
JackB | 10:6a81aeca25e3 | 1263 | { |
JackB | 10:6a81aeca25e3 | 1264 | return _bitmapAddress; |
JackB | 10:6a81aeca25e3 | 1265 | } |
JackB | 10:6a81aeca25e3 | 1266 | |
JackB | 10:6a81aeca25e3 | 1267 | uint16_t FT813::GetRamNoOfBitmaps(void) |
JackB | 10:6a81aeca25e3 | 1268 | { |
JackB | 10:6a81aeca25e3 | 1269 | return _bitmapCount; |
JackB | 10:6a81aeca25e3 | 1270 | } |
JackB | 10:6a81aeca25e3 | 1271 | |
JackB | 10:6a81aeca25e3 | 1272 | int FT813::LoadInflateFileBitmap(char *name, uint16_t fmt, uint16_t w, uint16_t h) |
JackB | 10:6a81aeca25e3 | 1273 | { |
JackB | 10:6a81aeca25e3 | 1274 | strcpy(_bitmaps[_bitmapCount].name, name); |
JackB | 10:6a81aeca25e3 | 1275 | _bitmaps[_bitmapCount].fmt = fmt; |
JackB | 10:6a81aeca25e3 | 1276 | _bitmaps[_bitmapCount].w = w; |
JackB | 10:6a81aeca25e3 | 1277 | _bitmaps[_bitmapCount].h = h; |
JackB | 10:6a81aeca25e3 | 1278 | _bitmaps[_bitmapCount].addr = _bitmapAddress; |
JackB | 10:6a81aeca25e3 | 1279 | // 1-bits/p L1 |
JackB | 10:6a81aeca25e3 | 1280 | if (_bitmaps[_bitmapCount].fmt == L1) { |
JackB | 10:6a81aeca25e3 | 1281 | _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 8; |
JackB | 10:6a81aeca25e3 | 1282 | } |
JackB | 10:6a81aeca25e3 | 1283 | // 2-bits/p L2 |
JackB | 10:6a81aeca25e3 | 1284 | if (_bitmaps[_bitmapCount].fmt == L2) { |
JackB | 10:6a81aeca25e3 | 1285 | _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 4; |
JackB | 10:6a81aeca25e3 | 1286 | } |
JackB | 10:6a81aeca25e3 | 1287 | // 4-bits/p L4 |
JackB | 10:6a81aeca25e3 | 1288 | if (_bitmaps[_bitmapCount].fmt == L4) { |
JackB | 10:6a81aeca25e3 | 1289 | _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h / 2; |
JackB | 10:6a81aeca25e3 | 1290 | } |
JackB | 10:6a81aeca25e3 | 1291 | // 8-bits/p L8 RGB332 ARGB2 PALETTED565 PALETTED4444 PALETTED8 |
JackB | 10:6a81aeca25e3 | 1292 | if ((_bitmaps[_bitmapCount].fmt == L8) || |
JackB | 10:6a81aeca25e3 | 1293 | (_bitmaps[_bitmapCount].fmt == RGB332) || |
JackB | 10:6a81aeca25e3 | 1294 | (_bitmaps[_bitmapCount].fmt == ARGB2) || |
JackB | 10:6a81aeca25e3 | 1295 | (_bitmaps[_bitmapCount].fmt == PALETTED565) || |
JackB | 10:6a81aeca25e3 | 1296 | (_bitmaps[_bitmapCount].fmt == PALETTED4444) || |
JackB | 10:6a81aeca25e3 | 1297 | (_bitmaps[_bitmapCount].fmt == PALETTED8)) { |
JackB | 10:6a81aeca25e3 | 1298 | _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h; |
JackB | 10:6a81aeca25e3 | 1299 | } |
JackB | 10:6a81aeca25e3 | 1300 | // 16-bits/p ARGB1555 ARGB4 RGB565 |
JackB | 10:6a81aeca25e3 | 1301 | if ((_bitmaps[_bitmapCount].fmt == ARGB1555) || |
JackB | 10:6a81aeca25e3 | 1302 | (_bitmaps[_bitmapCount].fmt == ARGB4) || |
JackB | 10:6a81aeca25e3 | 1303 | (_bitmaps[_bitmapCount].fmt == RGB565)) { |
JackB | 10:6a81aeca25e3 | 1304 | _bitmaps[_bitmapCount].size = _bitmaps[_bitmapCount].w * _bitmaps[_bitmapCount].h * 2; |
JackB | 10:6a81aeca25e3 | 1305 | } |
JackB | 10:6a81aeca25e3 | 1306 | LoadInflateFile(_bitmaps[_bitmapCount].addr, _bitmaps[_bitmapCount].name); // x 0, y 0, w 32, h 32, size 1024 |
JackB | 10:6a81aeca25e3 | 1307 | _bitmapAddress += _bitmaps[_bitmapCount].size; |
JackB | 10:6a81aeca25e3 | 1308 | _bitmapCount++; |
JackB | 10:6a81aeca25e3 | 1309 | } |
JackB | 10:6a81aeca25e3 | 1310 | |
JackB | 10:6a81aeca25e3 | 1311 | int FT813::ShowBitmapByName(char *name, uint16_t x, uint16_t y) |
JackB | 10:6a81aeca25e3 | 1312 | { |
JackB | 10:6a81aeca25e3 | 1313 | int index = GetImageIndexFromName(name); |
JackB | 10:6a81aeca25e3 | 1314 | ShowBitmapAtAddress(_bitmaps[index].addr, _bitmaps[index].fmt, x, y, _bitmaps[index].w, _bitmaps[index].h); |
JackB | 10:6a81aeca25e3 | 1315 | } |
JackB | 10:6a81aeca25e3 | 1316 | |
JackB | 10:6a81aeca25e3 | 1317 | uint16_t FT813::GetTouchedTag(void) |
JackB | 10:6a81aeca25e3 | 1318 | { |
JackB | 10:6a81aeca25e3 | 1319 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1320 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1321 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1322 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1323 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1324 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1325 | uint32_t TrackRegisterVal = Rd32(REG_TRACKER); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1326 | return TrackRegisterVal & 0xffff; |
cpm219 | 0:2d0ef4830603 | 1327 | } |
cpm219 | 0:2d0ef4830603 | 1328 | |
JackB | 10:6a81aeca25e3 | 1329 | uint16_t FT813::GetTouchedTag(uint8_t point_number) |
JackB | 10:6a81aeca25e3 | 1330 | { |
JackB | 10:6a81aeca25e3 | 1331 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1332 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1333 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1334 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1335 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1336 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1337 | // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1338 | uint32_t TrackRegisterVal = 0; |
JackB | 10:6a81aeca25e3 | 1339 | switch (point_number) { |
JackB | 10:6a81aeca25e3 | 1340 | case 0: |
JackB | 10:6a81aeca25e3 | 1341 | TrackRegisterVal = Rd32(REG_TRACKER); // First point |
JackB | 10:6a81aeca25e3 | 1342 | break; |
JackB | 10:6a81aeca25e3 | 1343 | case 1: |
JackB | 10:6a81aeca25e3 | 1344 | TrackRegisterVal = Rd32(REG_TRACKER_1); // Second point |
JackB | 10:6a81aeca25e3 | 1345 | break; |
JackB | 10:6a81aeca25e3 | 1346 | case 2: |
JackB | 10:6a81aeca25e3 | 1347 | TrackRegisterVal = Rd32(REG_TRACKER_2); // Third point |
JackB | 10:6a81aeca25e3 | 1348 | break; |
JackB | 10:6a81aeca25e3 | 1349 | case 3: |
JackB | 10:6a81aeca25e3 | 1350 | TrackRegisterVal = Rd32(REG_TRACKER_3); // Fourth point |
JackB | 10:6a81aeca25e3 | 1351 | break; |
JackB | 10:6a81aeca25e3 | 1352 | case 4: |
JackB | 10:6a81aeca25e3 | 1353 | TrackRegisterVal = Rd32(REG_TRACKER_4); // Fift point |
JackB | 10:6a81aeca25e3 | 1354 | break; |
cpm219 | 0:2d0ef4830603 | 1355 | } |
JackB | 10:6a81aeca25e3 | 1356 | return TrackRegisterVal & 0xffff; |
JackB | 10:6a81aeca25e3 | 1357 | } |
JackB | 10:6a81aeca25e3 | 1358 | |
JackB | 10:6a81aeca25e3 | 1359 | uint8_t FT813::GetTag(void) |
JackB | 10:6a81aeca25e3 | 1360 | { |
JackB | 10:6a81aeca25e3 | 1361 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1362 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1363 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1364 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1365 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1366 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1367 | uint32_t TagRegisterVal = Rd32(REG_TAG); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1368 | return TagRegisterVal & 0xff; |
JackB | 10:6a81aeca25e3 | 1369 | } |
JackB | 10:6a81aeca25e3 | 1370 | |
JackB | 10:6a81aeca25e3 | 1371 | uint16_t FT813::GetTagX(void) |
JackB | 10:6a81aeca25e3 | 1372 | { |
JackB | 10:6a81aeca25e3 | 1373 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1374 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1375 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1376 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1377 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1378 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1379 | uint32_t TagRegisterVal = Rd32(REG_TAG_X); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1380 | return TagRegisterVal & 0x7ff; |
JackB | 10:6a81aeca25e3 | 1381 | } |
JackB | 10:6a81aeca25e3 | 1382 | |
JackB | 10:6a81aeca25e3 | 1383 | uint16_t FT813::GetTagY(void) |
JackB | 10:6a81aeca25e3 | 1384 | { |
JackB | 10:6a81aeca25e3 | 1385 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1386 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1387 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1388 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1389 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1390 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1391 | uint32_t TagRegisterVal = Rd32(REG_TAG_Y); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1392 | return TagRegisterVal & 0x7ff; |
JackB | 10:6a81aeca25e3 | 1393 | } |
JackB | 10:6a81aeca25e3 | 1394 | |
JackB | 10:6a81aeca25e3 | 1395 | uint8_t FT813::GetTouchTag(void) |
JackB | 10:6a81aeca25e3 | 1396 | { |
JackB | 10:6a81aeca25e3 | 1397 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1398 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1399 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1400 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1401 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1402 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1403 | uint32_t TagRegisterVal = Rd32(REG_TOUCH_TAG); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1404 | return TagRegisterVal & 0xff; |
JackB | 10:6a81aeca25e3 | 1405 | } |
JackB | 10:6a81aeca25e3 | 1406 | |
JackB | 10:6a81aeca25e3 | 1407 | uint16_t FT813::GetTouchTagX(void) |
JackB | 10:6a81aeca25e3 | 1408 | { |
JackB | 10:6a81aeca25e3 | 1409 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1410 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1411 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1412 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1413 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1414 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
nikmaos | 13:5959af2ac87a | 1415 | uint32_t TagRegisterVal = Rd32(REG_TOUCH_SCREEN_XY); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1416 | return (TagRegisterVal >> 16) & 0xffff; |
JackB | 10:6a81aeca25e3 | 1417 | } |
JackB | 10:6a81aeca25e3 | 1418 | |
JackB | 10:6a81aeca25e3 | 1419 | uint16_t FT813::GetTouchTagY(void) |
JackB | 10:6a81aeca25e3 | 1420 | { |
JackB | 10:6a81aeca25e3 | 1421 | // REG_TOUCH_TAG |
JackB | 10:6a81aeca25e3 | 1422 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
JackB | 10:6a81aeca25e3 | 1423 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
JackB | 10:6a81aeca25e3 | 1424 | // REG_TOUCH_TAG_XY |
JackB | 10:6a81aeca25e3 | 1425 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
JackB | 10:6a81aeca25e3 | 1426 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
JackB | 10:6a81aeca25e3 | 1427 | uint32_t TagRegisterVal = Rd32(REG_TOUCH_TAG_XY); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1428 | return TagRegisterVal & 0xffff; |
JackB | 10:6a81aeca25e3 | 1429 | } |
JackB | 10:6a81aeca25e3 | 1430 | |
nikmaos | 13:5959af2ac87a | 1431 | uint32_t FT813::GetTouchTagXY(void) |
nikmaos | 13:5959af2ac87a | 1432 | { |
nikmaos | 13:5959af2ac87a | 1433 | // REG_TOUCH_TAG |
nikmaos | 13:5959af2ac87a | 1434 | // If the screen is being touched, the screen coordinates are looked up in the screen's tag buffer, |
nikmaos | 13:5959af2ac87a | 1435 | // delivering a final 8-bit tag value, in REG_TOUCH_TAG. |
nikmaos | 13:5959af2ac87a | 1436 | // REG_TOUCH_TAG_XY |
nikmaos | 13:5959af2ac87a | 1437 | // Because the tag lookup takes a full frame, and touch coordinates change continuously, |
nikmaos | 13:5959af2ac87a | 1438 | // the original (x; y) used for the tag lookup is also available in REG_TOUCH_TAG_XY. |
nikmaos | 13:5959af2ac87a | 1439 | return Rd32(REG_TOUCH_SCREEN_XY); // check if one of the tracking fields is touched |
nikmaos | 13:5959af2ac87a | 1440 | } |
nikmaos | 13:5959af2ac87a | 1441 | |
JackB | 10:6a81aeca25e3 | 1442 | uint16_t FT813::GetTouchConfig(void) |
JackB | 10:6a81aeca25e3 | 1443 | { |
JackB | 10:6a81aeca25e3 | 1444 | // Read 0x0381 |
JackB | 10:6a81aeca25e3 | 1445 | // 0000 0011 1000 0001 |
JackB | 10:6a81aeca25e3 | 1446 | // bit 15 0: capacitive, 1: resistive |
JackB | 10:6a81aeca25e3 | 1447 | // bit 10 - 4: I2C address of touch screen module: 0x011 1000 0x38 |
JackB | 10:6a81aeca25e3 | 1448 | // bit 3: 0: FocalTech, 1: Azoteq |
JackB | 10:6a81aeca25e3 | 1449 | // bit 1 - 0: sampler clocks 0x01 |
JackB | 10:6a81aeca25e3 | 1450 | uint32_t TouchConfigVal = Rd32(REG_TOUCH_CONFIG); // check if one of the tracking fields is touched |
JackB | 10:6a81aeca25e3 | 1451 | return TouchConfigVal & 0xffff; |
JackB | 10:6a81aeca25e3 | 1452 | } |
JackB | 10:6a81aeca25e3 | 1453 | |
JackB | 10:6a81aeca25e3 | 1454 | void FT813::SetTouchConfig(uint16_t TouchConfigVal = VAL_TOUCH_CONFIG) |
JackB | 10:6a81aeca25e3 | 1455 | { |
JackB | 10:6a81aeca25e3 | 1456 | Wr32(REG_TOUCH_CONFIG, (uint32_t) TouchConfigVal); |
JackB | 10:6a81aeca25e3 | 1457 | } |
JackB | 10:6a81aeca25e3 | 1458 | |
JackB | 10:6a81aeca25e3 | 1459 | |
JackB | 10:6a81aeca25e3 | 1460 | |
JackB | 10:6a81aeca25e3 | 1461 | |
JackB | 10:6a81aeca25e3 | 1462 | |
JackB | 10:6a81aeca25e3 | 1463 | void FT813::screenShot(void) |
JackB | 10:6a81aeca25e3 | 1464 | { |
JackB | 10:6a81aeca25e3 | 1465 | int bufferSize = 800*480; |
JackB | 10:6a81aeca25e3 | 1466 | char* pbuff = (char*)malloc(bufferSize); |
cpm219 | 0:2d0ef4830603 | 1467 | |
JackB | 10:6a81aeca25e3 | 1468 | // wr8(REG_SCREENSHOT_EN, 1); |
JackB | 10:6a81aeca25e3 | 1469 | // for (int ly = 0; ly < SCREEN_HEIGHT; ly++) { |
JackB | 10:6a81aeca25e3 | 1470 | // wr16(REG_SCREENSHOT_Y, ly); |
JackB | 10:6a81aeca25e3 | 1471 | // wr8(REG_SCREENSHOT_START, 1); |
JackB | 10:6a81aeca25e3 | 1472 | // |
JackB | 10:6a81aeca25e3 | 1473 | // //Read 64 bit registers to see if it is busy |
JackB | 10:6a81aeca25e3 | 1474 | // while (rd32(REG_SCREENSHOT_BUSY) | rd32(REG_SCREENSHOT_BUSY + 4)); |
JackB | 10:6a81aeca25e3 | 1475 | // |
JackB | 10:6a81aeca25e3 | 1476 | // wr8(REG_SCREENSHOT_READ , 1); |
JackB | 10:6a81aeca25e3 | 1477 | // for (int lx = 0; lx < SCREEN_WIDTH; lx ++) { |
JackB | 10:6a81aeca25e3 | 1478 | // //Read 32 bit pixel value from RAM_SCREENSHOT |
JackB | 10:6a81aeca25e3 | 1479 | // //The pixel format is BGRA: Blue is in lowest address and Alpha |
JackB | 10:6a81aeca25e3 | 1480 | // is in highest address |
JackB | 10:6a81aeca25e3 | 1481 | // screenshot[ly*SCREEN_HEIGHT + lx] = rd32(RAM_SCREENSHOT + lx*4); |
JackB | 10:6a81aeca25e3 | 1482 | // } |
JackB | 10:6a81aeca25e3 | 1483 | // wr8(REG_SCREENSHOT_READ, 0); |
JackB | 10:6a81aeca25e3 | 1484 | // } |
JackB | 10:6a81aeca25e3 | 1485 | // wr8(REG_SCREENSHOT_EN, 0); |
JackB | 10:6a81aeca25e3 | 1486 | |
JackB | 10:6a81aeca25e3 | 1487 | free(pbuff); |
JackB | 10:6a81aeca25e3 | 1488 | } |