USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
tests/USBMSD2/USB_CDC.h@1:ea8e179320d7, 2013-09-28 (annotated)
- Committer:
- va009039
- Date:
- Sat Sep 28 03:21:14 2013 +0000
- Revision:
- 1:ea8e179320d7
add USBMSD_Drop class. add CDC(Virtual COM) and HID(for example CMSIS-DAP), but KL25Z not work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:ea8e179320d7 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
va009039 | 1:ea8e179320d7 | 2 | * |
va009039 | 1:ea8e179320d7 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
va009039 | 1:ea8e179320d7 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
va009039 | 1:ea8e179320d7 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
va009039 | 1:ea8e179320d7 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
va009039 | 1:ea8e179320d7 | 7 | * Software is furnished to do so, subject to the following conditions: |
va009039 | 1:ea8e179320d7 | 8 | * |
va009039 | 1:ea8e179320d7 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
va009039 | 1:ea8e179320d7 | 10 | * substantial portions of the Software. |
va009039 | 1:ea8e179320d7 | 11 | * |
va009039 | 1:ea8e179320d7 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
va009039 | 1:ea8e179320d7 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
va009039 | 1:ea8e179320d7 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
va009039 | 1:ea8e179320d7 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
va009039 | 1:ea8e179320d7 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
va009039 | 1:ea8e179320d7 | 17 | */ |
va009039 | 1:ea8e179320d7 | 18 | |
va009039 | 1:ea8e179320d7 | 19 | #pragma once |
va009039 | 1:ea8e179320d7 | 20 | |
va009039 | 1:ea8e179320d7 | 21 | /* These headers are included for child class. */ |
va009039 | 1:ea8e179320d7 | 22 | #include "USBEndpoints.h" |
va009039 | 1:ea8e179320d7 | 23 | #include "USBDescriptor.h" |
va009039 | 1:ea8e179320d7 | 24 | #include "USBDevice_Types.h" |
va009039 | 1:ea8e179320d7 | 25 | |
va009039 | 1:ea8e179320d7 | 26 | #include "USBDevice.h" |
va009039 | 1:ea8e179320d7 | 27 | #include "CircBuffer.h" |
va009039 | 1:ea8e179320d7 | 28 | |
va009039 | 1:ea8e179320d7 | 29 | #define CDC_EPINT_IN EP1IN |
va009039 | 1:ea8e179320d7 | 30 | #define CDC_EPBULK_IN EP5IN |
va009039 | 1:ea8e179320d7 | 31 | #define CDC_EPBULK_OUT EP5OUT |
va009039 | 1:ea8e179320d7 | 32 | |
va009039 | 1:ea8e179320d7 | 33 | class USB_CDC { |
va009039 | 1:ea8e179320d7 | 34 | public: |
va009039 | 1:ea8e179320d7 | 35 | USB_CDC(USBDevice* device); |
va009039 | 1:ea8e179320d7 | 36 | |
va009039 | 1:ea8e179320d7 | 37 | /** target to virtual COM |
va009039 | 1:ea8e179320d7 | 38 | */ |
va009039 | 1:ea8e179320d7 | 39 | void putc(int c); |
va009039 | 1:ea8e179320d7 | 40 | |
va009039 | 1:ea8e179320d7 | 41 | /** virtial COM to target |
va009039 | 1:ea8e179320d7 | 42 | */ |
va009039 | 1:ea8e179320d7 | 43 | int getc(); |
va009039 | 1:ea8e179320d7 | 44 | |
va009039 | 1:ea8e179320d7 | 45 | int readable(); |
va009039 | 1:ea8e179320d7 | 46 | |
va009039 | 1:ea8e179320d7 | 47 | int writeable(); |
va009039 | 1:ea8e179320d7 | 48 | |
va009039 | 1:ea8e179320d7 | 49 | void baud_callback(int baudrate); |
va009039 | 1:ea8e179320d7 | 50 | void send_break_callback(uint16_t duration); |
va009039 | 1:ea8e179320d7 | 51 | void control_line_callback(int rts, int dtr); |
va009039 | 1:ea8e179320d7 | 52 | |
va009039 | 1:ea8e179320d7 | 53 | /* |
va009039 | 1:ea8e179320d7 | 54 | * Send a buffer |
va009039 | 1:ea8e179320d7 | 55 | * |
va009039 | 1:ea8e179320d7 | 56 | * @param endpoint endpoint which will be sent the buffer |
va009039 | 1:ea8e179320d7 | 57 | * @param buffer buffer to be sent |
va009039 | 1:ea8e179320d7 | 58 | * @param size length of the buffer |
va009039 | 1:ea8e179320d7 | 59 | * @returns true if successful |
va009039 | 1:ea8e179320d7 | 60 | */ |
va009039 | 1:ea8e179320d7 | 61 | bool send(uint8_t * buffer, uint32_t size); |
va009039 | 1:ea8e179320d7 | 62 | |
va009039 | 1:ea8e179320d7 | 63 | /* |
va009039 | 1:ea8e179320d7 | 64 | * Read a buffer from a certain endpoint. Warning: blocking |
va009039 | 1:ea8e179320d7 | 65 | * |
va009039 | 1:ea8e179320d7 | 66 | * @param endpoint endpoint to read |
va009039 | 1:ea8e179320d7 | 67 | * @param buffer buffer where will be stored bytes |
va009039 | 1:ea8e179320d7 | 68 | * @param size the number of bytes read will be stored in *size |
va009039 | 1:ea8e179320d7 | 69 | * @param maxSize the maximum length that can be read |
va009039 | 1:ea8e179320d7 | 70 | * @returns true if successful |
va009039 | 1:ea8e179320d7 | 71 | */ |
va009039 | 1:ea8e179320d7 | 72 | bool readEP(uint8_t * buffer, uint32_t * size); |
va009039 | 1:ea8e179320d7 | 73 | |
va009039 | 1:ea8e179320d7 | 74 | /* |
va009039 | 1:ea8e179320d7 | 75 | * Read a buffer from a certain endpoint. Warning: non blocking |
va009039 | 1:ea8e179320d7 | 76 | * |
va009039 | 1:ea8e179320d7 | 77 | * @param endpoint endpoint to read |
va009039 | 1:ea8e179320d7 | 78 | * @param buffer buffer where will be stored bytes |
va009039 | 1:ea8e179320d7 | 79 | * @param size the number of bytes read will be stored in *size |
va009039 | 1:ea8e179320d7 | 80 | * @param maxSize the maximum length that can be read |
va009039 | 1:ea8e179320d7 | 81 | * @returns true if successful |
va009039 | 1:ea8e179320d7 | 82 | */ |
va009039 | 1:ea8e179320d7 | 83 | bool readEP_NB(uint8_t * buffer, uint32_t * size); |
va009039 | 1:ea8e179320d7 | 84 | |
va009039 | 1:ea8e179320d7 | 85 | bool Request_callback(CONTROL_TRANSFER* transfer); |
va009039 | 1:ea8e179320d7 | 86 | bool RequestCompleted_callback(CONTROL_TRANSFER* transfer, uint8_t* buf, int length); |
va009039 | 1:ea8e179320d7 | 87 | bool EPBULK_OUT_callback(); |
va009039 | 1:ea8e179320d7 | 88 | |
va009039 | 1:ea8e179320d7 | 89 | protected: |
va009039 | 1:ea8e179320d7 | 90 | USBDevice* _device; |
va009039 | 1:ea8e179320d7 | 91 | CircBuffer<uint8_t> _rx_buf; |
va009039 | 1:ea8e179320d7 | 92 | volatile bool terminal_connected; |
va009039 | 1:ea8e179320d7 | 93 | }; |