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