Fork of the SD file system library from simon. Changed constructor allows to inject the SPI handler in order to reuse it.

Fork of SDFileSystem by Simon Ford

Committer:
wyunreal
Date:
Sat Jan 03 17:46:16 2015 +0000
Revision:
5:9050a1baede1
Parent:
4:498b360ea482
removing comments

Who changed what in which revision?

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