An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Revision 33:617765dcce6c, committed 2019-02-12
- Comitter:
- Helmut Tschemernjak
- Date:
- Tue Feb 12 16:54:21 2019 +0100
- Parent:
- 32:e68143c56bf3
- Child:
- 34:d3d60dbb84ea
- Commit message:
- Updated to work as well without FEATURE_USBSERIAL
Changed in this revision
| utils.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/utils.cpp Tue Feb 12 16:52:23 2019 +0100
+++ b/utils.cpp Tue Feb 12 16:54:21 2019 +0100
@@ -17,17 +17,13 @@
void InitSerial(int timeout, DigitalOut *led)
{
_useDprintf = true;
- bool uartActive;
- {
- {
- // need to turn rx low to avoid floating signal
- DigitalOut rx(USBRX);
- rx = 0;
- }
- DigitalIn uartRX(USBRX);
- uartActive = uartRX.read();
- }
+ bool uartActive = true;
+
#ifdef FEATURE_USBSERIAL
+ DigitalOut rx(USBRX); // need to turn rx low to avoid floating signal
+ rx = 0;
+ DigitalIn uartRX(USBRX);
+ uartActive = uartRX.read();
if (!uartActive) {
usb = new USBSerialBuffered();
Timer t;
@@ -42,20 +38,17 @@
usb = NULL;
DigitalOut rx(USBRX);
rx = 0; // need to turn tx low to avoid floating signal
- goto done;
}
- }
- }
- goto done;
- } else {
-#else
- {
+ }
+ }
+ }
#endif
+ if (uartActive) {
ser = new BufferedSerial(USBTX, USBRX);
ser->baud(230400);
ser->format(8);
}
-done:
+
time_t t = cvt_date(__DATE__, __TIME__);
if (t > time(NULL)) {
set_time(t);
@@ -113,10 +106,9 @@
usb->vprintf_irqsafe(format, arg);
if (newline)
usb->printf_irqsafe("\r\n");
-#else
- if (0) {
+ }
#endif
- } else if (ser) {
+ if (ser) {
// serial jas
int r = 0;
r = vsnprintf(NULL, 0, format, arg);
@@ -146,8 +138,13 @@
int count = 0;
memset(buf, 0, buflen);
+#ifdef FEATURE_USBSERIAL
if (usb == NULL && ser == NULL)
return NULL;
+#else
+ if (ser == NULL)
+ return NULL;
+#endif
Timer t;
int start = 0;
@@ -156,11 +153,13 @@
start = t.read_ms();
}
+#ifdef FEATURE_USBSERIAL
if (usb) {
usb->flush();
while(usb->readable())
usb->getc(); // flush old chars
}
+#endif
if (ser) {
while(ser->readable())
ser->getc(); // flush old chars
@@ -170,8 +169,10 @@
if (timeout_ms && t.read_ms() - start > timeout_ms)
return NULL;
int c = -2;
+#ifdef FEATURE_USBSERIAL
if (usb && usb->readable())
c = usb->getc();
+#endif
if (ser && ser->readable())
c = ser->getc();
if (c == -2)
@@ -185,16 +186,21 @@
buf[--count] = 0;
if (echo)
rprintf("\b \b");
+#ifdef FEATURE_USBSERIAL
if (usb)
usb->flush();
+#endif
continue;
}
if (echo) {
rprintf("%c", c);
+#ifdef FEATURE_USBSERIAL
if (usb)
usb->flush();
+#endif
}
+ start = t.read_ms();
buf[count] = c;
if (count++ >= buflen-2)
break;
Helmut Tschemernjak