diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 65b302f0..5441c226 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -165,16 +165,15 @@ static RAK12035_SoilMoisture RAK12035; #endif #ifdef RAK_WISBLOCK_GPS -static uint32_t gpsResetPin = 0; static bool i2cGPSFlag = false; static bool serialGPSFlag = false; #ifndef TELEM_RAK12500_ADDRESS -#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c +#define TELEM_RAK12500_ADDRESS 0x42 // RAK12500 u-blox ZOE-M8Q GPS via i2c #endif #include -static SFE_UBLOX_GNSS ublox_GNSS; +static SFE_UBLOX_GNSS ublox_GNSS; // RAK12500 u-blox ZOE-M8Q GPS via UART -class RAK12500LocationProvider : public LocationProvider { +class RAKI2CLocationProvider : public LocationProvider { long _lat = 0; long _lng = 0; long _alt = 0; @@ -207,7 +206,7 @@ public: bool isEnabled() override { return true; } }; -static RAK12500LocationProvider RAK12500_provider; +static RAKI2CLocationProvider RAK12500_provider; #endif // ============================================================ @@ -783,14 +782,14 @@ void EnvironmentSensorManager::rakGPSInit(){ Serial1.begin(9600); #endif - //search for the correct IO standby pin depending on socket used - if(gpsIsAwake(WB_IO2)){ - } - else if(gpsIsAwake(WB_IO4)){ - } - else if(gpsIsAwake(WB_IO5)){ - } - else{ + #ifdef PIN_3V3_EN + digitalWrite(PIN_3V3_EN,LOW); + delay(1000); + digitalWrite(PIN_3V3_EN,HIGH); + delay(2000); + #endif + + if(!gpsIsAwake()){ MESH_DEBUG_PRINTLN("No GPS found"); gps_active = false; gps_detected = false; @@ -804,18 +803,10 @@ void EnvironmentSensorManager::rakGPSInit(){ #endif } -bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ - - //set initial waking state - pinMode(ioPin,OUTPUT); - digitalWrite(ioPin,LOW); - delay(500); - digitalWrite(ioPin,HIGH); - delay(500); - +bool EnvironmentSensorManager::gpsIsAwake(){ //Try to init RAK12500 on I2C if (ublox_GNSS.begin(Wire) == true){ - MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin); + MESH_DEBUG_PRINTLN("RAK12500 I2C GPS init"); ublox_GNSS.setI2COutput(COM_TYPE_UBX); ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GPS); ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GALILEO); @@ -826,7 +817,6 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_QZSS); ublox_GNSS.setMeasurementRate(1000); ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); - gpsResetPin = ioPin; i2cGPSFlag = true; gps_active = true; gps_detected = true; @@ -834,20 +824,13 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ _location = &RAK12500_provider; return true; } else if (Serial1.available()) { - MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on"); -#ifdef PIN_GPS_EN - if(PIN_GPS_EN){ - gpsResetPin = PIN_GPS_EN; - } -#endif + MESH_DEBUG_PRINTLN("Serial GPS init correctly"); serialGPSFlag = true; gps_active = true; gps_detected = true; return true; } - pinMode(ioPin, INPUT); - MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next"); return false; } #endif @@ -855,8 +838,8 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ void EnvironmentSensorManager::start_gps() { gps_active = true; #ifdef RAK_WISBLOCK_GPS - pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, HIGH); + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); return; #endif @@ -871,8 +854,12 @@ void EnvironmentSensorManager::start_gps() { void EnvironmentSensorManager::stop_gps() { gps_active = false; #ifdef RAK_WISBLOCK_GPS - pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, LOW); + #ifdef SKY66122 + MESH_DEBUG_PRINTLN("GPS cannot be disabled as this would also disable SKY66122."); + return; + #endif + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, LOW); return; #endif diff --git a/src/helpers/sensors/EnvironmentSensorManager.h b/src/helpers/sensors/EnvironmentSensorManager.h index 29147c89..be1195dc 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.h +++ b/src/helpers/sensors/EnvironmentSensorManager.h @@ -30,7 +30,7 @@ protected: void initBasicGPS(); #ifdef RAK_BOARD void rakGPSInit(); - bool gpsIsAwake(uint8_t ioPin); + bool gpsIsAwake(); #endif #endif diff --git a/variants/rak3401/variant.h b/variants/rak3401/variant.h index a1a0e92c..5f49695c 100644 --- a/variants/rak3401/variant.h +++ b/variants/rak3401/variant.h @@ -181,6 +181,7 @@ static const uint8_t AREF = PIN_AREF; // in hardware via SetDIO2AsRfSwitchCtrl (microsecond-accurate, no GPIO needed). // The 5V boost for the PA is enabled by WB_IO2 (P0.34 = PIN_3V3_EN). #define SX126X_POWER_EN (21) // P0.21 = IO3 -> SKY66122 CSD+CPS (FEM enable) +#define SKY66122 // CTX is driven by SX1262 DIO2, not a GPIO #define SX126X_DIO2_AS_RF_SWITCH @@ -194,8 +195,8 @@ static const uint8_t AREF = PIN_AREF; #define P_LORA_BUSY SX126X_BUSY #define P_LORA_RESET SX126X_RESET -// enables 3.3V periphery like GPS or IO Module -// Do not toggle this for GPS power savings +// enables 3.3V periphery like GPS, the IO Module, and the SKY66122 5V boost +// Do NOT use this for GPS power savings as this will interfere with LoRa functionality #define PIN_3V3_EN (34) #define PIN_GPS_RX PIN_SERIAL1_RX