A copy of the mbed USBDevice with USBSerial library
Dependents: STM32L0_LoRa Smartage STM32L0_LoRa Turtle_RadioShuttle
USBSerial.cpp
00001 #include "mbed.h" 00002 #include "PinMap.h" 00003 00004 #ifdef FEATURE_USBSERIAL 00005 00006 /* Copyright (c) 2010-2011 mbed.org, MIT License 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00009 * and associated documentation files (the "Software"), to deal in the Software without 00010 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00011 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in all copies or 00015 * substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00018 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00020 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 */ 00023 00024 #include "stdint.h" 00025 #include "USBSerial.h" 00026 00027 int USBSerial::_putc(int c) { 00028 if (!terminal_connected) 00029 return 0; 00030 send((uint8_t *)&c, 1); 00031 return 1; 00032 } 00033 00034 int USBSerial::_getc() { 00035 uint8_t c = 0; 00036 while (buf.isEmpty()); 00037 buf.dequeue(&c); 00038 return c; 00039 } 00040 00041 00042 bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) { 00043 if(size > MAX_PACKET_SIZE_EPBULK) { 00044 return false; 00045 } 00046 if(!send(buf, size)) { 00047 return false; 00048 } 00049 return true; 00050 } 00051 00052 00053 00054 bool USBSerial::EPBULK_OUT_callback() { 00055 uint8_t c[65]; 00056 uint32_t size = 0; 00057 00058 //we read the packet received and put it on the circular buffer 00059 readEP(c, &size); 00060 for (uint32_t i = 0; i < size; i++) { 00061 buf.queue(c[i]); 00062 } 00063 00064 //call a potential handlenr 00065 if (rx) 00066 rx.call(); 00067 00068 return true; 00069 } 00070 00071 uint8_t USBSerial::available() { 00072 return buf.available(); 00073 } 00074 00075 bool USBSerial::connected() { 00076 return terminal_connected; 00077 } 00078 00079 #endif // FEATURE_USBSERIAL
Generated on Fri Jul 15 2022 20:07:58 by 1.7.2