From 423b8ad6036342c723bbe5f3151a1f441f424ebf Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 28 Nov 2023 12:39:32 -0600 Subject: [PATCH] Adds real GPS support to Raspberry Pi arch --- bin/config-dist.yaml | 5 +++++ src/gps/GPS.cpp | 10 ++++++---- src/platform/portduino/PortduinoGlue.cpp | 7 +++++++ src/platform/portduino/PortduinoGlue.h | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 43360eb2e..cde45d1f8 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -33,3 +33,8 @@ Lora: GPIO: # User: 6 + +# Define GPS + +GPS: +# SerialPath: /dev/ttyS0 diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 11c16ede9..7ea36c860 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -7,6 +7,7 @@ #include "ubx.h" #ifdef ARCH_PORTDUINO +#include "PortduinoGlue.h" #include "meshUtils.h" #include #endif @@ -15,11 +16,8 @@ #define GPS_RESET_MODE HIGH #endif -#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) +#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_RASPBERRY_PI) HardwareSerial *GPS::_serial_gps = &Serial1; -#elif defined(ARCH_RASPBERRY_PI) -// need a translation layer to make _serial_gps work with pigpio https://abyz.me.uk/rpi/pigpio/cif.html#serOpen -HardwareSerial *GPS::_serial_gps = NULL; #else HardwareSerial *GPS::_serial_gps = NULL; #endif @@ -907,6 +905,10 @@ GPS *GPS::createGps() #if defined(PIN_GPS_EN) if (!_en_gpio) _en_gpio = PIN_GPS_EN; +#endif +#ifdef ARCH_RASPBERRY_PI + if (!settingsMap[has_gps]) + return nullptr; #endif if (!_rx_gpio || !_serial_gps) // Configured to have no GPS at all return nullptr; diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 54d633530..06e18eb91 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -147,6 +147,13 @@ void portduinoSetup() if (yamlConfig["GPIO"]) { settingsMap[user] = yamlConfig["GPIO"]["User"].as(RADIOLIB_NC); } + if (yamlConfig["GPS"]) { + std::string serialPath = yamlConfig["GPS"]["SerialPath"].as(""); + if (serialPath != "") { + Serial1.setPath(serialPath); + settingsMap[has_gps] = 1; + } + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index ac356607f..b942ab46a 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,7 +4,7 @@ extern std::map settingsMap; -enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip }; +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip, has_gps }; int initGPIOPin(int pinNum, std::string gpioChipname); #endif \ No newline at end of file