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