gps: serial pin and configuration fixes (nrf52, meshadventurer, tracker_v1, heltec_tracker)

This commit is contained in:
Florent committed 2026-11-08 08:47:34 -04:00
1 parent 22ce208e68
commit d71a418748
11 files changed
+48 -72

No files matched your search

+2 -2
View File
@@ -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();
-19
View File
@@ -1,19 +0,0 @@
#pragma once
#include <helpers/sensors/LocationProvider.h>
// 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;
}
@@ -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),
+27 -28
View File
@@ -5,6 +5,14 @@
#include <Arduino.h>
#include <helpers/RefCountedDigitalPin.h>
#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<Stream&>(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");
}
}
};
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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
+9 -5
View File
@@ -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;
}
+2 -2
View File
@@ -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>
+1 -3
View File
@@ -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;
}
@@ -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);
}
+2
View File
@@ -117,6 +117,8 @@
#define GPS_RTC_INT (15) // P0.15
#define GPS_RESETB (46) // P1.14
#define GPS_BAUDRATE 115200
////////////////////////////////////////////////////////////////////////////////
// Temp+Lux Sensor