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