Brownout trigger code

Just in case you haven't got around it yet, I found the esp32 was detecting a brownout, but the cause was the Battery charge controller's watchdog timer (max 160seconds), which gets disabled automatically when using the M5Unified library.

I've seen this print in serial only a couple of times, but mostly it fails to say anything as it reboots (happens often):
E BOD: Brownout detector was triggered.

Turned out I needed to set the Watchdog timer for the battery charge chip to be disabled, otherwise the board reboots after 160s.
See

and the datasheet (search for 05h):

I used something like this: (DONT USE THIS - SEE END POST)

 Wire.begin(SDA, SCL, 100000);

  // verify chip id 0x49 at 0x0Ah
  Wire.beginTransmission(0x49);
  Wire.write(0x0A);
  Wire.endTransmission();
  Wire.requestFrom(0x49, 1);
  uint8_t chipId = Wire.read();
  if (chipId != 0x49) {
    //WS_DEBUG_PRINTLN("ERROR: AW32001E not found on I2C bus!");
    Wire.endTransmission();
    Wire.end();
  } else {
    //WS_DEBUG_PRINTLN("AW32001E detected on I2C bus.");
    // Disable AW32001E watchdog timer, read 05h, & 0x1F, write back
    Wire.beginTransmission(0x49);
    Wire.write(0x05);
    Wire.endTransmission();
    Wire.requestFrom(0x49, 1);
    uint8_t regVal = Wire.read();
    Wire.endTransmission();
    // WS_DEBUG_PRINTLN("AW32001E WDT reg before disable: " + String(regVal, BIN));
    delay(10);
    regVal &=
        0b00011111; // Clear bits 5:6 to disable Watchdog timer, 7 for discharge
    Wire.beginTransmission(0x49);
    Wire.write(0x05);
    Wire.write(regVal);
    Wire.endTransmission();
    Wire.end();
    delay(10);

    battery.enableCharge();
  }