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
USBDFU/WebUSBDFU.h@67:39396cc073f2, 2016-09-04 (annotated)
- Committer:
- devanlai
- Date:
- Sun Sep 04 03:13:09 2016 +0000
- Revision:
- 67:39396cc073f2
Add WebUSBDevice and WebUSBDFU classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
devanlai | 67:39396cc073f2 | 1 | /* |
devanlai | 67:39396cc073f2 | 2 | * Copyright 2016 Devan Lai |
devanlai | 67:39396cc073f2 | 3 | * |
devanlai | 67:39396cc073f2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
devanlai | 67:39396cc073f2 | 5 | * you may not use this file except in compliance with the License. |
devanlai | 67:39396cc073f2 | 6 | * You may obtain a copy of the License at |
devanlai | 67:39396cc073f2 | 7 | * |
devanlai | 67:39396cc073f2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
devanlai | 67:39396cc073f2 | 9 | * |
devanlai | 67:39396cc073f2 | 10 | * Unless required by applicable law or agreed to in writing, software |
devanlai | 67:39396cc073f2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
devanlai | 67:39396cc073f2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
devanlai | 67:39396cc073f2 | 13 | * See the License for the specific language governing permissions and |
devanlai | 67:39396cc073f2 | 14 | * limitations under the License. |
devanlai | 67:39396cc073f2 | 15 | */ |
devanlai | 67:39396cc073f2 | 16 | |
devanlai | 67:39396cc073f2 | 17 | #ifndef WEB_USB_DFU_H |
devanlai | 67:39396cc073f2 | 18 | #define WEB_USB_DFU_H |
devanlai | 67:39396cc073f2 | 19 | |
devanlai | 67:39396cc073f2 | 20 | #include "WebUSBDevice.h" |
devanlai | 67:39396cc073f2 | 21 | |
devanlai | 67:39396cc073f2 | 22 | class WebUSBDFU : public WebUSBDevice { |
devanlai | 67:39396cc073f2 | 23 | public: |
devanlai | 67:39396cc073f2 | 24 | /** |
devanlai | 67:39396cc073f2 | 25 | * Constructor |
devanlai | 67:39396cc073f2 | 26 | * |
devanlai | 67:39396cc073f2 | 27 | * @param vendor_id Your vendor_id |
devanlai | 67:39396cc073f2 | 28 | * @param product_id Your product_id |
devanlai | 67:39396cc073f2 | 29 | * @param product_release Your product_release |
devanlai | 67:39396cc073f2 | 30 | * @param connect Connect the device |
devanlai | 67:39396cc073f2 | 31 | */ |
devanlai | 67:39396cc073f2 | 32 | WebUSBDFU(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true); |
devanlai | 67:39396cc073f2 | 33 | |
devanlai | 67:39396cc073f2 | 34 | /** |
devanlai | 67:39396cc073f2 | 35 | * Attach a callback called when a DFU detach request is received |
devanlai | 67:39396cc073f2 | 36 | * |
devanlai | 67:39396cc073f2 | 37 | * @param tptr pointer to the object to call the member function on |
devanlai | 67:39396cc073f2 | 38 | * @param mptr pointer to the member function to be called |
devanlai | 67:39396cc073f2 | 39 | */ |
devanlai | 67:39396cc073f2 | 40 | template<typename T> |
devanlai | 67:39396cc073f2 | 41 | void attach(T* tptr, void (T::*mptr)(void)) { |
devanlai | 67:39396cc073f2 | 42 | if((mptr != NULL) && (tptr != NULL)) { |
devanlai | 67:39396cc073f2 | 43 | detach.attach(tptr, mptr); |
devanlai | 67:39396cc073f2 | 44 | } |
devanlai | 67:39396cc073f2 | 45 | } |
devanlai | 67:39396cc073f2 | 46 | |
devanlai | 67:39396cc073f2 | 47 | /** |
devanlai | 67:39396cc073f2 | 48 | * Attach a callback called when a DFU detach request is received |
devanlai | 67:39396cc073f2 | 49 | * |
devanlai | 67:39396cc073f2 | 50 | * @param func function pointer |
devanlai | 67:39396cc073f2 | 51 | */ |
devanlai | 67:39396cc073f2 | 52 | void attach(Callback<void()> func); |
devanlai | 67:39396cc073f2 | 53 | |
devanlai | 67:39396cc073f2 | 54 | protected: |
devanlai | 67:39396cc073f2 | 55 | /* |
devanlai | 67:39396cc073f2 | 56 | * Get string product descriptor |
devanlai | 67:39396cc073f2 | 57 | * |
devanlai | 67:39396cc073f2 | 58 | * @returns pointer to the string product descriptor |
devanlai | 67:39396cc073f2 | 59 | */ |
devanlai | 67:39396cc073f2 | 60 | virtual uint8_t * stringIproductDesc(); |
devanlai | 67:39396cc073f2 | 61 | |
devanlai | 67:39396cc073f2 | 62 | /* |
devanlai | 67:39396cc073f2 | 63 | * Get string interface descriptor |
devanlai | 67:39396cc073f2 | 64 | * |
devanlai | 67:39396cc073f2 | 65 | * @returns pointer to the string interface descriptor |
devanlai | 67:39396cc073f2 | 66 | */ |
devanlai | 67:39396cc073f2 | 67 | virtual uint8_t * stringIinterfaceDesc(); |
devanlai | 67:39396cc073f2 | 68 | |
devanlai | 67:39396cc073f2 | 69 | /* |
devanlai | 67:39396cc073f2 | 70 | * Get configuration descriptor |
devanlai | 67:39396cc073f2 | 71 | * |
devanlai | 67:39396cc073f2 | 72 | * @returns pointer to the configuration descriptor |
devanlai | 67:39396cc073f2 | 73 | */ |
devanlai | 67:39396cc073f2 | 74 | virtual uint8_t * configurationDesc(); |
devanlai | 67:39396cc073f2 | 75 | |
devanlai | 67:39396cc073f2 | 76 | /* |
devanlai | 67:39396cc073f2 | 77 | * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context |
devanlai | 67:39396cc073f2 | 78 | * This is used to handle extensions to standard requests |
devanlai | 67:39396cc073f2 | 79 | * and class specific requests |
devanlai | 67:39396cc073f2 | 80 | * |
devanlai | 67:39396cc073f2 | 81 | * @returns true if class handles this request |
devanlai | 67:39396cc073f2 | 82 | */ |
devanlai | 67:39396cc073f2 | 83 | virtual bool USBCallback_request(); |
devanlai | 67:39396cc073f2 | 84 | |
devanlai | 67:39396cc073f2 | 85 | /* |
devanlai | 67:39396cc073f2 | 86 | * Called by USBDevice layer. Set configuration of the device. |
devanlai | 67:39396cc073f2 | 87 | * For instance, you can add all endpoints that you need on this function. |
devanlai | 67:39396cc073f2 | 88 | * |
devanlai | 67:39396cc073f2 | 89 | * @param configuration Number of the configuration |
devanlai | 67:39396cc073f2 | 90 | * @returns true if class handles this request |
devanlai | 67:39396cc073f2 | 91 | */ |
devanlai | 67:39396cc073f2 | 92 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
devanlai | 67:39396cc073f2 | 93 | |
devanlai | 67:39396cc073f2 | 94 | /* |
devanlai | 67:39396cc073f2 | 95 | * Get the WebUSB allowed origin descriptor |
devanlai | 67:39396cc073f2 | 96 | * |
devanlai | 67:39396cc073f2 | 97 | * @returns pointer to the WebUSB allowed origin descriptor |
devanlai | 67:39396cc073f2 | 98 | */ |
devanlai | 67:39396cc073f2 | 99 | virtual uint8_t * allowedOriginsDesc(); |
devanlai | 67:39396cc073f2 | 100 | |
devanlai | 67:39396cc073f2 | 101 | /* |
devanlai | 67:39396cc073f2 | 102 | * Get WebUSB landing page URL descriptor |
devanlai | 67:39396cc073f2 | 103 | * |
devanlai | 67:39396cc073f2 | 104 | * @returns pointer to the landing page URL descriptor |
devanlai | 67:39396cc073f2 | 105 | */ |
devanlai | 67:39396cc073f2 | 106 | virtual uint8_t * urlIlandingPage(); |
devanlai | 67:39396cc073f2 | 107 | |
devanlai | 67:39396cc073f2 | 108 | /* |
devanlai | 67:39396cc073f2 | 109 | * Get WebUSB allowed origin URL descriptor |
devanlai | 67:39396cc073f2 | 110 | * |
devanlai | 67:39396cc073f2 | 111 | * @returns pointer to the allowed origin URL descriptor |
devanlai | 67:39396cc073f2 | 112 | */ |
devanlai | 67:39396cc073f2 | 113 | virtual uint8_t * urlIallowedOrigin(); |
devanlai | 67:39396cc073f2 | 114 | |
devanlai | 67:39396cc073f2 | 115 | private: |
devanlai | 67:39396cc073f2 | 116 | Callback<void()> detach; |
devanlai | 67:39396cc073f2 | 117 | |
devanlai | 67:39396cc073f2 | 118 | static void no_op() {}; |
devanlai | 67:39396cc073f2 | 119 | }; |
devanlai | 67:39396cc073f2 | 120 | |
devanlai | 67:39396cc073f2 | 121 | #endif |