gps: serial pin and configuration fixes (nrf52, meshadventurer, tracker_v1, heltec_tracker)
This commit is contained in:
1 parent
bd21096ce0
commit
a134188c62
11 files changed
+48
-72
No files matched your search
@@ -46,8 +46,8 @@ class AirohaGpsDriver : public NmeaGpsDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AirohaGpsDriver(HardwareSerial& serial)
|
AirohaGpsDriver(UART_TYPE& serial)
|
||||||
: NmeaGpsDriver(serial, -1, -1, -1, -1, nullptr, HIGH, LOW, 115200) {}
|
: NmeaGpsDriver(serial, -1, -1, -1, -1, nullptr, HIGH, LOW, GPS_BAUD_RATE) {}
|
||||||
|
|
||||||
void initialize() {
|
void initialize() {
|
||||||
NmeaGpsDriver::begin();
|
NmeaGpsDriver::begin();
|
||||||
|
|||||||
@@ -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
|
// Temporary migration adapter for targets and downstream boards. New code
|
||||||
// should inject a GpsDriver; this constructor will be removed once targets
|
// should inject a GpsDriver; this constructor will be removed once targets
|
||||||
// have been migrated.
|
// have been migrated.
|
||||||
MicroNMEALocationProvider(HardwareSerial& 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),
|
|
||||||
_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,
|
|
||||||
int pin_reset = GPS_RESET, int pin_en = GPS_EN,
|
int pin_reset = GPS_RESET, int pin_en = GPS_EN,
|
||||||
RefCountedDigitalPin* peripher_power = nullptr)
|
RefCountedDigitalPin* peripher_power = nullptr)
|
||||||
: nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock),
|
: nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock),
|
||||||
|
|||||||
@@ -5,6 +5,14 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <helpers/RefCountedDigitalPin.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
|
#ifndef PIN_GPS_TX
|
||||||
#define PIN_GPS_TX (-1)
|
#define PIN_GPS_TX (-1)
|
||||||
#endif
|
#endif
|
||||||
@@ -46,7 +54,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GPS_BAUD_RATE
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef PIN_GPS_SWITCH
|
#ifndef PIN_GPS_SWITCH
|
||||||
@@ -66,8 +78,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
class NmeaGpsDriver : public GpsDriver {
|
class NmeaGpsDriver : public GpsDriver {
|
||||||
Stream* _stream = nullptr;
|
UART_TYPE* _hardwareSerial = nullptr;
|
||||||
HardwareSerial* _hardwareSerial = nullptr;
|
|
||||||
RefCountedDigitalPin* _peripheralPower = nullptr;
|
RefCountedDigitalPin* _peripheralPower = nullptr;
|
||||||
int _txPin = -1;
|
int _txPin = -1;
|
||||||
int _rxPin = -1;
|
int _rxPin = -1;
|
||||||
@@ -87,12 +99,12 @@ class NmeaGpsDriver : public GpsDriver {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void startHardware() {
|
void startHardware() {
|
||||||
if (_stream == nullptr || _started) return;
|
if (_hardwareSerial == nullptr || _started) return;
|
||||||
|
|
||||||
if (_hardwareSerial != nullptr) {
|
if (_hardwareSerial != nullptr) {
|
||||||
#ifdef ESP32_PLATFORM
|
if (_txPin != -1 && _rxPin != -1) {
|
||||||
_hardwareSerial->setPins(_txPin, _rxPin);
|
_hardwareSerial->setPins(_txPin, _rxPin);
|
||||||
#endif
|
}
|
||||||
_hardwareSerial->begin(_baudRate);
|
_hardwareSerial->begin(_baudRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,14 +128,14 @@ class NmeaGpsDriver : public GpsDriver {
|
|||||||
public:
|
public:
|
||||||
NmeaGpsDriver() = default;
|
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,
|
int resetPin = GPS_RESET, int enablePin = GPS_EN,
|
||||||
RefCountedDigitalPin* peripheralPower = nullptr,
|
RefCountedDigitalPin* peripheralPower = nullptr,
|
||||||
int enableActive = GPS_EN_ACTIVE, int resetActive = GPS_RESET_ACTIVE,
|
int enableActive = GPS_EN_ACTIVE, int resetActive = GPS_RESET_ACTIVE,
|
||||||
uint32_t baudRate = GPS_BAUD_RATE,
|
uint32_t baudRate = GPS_BAUD_RATE,
|
||||||
int hardwareEnablePin = PIN_GPS_SWITCH,
|
int hardwareEnablePin = PIN_GPS_SWITCH,
|
||||||
int hardwareEnableActive = GPS_SWITCH_ACTIVE)
|
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),
|
_resetPin(resetPin), _enablePin(enablePin), _enableActive(enableActive),
|
||||||
_resetActive(resetActive), _baudRate(baudRate),
|
_resetActive(resetActive), _baudRate(baudRate),
|
||||||
_hardwareEnablePin(hardwareEnablePin), _hardwareEnableActive(hardwareEnableActive) {
|
_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 {
|
void begin() override {
|
||||||
#if !GPS_SWITCH_IS_HARDWARE
|
#if !GPS_SWITCH_IS_HARDWARE
|
||||||
_requestedOn = true;
|
_requestedOn = true;
|
||||||
@@ -232,11 +231,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int available() {
|
int available() {
|
||||||
return _stream == nullptr ? 0 : _stream->available();
|
return _hardwareSerial == nullptr ? 0 : _hardwareSerial->available();
|
||||||
}
|
}
|
||||||
|
|
||||||
int read() {
|
int read() {
|
||||||
return _stream == nullptr ? -1 : _stream->read();
|
return _hardwareSerial == nullptr ? -1 : _hardwareSerial->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
void drain() {
|
void drain() {
|
||||||
@@ -244,19 +243,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sendNmeaSentence(const char* sentence) {
|
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;
|
uint8_t checksum = 0;
|
||||||
const char* p = sentence + 1;
|
const char* p = sentence + 1;
|
||||||
while (*p != '\0' && *p != '*') checksum ^= (uint8_t)*p++;
|
while (*p != '\0' && *p != '*') checksum ^= (uint8_t)*p++;
|
||||||
|
|
||||||
_stream->print(sentence);
|
_hardwareSerial->print(sentence);
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
char checksumSuffix[6];
|
char checksumSuffix[6];
|
||||||
snprintf(checksumSuffix, sizeof(checksumSuffix), "*%02X\r\n", checksum);
|
snprintf(checksumSuffix, sizeof(checksumSuffix), "*%02X\r\n", checksum);
|
||||||
_stream->print(checksumSuffix);
|
_hardwareSerial->print(checksumSuffix);
|
||||||
} else {
|
} else {
|
||||||
_stream->print("\r\n");
|
_hardwareSerial->print("\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,7 @@ class RakLocationProvider : public LocationProvider {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
RakLocationProvider(RakI2cGpsDriver& driver, mesh::RTCClock* clock = nullptr,
|
RakLocationProvider(RakI2cGpsDriver& driver, mesh::RTCClock* clock = nullptr,
|
||||||
HardwareSerial& serial = Serial1)
|
UART_TYPE& serial = Serial1)
|
||||||
: _driver(driver), _nmeaDriver(serial), _nmea(_nmeaDriver, clock) {}
|
: _driver(driver), _nmeaDriver(serial), _nmea(_nmeaDriver, clock) {}
|
||||||
|
|
||||||
void syncTime() override {
|
void syncTime() override {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ build_flags =
|
|||||||
-D USE_PIN_TFT=1
|
-D USE_PIN_TFT=1
|
||||||
-D PIN_VEXT_EN=3 ; Vext is connected to VDD which is also connected to OLED & GPS
|
-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_TFT_LEDA_CTL=21 ; LEDK (switches on/off via mosfet to create the ground)
|
||||||
-D PIN_GPS_RX=33
|
-D PIN_GPS_TX=33 ; GPS module TX -> MCU RX (GPIO33)
|
||||||
-D PIN_GPS_TX=34
|
-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_EN=35 ; N-ch MOSFET Q2 drives P-ch high-side switch → active HIGH (default)
|
||||||
-D PIN_GPS_RESET=36
|
-D PIN_GPS_RESET=36
|
||||||
-D PIN_GPS_RESET_ACTIVE=LOW
|
-D PIN_GPS_RESET_ACTIVE=LOW
|
||||||
|
|||||||
@@ -23,9 +23,14 @@ public:
|
|||||||
: NmeaGpsDriver(Serial1, PIN_GPS_TX, PIN_GPS_RX, GPS_RESET, GPS_EN,
|
: NmeaGpsDriver(Serial1, PIN_GPS_TX, PIN_GPS_RX, GPS_RESET, GPS_EN,
|
||||||
&board.periph_power) {}
|
&board.periph_power) {}
|
||||||
|
|
||||||
void begin() override {
|
void reset() override {
|
||||||
NmeaGpsDriver::begin();
|
NmeaGpsDriver::reset();
|
||||||
sendNmeaSentence("$CFGSYS,h35155*68");
|
// 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() {
|
bool HWTSensorManager::begin() {
|
||||||
// init GPS port
|
// the GPS UART (pins, baud rate) is now configured by gps_driver when the GPS is started
|
||||||
Serial1.begin(115200, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ build_flags =
|
|||||||
-D SX126X_DIO2_AS_RF_SWITCH=false
|
-D SX126X_DIO2_AS_RF_SWITCH=false
|
||||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||||
-D SX126X_RX_BOOSTED_GAIN=1
|
-D SX126X_RX_BOOSTED_GAIN=1
|
||||||
-D PIN_GPS_RX=12
|
-D PIN_GPS_TX=12 ; GPS module TX -> MCU RX (GPIO12)
|
||||||
-D PIN_GPS_TX=15
|
-D PIN_GPS_RX=15 ; GPS module RX <- MCU TX (GPIO15)
|
||||||
-D DISPLAY_CLASS=SSD1306Display
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
build_src_filter = ${esp32_base.build_src_filter}
|
build_src_filter = ${esp32_base.build_src_filter}
|
||||||
+<../variants/meshadventurer>
|
+<../variants/meshadventurer>
|
||||||
|
|||||||
@@ -48,9 +48,7 @@ void MASensorManager::stop_gps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MASensorManager::begin() {
|
bool MASensorManager::begin() {
|
||||||
Serial1.setPins(PIN_GPS_RX, PIN_GPS_TX);
|
// the GPS UART (pins, baud rate) is now configured by gps_driver when the GPS is started
|
||||||
Serial1.begin(9600);
|
|
||||||
delay(500);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
class NanoG2UltraGpsDriver : public NmeaGpsDriver {
|
class NanoG2UltraGpsDriver : public NmeaGpsDriver {
|
||||||
public:
|
public:
|
||||||
NanoG2UltraGpsDriver(HardwareSerial& serial) : NmeaGpsDriver(serial) {
|
NanoG2UltraGpsDriver(UART_TYPE& serial) : NmeaGpsDriver(serial) {
|
||||||
pinMode(PIN_GPS_STANDBY, OUTPUT);
|
pinMode(PIN_GPS_STANDBY, OUTPUT);
|
||||||
digitalWrite(PIN_GPS_STANDBY, LOW);
|
digitalWrite(PIN_GPS_STANDBY, LOW);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,8 @@
|
|||||||
#define GPS_RTC_INT (15) // P0.15
|
#define GPS_RTC_INT (15) // P0.15
|
||||||
#define GPS_RESETB (46) // P1.14
|
#define GPS_RESETB (46) // P1.14
|
||||||
|
|
||||||
|
#define GPS_BAUDRATE 115200
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Temp+Lux Sensor
|
// Temp+Lux Sensor
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user