From 60fdf9fcb275e8529387b87f0752bd9448f81e92 Mon Sep 17 00:00:00 2001 From: lewis Date: Sat, 12 Nov 2022 20:09:25 +0800 Subject: [PATCH] Place PMU initialization before scanI2Cdevice --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 543568f09..0f7761b10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -246,6 +246,15 @@ void setup() digitalWrite(PIN_3V3_EN, 1); #endif + + // Currently only the tbeam has a PMU + // PMU initialization needs to be placed before scanI2Cdevice + power = new Power(); + power->setStatusHandler(powerStatus); + powerStatus->observe(&power->newStatus); + power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration + + #ifdef LILYGO_TBEAM_S3_CORE // In T-Beam-S3-core, the I2C device cannot be scanned before power initialization, otherwise the device will be stuck // PCF8563 RTC in tbeam-s3 uses Wire1 to share I2C bus @@ -254,11 +263,10 @@ void setup() rtc_found = PCF8563_RTC; DEBUG_MSG("PCF8563 RTC found\n"); } -#else - // We need to scan here to decide if we have a screen for nodeDB.init() - scanI2Cdevice(); #endif + // We need to scan here to decide if we have a screen for nodeDB.init() + scanI2Cdevice(); #ifdef HAS_SDCARD setupSDCard(); @@ -298,17 +306,12 @@ void setup() playStartMelody(); - // Currently only the tbeam has a PMU - power = new Power(); - power->setStatusHandler(powerStatus); - powerStatus->observe(&power->newStatus); - power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration /* * Repeat the scanning for I2C devices after power initialization or look for 'latecomers'. * Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core */ - scanI2Cdevice(); + // scanI2Cdevice(); // fixed screen override? if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO)