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