USB Device library for the STM32F103 with USB Device Firmware Upgrade (DFU) runtime support.

Dependents:   STM32F103C8T6_WebUSBDFU STM32F103C8T6_USBDFU STM32F103C8T6_USBDFU dfu_usb_stm32f103

Fork of USBDevice_STM32F103 by Zoltan Hudak

Revision:
66:390c4a31db54
Child:
67:39396cc073f2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDFU/USBDFU.h	Mon Aug 29 00:47:17 2016 +0000
@@ -0,0 +1,153 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef USB_DFU_H
+#define USB_DFU_H
+
+/* These headers are included for child class. */
+#include "USBEndpoints.h"
+#include "USBDescriptor.h"
+#include "USBDevice_Types.h"
+
+#include "USBDevice.h"
+
+#include "Callback.h"
+
+
+class USBDFU: public USBDevice {
+public:
+
+    /**
+    * Constructor
+    *
+    * @param vendor_id Your vendor_id
+    * @param product_id Your product_id
+    * @param product_release Your product_release
+    * @param connect Connect the device
+    */
+    USBDFU(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
+
+/**
+     *  Attach a callback called when a DFU detach request is received 
+     *
+     *  @param tptr pointer to the object to call the member function on
+     *  @param mptr pointer to the member function to be called
+     */
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void)) {
+        if((mptr != NULL) && (tptr != NULL)) {
+            detach.attach(tptr, mptr);
+        }
+    }
+
+    /**
+     * Attach a callback called when a DFU detach request is received
+     *
+     * @param func function pointer
+     */
+    void attach(Callback<void()> func);
+
+protected:
+    uint16_t reportLength;
+
+    /*
+    * Get string product descriptor
+    *
+    * @returns pointer to the string product descriptor
+    */
+    virtual uint8_t * stringIproductDesc();
+
+    /*
+    * Get string interface descriptor
+    *
+    * @returns pointer to the string interface descriptor
+    */
+    virtual uint8_t * stringIinterfaceDesc();
+
+    /*
+    * Get configuration descriptor
+    *
+    * @returns pointer to the configuration descriptor
+    */
+    virtual uint8_t * configurationDesc();
+
+    /*
+    * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
+    * This is used to handle extensions to standard requests
+    * and class specific requests
+    *
+    * @returns true if class handles this request
+    */
+    virtual bool USBCallback_request();
+
+
+    /*
+    * Called by USBDevice layer. Set configuration of the device.
+    * For instance, you can add all endpoints that you need on this function.
+    *
+    * @param configuration Number of the configuration
+    * @returns true if class handles this request
+    */
+    virtual bool USBCallback_setConfiguration(uint8_t configuration);
+
+    enum DFURequest {
+        DFU_DETACH,
+        DFU_DNLOAD,
+        DFU_UPLOAD,
+        DFU_GETSTATUS,
+        DFU_CLRSTATUS,
+        DFU_GETSTATE,
+        DFU_ABORT,
+    };
+    
+    enum DFUClass {
+        DFU_CLASS_APP_SPECIFIC = 0xFE,
+    };
+    
+    enum DFUSubClass {
+        DFU_SUBCLASS_DFU = 0x01,
+    };
+    
+    enum DFUProtocol {
+        DFU_PROTO_RUNTIME = 0x01,
+        DFU_PROTO_DFU = 0x02
+    };
+    
+    enum DFUDescriptorType {
+        DFU_DESCRIPTOR = 0x21,
+    };
+    
+    enum DFUAttributes {
+        DFU_ATTR_CAN_DOWNLOAD = 0x01,
+        DFU_ATTR_CAN_UPLOAD = 0x02,
+        DFU_ATTR_MANIFEST_TOLERANT = 0x04,
+        DFU_ATTR_WILL_DETACH = 0x08,
+    };
+    
+    enum DFUVersion {
+        DFU_VERSION_1_00 = 0x0100,
+        DFUSE_VERSION_1_1A = 0x011A,
+    };
+    
+private:
+    Callback<void()> detach;
+    
+    static void no_op() {};
+};
+
+#endif