USB MSD HID composite device hello world

Dependencies:   USBDevice mbed

Committer:
samux
Date:
Mon Jan 21 12:03:05 2013 +0000
Revision:
0:61e5ecd27a36
USB MSD HID composite device hello world

Who changed what in which revision?

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