USB CDC (serial) and USB MSC (strage) Composite Device. http://mbed.org/users/okini3939/notebook/USB_Device/
Dependencies: ChaNFSSD mbed ChaNFS
USBDevice/USBSERIAL/USBSerial.cpp@2:5db90410bb90, 2011-12-23 (annotated)
- Committer:
- okini3939
- Date:
- Fri Dec 23 16:37:58 2011 +0000
- Revision:
- 2:5db90410bb90
- Parent:
- 0:9b1d17d54055
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:9b1d17d54055 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
okini3939 | 0:9b1d17d54055 | 2 | * |
okini3939 | 0:9b1d17d54055 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
okini3939 | 0:9b1d17d54055 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
okini3939 | 0:9b1d17d54055 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
okini3939 | 0:9b1d17d54055 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
okini3939 | 0:9b1d17d54055 | 7 | * Software is furnished to do so, subject to the following conditions: |
okini3939 | 0:9b1d17d54055 | 8 | * |
okini3939 | 0:9b1d17d54055 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
okini3939 | 0:9b1d17d54055 | 10 | * substantial portions of the Software. |
okini3939 | 0:9b1d17d54055 | 11 | * |
okini3939 | 0:9b1d17d54055 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
okini3939 | 0:9b1d17d54055 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
okini3939 | 0:9b1d17d54055 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
okini3939 | 0:9b1d17d54055 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
okini3939 | 0:9b1d17d54055 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
okini3939 | 0:9b1d17d54055 | 17 | */ |
okini3939 | 0:9b1d17d54055 | 18 | |
okini3939 | 0:9b1d17d54055 | 19 | #include "stdint.h" |
okini3939 | 0:9b1d17d54055 | 20 | #include "USBSerial.h" |
okini3939 | 0:9b1d17d54055 | 21 | #include "USBBusInterface.h" |
okini3939 | 0:9b1d17d54055 | 22 | |
okini3939 | 0:9b1d17d54055 | 23 | |
okini3939 | 0:9b1d17d54055 | 24 | int USBSerial::_putc(int c) { |
okini3939 | 0:9b1d17d54055 | 25 | send((uint8_t *)&c, 1); |
okini3939 | 0:9b1d17d54055 | 26 | return 1; |
okini3939 | 0:9b1d17d54055 | 27 | } |
okini3939 | 0:9b1d17d54055 | 28 | |
okini3939 | 0:9b1d17d54055 | 29 | int USBSerial::_getc() { |
okini3939 | 0:9b1d17d54055 | 30 | uint8_t c; |
okini3939 | 0:9b1d17d54055 | 31 | while (buf.isEmpty()); |
okini3939 | 0:9b1d17d54055 | 32 | buf.dequeue(&c); |
okini3939 | 0:9b1d17d54055 | 33 | return c; |
okini3939 | 0:9b1d17d54055 | 34 | } |
okini3939 | 0:9b1d17d54055 | 35 | |
okini3939 | 0:9b1d17d54055 | 36 | |
okini3939 | 0:9b1d17d54055 | 37 | bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) { |
okini3939 | 0:9b1d17d54055 | 38 | if(size > MAX_PACKET_SIZE_EPBULK) { |
okini3939 | 0:9b1d17d54055 | 39 | return false; |
okini3939 | 0:9b1d17d54055 | 40 | } |
okini3939 | 0:9b1d17d54055 | 41 | if(!send(buf, size)) { |
okini3939 | 0:9b1d17d54055 | 42 | return false; |
okini3939 | 0:9b1d17d54055 | 43 | } |
okini3939 | 0:9b1d17d54055 | 44 | return true; |
okini3939 | 0:9b1d17d54055 | 45 | } |
okini3939 | 0:9b1d17d54055 | 46 | |
okini3939 | 0:9b1d17d54055 | 47 | |
okini3939 | 0:9b1d17d54055 | 48 | |
okini3939 | 0:9b1d17d54055 | 49 | bool USBSerial::EP2_OUT_callback() { |
okini3939 | 0:9b1d17d54055 | 50 | uint8_t c[65]; |
okini3939 | 0:9b1d17d54055 | 51 | uint16_t size = 0; |
okini3939 | 0:9b1d17d54055 | 52 | |
okini3939 | 0:9b1d17d54055 | 53 | //we read the packet received and put it on the circular buffer |
okini3939 | 0:9b1d17d54055 | 54 | readEP(c, &size); |
okini3939 | 0:9b1d17d54055 | 55 | for (int i = 0; i < size; i++) { |
okini3939 | 0:9b1d17d54055 | 56 | buf.queue(c[i]); |
okini3939 | 0:9b1d17d54055 | 57 | } |
okini3939 | 0:9b1d17d54055 | 58 | |
okini3939 | 0:9b1d17d54055 | 59 | //call a potential handler |
okini3939 | 0:9b1d17d54055 | 60 | rx.call(); |
okini3939 | 0:9b1d17d54055 | 61 | |
okini3939 | 0:9b1d17d54055 | 62 | // We reactivate the endpoint to receive next characters |
okini3939 | 0:9b1d17d54055 | 63 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
okini3939 | 0:9b1d17d54055 | 64 | return true; |
okini3939 | 0:9b1d17d54055 | 65 | } |
okini3939 | 0:9b1d17d54055 | 66 | |
okini3939 | 0:9b1d17d54055 | 67 | uint8_t USBSerial::available() { |
okini3939 | 0:9b1d17d54055 | 68 | return buf.available(); |
okini3939 | 0:9b1d17d54055 | 69 | } |
okini3939 | 0:9b1d17d54055 | 70 |