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