Fork of the official USBDevice library

Fork of USBDevice by mbed official

Committer:
screamer
Date:
Fri Apr 28 17:01:10 2017 +0000
Branch:
device-files
Revision:
76:f0fd8d911b24
Parent:
73:8d28a0cb7b43
Changed the layout of USBDevice implementation for various targets to match mbed-os/targets. This also reduces the amount of files being compiled as USBDevice code for other targets is not compiled.

Who changed what in which revision?

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