6 #include "USBEndpoints.h"
7 #include "USBDescriptor.h"
8 #include "USBDevice_Types.h"
14 #define REQ_DFU_DETACH 0x0
15 #define REQ_DFU_DNLOAD 0x1
16 #define REQ_DFU_UPLOAD 0x2
17 #define REQ_DFU_GETSTATUS 0x3
18 #define REQ_DFU_CLRSTATUS 0x4
19 #define REQ_DFU_GETSTATE 0x5
20 #define REQ_DFU_ABORT 0x6
22 #define DL_DFU_FUNCTIONAL_DESCRIPTOR 0x09
23 #define DT_DFU_FUNCTIONAL_DESCRIPTOR 0x21
25 #define DFU_VERSION_1_1 0x0110
27 #define DFU_INTERFACE_CLASS 0xFE
28 #define DFU_INTERFACE_SUBCLASS 0x01
29 #define DFU_INTERFACE_PROTOCOL_RUNTIME 0x01
30 #define DFU_INTERFACE_PROTOCOL_DFUMODE 0x02
32 #define DFU_BMATTRIBUTES_WILLDETACH (1<<3)
33 #define DFU_BMATTRIBUTES_MANIFEST_TOLERANT (1<<2) /* device keeps talking while flashing? */
34 #define DFU_BMATTRIBUTES_CANUPLOAD (1<<1)
35 #define DFU_BMATTRIBUTES_CANDOWNLOAD (1<<0)
40 #define DFU_GETSTATUS 3
41 #define DFU_CLRSTATUS 4
42 #define DFU_GETSTATE 5
47 typedef struct __attribute__ ((packed
))
50 uint8_t bDescriptorType
;
52 uint16_t wDetachTimeout
;
53 uint16_t wTransferSize
;
54 uint16_t bcdDFUVersion
;
55 } DFU_functional_descriptor
;
57 typedef struct __attribute__ ((packed
))
60 uint32_t bwPollTimeout
:24;
63 } DFU_Status_Response
;
66 class DFU
: public USB_Class_Receiver
, public Module
{
70 virtual bool USBEvent_Request(CONTROL_TRANSFER
&);
71 virtual bool USBEvent_RequestComplete(CONTROL_TRANSFER
&, uint8_t *buf
, uint32_t length
);
73 void on_module_loaded(void);
79 DFU_functional_descriptor dfu_descriptor
;
80 usbdesc_interface dfu_interface
;
82 usbdesc_string_l(12) dfu_string
;
84 DFU_Status_Response dfu_status
;