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