Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
USBSerial.cpp
00001 /* 00002 * Copyright (c) 2018-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "stdint.h" 00019 #include "USBSerial.h" 00020 #include "usb_phy_api.h" 00021 00022 00023 USBSerial::USBSerial(bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release): 00024 USBCDC(get_usb_phy(), vendor_id, product_id, product_release) 00025 { 00026 _settings_changed_callback = 0; 00027 00028 if (connect_blocking) { 00029 connect(); 00030 wait_ready(); 00031 } else { 00032 init(); 00033 } 00034 } 00035 00036 USBSerial::USBSerial(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release): 00037 USBCDC(phy, vendor_id, product_id, product_release) 00038 { 00039 _settings_changed_callback = 0; 00040 } 00041 00042 USBSerial::~USBSerial() 00043 { 00044 deinit(); 00045 } 00046 00047 int USBSerial::_putc(int c) 00048 { 00049 if (send((uint8_t *)&c, 1)) { 00050 return c; 00051 } else { 00052 return -1; 00053 } 00054 } 00055 00056 int USBSerial::_getc() 00057 { 00058 uint8_t c = 0; 00059 if (receive(&c, sizeof(c))) { 00060 return c; 00061 } else { 00062 return -1; 00063 } 00064 } 00065 00066 void USBSerial::data_rx() 00067 { 00068 assert_locked(); 00069 00070 //call a potential handler 00071 if (rx) { 00072 rx.call(); 00073 } 00074 } 00075 00076 uint8_t USBSerial::available() 00077 { 00078 USBCDC::lock(); 00079 00080 uint8_t size = 0; 00081 if (!_rx_in_progress) { 00082 size = _rx_size > 0xFF ? 0xFF : _rx_size; 00083 } 00084 00085 USBCDC::unlock(); 00086 return size; 00087 } 00088 00089 bool USBSerial::connected() 00090 { 00091 return _terminal_connected; 00092 }
Generated on Tue Jul 12 2022 13:55:03 by
