Description

Dependents:   RoboPanorama

Fork of SDFileSystem by Simon Ford

Committer:
lndv3
Date:
Fri Oct 12 16:41:32 2012 +0000
Revision:
1:97e0c0200e51
Parent:
0:b1ddfc9a9b25
Commit.

Who changed what in which revision?

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