diff --git a/src/Power.cpp b/src/Power.cpp index 767c5ca0c..d3782a2a4 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -368,8 +368,21 @@ bool Power::axpChipInit() #ifdef HAS_PMU + TwoWire * w = NULL; + + // Use macro to distinguish which wire is used by PMU +#ifdef PMU_USE_WIRE1 + w = &Wire1; +#else + w = &Wire; +#endif + + /** + * It is not necessary to specify the wire pin, + * just input the wire, because the wire has been initialized in main.cpp + */ if (!PMU) { - PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL); + PMU = new XPowersAXP2101(*w); if (!PMU->init()) { DEBUG_MSG("Warning: Failed to find AXP2101 power management\n"); delete PMU; @@ -380,7 +393,7 @@ bool Power::axpChipInit() } if (!PMU) { - PMU = new XPowersAXP192(Wire, I2C_SDA, I2C_SCL); + PMU = new XPowersAXP192(*w); if (!PMU->init()) { DEBUG_MSG("Warning: Failed to find AXP192 power management\n"); delete PMU; @@ -396,7 +409,9 @@ bool Power::axpChipInit() * In order not to affect other devices, if the initialization of the PMU fails, Wire needs to be re-initialized once, * if there are multiple devices sharing the bus. * * */ - Wire.begin(I2C_SDA, I2C_SCL); +#ifndef PMU_USE_WIRE1 + w->begin(I2C_SDA, I2C_SCL); +#endif return false; } @@ -456,6 +471,23 @@ bool Power::axpChipInit() PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300); PMU->enablePowerOutput(XPOWERS_DCDC3); + /** + * ALDO2 cannot be turned off. + * It is a necessary condition for sensor communication. + * It must be turned on to properly access the sensor and screen + * It is also responsible for the power supply of PCF8563 + */ + PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO2); + + // 6-axis , magnetometer ,bme280 , oled screen power channel + PMU->setPowerChannelVoltage(XPOWERS_ALDO1, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO1); + + // sdcard power channle + PMU->setPowerChannelVoltage(XPOWERS_BLDO1, 3300); + PMU->enablePowerOutput(XPOWERS_BLDO1); + // PMU->setPowerChannelVoltage(XPOWERS_DCDC4, 3300); // PMU->enablePowerOutput(XPOWERS_DCDC4); diff --git a/src/configuration.h b/src/configuration.h index d91a674c2..524dbec36 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -108,7 +108,8 @@ along with this program. If not, see . #define MCP9808_ADDR 0x18 #define INA_ADDR 0x40 #define INA_ADDR_ALTERNATE 0x41 - +#define QMC6310_ADDR 0x1C +#define QMI8658_ADDR 0x6B // ----------------------------------------------------------------------------- // GPS // ----------------------------------------------------------------------------- diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 3591d307b..7f62a7604 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -145,6 +145,14 @@ void scanI2Cdevice(void) nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr; DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr); } + if(addr == QMC6310_ADDR){ + DEBUG_MSG("QMC6310 3-Axis magnetic sensor found at address 0x%x\n", (uint8_t)addr); + // nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr; //Uncomment after protobufs PR is merged + } + if(addr == QMI8658_ADDR){ + DEBUG_MSG("QMI8658 6-Axis inertial measurement sensor found at address 0x%x\n", (uint8_t)addr); + // nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr; //Uncomment after protobufs PR is merged + } } else if (err == 4) { DEBUG_MSG("Unknow error at address 0x%x\n", addr); } diff --git a/src/main.cpp b/src/main.cpp index 5d3d30d0c..c5df7e021 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -214,6 +214,10 @@ void setup() // router = new DSRRouter(); router = new ReliableRouter(); +#ifdef I2C_SDA1 + Wire1.begin(I2C_SDA1, I2C_SCL1); +#endif + #ifdef I2C_SDA Wire.begin(I2C_SDA, I2C_SCL); #elif HAS_WIRE @@ -229,7 +233,6 @@ void setup() delay(1); #endif - scanI2Cdevice(); #ifdef RAK4630 // scanEInkDevice(); #endif @@ -269,6 +272,12 @@ void setup() powerStatus->observe(&power->newStatus); power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration + /* + * Move the scanning I2C device to the back of power initialization. + * Some boards need to be powered on to correctly scan to the device address, such as t-beam-s3-core + */ + scanI2Cdevice(); + // Init our SPI controller (must be before screen and lora) initSPI(); #ifndef ARCH_ESP32 diff --git a/variants/tbeam-s3-core/pins_arduino.h b/variants/tbeam-s3-core/pins_arduino.h index 7b0193e0e..50c993f3a 100644 --- a/variants/tbeam-s3-core/pins_arduino.h +++ b/variants/tbeam-s3-core/pins_arduino.h @@ -25,5 +25,12 @@ static const uint8_t MOSI = 11; static const uint8_t MISO = 13; static const uint8_t SCK = 12; +#define SDMMC_CMD (35) +#define SDMMC_CLK (36) +#define SDMMC_DATA (37) + +#define ACCEL_INT1 (34) +#define ACCEL_INT2 (33) +#define RTC_INT (14) #endif /* Pins_Arduino_h */ diff --git a/variants/tbeam-s3-core/platformio.ini b/variants/tbeam-s3-core/platformio.ini index 9adfb90dc..99d315a69 100644 --- a/variants/tbeam-s3-core/platformio.ini +++ b/variants/tbeam-s3-core/platformio.ini @@ -5,7 +5,9 @@ board = tbeam-s3-core lib_deps = ${esp32s3_base.lib_deps} + lewisxhe/PCF8563_Library@1.0.1 + build_flags = ${esp32s3_base.build_flags} -Ivariants/tbeam-s3-core - + -DPCF8563_RTC=0x51 ;Putting definitions in variant.h does not compile correctly diff --git a/variants/tbeam-s3-core/variant.h b/variants/tbeam-s3-core/variant.h index 8fe181ad0..63387c00a 100644 --- a/variants/tbeam-s3-core/variant.h +++ b/variants/tbeam-s3-core/variant.h @@ -1,12 +1,18 @@ // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep -#define I2C_SDA 42 -#define I2C_SCL 41 +#define I2C_SDA1 42 //Used for PMU management +#define I2C_SCL1 41 //Used for PMU management + +#define I2C_SDA 17 //For sensors and screens +#define I2C_SCL 18 //For sensors and screens #define BUTTON_PIN 0 // The middle button GPIO on the T-Beam S3 //#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere. // #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +#define BUTTON1_PIN 47 //Additional keys + + #define LED_INVERTED 1 // #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 @@ -36,6 +42,9 @@ // #define PMU_IRQ 40 #define HAS_AXP2101 +// Specify the PMU as Wire1. In the t-beam-s3-core, the PMU enjoys a separate bus +#define PMU_USE_WIRE1 + #define RF95_SCK 12 #define RF95_MISO 13 #define RF95_MOSI 11 @@ -47,3 +56,10 @@ #define GPS_1PPS_PIN 6 +#define HAS_SDCARD //Have 3-bit SDMMC interface SD card slot + +// PCF8563 RTC Module +// #define PCF8563_RTC 0x51 //Putting definitions in variant. h does not compile correctly + +#define HAS_RTC 1 +