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