55#include " ../debugprint.h"
66#include " lx_servo.h"
77
8+ void SerialDriveManager::beginSinglePin (SerialInterface* port, int txRxPin) {
9+ interface_ = port;
10+ uartSinglePin_ = txRxPin;
11+ if (!interface_)
12+ return ;
13+ #ifdef ARDUINO_ARCH_ESP32
14+ auto serial = (HardwareSerial*)interface_;
15+ serial->begin (115200 , SERIAL_8N1, txRxPin, txRxPin);
16+ pinMode (txRxPin, OUTPUT | PULLUP);
17+ #endif
18+ delay (3 );
19+ while (interface_->available ())
20+ interface_->read ();
21+ }
22+
23+ void SerialDriveManager::beginDualPins (SerialInterface* port, int txPin, int rxPin) {
24+ interface_ = port;
25+ if (!interface_)
26+ return ;
27+ uartSinglePin_ = GPIO_NUM_NC;
28+ #ifdef ARDUINO
29+ auto serial = (HardwareSerial*)interface_;
30+ serial->begin (115200 , SERIAL_8N1, txPin, rxPin);
31+ #endif
32+ pinMode (txPin, OUTPUT | PULLUP);
33+ pinMode (rxPin, INPUT | PULLDOWN);
34+ }
35+
836void SerialDriveManager::addDrive (MotorDrive* drive) {
937 if (driveCount_ < MAX_DRIVES) {
1038 drives_[driveCount_++] = drive;
@@ -48,6 +76,13 @@ void SerialDriveManager::handleIncoming(uint32_t id, uint8_t const* indata, uint
4876}
4977
5078void SerialDriveManager::iterate (uint32_t now) {
79+ if (uartSinglePin_ != GPIO_NUM_NC) {
80+ if (interface_->availableForWrite () < 1 ) { // finished write
81+ pinMode (uartSinglePin_, INPUT | PULLUP);
82+ delayMicroseconds (10 );
83+ }
84+ }
85+
5186 uint8_t buf[INBUF_LEN];
5287 int len = 0 ;
5388 while (interface_->available () && (len < INBUF_LEN)) {
@@ -57,3 +92,13 @@ void SerialDriveManager::iterate(uint32_t now) {
5792 handleIncoming (0 , buf, len, now);
5893 }
5994}
95+
96+ void SerialDriveManager::write (uint8_t const * data, uint8_t len) {
97+ if (!interface_ || len == 0 ) return ;
98+ #if defined ARDUINO_ARCH_ESP32
99+ if (uartSinglePin_ != GPIO_NUM_NC)
100+ pinMode (uartSinglePin_, OUTPUT | PULLUP);
101+ delayMicroseconds (10 );
102+ #endif
103+ interface_->write (data, len);
104+ }
0 commit comments