![](/media/cache/profiles/c51ce410c124a10e0db5e4b97fc2af39.50x50_q85.jpg)
SDFileSystem.h@0:666a082cf50f, 2009-11-19 (annotated)
- Committer:
- simon
- Date:
- Thu Nov 19 14:04:44 2009 +0000
- Revision:
- 0:666a082cf50f
- Child:
- 2:849162a1207f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:666a082cf50f | 1 | /* mbed Microcontroller Library - SDFileSystem |
simon | 0:666a082cf50f | 2 | * Copyright (c) 2008-2009, sford |
simon | 0:666a082cf50f | 3 | */ |
simon | 0:666a082cf50f | 4 | |
simon | 0:666a082cf50f | 5 | #ifndef SDFILESYSTEM_H |
simon | 0:666a082cf50f | 6 | #define SDFILESYSTEM_H |
simon | 0:666a082cf50f | 7 | |
simon | 0:666a082cf50f | 8 | #include "mbed.h" |
simon | 0:666a082cf50f | 9 | #include "FATFileSystem.h" |
simon | 0:666a082cf50f | 10 | |
simon | 0:666a082cf50f | 11 | /* Class: SDFileSystem |
simon | 0:666a082cf50f | 12 | * Access the filesystem on an SD Card using SPI |
simon | 0:666a082cf50f | 13 | * |
simon | 0:666a082cf50f | 14 | * Example: |
simon | 0:666a082cf50f | 15 | * > SDFileSystem sd(p5, p6, p7, p12, "sd"); |
simon | 0:666a082cf50f | 16 | * > |
simon | 0:666a082cf50f | 17 | * > int main() { |
simon | 0:666a082cf50f | 18 | * > FILE *fp = fopen("/sd/myfile.txt", "w"); |
simon | 0:666a082cf50f | 19 | * > fprintf(fp, "Hello World!\n"); |
simon | 0:666a082cf50f | 20 | * > fclose(fp); |
simon | 0:666a082cf50f | 21 | * > } |
simon | 0:666a082cf50f | 22 | */ |
simon | 0:666a082cf50f | 23 | class SDFileSystem : public FATFileSystem { |
simon | 0:666a082cf50f | 24 | public: |
simon | 0:666a082cf50f | 25 | |
simon | 0:666a082cf50f | 26 | /* Constructor: SDFileSystem |
simon | 0:666a082cf50f | 27 | * Create the File System for accessing an SD Card using SPI |
simon | 0:666a082cf50f | 28 | * |
simon | 0:666a082cf50f | 29 | * Variables: |
simon | 0:666a082cf50f | 30 | * mosi - SPI mosi pin connected to SD Card |
simon | 0:666a082cf50f | 31 | * miso - SPI miso pin conencted to SD Card |
simon | 0:666a082cf50f | 32 | * sclk - SPI sclk pin connected to SD Card |
simon | 0:666a082cf50f | 33 | * cs - DigitalOut pin used as SD Card chip select |
simon | 0:666a082cf50f | 34 | * name - The name used to access the filesystem |
simon | 0:666a082cf50f | 35 | */ |
simon | 0:666a082cf50f | 36 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
simon | 0:666a082cf50f | 37 | virtual int disk_initialize(); |
simon | 0:666a082cf50f | 38 | virtual int disk_write(const char *buffer, int block_number); |
simon | 0:666a082cf50f | 39 | virtual int disk_read(char *buffer, int block_number); |
simon | 0:666a082cf50f | 40 | virtual int disk_status(); |
simon | 0:666a082cf50f | 41 | virtual int disk_sync(); |
simon | 0:666a082cf50f | 42 | virtual int disk_sectors(); |
simon | 0:666a082cf50f | 43 | |
simon | 0:666a082cf50f | 44 | protected: |
simon | 0:666a082cf50f | 45 | |
simon | 0:666a082cf50f | 46 | int _cmd(int cmd, int arg); |
simon | 0:666a082cf50f | 47 | int _read(char *buffer, int length); |
simon | 0:666a082cf50f | 48 | int _write(const char *buffer, int length); |
simon | 0:666a082cf50f | 49 | int _sd_sectors(); |
simon | 0:666a082cf50f | 50 | int _sectors; |
simon | 0:666a082cf50f | 51 | |
simon | 0:666a082cf50f | 52 | SPI _spi; |
simon | 0:666a082cf50f | 53 | DigitalOut _cs; |
simon | 0:666a082cf50f | 54 | }; |
simon | 0:666a082cf50f | 55 | |
simon | 0:666a082cf50f | 56 | #endif |