USB composite device example program, drag-and-drop flash writer.

Dependencies:   SWD USBDevice mbed BaseDAP

Committer:
va009039
Date:
Sat Sep 28 03:21:14 2013 +0000
Revision:
1:ea8e179320d7
add USBMSD_Drop class. add CDC(Virtual COM) and HID(for example CMSIS-DAP), but KL25Z not work.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 1:ea8e179320d7 1 // USBMSD_Drop.h 2013/9/26
va009039 1:ea8e179320d7 2 #pragma once
va009039 1:ea8e179320d7 3 #include "USBMSD.h"
va009039 1:ea8e179320d7 4 #include "USBMSD2.h"
va009039 1:ea8e179320d7 5 #include "RomDisk.h"
va009039 1:ea8e179320d7 6
va009039 1:ea8e179320d7 7 #ifdef TARGET_LPC1768
va009039 1:ea8e179320d7 8 #define USBMSD USBMSD2
va009039 1:ea8e179320d7 9 #endif
va009039 1:ea8e179320d7 10
va009039 1:ea8e179320d7 11 /** drag-and-drop using the USBMSD class
va009039 1:ea8e179320d7 12 *
va009039 1:ea8e179320d7 13 * @code
va009039 1:ea8e179320d7 14 * #include "mbed.h"
va009039 1:ea8e179320d7 15 * #include "USBMSD_Drop.h"
va009039 1:ea8e179320d7 16 * Serial pc(USBTX, USBRX);
va009039 1:ea8e179320d7 17 * USBMSD_Drop* host;
va009039 1:ea8e179320d7 18 *
va009039 1:ea8e179320d7 19 * void callback(const uint8_t* data, int len, int offset, int total)
va009039 1:ea8e179320d7 20 * {
va009039 1:ea8e179320d7 21 * for(int i = 0; i < len && (offset+i) < total; i++) {
va009039 1:ea8e179320d7 22 * pc.putc(data[i]);
va009039 1:ea8e179320d7 23 * }
va009039 1:ea8e179320d7 24 * }
va009039 1:ea8e179320d7 25 *
va009039 1:ea8e179320d7 26 * int main() {
va009039 1:ea8e179320d7 27 * host = new USBMSD_Drop();
va009039 1:ea8e179320d7 28 * host->attach(callback);
va009039 1:ea8e179320d7 29 * while(1); // forever
va009039 1:ea8e179320d7 30 * }
va009039 1:ea8e179320d7 31 * @endcode
va009039 1:ea8e179320d7 32 */
va009039 1:ea8e179320d7 33 class USBMSD_Drop : public USBMSD {
va009039 1:ea8e179320d7 34 public:
va009039 1:ea8e179320d7 35 /** create drag-and-drop file transfer
va009039 1:ea8e179320d7 36 */
va009039 1:ea8e179320d7 37 USBMSD_Drop();
va009039 1:ea8e179320d7 38 virtual ~USBMSD_Drop() {}
va009039 1:ea8e179320d7 39
va009039 1:ea8e179320d7 40 /** drag-and-drop file received
va009039 1:ea8e179320d7 41 *
va009039 1:ea8e179320d7 42 * @param data received data pointer
va009039 1:ea8e179320d7 43 * @param len data length
va009039 1:ea8e179320d7 44 * @param offset offset from file top
va009039 1:ea8e179320d7 45 * @param total total file size
va009039 1:ea8e179320d7 46 */
va009039 1:ea8e179320d7 47 virtual void Drop(const uint8_t* data, int len, int offset, int total){};
va009039 1:ea8e179320d7 48
va009039 1:ea8e179320d7 49 /**
va009039 1:ea8e179320d7 50 * Attach a callback for when a file is received
va009039 1:ea8e179320d7 51 *
va009039 1:ea8e179320d7 52 * @param fptr function pointer
va009039 1:ea8e179320d7 53 */
va009039 1:ea8e179320d7 54 void attach(void (*fptr)(const uint8_t* data, int len, int offset, int total));
va009039 1:ea8e179320d7 55 protected:
va009039 1:ea8e179320d7 56 virtual int disk_initialize();
va009039 1:ea8e179320d7 57 virtual int disk_status();
va009039 1:ea8e179320d7 58 virtual int disk_read(uint8_t * data, uint64_t block);
va009039 1:ea8e179320d7 59 virtual int disk_write(const uint8_t * data, uint64_t block);
va009039 1:ea8e179320d7 60 virtual uint64_t disk_sectors();
va009039 1:ea8e179320d7 61 virtual uint64_t disk_size();
va009039 1:ea8e179320d7 62 uint8_t _status;
va009039 1:ea8e179320d7 63
va009039 1:ea8e179320d7 64 void _drop(const uint8_t* data, int len, int offset, int total);
va009039 1:ea8e179320d7 65 void (*_drop_evt)(const uint8_t* data, int len, int offset, int total);
va009039 1:ea8e179320d7 66
va009039 1:ea8e179320d7 67 DirEntry* findNewFile(const uint8_t* data, uint32_t block);
va009039 1:ea8e179320d7 68 DirEntry _dir_entry;
va009039 1:ea8e179320d7 69 DirEntry* _result;
va009039 1:ea8e179320d7 70 DirEntry* _file;
va009039 1:ea8e179320d7 71 RomDisk _disk;
va009039 1:ea8e179320d7 72 int _seq;
va009039 1:ea8e179320d7 73 int _prev_block;
va009039 1:ea8e179320d7 74 int _addr;
va009039 1:ea8e179320d7 75 };