Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DFU.h Source File

DFU.h

00001 #ifndef _DFU_H
00002 #define _DFU_H
00003 
00004 #include "USB.h"
00005 
00006 #include "USBEndpoints.h"
00007 #include "USBDescriptor.h"
00008 #include "USBDevice_Types.h"
00009 
00010 #include "Module.h"
00011 
00012 #include <stdint.h>
00013 
00014 #define REQ_DFU_DETACH      0x0
00015 #define REQ_DFU_DNLOAD      0x1
00016 #define REQ_DFU_UPLOAD      0x2
00017 #define REQ_DFU_GETSTATUS   0x3
00018 #define REQ_DFU_CLRSTATUS   0x4
00019 #define REQ_DFU_GETSTATE    0x5
00020 #define REQ_DFU_ABORT       0x6
00021 
00022 #define DL_DFU_FUNCTIONAL_DESCRIPTOR    0x09
00023 #define DT_DFU_FUNCTIONAL_DESCRIPTOR    0x21
00024 
00025 #define DFU_VERSION_1_1                 0x0110
00026 
00027 #define DFU_INTERFACE_CLASS             0xFE
00028 #define DFU_INTERFACE_SUBCLASS          0x01
00029 #define DFU_INTERFACE_PROTOCOL_RUNTIME  0x01
00030 #define DFU_INTERFACE_PROTOCOL_DFUMODE  0x02
00031 
00032 #define DFU_BMATTRIBUTES_WILLDETACH         (1<<3)
00033 #define DFU_BMATTRIBUTES_MANIFEST_TOLERANT  (1<<2)  /* device keeps talking while flashing? */
00034 #define DFU_BMATTRIBUTES_CANUPLOAD          (1<<1)
00035 #define DFU_BMATTRIBUTES_CANDOWNLOAD        (1<<0)
00036 
00037 #define DFU_DETACH      0
00038 #define DFU_DNLOAD      1
00039 #define DFU_UPLOAD      2
00040 #define DFU_GETSTATUS   3
00041 #define DFU_CLRSTATUS   4
00042 #define DFU_GETSTATE    5
00043 #define DFU_ABORT       6
00044 
00045 class DFU;
00046 
00047 typedef struct __attribute__ ((packed))
00048 {
00049     uint8_t     bLength;
00050     uint8_t     bDescriptorType;
00051     uint8_t     bmAttributes;
00052     uint16_t    wDetachTimeout;
00053     uint16_t    wTransferSize;
00054     uint16_t    bcdDFUVersion;
00055 } DFU_functional_descriptor;
00056 
00057 typedef struct __attribute__ ((packed))
00058 {
00059     uint8_t     bStatus;
00060     uint32_t     bwPollTimeout:24;
00061     uint8_t     bState;
00062     uint8_t     iString;
00063 } DFU_Status_Response;
00064 
00065 
00066 class DFU : public USB_Class_Receiver, public Module {
00067 public:
00068     DFU(USB *);
00069 
00070     virtual bool USBEvent_Request(CONTROL_TRANSFER&);
00071     virtual bool USBEvent_RequestComplete(CONTROL_TRANSFER&, uint8_t *buf, uint32_t length);
00072 
00073     void on_module_loaded(void);
00074     void on_idle(void*);
00075 
00076 protected:
00077     USB *usb;
00078 
00079     DFU_functional_descriptor   dfu_descriptor;
00080     usbdesc_interface           dfu_interface;
00081 
00082     usbdesc_string_l(12)        dfu_string;
00083 
00084     DFU_Status_Response         dfu_status;
00085 
00086     int prep_for_detach;
00087 };
00088 
00089 #endif /* _DFU_H */