4D systems Picaso uLCD 32PTU touch display library

Committer:
CaptainR
Date:
Tue Sep 27 11:10:20 2016 +0000
Revision:
24:19c77967674e
Parent:
23:dd2c28fa4dfd
Child:
25:015631f9e875
find next and find next return

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CaptainR 20:88e137b9ea46 1 //
CaptainR 20:88e137b9ea46 2 // Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
CaptainR 20:88e137b9ea46 3 // Tested with NUCLEO L152RE development board
CaptainR 20:88e137b9ea46 4 // Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
CaptainR 20:88e137b9ea46 5 //
CaptainR 20:88e137b9ea46 6 // Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify
CaptainR 20:88e137b9ea46 7 // it under the terms of the GNU General Public License as published by
CaptainR 20:88e137b9ea46 8 // the Free Software Foundation, either version 3 of the License, or
CaptainR 20:88e137b9ea46 9 // (at your option) any later version.
CaptainR 20:88e137b9ea46 10 //
CaptainR 20:88e137b9ea46 11 // Picaso_4DGL-32PTU is distributed in the hope that it will be useful,
CaptainR 20:88e137b9ea46 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
CaptainR 20:88e137b9ea46 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
CaptainR 20:88e137b9ea46 14 // GNU General Public License for more details.
CaptainR 20:88e137b9ea46 15 //
CaptainR 20:88e137b9ea46 16 // You can see GNU General Public License at <http://www.gnu.org/licenses/>.
CaptainR 20:88e137b9ea46 17 //
CaptainR 20:88e137b9ea46 18
CaptainR 20:88e137b9ea46 19 #include "mbed.h"
CaptainR 20:88e137b9ea46 20 #include "Picaso_4DGL-32PTU.h"
CaptainR 20:88e137b9ea46 21
CaptainR 20:88e137b9ea46 22 //**************************************************************************
CaptainR 20:88e137b9ea46 23 // Starts up the FAT16 disk file services and allocates a small 32 byte control block
CaptainR 20:88e137b9ea46 24 // for subsequent use. When you open a file using the “File Open” command
CaptainR 20:88e137b9ea46 25 // further 512 + 44 = 556 bytes are attached to the FAT16 file control block.
CaptainR 20:88e137b9ea46 26 // When you close a file using the “File Close” command, the 556 byte allocation
CaptainR 20:88e137b9ea46 27 // is released leaving the 32 byte file control block.
CaptainR 20:88e137b9ea46 28 // The File Mount command must be called before any other FAT16 file related
CaptainR 20:88e137b9ea46 29 // functions can be used. The control block and all FAT16 file resources are
CaptainR 20:88e137b9ea46 30 // completely released with the “File Unmount” command.
CaptainR 20:88e137b9ea46 31 //**************************************************************************
CaptainR 20:88e137b9ea46 32 bool PICASO_4DGL :: file_Mount() {
CaptainR 20:88e137b9ea46 33
CaptainR 20:88e137b9ea46 34 char command[2] = "";
CaptainR 20:88e137b9ea46 35
CaptainR 20:88e137b9ea46 36 command[0] = (FILE_MOUNT >> (8*1)) & 0xff;
CaptainR 20:88e137b9ea46 37 command[1] = (FILE_MOUNT >> (8*0)) & 0xff;
CaptainR 20:88e137b9ea46 38
CaptainR 20:88e137b9ea46 39 writeCOMMAND(command, 2);
CaptainR 20:88e137b9ea46 40 bool success = fileMountResponse();
CaptainR 20:88e137b9ea46 41 #ifdef DEBUGMODE
CaptainR 20:88e137b9ea46 42 pc.printf("\n\r DEBUG: FAT16 Mount: %s\n\r", success ? "true" : "false");
CaptainR 20:88e137b9ea46 43 #endif
CaptainR 20:88e137b9ea46 44 return success;
CaptainR 20:88e137b9ea46 45 }
CaptainR 21:ea68a8a3cea4 46
CaptainR 21:ea68a8a3cea4 47 //**************************************************************************
CaptainR 21:ea68a8a3cea4 48 // Returns the most recent error code or 0 if there were no errors.
CaptainR 21:ea68a8a3cea4 49 // Returns Error Number.
CaptainR 21:ea68a8a3cea4 50 // 1 IDE command execution error
CaptainR 21:ea68a8a3cea4 51 // 2 CARD not present
CaptainR 21:ea68a8a3cea4 52 // 3 WRONG partition type, not FAT16
CaptainR 21:ea68a8a3cea4 53 // 4 MBR sector invalid signature
CaptainR 21:ea68a8a3cea4 54 // 5 Boot Record invalid signature
CaptainR 21:ea68a8a3cea4 55 // 6 Media not mounted
CaptainR 21:ea68a8a3cea4 56 // 7 File not found in open for read
CaptainR 21:ea68a8a3cea4 57 // 8 File not open
CaptainR 21:ea68a8a3cea4 58 // 9 Fat attempt to read beyond EOF
CaptainR 21:ea68a8a3cea4 59 // 10 Reached the end of file
CaptainR 21:ea68a8a3cea4 60 // 11 Invalid cluster value > maxcls
CaptainR 21:ea68a8a3cea4 61 // 12 All root dir entry are taken
CaptainR 21:ea68a8a3cea4 62 // 13 All clusters in partition are taken
CaptainR 21:ea68a8a3cea4 63 // 14 A file with same name exist already
CaptainR 21:ea68a8a3cea4 64 // 15 Cannot init the CARD
CaptainR 21:ea68a8a3cea4 65 // 16 Cannot read the MBR
CaptainR 21:ea68a8a3cea4 66 // 17 Malloc could not allocate the FILE struct
CaptainR 21:ea68a8a3cea4 67 // 18 Mode was not r.w.
CaptainR 21:ea68a8a3cea4 68 // 19 Failure during FILE search
CaptainR 21:ea68a8a3cea4 69 // 20 Invalid Filename
CaptainR 21:ea68a8a3cea4 70 // 21 bad media
CaptainR 21:ea68a8a3cea4 71 // 22 Sector Read fail
CaptainR 21:ea68a8a3cea4 72 // 23 Sector write fail
CaptainR 21:ea68a8a3cea4 73 //**************************************************************************
CaptainR 21:ea68a8a3cea4 74 short PICASO_4DGL :: file_Error() {
CaptainR 21:ea68a8a3cea4 75
CaptainR 21:ea68a8a3cea4 76 char command[2] = "";
CaptainR 21:ea68a8a3cea4 77
CaptainR 21:ea68a8a3cea4 78 command[0] = (FILE_ERROR >> (8*1)) & 0xff;
CaptainR 21:ea68a8a3cea4 79 command[1] = (FILE_ERROR >> (8*0)) & 0xff;
CaptainR 21:ea68a8a3cea4 80
CaptainR 21:ea68a8a3cea4 81 writeCOMMAND(command, 2);
CaptainR 21:ea68a8a3cea4 82 short error = fileErrorResponse();
CaptainR 21:ea68a8a3cea4 83 #ifdef DEBUGMODE
CaptainR 21:ea68a8a3cea4 84 pc.printf("\n\r DEBUG: FAT16 Error: %i\n\r", error);
CaptainR 21:ea68a8a3cea4 85 #endif
CaptainR 21:ea68a8a3cea4 86 return error;
CaptainR 21:ea68a8a3cea4 87 }
CaptainR 21:ea68a8a3cea4 88
CaptainR 22:cea582ea74c1 89 //**************************************************************************
CaptainR 22:cea582ea74c1 90 // Returns number of files found that match the criteria.
CaptainR 22:cea582ea74c1 91 // The wild card character '*' matches up with any combination of allowable
CaptainR 22:cea582ea74c1 92 // characters and '?' matches up with any single allowable character.
CaptainR 22:cea582ea74c1 93 //**************************************************************************
CaptainR 22:cea582ea74c1 94 short PICASO_4DGL :: file_Count(char *filename) {
CaptainR 22:cea582ea74c1 95
CaptainR 22:cea582ea74c1 96 int size = 3 + strlen(filename);
CaptainR 22:cea582ea74c1 97 int i, k, j = 2;
CaptainR 22:cea582ea74c1 98 char *command;
CaptainR 22:cea582ea74c1 99 command = (char *)malloc(sizeof(char) * size);
CaptainR 22:cea582ea74c1 100 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 22:cea582ea74c1 101
CaptainR 22:cea582ea74c1 102 command[0] = (FILE_COUNT >> (8*1)) & 0xff;
CaptainR 22:cea582ea74c1 103 command[1] = (FILE_COUNT >> (8*0)) & 0xff;
CaptainR 22:cea582ea74c1 104 for (k = 0; k < size-1; k++) command[j++] = filename[k];
CaptainR 22:cea582ea74c1 105 command[j] = 0;
CaptainR 22:cea582ea74c1 106
CaptainR 22:cea582ea74c1 107 writeCOMMAND(command, size);
CaptainR 22:cea582ea74c1 108 short success = fileCountResponse();
CaptainR 22:cea582ea74c1 109 free(command);
CaptainR 22:cea582ea74c1 110 #ifdef DEBUGMODE
CaptainR 22:cea582ea74c1 111 pc.printf("\n\r DEBUG: %s count = %i\n\r", filename, success);
CaptainR 22:cea582ea74c1 112 #endif
CaptainR 22:cea582ea74c1 113 return success;
CaptainR 22:cea582ea74c1 114 }
CaptainR 22:cea582ea74c1 115
CaptainR 22:cea582ea74c1 116 //**************************************************************************
CaptainR 22:cea582ea74c1 117 // Lists the stream of file names that agree with the search key on the Display Screen.
CaptainR 22:cea582ea74c1 118 // Returns number of files found that match the criteria.
CaptainR 22:cea582ea74c1 119 // The wild card character '*' matches up with any combination of allowable characters
CaptainR 22:cea582ea74c1 120 // and '?' matches up with any single allowable character.
CaptainR 22:cea582ea74c1 121 //
CaptainR 22:cea582ea74c1 122 // Note: “Find First File and Report” and “Find Next File and Report” are
CaptainR 22:cea582ea74c1 123 // recommended alternatives in order to return the responses.
CaptainR 22:cea582ea74c1 124 //**************************************************************************
CaptainR 22:cea582ea74c1 125 short PICASO_4DGL :: file_Dir(char *filename) {
CaptainR 22:cea582ea74c1 126
CaptainR 22:cea582ea74c1 127 int size = 3 + strlen(filename);
CaptainR 22:cea582ea74c1 128 int i, k, j = 2;
CaptainR 22:cea582ea74c1 129 char *command;
CaptainR 22:cea582ea74c1 130 command = (char *)malloc(sizeof(char) * size);
CaptainR 22:cea582ea74c1 131 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 22:cea582ea74c1 132
CaptainR 22:cea582ea74c1 133 command[0] = (FILE_DIR >> (8*1)) & 0xff;
CaptainR 22:cea582ea74c1 134 command[1] = (FILE_DIR >> (8*0)) & 0xff;
CaptainR 22:cea582ea74c1 135 for (k = 0; k < size-1; k++) command[j++] = filename[k];
CaptainR 22:cea582ea74c1 136 command[j] = 0;
CaptainR 22:cea582ea74c1 137
CaptainR 22:cea582ea74c1 138 writeCOMMAND(command, size);
CaptainR 22:cea582ea74c1 139 short success = fileCountResponse();
CaptainR 22:cea582ea74c1 140 free(command);
CaptainR 22:cea582ea74c1 141 #ifdef DEBUGMODE
CaptainR 22:cea582ea74c1 142 pc.printf("\n\r DEBUG: %s count = %i\n\r", filename, success);
CaptainR 22:cea582ea74c1 143 #endif
CaptainR 22:cea582ea74c1 144 return success;
CaptainR 22:cea582ea74c1 145 }
CaptainR 22:cea582ea74c1 146
CaptainR 22:cea582ea74c1 147 //**************************************************************************
CaptainR 22:cea582ea74c1 148 // Returns true if at least 1 file exists that satisfies the file argument.
CaptainR 22:cea582ea74c1 149 // Wildcards are usually used so if the “Find First File” command returns true,
CaptainR 22:cea582ea74c1 150 // further tests can be made using the “Find Next File” command to find all
CaptainR 22:cea582ea74c1 151 // the files that match the wildcard class.
CaptainR 22:cea582ea74c1 152 // Note that the filename is printed on the screen.
CaptainR 22:cea582ea74c1 153 //
CaptainR 22:cea582ea74c1 154 // Note: “Find First File and Report” and “Find Next File and Report” are
CaptainR 22:cea582ea74c1 155 // recommended alternatives in order to return the responses.
CaptainR 22:cea582ea74c1 156 //**************************************************************************
CaptainR 22:cea582ea74c1 157 void PICASO_4DGL :: file_FindFirst(char *filename) {
CaptainR 22:cea582ea74c1 158
CaptainR 22:cea582ea74c1 159 int size = 3 + strlen(filename);
CaptainR 22:cea582ea74c1 160 int i, k, j = 2;
CaptainR 22:cea582ea74c1 161 char *command;
CaptainR 22:cea582ea74c1 162 command = (char *)malloc(sizeof(char) * size);
CaptainR 22:cea582ea74c1 163 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 22:cea582ea74c1 164
CaptainR 22:cea582ea74c1 165 command[0] = (FILE_FIRST >> (8*1)) & 0xff;
CaptainR 22:cea582ea74c1 166 command[1] = (FILE_FIRST >> (8*0)) & 0xff;
CaptainR 22:cea582ea74c1 167 for (k = 0; k < size-1; k++) command[j++] = filename[k];
CaptainR 22:cea582ea74c1 168 command[j] = 0;
CaptainR 22:cea582ea74c1 169
CaptainR 24:19c77967674e 170 puts("\n\rFirst file = ");
CaptainR 22:cea582ea74c1 171 writeCOMMAND(command, size);
CaptainR 22:cea582ea74c1 172 bool success = writeSectorResponse(3);
CaptainR 22:cea582ea74c1 173 free(command);
CaptainR 22:cea582ea74c1 174 #ifdef DEBUGMODE
CaptainR 24:19c77967674e 175 pc.printf("\n\r DEBUG: %s Found = %s\n\r", filename, success ? " true" : "false");
CaptainR 22:cea582ea74c1 176 #endif
CaptainR 22:cea582ea74c1 177 }
CaptainR 22:cea582ea74c1 178
CaptainR 22:cea582ea74c1 179 //**************************************************************************
CaptainR 22:cea582ea74c1 180 // The Find First File and Report command returns the length of the filename
CaptainR 22:cea582ea74c1 181 // and the filename if at least 1 file exists that matches the criteria.
CaptainR 22:cea582ea74c1 182 //
CaptainR 22:cea582ea74c1 183 // Wildcards are usually used so if Find First File and Report command
CaptainR 22:cea582ea74c1 184 // returns the stringlength and filename, further tests can be made using
CaptainR 22:cea582ea74c1 185 // “Find Next File” or “Find Next File and Report” commands to find all the files
CaptainR 22:cea582ea74c1 186 // that match the wildcard class.
CaptainR 23:dd2c28fa4dfd 187 //
CaptainR 23:dd2c28fa4dfd 188 // you have to give the function the output char array to put filename in
CaptainR 22:cea582ea74c1 189 //**************************************************************************
CaptainR 23:dd2c28fa4dfd 190 short PICASO_4DGL :: file_FindFirstRet(char *filename, char *outStr) {
CaptainR 22:cea582ea74c1 191
CaptainR 23:dd2c28fa4dfd 192 int size = 3 + strlen(filename);
CaptainR 22:cea582ea74c1 193 int i, k, j = 2;
CaptainR 22:cea582ea74c1 194 char *command;
CaptainR 22:cea582ea74c1 195 command = (char *)malloc(sizeof(char) * size);
CaptainR 22:cea582ea74c1 196 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 22:cea582ea74c1 197
CaptainR 22:cea582ea74c1 198 command[0] = (FILE_FIRST_RET >> (8*1)) & 0xff;
CaptainR 22:cea582ea74c1 199 command[1] = (FILE_FIRST_RET >> (8*0)) & 0xff;
CaptainR 23:dd2c28fa4dfd 200 for (k = 0; k < size-1; k++) command[j++] = filename[k];
CaptainR 22:cea582ea74c1 201 command[j] = 0;
CaptainR 22:cea582ea74c1 202
CaptainR 22:cea582ea74c1 203 writeCOMMAND(command, size);
CaptainR 23:dd2c28fa4dfd 204 short len = getFilenameResponse(outStr);
CaptainR 22:cea582ea74c1 205
CaptainR 22:cea582ea74c1 206 free(command);
CaptainR 22:cea582ea74c1 207 #ifdef DEBUGMODE
CaptainR 23:dd2c28fa4dfd 208 pc.printf("\n\r DEBUG: Searching for %s Found filename = %s\n\r", filename, outStr);
CaptainR 22:cea582ea74c1 209 #endif
CaptainR 23:dd2c28fa4dfd 210 return len;
CaptainR 22:cea582ea74c1 211 }
CaptainR 21:ea68a8a3cea4 212
CaptainR 24:19c77967674e 213 //**************************************************************************
CaptainR 24:19c77967674e 214 // The Find Next File command returns true if more file exists that satisfies
CaptainR 24:19c77967674e 215 // the file argument that was given for the “Find First File” or
CaptainR 24:19c77967674e 216 // “Find First File and Report” commands.
CaptainR 24:19c77967674e 217 // Wildcards must be used for the “Find First File” or “Find First File and Report”
CaptainR 24:19c77967674e 218 // commands else this function will always return zero as the only occurrence
CaptainR 24:19c77967674e 219 // will have already been found.
CaptainR 24:19c77967674e 220 //
CaptainR 24:19c77967674e 221 // Note that the filename is printed on the screen.
CaptainR 24:19c77967674e 222 //**************************************************************************
CaptainR 24:19c77967674e 223 void PICASO_4DGL :: file_FindNext() {
CaptainR 24:19c77967674e 224
CaptainR 24:19c77967674e 225 char command[2];
CaptainR 24:19c77967674e 226
CaptainR 24:19c77967674e 227 command[0] = (FILE_NEXT >> (8*1)) & 0xff;
CaptainR 24:19c77967674e 228 command[1] = (FILE_NEXT >> (8*0)) & 0xff;
CaptainR 24:19c77967674e 229
CaptainR 24:19c77967674e 230 puts("\n\rNext file = ");
CaptainR 24:19c77967674e 231 writeCOMMAND(command, 2);
CaptainR 24:19c77967674e 232 bool success = writeSectorResponse(3);
CaptainR 24:19c77967674e 233 #ifdef DEBUGMODE
CaptainR 24:19c77967674e 234 pc.printf("\n\r DEBUG: next file found = %s\n\r", success ? " true" : "false");
CaptainR 24:19c77967674e 235 #endif
CaptainR 24:19c77967674e 236 }
CaptainR 24:19c77967674e 237
CaptainR 24:19c77967674e 238 //**************************************************************************
CaptainR 24:19c77967674e 239 // Returns length of the filename and the filename if at least 1 file exists
CaptainR 24:19c77967674e 240 // that matches the criteria given for the “Find First File” or
CaptainR 24:19c77967674e 241 // “Find First File and Report” commands.
CaptainR 24:19c77967674e 242 // Wildcards must be used for the “Find First File” or “Find First File and Report”
CaptainR 24:19c77967674e 243 // commands else this function will always return zero as the only occurrence will have
CaptainR 24:19c77967674e 244 // already been found.
CaptainR 24:19c77967674e 245 //
CaptainR 24:19c77967674e 246 // Wildcards are usually used, so if the “Find First File” or “Find First File and Report”
CaptainR 24:19c77967674e 247 // commands return the stringlength and filename, further tests can be made using Find
CaptainR 24:19c77967674e 248 // Next File and Report command to find all the files that match the wildcard class.
CaptainR 24:19c77967674e 249 //**************************************************************************
CaptainR 24:19c77967674e 250 short PICASO_4DGL :: file_FindNextRet(char *outStr) {
CaptainR 24:19c77967674e 251
CaptainR 24:19c77967674e 252 char command[2];
CaptainR 24:19c77967674e 253
CaptainR 24:19c77967674e 254 command[0] = (FILE_NEXT_RET >> (8*1)) & 0xff;
CaptainR 24:19c77967674e 255 command[1] = (FILE_NEXT_RET >> (8*0)) & 0xff;
CaptainR 24:19c77967674e 256
CaptainR 24:19c77967674e 257 writeCOMMAND(command, 2);
CaptainR 24:19c77967674e 258 short len = getFilenameResponse(outStr);
CaptainR 24:19c77967674e 259
CaptainR 24:19c77967674e 260 #ifdef DEBUGMODE
CaptainR 24:19c77967674e 261 pc.printf("\n\r DEBUG: Found next filename = %s\n\r", outStr);
CaptainR 24:19c77967674e 262 #endif
CaptainR 24:19c77967674e 263 return len;
CaptainR 24:19c77967674e 264 }
CaptainR 21:ea68a8a3cea4 265
CaptainR 21:ea68a8a3cea4 266
CaptainR 24:19c77967674e 267