diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 876dc9c33c..5718700648 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -218,6 +218,11 @@ void setup() { #endif #ifdef DISPLAY_CLASS +#ifdef RAK_BOARD + // sensors.begin() GPS probe may power-cycle 3V3_S rail (via WB_IO2), + // which resets the SSD1306. Re-init the display before starting UI. + if (disp) display.begin(); +#endif ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved #endif } diff --git a/src/helpers/ArduinoSerialInterface.h b/src/helpers/ArduinoSerialInterface.h index c4086353aa..f2c8ac097d 100644 --- a/src/helpers/ArduinoSerialInterface.h +++ b/src/helpers/ArduinoSerialInterface.h @@ -14,11 +14,8 @@ class ArduinoSerialInterface : public BaseSerialInterface { public: ArduinoSerialInterface() { _isEnabled = false; _state = 0; } - void begin(Stream& serial) { - _serial = &serial; - #ifdef RAK_4631 - pinMode(WB_IO2, OUTPUT); - #endif + void begin(Stream& serial) { + _serial = &serial; } // BaseSerialInterface methods diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 19472406d8..32828a9ba2 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -655,7 +655,14 @@ void EnvironmentSensorManager::rakGPSInit(){ // MESH_DEBUG_PRINTLN("RAK base board is RAK19007/10"); // MESH_DEBUG_PRINTLN("GPS is installed on Socket A"); } - else if(gpsIsAwake(WB_IO4)){ + + // WB_IO2 controls the 3V3_S switched peripheral rail on RAK these boards. + // gpsIsAwake() leaves the pin as INPUT on failure, killing the rail. + // Restore it now, before probing other sockets. + pinMode(WB_IO2, OUTPUT); + digitalWrite(WB_IO2, HIGH); + + if(gpsIsAwake(WB_IO4)){ // MESH_DEBUG_PRINTLN("RAK base board is RAK19003/9"); // MESH_DEBUG_PRINTLN("GPS is installed on Socket C"); } diff --git a/variants/rak4631/RAK4631Board.cpp b/variants/rak4631/RAK4631Board.cpp index 9fb47b432e..26b51af9c2 100644 --- a/variants/rak4631/RAK4631Board.cpp +++ b/variants/rak4631/RAK4631Board.cpp @@ -16,6 +16,9 @@ void RAK4631Board::initiateShutdown(uint8_t reason) { // Disable LoRa module power before shutdown digitalWrite(SX126X_POWER_EN, LOW); + // Disable 3V3 switched peripherals + digitalWrite(PIN_3V3_EN, LOW); + if (reason == SHUTDOWN_REASON_LOW_VOLTAGE || reason == SHUTDOWN_REASON_BOOT_PROTECT) { configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel); diff --git a/variants/rak4631/variant.cpp b/variants/rak4631/variant.cpp index bd85e97133..d562189f9b 100644 --- a/variants/rak4631/variant.cpp +++ b/variants/rak4631/variant.cpp @@ -44,6 +44,9 @@ void initVariant() ledOff(PIN_LED1); pinMode(PIN_LED2, OUTPUT); - ledOff(PIN_LED2);; -} + ledOff(PIN_LED2); + // 3V3 Power Rail + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); +} diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 38cc88685c..b2edc9b85c 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -59,6 +59,8 @@ extern "C" static const uint8_t WB_SPI_MISO = 29; // IO_SLOT static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT +#define PIN_3V3_EN WB_IO2 // 3V3_S switched peripheral rail control + // Number of pins defined in PinDescription array #define PINS_COUNT (48) #define NUM_DIGITAL_PINS (48)