test

Dependencies:   FatFileSystem TextLCD mbed

Committer:
y_notsu
Date:
Tue Sep 18 07:24:22 2012 +0000
Revision:
0:2c37ad282618
test

Who changed what in which revision?

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