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