,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Thu Feb 15 14:29:23 2018 +0000
Revision:
15:2a20c3d2616e
Parent:
10:41552d038a69
j

Who changed what in which revision?

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