partly working USB Device lib for STM32F746NG Discovery both Interface are working
Dependents: DISCO-F746NG-USB_Device McLighTT project_Keyboard_to_the_Keyboard MIDIInstrumentPADProject ... more
USBSerial/USBCDC.h@0:0a2eaa300982, 2016-07-31 (annotated)
- Committer:
- DieterGraef
- Date:
- Sun Jul 31 17:47:35 2016 +0000
- Revision:
- 0:0a2eaa300982
partly working USB Device library - serial and MIDI is working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:0a2eaa300982 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
DieterGraef | 0:0a2eaa300982 | 2 | * |
DieterGraef | 0:0a2eaa300982 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
DieterGraef | 0:0a2eaa300982 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
DieterGraef | 0:0a2eaa300982 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
DieterGraef | 0:0a2eaa300982 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
DieterGraef | 0:0a2eaa300982 | 7 | * Software is furnished to do so, subject to the following conditions: |
DieterGraef | 0:0a2eaa300982 | 8 | * |
DieterGraef | 0:0a2eaa300982 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
DieterGraef | 0:0a2eaa300982 | 10 | * substantial portions of the Software. |
DieterGraef | 0:0a2eaa300982 | 11 | * |
DieterGraef | 0:0a2eaa300982 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
DieterGraef | 0:0a2eaa300982 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
DieterGraef | 0:0a2eaa300982 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
DieterGraef | 0:0a2eaa300982 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DieterGraef | 0:0a2eaa300982 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
DieterGraef | 0:0a2eaa300982 | 17 | */ |
DieterGraef | 0:0a2eaa300982 | 18 | |
DieterGraef | 0:0a2eaa300982 | 19 | #ifndef USBCDC_H |
DieterGraef | 0:0a2eaa300982 | 20 | #define USBCDC_H |
DieterGraef | 0:0a2eaa300982 | 21 | |
DieterGraef | 0:0a2eaa300982 | 22 | /* These headers are included for child class. */ |
DieterGraef | 0:0a2eaa300982 | 23 | #include "USBEndpoints.h" |
DieterGraef | 0:0a2eaa300982 | 24 | #include "USBDescriptor.h" |
DieterGraef | 0:0a2eaa300982 | 25 | #include "USBDevice_Types.h" |
DieterGraef | 0:0a2eaa300982 | 26 | |
DieterGraef | 0:0a2eaa300982 | 27 | #include "USBDevice.h" |
DieterGraef | 0:0a2eaa300982 | 28 | |
DieterGraef | 0:0a2eaa300982 | 29 | class USBCDC: public USBDevice { |
DieterGraef | 0:0a2eaa300982 | 30 | public: |
DieterGraef | 0:0a2eaa300982 | 31 | |
DieterGraef | 0:0a2eaa300982 | 32 | /* |
DieterGraef | 0:0a2eaa300982 | 33 | * Constructor |
DieterGraef | 0:0a2eaa300982 | 34 | * |
DieterGraef | 0:0a2eaa300982 | 35 | * @param vendor_id Your vendor_id |
DieterGraef | 0:0a2eaa300982 | 36 | * @param product_id Your product_id |
DieterGraef | 0:0a2eaa300982 | 37 | * @param product_release Your preoduct_release |
DieterGraef | 0:0a2eaa300982 | 38 | * @param connect_blocking define if the connection must be blocked if USB not plugged in |
DieterGraef | 0:0a2eaa300982 | 39 | */ |
DieterGraef | 0:0a2eaa300982 | 40 | USBCDC(uint16_t HW_Interface,uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking); |
DieterGraef | 0:0a2eaa300982 | 41 | |
DieterGraef | 0:0a2eaa300982 | 42 | protected: |
DieterGraef | 0:0a2eaa300982 | 43 | |
DieterGraef | 0:0a2eaa300982 | 44 | /* |
DieterGraef | 0:0a2eaa300982 | 45 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
DieterGraef | 0:0a2eaa300982 | 46 | * |
DieterGraef | 0:0a2eaa300982 | 47 | * @returns pointer to the device descriptor |
DieterGraef | 0:0a2eaa300982 | 48 | */ |
DieterGraef | 0:0a2eaa300982 | 49 | virtual uint8_t * deviceDesc(); |
DieterGraef | 0:0a2eaa300982 | 50 | |
DieterGraef | 0:0a2eaa300982 | 51 | /* |
DieterGraef | 0:0a2eaa300982 | 52 | * Get string product descriptor |
DieterGraef | 0:0a2eaa300982 | 53 | * |
DieterGraef | 0:0a2eaa300982 | 54 | * @returns pointer to the string product descriptor |
DieterGraef | 0:0a2eaa300982 | 55 | */ |
DieterGraef | 0:0a2eaa300982 | 56 | virtual uint8_t * stringIproductDesc(); |
DieterGraef | 0:0a2eaa300982 | 57 | |
DieterGraef | 0:0a2eaa300982 | 58 | /* |
DieterGraef | 0:0a2eaa300982 | 59 | * Get string interface descriptor |
DieterGraef | 0:0a2eaa300982 | 60 | * |
DieterGraef | 0:0a2eaa300982 | 61 | * @returns pointer to the string interface descriptor |
DieterGraef | 0:0a2eaa300982 | 62 | */ |
DieterGraef | 0:0a2eaa300982 | 63 | virtual uint8_t * stringIinterfaceDesc(); |
DieterGraef | 0:0a2eaa300982 | 64 | |
DieterGraef | 0:0a2eaa300982 | 65 | /* |
DieterGraef | 0:0a2eaa300982 | 66 | * Get configuration descriptor |
DieterGraef | 0:0a2eaa300982 | 67 | * |
DieterGraef | 0:0a2eaa300982 | 68 | * @returns pointer to the configuration descriptor |
DieterGraef | 0:0a2eaa300982 | 69 | */ |
DieterGraef | 0:0a2eaa300982 | 70 | virtual uint8_t * configurationDesc(); |
DieterGraef | 0:0a2eaa300982 | 71 | |
DieterGraef | 0:0a2eaa300982 | 72 | /* |
DieterGraef | 0:0a2eaa300982 | 73 | * Send a buffer |
DieterGraef | 0:0a2eaa300982 | 74 | * |
DieterGraef | 0:0a2eaa300982 | 75 | * @param endpoint endpoint which will be sent the buffer |
DieterGraef | 0:0a2eaa300982 | 76 | * @param buffer buffer to be sent |
DieterGraef | 0:0a2eaa300982 | 77 | * @param size length of the buffer |
DieterGraef | 0:0a2eaa300982 | 78 | * @returns true if successful |
DieterGraef | 0:0a2eaa300982 | 79 | */ |
DieterGraef | 0:0a2eaa300982 | 80 | bool send(uint8_t * buffer, uint32_t size); |
DieterGraef | 0:0a2eaa300982 | 81 | |
DieterGraef | 0:0a2eaa300982 | 82 | /* |
DieterGraef | 0:0a2eaa300982 | 83 | * Read a buffer from a certain endpoint. Warning: blocking |
DieterGraef | 0:0a2eaa300982 | 84 | * |
DieterGraef | 0:0a2eaa300982 | 85 | * @param endpoint endpoint to read |
DieterGraef | 0:0a2eaa300982 | 86 | * @param buffer buffer where will be stored bytes |
DieterGraef | 0:0a2eaa300982 | 87 | * @param size the number of bytes read will be stored in *size |
DieterGraef | 0:0a2eaa300982 | 88 | * @param maxSize the maximum length that can be read |
DieterGraef | 0:0a2eaa300982 | 89 | * @returns true if successful |
DieterGraef | 0:0a2eaa300982 | 90 | */ |
DieterGraef | 0:0a2eaa300982 | 91 | bool readEP(uint8_t * buffer, uint32_t * size); |
DieterGraef | 0:0a2eaa300982 | 92 | |
DieterGraef | 0:0a2eaa300982 | 93 | /* |
DieterGraef | 0:0a2eaa300982 | 94 | * Read a buffer from a certain endpoint. Warning: non blocking |
DieterGraef | 0:0a2eaa300982 | 95 | * |
DieterGraef | 0:0a2eaa300982 | 96 | * @param endpoint endpoint to read |
DieterGraef | 0:0a2eaa300982 | 97 | * @param buffer buffer where will be stored bytes |
DieterGraef | 0:0a2eaa300982 | 98 | * @param size the number of bytes read will be stored in *size |
DieterGraef | 0:0a2eaa300982 | 99 | * @param maxSize the maximum length that can be read |
DieterGraef | 0:0a2eaa300982 | 100 | * @returns true if successful |
DieterGraef | 0:0a2eaa300982 | 101 | */ |
DieterGraef | 0:0a2eaa300982 | 102 | bool readEP_NB(uint8_t * buffer, uint32_t * size); |
DieterGraef | 0:0a2eaa300982 | 103 | |
DieterGraef | 0:0a2eaa300982 | 104 | /* |
DieterGraef | 0:0a2eaa300982 | 105 | * Called by USBCallback_requestCompleted when CDC line coding is changed |
DieterGraef | 0:0a2eaa300982 | 106 | * Warning: Called in ISR |
DieterGraef | 0:0a2eaa300982 | 107 | * |
DieterGraef | 0:0a2eaa300982 | 108 | * @param baud The baud rate |
DieterGraef | 0:0a2eaa300982 | 109 | * @param bits The number of bits in a word (5-8) |
DieterGraef | 0:0a2eaa300982 | 110 | * @param parity The parity |
DieterGraef | 0:0a2eaa300982 | 111 | * @param stop The number of stop bits (1 or 2) |
DieterGraef | 0:0a2eaa300982 | 112 | */ |
DieterGraef | 0:0a2eaa300982 | 113 | virtual void lineCodingChanged(int baud, int bits, int parity, int stop) {}; |
DieterGraef | 0:0a2eaa300982 | 114 | |
DieterGraef | 0:0a2eaa300982 | 115 | protected: |
DieterGraef | 0:0a2eaa300982 | 116 | virtual bool USBCallback_request(); |
DieterGraef | 0:0a2eaa300982 | 117 | virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length); |
DieterGraef | 0:0a2eaa300982 | 118 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
DieterGraef | 0:0a2eaa300982 | 119 | volatile bool terminal_connected; |
DieterGraef | 0:0a2eaa300982 | 120 | |
DieterGraef | 0:0a2eaa300982 | 121 | }; |
DieterGraef | 0:0a2eaa300982 | 122 | |
DieterGraef | 0:0a2eaa300982 | 123 | #endif |