![](/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
SDFileSystem.h@0:b8ab9a03a28d, 2011-07-06 (annotated)
- Committer:
- halfpitch
- Date:
- Wed Jul 06 16:22:44 2011 +0000
- Revision:
- 0:b8ab9a03a28d
Rev.A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
halfpitch | 0:b8ab9a03a28d | 1 | /* mbed Microcontroller Library - SDFileSystem |
halfpitch | 0:b8ab9a03a28d | 2 | * Copyright (c) 2008-2009, sford |
halfpitch | 0:b8ab9a03a28d | 3 | */ |
halfpitch | 0:b8ab9a03a28d | 4 | |
halfpitch | 0:b8ab9a03a28d | 5 | // VERY DRAFT CODE!!! |
halfpitch | 0:b8ab9a03a28d | 6 | |
halfpitch | 0:b8ab9a03a28d | 7 | #ifndef SDFILESYSTEM_H |
halfpitch | 0:b8ab9a03a28d | 8 | #define SDFILESYSTEM_H |
halfpitch | 0:b8ab9a03a28d | 9 | |
halfpitch | 0:b8ab9a03a28d | 10 | #include "mbed.h" |
halfpitch | 0:b8ab9a03a28d | 11 | #include "FATFileSystem.h" |
halfpitch | 0:b8ab9a03a28d | 12 | |
halfpitch | 0:b8ab9a03a28d | 13 | //Nest Egg Inc.----- |
halfpitch | 0:b8ab9a03a28d | 14 | //http://wizard.nestegg.jp/ |
halfpitch | 0:b8ab9a03a28d | 15 | #include "wwChipSelect.h" |
halfpitch | 0:b8ab9a03a28d | 16 | |
halfpitch | 0:b8ab9a03a28d | 17 | //channel No must be A4 A3 A2 A1 |
halfpitch | 0:b8ab9a03a28d | 18 | //#define ch_num 0x05 //channel No 0101, depend on your SPI module setting. (1:High 0:Low) |
halfpitch | 0:b8ab9a03a28d | 19 | #define reset_ch 0x00 //channel No 0000, for reset. |
halfpitch | 0:b8ab9a03a28d | 20 | //------------------ |
halfpitch | 0:b8ab9a03a28d | 21 | |
halfpitch | 0:b8ab9a03a28d | 22 | /* Class: SDFileSystem |
halfpitch | 0:b8ab9a03a28d | 23 | * Access the filesystem on an SD Card using SPI |
halfpitch | 0:b8ab9a03a28d | 24 | * |
halfpitch | 0:b8ab9a03a28d | 25 | * Example: |
halfpitch | 0:b8ab9a03a28d | 26 | * > SDFileSystem sd(p5, p6, p7, p12, "sd"); |
halfpitch | 0:b8ab9a03a28d | 27 | * > |
halfpitch | 0:b8ab9a03a28d | 28 | * > int main() { |
halfpitch | 0:b8ab9a03a28d | 29 | * > FILE *fp = fopen("/sd/myfile.txt", "w"); |
halfpitch | 0:b8ab9a03a28d | 30 | * > fprintf(fp, "Hello World!\n"); |
halfpitch | 0:b8ab9a03a28d | 31 | * > fclose(fp); |
halfpitch | 0:b8ab9a03a28d | 32 | * > } |
halfpitch | 0:b8ab9a03a28d | 33 | */ |
halfpitch | 0:b8ab9a03a28d | 34 | class SDFileSystem : public FATFileSystem { |
halfpitch | 0:b8ab9a03a28d | 35 | public: |
halfpitch | 0:b8ab9a03a28d | 36 | |
halfpitch | 0:b8ab9a03a28d | 37 | /* Constructor: SDFileSystem |
halfpitch | 0:b8ab9a03a28d | 38 | * Create the File System for accessing an SD Card using SPI |
halfpitch | 0:b8ab9a03a28d | 39 | * |
halfpitch | 0:b8ab9a03a28d | 40 | * Variables: |
halfpitch | 0:b8ab9a03a28d | 41 | * mosi - SPI mosi pin connected to SD Card |
halfpitch | 0:b8ab9a03a28d | 42 | * miso - SPI miso pin conencted to SD Card |
halfpitch | 0:b8ab9a03a28d | 43 | * sclk - SPI sclk pin connected to SD Card |
halfpitch | 0:b8ab9a03a28d | 44 | * cs - DigitalOut pin used as SD Card chip select |
halfpitch | 0:b8ab9a03a28d | 45 | * name - The name used to access the filesystem |
halfpitch | 0:b8ab9a03a28d | 46 | */ |
halfpitch | 0:b8ab9a03a28d | 47 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
halfpitch | 0:b8ab9a03a28d | 48 | |
halfpitch | 0:b8ab9a03a28d | 49 | //Nest Egg Inc.----- |
halfpitch | 0:b8ab9a03a28d | 50 | //http://wizard.nestegg.jp/ |
halfpitch | 0:b8ab9a03a28d | 51 | void SetCh(int ch); |
halfpitch | 0:b8ab9a03a28d | 52 | //------------------ |
halfpitch | 0:b8ab9a03a28d | 53 | virtual int disk_initialize(); |
halfpitch | 0:b8ab9a03a28d | 54 | virtual int disk_write(const char *buffer, int block_number); |
halfpitch | 0:b8ab9a03a28d | 55 | virtual int disk_read(char *buffer, int block_number); |
halfpitch | 0:b8ab9a03a28d | 56 | virtual int disk_status(); |
halfpitch | 0:b8ab9a03a28d | 57 | virtual int disk_sync(); |
halfpitch | 0:b8ab9a03a28d | 58 | virtual int disk_sectors(); |
halfpitch | 0:b8ab9a03a28d | 59 | |
halfpitch | 0:b8ab9a03a28d | 60 | protected: |
halfpitch | 0:b8ab9a03a28d | 61 | |
halfpitch | 0:b8ab9a03a28d | 62 | int _cmd(int cmd, int arg); |
halfpitch | 0:b8ab9a03a28d | 63 | int _cmdx(int cmd, int arg); |
halfpitch | 0:b8ab9a03a28d | 64 | int _cmd8(); |
halfpitch | 0:b8ab9a03a28d | 65 | int _cmd58(); |
halfpitch | 0:b8ab9a03a28d | 66 | int initialise_card(); |
halfpitch | 0:b8ab9a03a28d | 67 | int initialise_card_v1(); |
halfpitch | 0:b8ab9a03a28d | 68 | int initialise_card_v2(); |
halfpitch | 0:b8ab9a03a28d | 69 | |
halfpitch | 0:b8ab9a03a28d | 70 | |
halfpitch | 0:b8ab9a03a28d | 71 | int _read(char *buffer, int length); |
halfpitch | 0:b8ab9a03a28d | 72 | int _write(const char *buffer, int length); |
halfpitch | 0:b8ab9a03a28d | 73 | int _sd_sectors(); |
halfpitch | 0:b8ab9a03a28d | 74 | int _sectors; |
halfpitch | 0:b8ab9a03a28d | 75 | |
halfpitch | 0:b8ab9a03a28d | 76 | SPI _spi; |
halfpitch | 0:b8ab9a03a28d | 77 | //Nest Egg Inc.----- |
halfpitch | 0:b8ab9a03a28d | 78 | //DigitalOut _cs; |
halfpitch | 0:b8ab9a03a28d | 79 | wwChipSelect _cs; |
halfpitch | 0:b8ab9a03a28d | 80 | |
halfpitch | 0:b8ab9a03a28d | 81 | //------------------ |
halfpitch | 0:b8ab9a03a28d | 82 | |
halfpitch | 0:b8ab9a03a28d | 83 | }; |
halfpitch | 0:b8ab9a03a28d | 84 | |
halfpitch | 0:b8ab9a03a28d | 85 | #endif |