![](/media/cache/profiles/c8ecfaea0b7e3aa83b017a786d53b9e8.50x50_q85.jpg)
White Wizard micro SD Card module test program.You can use White Wizard SPI system easily! Details : http://wizard.nestegg.jp/sd.html
Diff: SDFileSystem.h
- Revision:
- 0:b8ab9a03a28d
diff -r 000000000000 -r b8ab9a03a28d SDFileSystem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.h Wed Jul 06 16:22:44 2011 +0000 @@ -0,0 +1,85 @@ +/* mbed Microcontroller Library - SDFileSystem + * Copyright (c) 2008-2009, sford + */ + +// VERY DRAFT CODE!!! + +#ifndef SDFILESYSTEM_H +#define SDFILESYSTEM_H + +#include "mbed.h" +#include "FATFileSystem.h" + +//Nest Egg Inc.----- +//http://wizard.nestegg.jp/ +#include "wwChipSelect.h" + +//channel No must be A4 A3 A2 A1 +//#define ch_num 0x05 //channel No 0101, depend on your SPI module setting. (1:High 0:Low) +#define reset_ch 0x00 //channel No 0000, for reset. +//------------------ + +/* Class: SDFileSystem + * Access the filesystem on an SD Card using SPI + * + * Example: + * > SDFileSystem sd(p5, p6, p7, p12, "sd"); + * > + * > int main() { + * > FILE *fp = fopen("/sd/myfile.txt", "w"); + * > fprintf(fp, "Hello World!\n"); + * > fclose(fp); + * > } + */ +class SDFileSystem : public FATFileSystem { +public: + + /* Constructor: SDFileSystem + * Create the File System for accessing an SD Card using SPI + * + * Variables: + * mosi - SPI mosi pin connected to SD Card + * miso - SPI miso pin conencted to SD Card + * sclk - SPI sclk pin connected to SD Card + * cs - DigitalOut pin used as SD Card chip select + * name - The name used to access the filesystem + */ + SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); + +//Nest Egg Inc.----- +//http://wizard.nestegg.jp/ + void SetCh(int ch); +//------------------ + virtual int disk_initialize(); + virtual int disk_write(const char *buffer, int block_number); + virtual int disk_read(char *buffer, int block_number); + virtual int disk_status(); + virtual int disk_sync(); + virtual int disk_sectors(); + +protected: + + int _cmd(int cmd, int arg); + int _cmdx(int cmd, int arg); + int _cmd8(); + int _cmd58(); + int initialise_card(); + int initialise_card_v1(); + int initialise_card_v2(); + + + int _read(char *buffer, int length); + int _write(const char *buffer, int length); + int _sd_sectors(); + int _sectors; + + SPI _spi; + //Nest Egg Inc.----- + //DigitalOut _cs; + wwChipSelect _cs; + + //------------------ + +}; + +#endif