This fork re-enables FRDM boards and adds WebUSB CDC functionality

Fork of USBDevice_STM32F103 by Devan Lai

Committer:
Lars Knudsen
Date:
Tue Jul 11 21:02:39 2017 +0200
Revision:
72:1d8a6665d607
Parent:
67:39396cc073f2
Adding MS OS 2.0 support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
devanlai 66:390c4a31db54 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
devanlai 66:390c4a31db54 2 *
devanlai 66:390c4a31db54 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
devanlai 66:390c4a31db54 4 * and associated documentation files (the "Software"), to deal in the Software without
devanlai 66:390c4a31db54 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
devanlai 66:390c4a31db54 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
devanlai 66:390c4a31db54 7 * Software is furnished to do so, subject to the following conditions:
devanlai 66:390c4a31db54 8 *
devanlai 66:390c4a31db54 9 * The above copyright notice and this permission notice shall be included in all copies or
devanlai 66:390c4a31db54 10 * substantial portions of the Software.
devanlai 66:390c4a31db54 11 *
devanlai 66:390c4a31db54 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
devanlai 66:390c4a31db54 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
devanlai 66:390c4a31db54 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
devanlai 66:390c4a31db54 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
devanlai 66:390c4a31db54 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
devanlai 66:390c4a31db54 17 */
devanlai 66:390c4a31db54 18
devanlai 66:390c4a31db54 19 #ifndef USB_DFU_H
devanlai 66:390c4a31db54 20 #define USB_DFU_H
devanlai 66:390c4a31db54 21
devanlai 66:390c4a31db54 22 /* These headers are included for child class. */
devanlai 66:390c4a31db54 23 #include "USBEndpoints.h"
devanlai 66:390c4a31db54 24 #include "USBDescriptor.h"
devanlai 66:390c4a31db54 25 #include "USBDevice_Types.h"
devanlai 66:390c4a31db54 26
devanlai 66:390c4a31db54 27 #include "USBDevice.h"
devanlai 66:390c4a31db54 28
devanlai 66:390c4a31db54 29 #include "Callback.h"
devanlai 66:390c4a31db54 30
devanlai 66:390c4a31db54 31
devanlai 66:390c4a31db54 32 class USBDFU: public USBDevice {
devanlai 66:390c4a31db54 33 public:
devanlai 66:390c4a31db54 34
devanlai 66:390c4a31db54 35 /**
devanlai 66:390c4a31db54 36 * Constructor
devanlai 66:390c4a31db54 37 *
devanlai 66:390c4a31db54 38 * @param vendor_id Your vendor_id
devanlai 66:390c4a31db54 39 * @param product_id Your product_id
devanlai 66:390c4a31db54 40 * @param product_release Your product_release
devanlai 66:390c4a31db54 41 * @param connect Connect the device
devanlai 66:390c4a31db54 42 */
devanlai 66:390c4a31db54 43 USBDFU(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
devanlai 66:390c4a31db54 44
devanlai 66:390c4a31db54 45 /**
devanlai 66:390c4a31db54 46 * Attach a callback called when a DFU detach request is received
devanlai 66:390c4a31db54 47 *
devanlai 66:390c4a31db54 48 * @param tptr pointer to the object to call the member function on
devanlai 66:390c4a31db54 49 * @param mptr pointer to the member function to be called
devanlai 66:390c4a31db54 50 */
devanlai 66:390c4a31db54 51 template<typename T>
devanlai 66:390c4a31db54 52 void attach(T* tptr, void (T::*mptr)(void)) {
devanlai 66:390c4a31db54 53 if((mptr != NULL) && (tptr != NULL)) {
devanlai 66:390c4a31db54 54 detach.attach(tptr, mptr);
devanlai 66:390c4a31db54 55 }
devanlai 66:390c4a31db54 56 }
devanlai 66:390c4a31db54 57
devanlai 66:390c4a31db54 58 /**
devanlai 66:390c4a31db54 59 * Attach a callback called when a DFU detach request is received
devanlai 66:390c4a31db54 60 *
devanlai 66:390c4a31db54 61 * @param func function pointer
devanlai 66:390c4a31db54 62 */
devanlai 66:390c4a31db54 63 void attach(Callback<void()> func);
devanlai 66:390c4a31db54 64
devanlai 66:390c4a31db54 65 protected:
devanlai 66:390c4a31db54 66 uint16_t reportLength;
devanlai 66:390c4a31db54 67
devanlai 66:390c4a31db54 68 /*
devanlai 66:390c4a31db54 69 * Get string product descriptor
devanlai 66:390c4a31db54 70 *
devanlai 66:390c4a31db54 71 * @returns pointer to the string product descriptor
devanlai 66:390c4a31db54 72 */
devanlai 66:390c4a31db54 73 virtual uint8_t * stringIproductDesc();
devanlai 66:390c4a31db54 74
devanlai 66:390c4a31db54 75 /*
devanlai 66:390c4a31db54 76 * Get string interface descriptor
devanlai 66:390c4a31db54 77 *
devanlai 66:390c4a31db54 78 * @returns pointer to the string interface descriptor
devanlai 66:390c4a31db54 79 */
devanlai 66:390c4a31db54 80 virtual uint8_t * stringIinterfaceDesc();
devanlai 66:390c4a31db54 81
devanlai 66:390c4a31db54 82 /*
devanlai 66:390c4a31db54 83 * Get configuration descriptor
devanlai 66:390c4a31db54 84 *
devanlai 66:390c4a31db54 85 * @returns pointer to the configuration descriptor
devanlai 66:390c4a31db54 86 */
devanlai 66:390c4a31db54 87 virtual uint8_t * configurationDesc();
devanlai 66:390c4a31db54 88
devanlai 66:390c4a31db54 89 /*
devanlai 66:390c4a31db54 90 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
devanlai 66:390c4a31db54 91 * This is used to handle extensions to standard requests
devanlai 66:390c4a31db54 92 * and class specific requests
devanlai 66:390c4a31db54 93 *
devanlai 66:390c4a31db54 94 * @returns true if class handles this request
devanlai 66:390c4a31db54 95 */
devanlai 66:390c4a31db54 96 virtual bool USBCallback_request();
devanlai 66:390c4a31db54 97
devanlai 66:390c4a31db54 98
devanlai 66:390c4a31db54 99 /*
devanlai 66:390c4a31db54 100 * Called by USBDevice layer. Set configuration of the device.
devanlai 66:390c4a31db54 101 * For instance, you can add all endpoints that you need on this function.
devanlai 66:390c4a31db54 102 *
devanlai 66:390c4a31db54 103 * @param configuration Number of the configuration
devanlai 66:390c4a31db54 104 * @returns true if class handles this request
devanlai 66:390c4a31db54 105 */
devanlai 66:390c4a31db54 106 virtual bool USBCallback_setConfiguration(uint8_t configuration);
devanlai 66:390c4a31db54 107
devanlai 66:390c4a31db54 108 private:
devanlai 66:390c4a31db54 109 Callback<void()> detach;
devanlai 66:390c4a31db54 110
devanlai 66:390c4a31db54 111 static void no_op() {};
devanlai 66:390c4a31db54 112 };
devanlai 66:390c4a31db54 113
devanlai 66:390c4a31db54 114 #endif