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