MI0283QT Library Program demostration

Dependencies:   mbed MI0283QTlib

Committer:
clemente
Date:
Sat May 26 21:03:21 2012 +0000
Revision:
0:4c87cf4af8b5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
clemente 0:4c87cf4af8b5 1 /* mbed SDFileSystem Library, for providing file access to SD cards
clemente 0:4c87cf4af8b5 2 * Copyright (c) 2008-2010, sford
clemente 0:4c87cf4af8b5 3 *
clemente 0:4c87cf4af8b5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
clemente 0:4c87cf4af8b5 5 * of this software and associated documentation files (the "Software"), to deal
clemente 0:4c87cf4af8b5 6 * in the Software without restriction, including without limitation the rights
clemente 0:4c87cf4af8b5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
clemente 0:4c87cf4af8b5 8 * copies of the Software, and to permit persons to whom the Software is
clemente 0:4c87cf4af8b5 9 * furnished to do so, subject to the following conditions:
clemente 0:4c87cf4af8b5 10 *
clemente 0:4c87cf4af8b5 11 * The above copyright notice and this permission notice shall be included in
clemente 0:4c87cf4af8b5 12 * all copies or substantial portions of the Software.
clemente 0:4c87cf4af8b5 13 *
clemente 0:4c87cf4af8b5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
clemente 0:4c87cf4af8b5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
clemente 0:4c87cf4af8b5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
clemente 0:4c87cf4af8b5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
clemente 0:4c87cf4af8b5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
clemente 0:4c87cf4af8b5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
clemente 0:4c87cf4af8b5 20 * THE SOFTWARE.
clemente 0:4c87cf4af8b5 21 */
clemente 0:4c87cf4af8b5 22
clemente 0:4c87cf4af8b5 23 #ifndef MBED_SDFILESYSTEM_H
clemente 0:4c87cf4af8b5 24 #define MBED_SDFILESYSTEM_H
clemente 0:4c87cf4af8b5 25
clemente 0:4c87cf4af8b5 26 #include "mbed.h"
clemente 0:4c87cf4af8b5 27 #include "FATFileSystem.h"
clemente 0:4c87cf4af8b5 28
clemente 0:4c87cf4af8b5 29 /** Access the filesystem on an SD Card using SPI
clemente 0:4c87cf4af8b5 30 *
clemente 0:4c87cf4af8b5 31 * @code
clemente 0:4c87cf4af8b5 32 * #include "mbed.h"
clemente 0:4c87cf4af8b5 33 * #include "SDFileSystem.h"
clemente 0:4c87cf4af8b5 34 *
clemente 0:4c87cf4af8b5 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
clemente 0:4c87cf4af8b5 36 *
clemente 0:4c87cf4af8b5 37 * int main() {
clemente 0:4c87cf4af8b5 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
clemente 0:4c87cf4af8b5 39 * fprintf(fp, "Hello World!\n");
clemente 0:4c87cf4af8b5 40 * fclose(fp);
clemente 0:4c87cf4af8b5 41 * }
clemente 0:4c87cf4af8b5 42 */
clemente 0:4c87cf4af8b5 43 class SDFileSystem : public FATFileSystem {
clemente 0:4c87cf4af8b5 44 public:
clemente 0:4c87cf4af8b5 45
clemente 0:4c87cf4af8b5 46 /** Create the File System for accessing an SD Card using SPI
clemente 0:4c87cf4af8b5 47 *
clemente 0:4c87cf4af8b5 48 * @param mosi SPI mosi pin connected to SD Card
clemente 0:4c87cf4af8b5 49 * @param miso SPI miso pin conencted to SD Card
clemente 0:4c87cf4af8b5 50 * @param sclk SPI sclk pin connected to SD Card
clemente 0:4c87cf4af8b5 51 * @param cs DigitalOut pin used as SD Card chip select
clemente 0:4c87cf4af8b5 52 * @param name The name used to access the virtual filesystem
clemente 0:4c87cf4af8b5 53 */
clemente 0:4c87cf4af8b5 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
clemente 0:4c87cf4af8b5 55 virtual int disk_initialize();
clemente 0:4c87cf4af8b5 56 virtual int disk_write(const char *buffer, int block_number);
clemente 0:4c87cf4af8b5 57 virtual int disk_read(char *buffer, int block_number);
clemente 0:4c87cf4af8b5 58 virtual int disk_status();
clemente 0:4c87cf4af8b5 59 virtual int disk_sync();
clemente 0:4c87cf4af8b5 60 virtual int disk_sectors();
clemente 0:4c87cf4af8b5 61
clemente 0:4c87cf4af8b5 62 protected:
clemente 0:4c87cf4af8b5 63
clemente 0:4c87cf4af8b5 64 int _cmd(int cmd, int arg);
clemente 0:4c87cf4af8b5 65 int _cmdx(int cmd, int arg);
clemente 0:4c87cf4af8b5 66 int _cmd8();
clemente 0:4c87cf4af8b5 67 int _cmd58();
clemente 0:4c87cf4af8b5 68 int initialise_card();
clemente 0:4c87cf4af8b5 69 int initialise_card_v1();
clemente 0:4c87cf4af8b5 70 int initialise_card_v2();
clemente 0:4c87cf4af8b5 71
clemente 0:4c87cf4af8b5 72 int _read(char *buffer, int length);
clemente 0:4c87cf4af8b5 73 int _write(const char *buffer, int length);
clemente 0:4c87cf4af8b5 74 int _sd_sectors();
clemente 0:4c87cf4af8b5 75 int _sectors;
clemente 0:4c87cf4af8b5 76
clemente 0:4c87cf4af8b5 77 SPI _spi;
clemente 0:4c87cf4af8b5 78 DigitalOut _cs;
clemente 0:4c87cf4af8b5 79 };
clemente 0:4c87cf4af8b5 80
clemente 0:4c87cf4af8b5 81 #endif