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