Skip to content

Commit

Permalink
update axp ext power input issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitshaoxiang committed Feb 4, 2024
1 parent 5a23ea4 commit c26f1b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/AXP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ void AXP::begin() {
ina3221.begin(&Wire1);
axp2101.set_lcd_back_light_voltage(3000);
axp2101.set_lcd_and_tf_voltage(3300);
axp2101.set_bus_5v(true);
if (ina3221.getVoltage(INA3221_CH2) > 4.5f)
axp2101.set_bus_5v(false);
else {
axp2101.set_bus_5v(true);
}
axp2101.set_sys_led(true);
} else {
_pmic = pmic_unknown;
Expand Down
2 changes: 0 additions & 2 deletions src/AXP192.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ void AXP192::begin() {
delay(100);
// I2C_WriteByteDataAt(0X15,0XFE,0XFF);

SetPeripherialsPower(true);

// axp: check v-bus status
if (Read8bit(0x00) & 0x08) {
Write1Byte(0x30, Read8bit(0x30) | 0x80);
Expand Down

3 comments on commit c26f1b6

@colintd
Copy link

@colintd colintd commented on c26f1b6 May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a similar fix in my local copy, but rather than read the voltage, I used the VBUS status from the AXP2101.

I think this is more resilient, as the VBUS source is only usable if the AXP2101 thinks it is good, and in testing there are windows where the voltage reading and the AXP2101 result disagree. It is also the same intent as the existing test in the AXP192 path

Happy to submit a pull request or you could use directly from the following sample.

AXP2102.cpp:

uint8_t AXP2101::axp2101_get_vbus_status(void) {
  uint8_t status = readRegister8(_addr, AXP2101_PMU_STATUS_1, _speed);
  if (status & 0x20) {
      return (true);
   } else {
      return (false); 
   }
 }     

AXP2101.h

#define AXP2101_PMU_STATUS_1            0x00
uint8_t axp2101_get_vbus_status(void);   

AXP.cpp

  // If VBUS is powered externally, leave internal converter disabled
  axp2101.set_bus_5v(!axp2101.axp2101_get_vbus_status());

@robouden
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colintd

Thanks for the suggestion. Yes, love to see that code implemented.

@robouden
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colintd

Does your fix also works when only external (no USB) power is applied to the VBAT?

Regards
Rob Oudendijk

Please sign in to comment.