4D systems Picaso uLCD 32PTU touch display library

Picaso_4DGL-32PTU_File.cpp

Committer:
CaptainR
Date:
2016-09-26
Revision:
21:ea68a8a3cea4
Parent:
20:88e137b9ea46
Child:
22:cea582ea74c1

File content as of revision 21:ea68a8a3cea4:

//
//  Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
//  Tested with NUCLEO L152RE development board
//  Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
//
// Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Picaso_4DGL-32PTU is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You can see GNU General Public License at <http://www.gnu.org/licenses/>.
//

#include "mbed.h"
#include "Picaso_4DGL-32PTU.h"

//**************************************************************************
// Starts up the FAT16 disk file services and allocates a small 32 byte control block
// for subsequent use. When you open a file using the “File Open” command
// further 512 + 44 = 556 bytes are attached to the FAT16 file control block.
// When you close a file using the “File Close” command, the 556 byte allocation
// is released leaving the 32 byte file control block.
// The File Mount command must be called before any other FAT16 file related
// functions can be used. The control block and all FAT16 file resources are
// completely released with the “File Unmount” command.
//**************************************************************************
bool PICASO_4DGL :: file_Mount() {

    char command[2] = "";
    
    command[0] = (FILE_MOUNT >> (8*1)) & 0xff;
    command[1] = (FILE_MOUNT >> (8*0)) & 0xff;
    
    writeCOMMAND(command, 2);
    bool success = fileMountResponse();
#ifdef DEBUGMODE
    pc.printf("\n\r DEBUG: FAT16 Mount: %s\n\r", success ? "true" : "false");
#endif
    return success;
}

//**************************************************************************
// Returns the most recent error code or 0 if there were no errors.
// Returns Error Number.
// 1    IDE command execution error
// 2    CARD not present
// 3    WRONG partition type, not FAT16
// 4    MBR sector invalid signature
// 5    Boot Record invalid signature
// 6    Media not mounted
// 7    File not found in open for read
// 8    File not open
// 9    Fat attempt to read beyond EOF
// 10   Reached the end of file
// 11   Invalid cluster value > maxcls
// 12   All root dir entry are taken
// 13   All clusters in partition are taken
// 14   A file with same name exist already
// 15   Cannot init the CARD
// 16   Cannot read the MBR
// 17   Malloc could not allocate the FILE struct
// 18   Mode was not r.w.
// 19   Failure during FILE search
// 20   Invalid Filename
// 21   bad media
// 22   Sector Read fail
// 23   Sector write fail
//**************************************************************************
short PICASO_4DGL :: file_Error() {

    char command[2] = "";
    
    command[0] = (FILE_ERROR >> (8*1)) & 0xff;
    command[1] = (FILE_ERROR >> (8*0)) & 0xff;
    
    writeCOMMAND(command, 2);
    short error = fileErrorResponse();
#ifdef DEBUGMODE
    pc.printf("\n\r DEBUG: FAT16 Error: %i\n\r", error);
#endif
    return error;
}