@hacxx I was able to work out the problem. I implemented changes to the m5stack board_m5cores3 component which makes it enable the correct AXP2101 power management for I2C for the Port A Grove port when using USB-C power.
My issue was when using the device with the DIN base and the battery on and a sensor (CO2L) plugged into the Grove Port A (I2C), the device would be working. But if I disconnect USB-C from my computer and switch off the DIN base power, then switch the DIN base back on and plug USB-C back in (simulating a complete power outage of mains and battery) the device would boot loop with the message about SDA being held low.
The only way for me to get out of the loop is to unplug the CO2L from Port A. Then the device would boot on its next attempt and the I2C port recovery would be successful. Finally, I could plugin the CO2L, reset using the button, and everything would work again.
The issue was I needed to call M5.Power.setExtOutput during setup() of the BoardM5CoreS3 class from the https://github.com/m5stack/M5CoreS3-Esphome repo's components.
void BoardM5CoreS3::setup() { M5.begin(); ESP_LOGI(TAG, "Enabling 5V power output on the external ports"); M5.Power.setExtOutput(true); ESP_LOGI(TAG, "Turning off display panel backlight"); M5.Display.setBrightness(0); }I implemented this in a custom component which I then add as an external_component to my ESPHome config. I added additional functionality in a separate component, to expose the AXP2101 battery level, charging status, etc. I also added an automation action to allow printing out debug state info from the AXP2101, to help with debugging the IRQ and other power management concerns.
In my ESPHome config it looks like this now and the CO2L sensor works reliably now without the controller going into boot-loops from various power loss/power source change scenarios:
esphome: name: ${hostname} friendly_name: ${friendlyname} platformio_options: board_build.flash_mode: dio board_build.mcu: esp32s3 board_build.f_cpu: 240000000L libraries: - m5stack/M5Unified external_components: - source: type: git url: https://github.com/terpasaurus-midwest/esphome-fork ref: m5cores3 path: my_components refresh: 2min components: [m5cores3_power, board_m5cores3] board_m5cores3: id: m5_board m5cores3_power: id: m5_power battery_sensor: name: "Battery Level" id: battery_level battery_present_sensor: name: "Battery Present" id: battery_present battery_charging_sensor: name: "Battery Charging" id: battery_charging