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