1 /* Copyright (c) 2010-2011 mbed.org, MIT License
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 /* These headers are included for child class. */
23 #include "USBEndpoints.h"
24 #include "USBDescriptor.h"
25 #include "USBDevice_Types.h"
27 #include "USBDevice.h"
29 class USBCDC: public USBDevice {
35 * @param vendor_id Your vendor_id
36 * @param product_id Your product_id
37 * @param product_release Your preoduct_release
38 * @param connect_blocking define if the connection must be blocked if USB not plugged in
40 USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
45 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
47 * @returns pointer to the device descriptor
49 virtual uint8_t * deviceDesc();
52 * Get string product descriptor
54 * @returns pointer to the string product descriptor
56 virtual uint8_t * stringIproductDesc();
59 * Get string interface descriptor
61 * @returns pointer to the string interface descriptor
63 virtual uint8_t * stringIinterfaceDesc();
66 * Get configuration descriptor
68 * @returns pointer to the configuration descriptor
70 virtual uint8_t * configurationDesc();
75 * @param endpoint endpoint which will be sent the buffer
76 * @param buffer buffer to be sent
77 * @param size length of the buffer
78 * @returns true if successful
80 bool send(uint8_t * buffer, uint32_t size);
83 * Read a buffer from a certain endpoint. Warning: blocking
85 * @param endpoint endpoint to read
86 * @param buffer buffer where will be stored bytes
87 * @param size the number of bytes read will be stored in *size
88 * @param maxSize the maximum length that can be read
89 * @returns true if successful
91 bool readEP(uint8_t * buffer, uint32_t * size);
94 * Read a buffer from a certain endpoint. Warning: non blocking
96 * @param endpoint endpoint to read
97 * @param buffer buffer where will be stored bytes
98 * @param size the number of bytes read will be stored in *size
99 * @param maxSize the maximum length that can be read
100 * @returns true if successful
102 bool readEP_NB(uint8_t * buffer, uint32_t * size);
105 * Called by USBCallback_requestCompleted when CDC line coding is changed
106 * Warning: Called in ISR
108 * @param baud The baud rate
109 * @param bits The number of bits in a word (5-8)
110 * @param parity The parity
111 * @param stop The number of stop bits (1 or 2)
113 virtual void lineCodingChanged(int baud, int bits, int parity, int stop) {};
116 virtual bool USBCallback_request();
117 virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length);
118 virtual bool USBCallback_setConfiguration(uint8_t configuration);
119 volatile bool terminal_connected;