avoid multiple USB serial begin (taken from F1)

This commit is contained in:
stevstrong 2017-06-20 18:50:23 +02:00
parent f1e2cba93b
commit d872cb1963
2 changed files with 9 additions and 1 deletions

View File

@ -36,20 +36,25 @@
#ifdef SERIAL_USB
#define USB_TIMEOUT 50
bool USBSerial::_hasBegun = false;
USBSerial::USBSerial(void) {
}
void USBSerial::begin(void) {
if (_hasBegun)
return;
_hasBegun = true;
setupUSB();
}
void USBSerial::begin(int) {
setupUSB();
this->begin();
}
void USBSerial::end(void) {
disableUSB();
_hasBegun = false;
}
size_t USBSerial::write(uint8 ch) {

View File

@ -65,6 +65,9 @@ public:
void enableBlockingTx(void);
void disableBlockingTx(void);
protected:
static bool _hasBegun;
};
extern USBSerial SerialUSB;