remove Serial.started(), make it safe to call Serial.begin() multiple times
This commit is contained in:
1 parent
7e6891e5c8
commit
49691adb81
6 files changed
+20
-11
No files matched your search
+7
-1
@@ -66,6 +66,9 @@ void Uart::begin(unsigned long baudrate)
|
||||
|
||||
void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
|
||||
{
|
||||
// skip if already begun
|
||||
if ( _begun ) return;
|
||||
|
||||
nrfUart->PSELTXD = uc_pinTX;
|
||||
nrfUart->PSELRXD = uc_pinRX;
|
||||
|
||||
@@ -77,7 +80,6 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
|
||||
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrfBaudRate;
|
||||
|
||||
if (baudrate <= 1200) {
|
||||
@@ -152,6 +154,10 @@ void Uart::end()
|
||||
nrfUart->PSELCTS = 0xFFFFFFFF;
|
||||
|
||||
rxBuffer.clear();
|
||||
|
||||
vSemaphoreDelete(_mutex);
|
||||
_mutex = NULL;
|
||||
_begun = false;
|
||||
}
|
||||
|
||||
void Uart::flush()
|
||||
|
||||
+4
-3
@@ -46,9 +46,10 @@ class Uart : public HardwareSerial
|
||||
|
||||
void IrqHandler();
|
||||
|
||||
bool started(void) { return _begun; }
|
||||
|
||||
operator bool() { return true; }
|
||||
operator bool ()
|
||||
{
|
||||
return _begun;
|
||||
}
|
||||
|
||||
private:
|
||||
NRF_UART_Type *nrfUart;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ static void loop_task(void* arg)
|
||||
|
||||
#if CFG_DEBUG
|
||||
// If Serial is not begin(), call it to avoid hard fault
|
||||
if ( !Serial.started() ) Serial.begin(115200);
|
||||
if ( !Serial ) Serial.begin(115200);
|
||||
dbgPrintVersion();
|
||||
Bluefruit_printInfo();
|
||||
#endif
|
||||
|
||||
@@ -49,8 +49,12 @@ USBSerial::USBSerial(void)
|
||||
}
|
||||
|
||||
// Baud and config is ignore in CDC
|
||||
void USBSerial::begin(uint32_t baud) { }
|
||||
void USBSerial::begin(uint32_t baud, uint8_t config) { }
|
||||
void USBSerial::begin (uint32_t baud)
|
||||
{
|
||||
}
|
||||
void USBSerial::begin (uint32_t baud, uint8_t config)
|
||||
{
|
||||
}
|
||||
|
||||
void USBSerial::end(void)
|
||||
{
|
||||
|
||||
@@ -62,8 +62,6 @@ public:
|
||||
|
||||
size_t readBytes(char *buffer, size_t length);
|
||||
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
|
||||
bool started(void) { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -637,14 +637,14 @@ void Bluefruit_printInfo(void)
|
||||
void AdafruitBluefruit::printInfo(void)
|
||||
{
|
||||
// Skip if Serial is not initialised
|
||||
if ( !Serial.started() ) return;
|
||||
if ( !Serial ) return;
|
||||
|
||||
// Skip if Bluefruit.begin() is not called
|
||||
if ( _ble_event_sem == NULL ) return;
|
||||
|
||||
Serial.println("--------- SoftDevice Config ---------");
|
||||
|
||||
char const * title_fmt = "%-16s: ";
|
||||
char const * title_fmt = "%-16s: ";
|
||||
|
||||
/*------------- SoftDevice Config -------------*/
|
||||
// Max uuid128
|
||||
|
||||
Reference in new issue
Block a user