diff --git a/src/helpers/sensors/AirohaGpsDriver.h b/src/helpers/sensors/AirohaGpsDriver.h index cd94d4195..9ba8a55d2 100644 --- a/src/helpers/sensors/AirohaGpsDriver.h +++ b/src/helpers/sensors/AirohaGpsDriver.h @@ -46,8 +46,8 @@ class AirohaGpsDriver : public NmeaGpsDriver { } public: - AirohaGpsDriver(HardwareSerial& serial) - : NmeaGpsDriver(serial, -1, -1, -1, -1, nullptr, HIGH, LOW, 115200) {} + AirohaGpsDriver(UART_TYPE& serial) + : NmeaGpsDriver(serial, -1, -1, -1, -1, nullptr, HIGH, LOW, GPS_BAUD_RATE) {} void initialize() { NmeaGpsDriver::begin(); diff --git a/src/helpers/sensors/AirohaSleep.h b/src/helpers/sensors/AirohaSleep.h deleted file mode 100644 index 6637d0fbf..000000000 --- a/src/helpers/sensors/AirohaSleep.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include - -// Board must keep the GPS RTC backup pin powered and can cut GPS power once we return. -// Returns true if the command was acked within 3 attempts, otherwise returns false. -static inline bool airohaEnterSleep(LocationProvider* nmea) { - for (uint8_t attempt = 0; attempt < 3; attempt++) { - nmea->drain(); - nmea->sendSentence("$PAIR650,0"); - if (nmea->waitFor("$PAIR001,650,0", 50)) { // wait for the command received signal - #ifdef GPS_NMEA_DEBUG - Serial.printf("Airoha RTC Backup sleep command accepted by GPS after %u attempts\r\n", attempt + 1); - #endif - nmea->waitFor("$PAIR650,0", 50); // give the GPS 50ms grace to signal it is ready for sleep - return true; - } - } - return false; -} \ No newline at end of file diff --git a/src/helpers/sensors/MicroNMEALocationProvider.h b/src/helpers/sensors/MicroNMEALocationProvider.h index 3c2adc6ea..db279acb9 100644 --- a/src/helpers/sensors/MicroNMEALocationProvider.h +++ b/src/helpers/sensors/MicroNMEALocationProvider.h @@ -119,15 +119,7 @@ public: // Temporary migration adapter for targets and downstream boards. New code // should inject a GpsDriver; this constructor will be removed once targets // have been migrated. - MicroNMEALocationProvider(HardwareSerial& serial, mesh::RTCClock* clock = nullptr, - int pin_reset = GPS_RESET, int pin_en = GPS_EN, - RefCountedDigitalPin* peripher_power = nullptr) - : nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock), - _driver(new NmeaGpsDriver(serial, PIN_GPS_TX, PIN_GPS_RX, pin_reset, pin_en, - peripher_power)), - _ownsDriver(true) {} - - MicroNMEALocationProvider(Stream& serial, mesh::RTCClock* clock = nullptr, + MicroNMEALocationProvider(UART_TYPE& serial, mesh::RTCClock* clock = nullptr, int pin_reset = GPS_RESET, int pin_en = GPS_EN, RefCountedDigitalPin* peripher_power = nullptr) : nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock), diff --git a/src/helpers/sensors/NmeaGpsDriver.h b/src/helpers/sensors/NmeaGpsDriver.h index abecb8176..25acff455 100644 --- a/src/helpers/sensors/NmeaGpsDriver.h +++ b/src/helpers/sensors/NmeaGpsDriver.h @@ -5,6 +5,14 @@ #include #include +#ifndef UART_TYPE +#ifdef NRF52_PLATFORM + #define UART_TYPE Uart +#else + #define UART_TYPE HardwareSerial +#endif +#endif + #ifndef PIN_GPS_TX #define PIN_GPS_TX (-1) #endif @@ -46,7 +54,11 @@ #endif #ifndef GPS_BAUD_RATE - #define GPS_BAUD_RATE 9600 + #ifdef GPS_BAUDRATE + #define GPS_BAUD_RATE GPS_BAUDRATE + #else + #define GPS_BAUD_RATE 9600 + #endif #endif #ifndef PIN_GPS_SWITCH @@ -66,8 +78,8 @@ #endif class NmeaGpsDriver : public GpsDriver { - Stream* _stream = nullptr; - HardwareSerial* _hardwareSerial = nullptr; + UART_TYPE* _hardwareSerial = nullptr; + RefCountedDigitalPin* _peripheralPower = nullptr; int _txPin = -1; int _rxPin = -1; @@ -87,12 +99,12 @@ class NmeaGpsDriver : public GpsDriver { #endif void startHardware() { - if (_stream == nullptr || _started) return; + if (_hardwareSerial == nullptr || _started) return; if (_hardwareSerial != nullptr) { -#ifdef ESP32_PLATFORM - _hardwareSerial->setPins(_txPin, _rxPin); -#endif + if (_txPin != -1 && _rxPin != -1) { + _hardwareSerial->setPins(_txPin, _rxPin); + } _hardwareSerial->begin(_baudRate); } @@ -116,14 +128,14 @@ class NmeaGpsDriver : public GpsDriver { public: NmeaGpsDriver() = default; - NmeaGpsDriver(Stream& stream, int txPin = PIN_GPS_TX, int rxPin = PIN_GPS_RX, + NmeaGpsDriver(UART_TYPE& serial, int txPin = PIN_GPS_TX, int rxPin = PIN_GPS_RX, int resetPin = GPS_RESET, int enablePin = GPS_EN, RefCountedDigitalPin* peripheralPower = nullptr, int enableActive = GPS_EN_ACTIVE, int resetActive = GPS_RESET_ACTIVE, uint32_t baudRate = GPS_BAUD_RATE, int hardwareEnablePin = PIN_GPS_SWITCH, int hardwareEnableActive = GPS_SWITCH_ACTIVE) - : _stream(&stream), _peripheralPower(peripheralPower), _txPin(txPin), _rxPin(rxPin), + : _hardwareSerial(&serial), _peripheralPower(peripheralPower), _txPin(txPin), _rxPin(rxPin), _resetPin(resetPin), _enablePin(enablePin), _enableActive(enableActive), _resetActive(resetActive), _baudRate(baudRate), _hardwareEnablePin(hardwareEnablePin), _hardwareEnableActive(hardwareEnableActive) { @@ -140,19 +152,6 @@ public: } } - NmeaGpsDriver(HardwareSerial& serial, int txPin = PIN_GPS_TX, int rxPin = PIN_GPS_RX, - int resetPin = GPS_RESET, int enablePin = GPS_EN, - RefCountedDigitalPin* peripheralPower = nullptr, - int enableActive = GPS_EN_ACTIVE, int resetActive = GPS_RESET_ACTIVE, - uint32_t baudRate = GPS_BAUD_RATE, - int hardwareEnablePin = PIN_GPS_SWITCH, - int hardwareEnableActive = GPS_SWITCH_ACTIVE) - : NmeaGpsDriver(static_cast(serial), txPin, rxPin, resetPin, enablePin, - peripheralPower, enableActive, resetActive, baudRate, - hardwareEnablePin, hardwareEnableActive) { - _hardwareSerial = &serial; - } - void begin() override { #if !GPS_SWITCH_IS_HARDWARE _requestedOn = true; @@ -232,11 +231,11 @@ public: } int available() { - return _stream == nullptr ? 0 : _stream->available(); + return _hardwareSerial == nullptr ? 0 : _hardwareSerial->available(); } int read() { - return _stream == nullptr ? -1 : _stream->read(); + return _hardwareSerial == nullptr ? -1 : _hardwareSerial->read(); } void drain() { @@ -244,19 +243,19 @@ public: } void sendNmeaSentence(const char* sentence) { - if (_stream == nullptr || sentence == nullptr || sentence[0] != '$') return; + if (_hardwareSerial == nullptr || sentence == nullptr || sentence[0] != '$') return; uint8_t checksum = 0; const char* p = sentence + 1; while (*p != '\0' && *p != '*') checksum ^= (uint8_t)*p++; - _stream->print(sentence); + _hardwareSerial->print(sentence); if (*p == '\0') { char checksumSuffix[6]; snprintf(checksumSuffix, sizeof(checksumSuffix), "*%02X\r\n", checksum); - _stream->print(checksumSuffix); + _hardwareSerial->print(checksumSuffix); } else { - _stream->print("\r\n"); + _hardwareSerial->print("\r\n"); } } }; diff --git a/src/helpers/sensors/RakLocationProvider.h b/src/helpers/sensors/RakLocationProvider.h index 7deddf43b..094e70ece 100644 --- a/src/helpers/sensors/RakLocationProvider.h +++ b/src/helpers/sensors/RakLocationProvider.h @@ -29,7 +29,7 @@ class RakLocationProvider : public LocationProvider { public: RakLocationProvider(RakI2cGpsDriver& driver, mesh::RTCClock* clock = nullptr, - HardwareSerial& serial = Serial1) + UART_TYPE& serial = Serial1) : _driver(driver), _nmeaDriver(serial), _nmea(_nmeaDriver, clock) {} void syncTime() override { diff --git a/variants/heltec_tracker/platformio.ini b/variants/heltec_tracker/platformio.ini index 75d1cadf3..3affd8ae0 100644 --- a/variants/heltec_tracker/platformio.ini +++ b/variants/heltec_tracker/platformio.ini @@ -31,8 +31,8 @@ build_flags = -D USE_PIN_TFT=1 -D PIN_VEXT_EN=3 ; Vext is connected to VDD which is also connected to OLED & GPS -D PIN_TFT_LEDA_CTL=21 ; LEDK (switches on/off via mosfet to create the ground) - -D PIN_GPS_RX=33 - -D PIN_GPS_TX=34 + -D PIN_GPS_TX=33 ; GPS module TX -> MCU RX (GPIO33) + -D PIN_GPS_RX=34 ; GPS module RX <- MCU TX (GPIO34) -D PIN_GPS_EN=35 ; N-ch MOSFET Q2 drives P-ch high-side switch → active HIGH (default) -D PIN_GPS_RESET=36 -D PIN_GPS_RESET_ACTIVE=LOW diff --git a/variants/heltec_tracker/target.cpp b/variants/heltec_tracker/target.cpp index 041cb2b85..67f98306c 100644 --- a/variants/heltec_tracker/target.cpp +++ b/variants/heltec_tracker/target.cpp @@ -23,9 +23,14 @@ public: : NmeaGpsDriver(Serial1, PIN_GPS_TX, PIN_GPS_RX, GPS_RESET, GPS_EN, &board.periph_power) {} - void begin() override { - NmeaGpsDriver::begin(); - sendNmeaSentence("$CFGSYS,h35155*68"); + void reset() override { + NmeaGpsDriver::reset(); + // Send configuration after reset + if (isActive()) { + delay(250); + sendNmeaSentence("$CFGSYS,h35155*68"); + // TODO: remove active wait (250ms is a lot) + } } }; @@ -64,8 +69,7 @@ void HWTSensorManager::stop_gps() { } bool HWTSensorManager::begin() { - // init GPS port - Serial1.begin(115200, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX); + // the GPS UART (pins, baud rate) is now configured by gps_driver when the GPS is started return true; } diff --git a/variants/meshadventurer/platformio.ini b/variants/meshadventurer/platformio.ini index 4af0f7f70..5e35251cc 100644 --- a/variants/meshadventurer/platformio.ini +++ b/variants/meshadventurer/platformio.ini @@ -23,8 +23,8 @@ build_flags = -D SX126X_DIO2_AS_RF_SWITCH=false -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_RX_BOOSTED_GAIN=1 - -D PIN_GPS_RX=12 - -D PIN_GPS_TX=15 + -D PIN_GPS_TX=12 ; GPS module TX -> MCU RX (GPIO12) + -D PIN_GPS_RX=15 ; GPS module RX <- MCU TX (GPIO15) -D DISPLAY_CLASS=SSD1306Display build_src_filter = ${esp32_base.build_src_filter} +<../variants/meshadventurer> diff --git a/variants/meshadventurer/target.cpp b/variants/meshadventurer/target.cpp index 827e23b73..1ccfe1510 100644 --- a/variants/meshadventurer/target.cpp +++ b/variants/meshadventurer/target.cpp @@ -48,9 +48,7 @@ void MASensorManager::stop_gps() { } bool MASensorManager::begin() { - Serial1.setPins(PIN_GPS_RX, PIN_GPS_TX); - Serial1.begin(9600); - delay(500); + // the GPS UART (pins, baud rate) is now configured by gps_driver when the GPS is started return true; } diff --git a/variants/nano_g2_ultra/NanoG2UltraGpsDriver.h b/variants/nano_g2_ultra/NanoG2UltraGpsDriver.h index 7e3bd1096..76270d329 100644 --- a/variants/nano_g2_ultra/NanoG2UltraGpsDriver.h +++ b/variants/nano_g2_ultra/NanoG2UltraGpsDriver.h @@ -4,7 +4,7 @@ class NanoG2UltraGpsDriver : public NmeaGpsDriver { public: - NanoG2UltraGpsDriver(HardwareSerial& serial) : NmeaGpsDriver(serial) { + NanoG2UltraGpsDriver(UART_TYPE& serial) : NmeaGpsDriver(serial) { pinMode(PIN_GPS_STANDBY, OUTPUT); digitalWrite(PIN_GPS_STANDBY, LOW); } diff --git a/variants/t1000-e/variant.h b/variants/t1000-e/variant.h index bd5090733..17a5538c4 100644 --- a/variants/t1000-e/variant.h +++ b/variants/t1000-e/variant.h @@ -117,6 +117,8 @@ #define GPS_RTC_INT (15) // P0.15 #define GPS_RESETB (46) // P1.14 +#define GPS_BAUDRATE 115200 + //////////////////////////////////////////////////////////////////////////////// // Temp+Lux Sensor