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