diff --git a/src/helpers/RefCountedDigitalPin.h b/src/helpers/RefCountedDigitalPin.h index f30c4c58..b971ba98 100644 --- a/src/helpers/RefCountedDigitalPin.h +++ b/src/helpers/RefCountedDigitalPin.h @@ -14,10 +14,13 @@ public: digitalWrite(_pin, !_active); // initial state } + // Both set the level, then make the pin an output again, since other code may have left it + // an input. On a RAK19007 with a RAK12501, WB_IO2 left as an input keeps 3V3_S in its last state. void claim() { _claims++; if (_claims > 0) { digitalWrite(_pin, _active); + pinMode(_pin, OUTPUT); } } @@ -27,6 +30,7 @@ public: _claims--; if (_claims == 0) { digitalWrite(_pin, !_active); + pinMode(_pin, OUTPUT); } } }; diff --git a/src/helpers/sensors/RakLocationProvider.h b/src/helpers/sensors/RakLocationProvider.h index db437b95..903546ba 100644 --- a/src/helpers/sensors/RakLocationProvider.h +++ b/src/helpers/sensors/RakLocationProvider.h @@ -28,9 +28,11 @@ class RakLocationProvider : public LocationProvider { } public: + // serialPower, if given, switches the serial module's supply (WB_IO2 on WisBlock bases). RakLocationProvider(RakI2cGpsDriver& driver, mesh::RTCClock* clock = nullptr, - UART_TYPE& serial = Serial1) - : _driver(driver), _nmeaDriver(serial), _nmea(_nmeaDriver, clock) {} + UART_TYPE& serial = Serial1, RefCountedDigitalPin* serialPower = nullptr) + : _driver(driver), _nmeaDriver(serial, PIN_GPS_TX, PIN_GPS_RX, GPS_RESET, GPS_EN, serialPower), + _nmea(_nmeaDriver, clock) {} void syncTime() override { LocationProvider::syncTime(); @@ -112,6 +114,8 @@ public: // the serial module is started first, then the I2C module is probed _nmeaDriver.begin(); if (_driver.detect(timeout_ms)) { + // The serial driver keeps its claim on serialPower, so the rail stays as it is without one. + // The RAK12500 driver switches its own power pin, and serialPower is only used on the serial path. _useI2c = true; } else if (!_nmeaDriver.detect(0)) { _nmeaDriver.stop(); diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 4c13b0d7..c5d94d51 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -55,6 +55,14 @@ build_src_filter = ${rak4631.build_src_filter} + +<../examples/simple_repeater> +; Lets `gps off`, periodic mode and shutdown cut the power to a serial GPS (RAK12501). +; WB_IO2 switches the shared 3V3_S slot rail, so this also powers down any other slot module. +[env:RAK_4631_repeater_gps_power] +extends = env:RAK_4631_repeater +build_flags = + ${env:RAK_4631_repeater.build_flags} + -D GPS_RAIL_POWER_CONTROL + [env:RAK_4631_repeater_ethernet] extends = rak4631 build_flags = diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index 158de2b5..813cb807 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -27,7 +27,16 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock); #if ENV_INCLUDE_GPS #include RakI2cGpsDriver gps_driver; + #ifdef GPS_RAIL_POWER_CONTROL + #ifdef ETHERNET_ENABLED + #error "GPS_RAIL_POWER_CONTROL would cut the RAK13800's power, which also comes from WB_IO2" + #endif + // WB_IO2 switches 3V3_S, which powers the serial GPS and every other slot module. + RefCountedDigitalPin gps_rail(WB_IO2); + RakLocationProvider location(gps_driver, &rtc_clock, Serial1, &gps_rail); + #else RakLocationProvider location(gps_driver, &rtc_clock); + #endif EnvironmentSensorManager sensors(location); #else EnvironmentSensorManager sensors;