Browse Source

feat: add USB CDC bridge transport support

pull/2959/head
Darryl Hodgins 2 weeks ago
parent
commit
543fbfc6f3
  1. 4
      examples/simple_repeater/MyMesh.h
  2. 8
      examples/simple_repeater/main.cpp
  3. 12
      src/helpers/bridges/RS232Bridge.cpp

4
examples/simple_repeater/MyMesh.h

@ -14,6 +14,10 @@
#endif #endif
#ifdef WITH_RS232_BRIDGE #ifdef WITH_RS232_BRIDGE
#ifdef WITH_USB_SERIAL_BRIDGE
#include <Adafruit_TinyUSB.h>
extern Adafruit_USBD_CDC bridgeSerial;
#endif
#include "helpers/bridges/RS232Bridge.h" #include "helpers/bridges/RS232Bridge.h"
#define WITH_BRIDGE #define WITH_BRIDGE
#endif #endif

8
examples/simple_repeater/main.cpp

@ -3,6 +3,10 @@
#include "MyMesh.h" #include "MyMesh.h"
#ifdef WITH_USB_SERIAL_BRIDGE
Adafruit_USBD_CDC bridgeSerial;
#endif
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS
#include "UITask.h" #include "UITask.h"
static UITask ui_task(display); static UITask ui_task(display);
@ -36,6 +40,10 @@ static unsigned long userBtnDownAt = 0;
#endif #endif
void setup() { void setup() {
#ifdef WITH_USB_SERIAL_BRIDGE
// Register the second CDC interface before Serial mounts the USB device.
bridgeSerial.begin(115200);
#endif
Serial.begin(115200); Serial.begin(115200);
delay(1000); delay(1000);

12
src/helpers/bridges/RS232Bridge.cpp

@ -2,6 +2,10 @@
#include <HardwareSerial.h> #include <HardwareSerial.h>
#ifdef WITH_USB_SERIAL_BRIDGE
#include <Adafruit_TinyUSB.h>
#endif
#ifdef WITH_RS232_BRIDGE #ifdef WITH_RS232_BRIDGE
RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager *mgr, mesh::RTCClock *rtc) RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager *mgr, mesh::RTCClock *rtc)
@ -9,6 +13,9 @@ RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager *
void RS232Bridge::begin() { void RS232Bridge::begin() {
BRIDGE_DEBUG_PRINTLN("Initializing at %d baud...\n", _prefs->bridge_baud); BRIDGE_DEBUG_PRINTLN("Initializing at %d baud...\n", _prefs->bridge_baud);
#ifdef WITH_USB_SERIAL_BRIDGE
static_cast<Adafruit_USBD_CDC*>(_serial)->begin(_prefs->bridge_baud);
#else
#if !defined(WITH_RS232_BRIDGE_RX) || !defined(WITH_RS232_BRIDGE_TX) #if !defined(WITH_RS232_BRIDGE_RX) || !defined(WITH_RS232_BRIDGE_TX)
#error "WITH_RS232_BRIDGE_RX and WITH_RS232_BRIDGE_TX must be defined" #error "WITH_RS232_BRIDGE_RX and WITH_RS232_BRIDGE_TX must be defined"
#endif #endif
@ -28,6 +35,7 @@ void RS232Bridge::begin() {
#error RS232Bridge was not tested on the current platform #error RS232Bridge was not tested on the current platform
#endif #endif
((HardwareSerial *)_serial)->begin(_prefs->bridge_baud); ((HardwareSerial *)_serial)->begin(_prefs->bridge_baud);
#endif
// Update bridge state // Update bridge state
_initialized = true; _initialized = true;
@ -35,7 +43,11 @@ void RS232Bridge::begin() {
void RS232Bridge::end() { void RS232Bridge::end() {
BRIDGE_DEBUG_PRINTLN("Stopping...\n"); BRIDGE_DEBUG_PRINTLN("Stopping...\n");
#ifdef WITH_USB_SERIAL_BRIDGE
static_cast<Adafruit_USBD_CDC*>(_serial)->end();
#else
((HardwareSerial *)_serial)->end(); ((HardwareSerial *)_serial)->end();
#endif
// Update bridge state // Update bridge state
_initialized = false; _initialized = false;

Loading…
Cancel
Save