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

Dependencies:   SWD USBDevice mbed BaseDAP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBMSD_Drop.h Source File

USBMSD_Drop.h

00001 // USBMSD_Drop.h 2013/9/26
00002 #pragma once
00003 #include "USBMSD.h"
00004 #include "USBMSD2.h"
00005 #include "RomDisk.h"
00006 
00007 #ifdef TARGET_LPC1768
00008 #define USBMSD USBMSD2
00009 #endif 
00010 
00011 /** drag-and-drop using the USBMSD class
00012  *
00013  * @code
00014  * #include "mbed.h"
00015  * #include "USBMSD_Drop.h"
00016  * Serial pc(USBTX, USBRX);
00017  * USBMSD_Drop* host;
00018  * 
00019  * void callback(const uint8_t* data, int len, int offset, int total)
00020  * {
00021  *     for(int i = 0; i < len && (offset+i) < total; i++) {
00022  *         pc.putc(data[i]);
00023  *     }
00024  * }
00025  * 
00026  * int main() {
00027  *     host = new USBMSD_Drop();
00028  *     host->attach(callback);
00029  *     while(1); // forever
00030  * }
00031  * @endcode
00032  */
00033 class USBMSD_Drop : public USBMSD {
00034 public:
00035     /** create drag-and-drop file transfer
00036      */
00037     USBMSD_Drop();
00038     virtual ~USBMSD_Drop() {}
00039 
00040     /** drag-and-drop file received
00041      *
00042      * @param data received data pointer
00043      * @param len data length
00044      * @param offset offset from file top
00045      * @param total total file size
00046      */
00047     virtual void Drop(const uint8_t* data, int len, int offset, int total){};
00048 
00049     /**
00050      * Attach a callback for when a file is received
00051      *
00052      * @param fptr function pointer
00053      */
00054     void attach(void (*fptr)(const uint8_t* data, int len, int offset, int total));
00055 protected:
00056     virtual int disk_initialize();
00057     virtual int disk_status();
00058     virtual int disk_read(uint8_t * data, uint64_t block);
00059     virtual int disk_write(const uint8_t * data, uint64_t block);
00060     virtual uint64_t disk_sectors();
00061     virtual uint64_t disk_size();
00062     uint8_t _status;
00063 
00064     void _drop(const uint8_t* data, int len, int offset, int total);
00065     void (*_drop_evt)(const uint8_t* data, int len, int offset, int total);
00066     
00067     DirEntry* findNewFile(const uint8_t* data, uint32_t block);
00068     DirEntry _dir_entry;
00069     DirEntry* _result;
00070     DirEntry* _file;
00071     RomDisk _disk;
00072     int _seq;
00073     int _prev_block;
00074     int _addr;
00075 };