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