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