USBMSD SD card Hello World for Mbed platforms
Dependencies: mbed USBMSD_SD USBDevice
USBMSD_SD/USBMSD_SD.h@19:148a0b8d23bc, 2011-12-11 (annotated)
- Committer:
- samux
- Date:
- Sun Dec 11 15:42:23 2011 +0000
- Revision:
- 19:148a0b8d23bc
add disk_status to check if init and write protection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
19:148a0b8d23bc | 1 | /* mbed USBMSD_SD Library, for providing file access to SD cards |
samux |
19:148a0b8d23bc | 2 | * Copyright (c) 2008-2010, sford |
samux |
19:148a0b8d23bc | 3 | * |
samux |
19:148a0b8d23bc | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
samux |
19:148a0b8d23bc | 5 | * of this software and associated documentation files (the "Software"), to deal |
samux |
19:148a0b8d23bc | 6 | * in the Software without restriction, including without limitation the rights |
samux |
19:148a0b8d23bc | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
samux |
19:148a0b8d23bc | 8 | * copies of the Software, and to permit persons to whom the Software is |
samux |
19:148a0b8d23bc | 9 | * furnished to do so, subject to the following conditions: |
samux |
19:148a0b8d23bc | 10 | * |
samux |
19:148a0b8d23bc | 11 | * The above copyright notice and this permission notice shall be included in |
samux |
19:148a0b8d23bc | 12 | * all copies or substantial portions of the Software. |
samux |
19:148a0b8d23bc | 13 | * |
samux |
19:148a0b8d23bc | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
samux |
19:148a0b8d23bc | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
samux |
19:148a0b8d23bc | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
samux |
19:148a0b8d23bc | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
samux |
19:148a0b8d23bc | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux |
19:148a0b8d23bc | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
samux |
19:148a0b8d23bc | 20 | * THE SOFTWARE. |
samux |
19:148a0b8d23bc | 21 | */ |
samux |
19:148a0b8d23bc | 22 | |
samux |
19:148a0b8d23bc | 23 | #ifndef USBMSD_SD_H |
samux |
19:148a0b8d23bc | 24 | #define USBMSD_SD_H |
samux |
19:148a0b8d23bc | 25 | |
samux |
19:148a0b8d23bc | 26 | #include "mbed.h" |
samux |
19:148a0b8d23bc | 27 | #include "USBMSD.h" |
samux |
19:148a0b8d23bc | 28 | |
samux |
19:148a0b8d23bc | 29 | /** Use the SDcard as mass storage device using the USBMSD class |
samux |
19:148a0b8d23bc | 30 | * |
samux |
19:148a0b8d23bc | 31 | * @code |
samux |
19:148a0b8d23bc | 32 | * #include "mbed.h" |
samux |
19:148a0b8d23bc | 33 | * #include "USBMSD_SD.h" |
samux |
19:148a0b8d23bc | 34 | * |
samux |
19:148a0b8d23bc | 35 | * USBMSD_SD sd(p5, p6, p7, p8); |
samux |
19:148a0b8d23bc | 36 | * |
samux |
19:148a0b8d23bc | 37 | * int main() { |
samux |
19:148a0b8d23bc | 38 | * while(1); |
samux |
19:148a0b8d23bc | 39 | * } |
samux |
19:148a0b8d23bc | 40 | * |
samux |
19:148a0b8d23bc | 41 | * @endcode |
samux |
19:148a0b8d23bc | 42 | */ |
samux |
19:148a0b8d23bc | 43 | class USBMSD_SD : public USBMSD { |
samux |
19:148a0b8d23bc | 44 | public: |
samux |
19:148a0b8d23bc | 45 | |
samux |
19:148a0b8d23bc | 46 | /** Create the File System for accessing an SD Card using SPI |
samux |
19:148a0b8d23bc | 47 | * |
samux |
19:148a0b8d23bc | 48 | * @param mosi SPI mosi pin connected to SD Card |
samux |
19:148a0b8d23bc | 49 | * @param miso SPI miso pin conencted to SD Card |
samux |
19:148a0b8d23bc | 50 | * @param sclk SPI sclk pin connected to SD Card |
samux |
19:148a0b8d23bc | 51 | * @param cs DigitalOut pin used as SD Card chip select |
samux |
19:148a0b8d23bc | 52 | * @param name The name used to access the virtual filesystem |
samux |
19:148a0b8d23bc | 53 | */ |
samux |
19:148a0b8d23bc | 54 | USBMSD_SD(PinName mosi, PinName miso, PinName sclk, PinName cs); |
samux |
19:148a0b8d23bc | 55 | virtual int disk_initialize(); |
samux |
19:148a0b8d23bc | 56 | virtual int disk_write(const char *buffer, int block_number); |
samux |
19:148a0b8d23bc | 57 | virtual int disk_read(char *buffer, int block_number); |
samux |
19:148a0b8d23bc | 58 | virtual int disk_status(); |
samux |
19:148a0b8d23bc | 59 | virtual int disk_sync(); |
samux |
19:148a0b8d23bc | 60 | virtual int disk_sectors(); |
samux |
19:148a0b8d23bc | 61 | virtual int disk_size(); |
samux |
19:148a0b8d23bc | 62 | |
samux |
19:148a0b8d23bc | 63 | protected: |
samux |
19:148a0b8d23bc | 64 | |
samux |
19:148a0b8d23bc | 65 | int _cmd(int cmd, int arg); |
samux |
19:148a0b8d23bc | 66 | int _cmdx(int cmd, int arg); |
samux |
19:148a0b8d23bc | 67 | int _cmd8(); |
samux |
19:148a0b8d23bc | 68 | int _cmd58(); |
samux |
19:148a0b8d23bc | 69 | int initialise_card(); |
samux |
19:148a0b8d23bc | 70 | int initialise_card_v1(); |
samux |
19:148a0b8d23bc | 71 | int initialise_card_v2(); |
samux |
19:148a0b8d23bc | 72 | |
samux |
19:148a0b8d23bc | 73 | int _read(char *buffer, int length); |
samux |
19:148a0b8d23bc | 74 | int _write(const char *buffer, int length); |
samux |
19:148a0b8d23bc | 75 | int _sd_sectors(); |
samux |
19:148a0b8d23bc | 76 | int _sectors; |
samux |
19:148a0b8d23bc | 77 | |
samux |
19:148a0b8d23bc | 78 | int capacity; |
samux |
19:148a0b8d23bc | 79 | int _status; |
samux |
19:148a0b8d23bc | 80 | |
samux |
19:148a0b8d23bc | 81 | SPI _spi; |
samux |
19:148a0b8d23bc | 82 | DigitalOut _cs; |
samux |
19:148a0b8d23bc | 83 | }; |
samux |
19:148a0b8d23bc | 84 | |
samux |
19:148a0b8d23bc | 85 | #endif |