Giter Club home page Giter Club logo

xpowerslib's Introduction

 __   __     _____                           _      _ _
 \ \ / /    |  __ \                         | |    (_) |
  \ V /_____| |__) |____      _____ _ __ ___| |     _| |__
   > <______|  ___/ _ \ \ /\ / / _ \ '__/ __| |    | | '_ \
  / . \     | |  | (_) \ V  V /  __/ |  \__ \ |____| | |_) |
 /_/ \_\    |_|   \___/ \_/\_/ \___|_|  |___/______|_|_.__/

Build esp-idf Build PlatformIO Build Arduino arduino-library-badge

LICENSE ISSUES FROK STAR releases

🎉 LilyGo invests time and resources to provide this open source code, please support LilyGo 
and open source hardware by purchasing products from LilyGo!
Written by Lewis He for LilyGo. MIT license, all text above must be included in 
any redistribution

❗️❗️❗️ WARN:

⚠️ Please do not run the example without knowing the external load voltage of the PMU,
it may burn your external load,please check the voltage setting before running the example,
if there is any loss,please bear it by yourself

✨ Library specially written for XPowers, supporting CircuitPython, Micropython, Arduino, ESP-IDF

✨ Through esp32,esp32s3 verification,other platforms have not been tested. Due to the many functions of the chip,it cannot be verified one by one.

Chip Resource List

CHIP AXP192 AXP202 AXP2101 Remarks
DC1 0.7V-3.5V /1.2A X 1.5-3.4V /2A
DC2 0.7-2.275V /1.6A 0.7-2.275V /1.6A 0.5-1.2V,1.22-1.54V /2A
DC3 0.7-3.5V /0.7A 0.7-3.5V /1.2A 0.5-1.2V,1.22-1.54V,1.6-3.4V /2A
DC4 x x 0.5-1.2V,1.22-1.84V /1.5A
DC5 x x 1.2V,1.4-3.7V /1A
LDO1(VRTC) 3.3V /30mA 3.3V /30mA 1.8V /30mA
LDO2 1.8V-3.3V /200mA 1.8V-3.3V /200mA x
LDO3 1.8-3.3V /200mA 0.7-3.5V /200mA x
LDO4 X 1.8V-3.3V /200mA x
LDO5/IO0 1.8-3.3V /50mA 1.8-3.3V /50mA x
ALDO1 x x 0.5-3.5V /300mA
ALDO2 x x 0.5-3.5V /300mA
ALDO3 x x 0.5-3.5V /300mA
ALDO4 x x 0.5-3.5V /300mA
BLDO1 x x 0.5-3.5V /300mA
BLDO2 x x 0.5-3.5V /300mA
DLDO1 x x (LDO Mode)0.5-3.3V/ 0.5-1.4V/300mA,(SW Mode)Switch Function Dependent on DC1
DLDO2 x x (LDO Mode)0.5-3.3V/ 0.5-1.4V/300mA,(SW Mode)Switch Function Dependent on DC4
CPUSLDO x x 0.5-1.4V /30mA Dependent on DC4

AXP2101 Notes:

  • Whether DLDO1/DLDO2/RTCLDO2/GPIO1 can be used depends on the chip. It is not available by default. RTCLDO1 has a default voltage, which is generally 1.8V by default. The voltage value cannot be changed or turned off through the register.

xpowerslib's People

Contributors

custodey avatar lewisxhe avatar mathieucarbou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xpowerslib's Issues

Is there an equivalent to AXP192's getBatteryChargeCurrent and getVbusCurrent in AXP2101?

Hey! I'm porting my ttgo t-beam's code to run on the newer model with AXP2101. For AXP192 I've got these lines of code reading the current consumption:

status.batt_milliamp = pmu->getBatteryChargeCurrent();
status.batt_milliamp = -pmu->getBattDischargeCurrent();
status.power_draw_milliamp = pmu->getVbusCurrent();

Is there an equivalent for AXP2101?

Thanks.

esp-idf v5.3 small change

Additional fields to take into account

victus: {3325} diff components/XPowersLib/src/XPowersCommon.{tpp,tpp.orig}
175,181d174
< #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,3,0))
<           // New fields since esp-idf-v5.3-beta1
<           .scl_wait_us = 0,
<           .flags = {
<             . disable_ack_check = 0
<           }
< #endif

Consider replacing the variable name PMU in examples with anything else

Espressif defines a PMU variable declared as extern for some of their SOCs (in my case it was the ESP32H2):
https://github.com/espressif/esp-idf/blob/1cb4f3468d64c9e8bde196b15df37cbcd4b31395/components/soc/esp32h2/include/soc/pmu_struct.h#L761
This code is precompiled into the esp32-arduino-lib library installed by Arduino. If you run the example programs on these SOCs, everything will get messed up due to the global PMU variable.

I encountered this problem when debugging the sleep function of ESP32-H2. It took me some time to troubleshoot this issue because the compiler doesn't directly prompt the error.
The sleep-related functions of ESP32-H2 will reference the PMU variable, which will cause the sleep function to not run properly and cause core panic.
https://github.com/espressif/esp-idf/blob/1cb4f3468d64c9e8bde196b15df37cbcd4b31395/components/esp_hw_support/sleep_wake_stub.c#L71-L74
https://github.com/espressif/esp-idf/blob/1cb4f3468d64c9e8bde196b15df37cbcd4b31395/components/esp_hw_support/sleep_modes.c#L2060

This problem can be reproduced by running AXP2101_Sleep_Example.ino on ESP32-H2. Switch 'Core Debug Level' to 'Verbose' and it should show something like

Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0). 

Core  0 register dump:
MEPC    : 0x40803bd8  RA      : 0x408058c8  SP      : 0x40817c50  GP      : 0x4080e194  
TP      : 0x40806dd8  T0      : 0x40003128  T1      : 0x40000038  T2      : 0x00000000  
S0/FP   : 0x80000000  S1      : 0x00000010  A0      : 0x4080e61c  A1      : 0x80000010  
A2      : 0x00000000  A3      : 0x40000000  A4      : 0x4080f090  A5      : 0x00000000  
A6      : 0x00000003  A7      : 0x00000037  S2      : 0x00000001  S3      : 0x00000000  
S4      : 0x004c494c  S5      : 0x00000001  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000001  S10     : 0x4080f74c  S11     : 0x00000000  
T3      : 0x00000000  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000  
MSTATUS : 0x00001881  MTVEC   : 0x40800001  MCAUSE  : 0x00000018  MTVAL   : 0x00008082  
MHARTID : 0x00000000  

and reboot

Default voltage and Startup Sequence?

AXP2101.pdf
Is it true that the first time it starts, the DCDC1 voltage will be 3.3 Vdc according to section 7.6 of the datasheet I attached? How will the starting order of the voltages be configured? I don't see instructions in the documentation.
Please help me!

Next release ?

Would it be possible to release the new changes and pio pkg publish them ?
Thanks!

AXP192: getBattVoltage() always returning 0

AXP192_showstatus(): [src/power.cpp] Battery charging, 0.00V @ 752mAh

code:

if (pmu.isBatteryConnect())
    if (pmu.isCharging())
      ESP_LOGI(TAG, "Battery charging, %.2fV @ %.0fmAh",
               pmu.getBattVoltage() / 1000, pmu.getBatteryChargeCurrent());

AXP2101 using PWRON as EN mode

Hello, from the datasheet I read that the AXP2101 pin for EX/PWRON can be configured as "enable pin" so that we do not need the PWRKEY to be pressed every time.

from the library it is not clear to me how to setup the PMU so that it will simply turn on/off using the pin as an ENABLE signal.

could you please help ?

thanks

Charger voltage settings

Hello Dear,

Thanks alot for your work.
I think the structure should start with 1 and not with 0 according to the datasheet.
000 is 'reserved'
Kindly check if i am right or wrong.
This the following changes the charger outputs a proper voltage.
typedef enum __xpowers_axp2101_chg_vol {
XPOWERS_AXP2101_CHG_VOL_4V = 1,
XPOWERS_AXP2101_CHG_VOL_4V1,
XPOWERS_AXP2101_CHG_VOL_4V2,
XPOWERS_AXP2101_CHG_VOL_4V35,
XPOWERS_AXP2101_CHG_VOL_4V4,
XPOWERS_AXP2101_CHG_VOL_MAX
} xpowers_axp2101_chg_vol_t;

SYStem Current

Is there any way to get current system uses, my board have SY6970 chip.
Thank you!

Volos

help with AXP2101 begin or init

Hi,

I'm trying to init/begin the chip AXP2101 of the new T-Beam V1.2

#define I2C_SDA 21
#define I2C_SCL 22
bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, I2C_SDA, I2C_SCL);

results always returns 1 , which I asume is "not" begin successful, right?

The library is not supported in pure C language

Hi,

I've been trying to use the library in my project from PlatformIO (v0.1.7) but after having it included in my espidf pure C code, the compiler complains about hpp and tpp files (because they are actually not C friendly and cannot be compiled and included in a C project: see https://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions).

Can you please make it so it would be usable? Or is there an alternative to manage the PMU (I have T-7080G-S3) using other libs?

Temperature function for AXP 2101

Hello, firstly thank you for creating and managing this library. It has been very helpful to track these parameters of the microcontrollers.

I have 2 T-Beams, one with the AXP192 and one with AXP 2101. My aim is to retrieve if the T-Beam is charging, temperature, battery voltage and percentage and forward it to TTN. For the AXP192, I can see all these parameters but for AXP2101, the example does not show how to retrieve temperature data.

However, when I add the statement PMU.getBattVoltage() and print it out and send it to ttn, it produces a faulty value. For example. it returns temperature as 58.2 degrees when it should be in the 30s range. Is this function not configured for the AXP2101?

Thank you.

Are AXP2101 and AXP2102 the same?

Hello, i'm trying to compile some examples and when i open the "AXP2101_Example" right at the start the file i see:

// Defined using AXP2102
#define XPOWERS_CHIP_AXP2102

And if i try to use:

#define XPOWERS_CHIP_AXP2101

it doesn't exist, so do AXP2101 and AXP2102 use the same protocol and can be used interchangeably? or i'm just a dummy?

PMU is not online...Please help me!

Dear lewisxhe,
when I scan i2c address, I received 0x34.
but when I use example AXP2101_Voltage_Example, I received "PMU is not online"
I don't know why, i2c bus is ok, 2 resistors pullup is ok, but my device can't connect to AXP2101!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here is my code:

#define XPOWERS_CHIP_AXP2101

#include <Wire.h>
#include <Arduino.h>
#include "XPowersLib.h"

XPowersPMU PMU;

#ifndef CONFIG_PMU_SDA
#define CONFIG_PMU_SDA 10
#endif

#ifndef CONFIG_PMU_SCL
#define CONFIG_PMU_SCL 9
#endif

#ifndef CONFIG_PMU_IRQ
#define CONFIG_PMU_IRQ 8
#endif

const uint8_t i2c_sda = CONFIG_PMU_SDA;
const uint8_t i2c_scl = CONFIG_PMU_SCL;
const uint8_t pmu_irq_pin = CONFIG_PMU_IRQ;

uint16_t targetVol;
//uint16_t vol = 0;


void setup()
{
    Serial.begin(115200);
    Wire.begin();
    bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl);
    delay(100);

    if (result == false) {
      Serial.println("PMU is not online..."); while (1)delay(50);
    }

    Serial.println("AXP2101 Power Output Test.");

    PMU.disableDC2();
    PMU.disableDC3();
    PMU.disableDC4();
    PMU.disableDC5();
    PMU.disableALDO1();
    PMU.disableALDO2();
    PMU.disableALDO3();
    PMU.disableALDO4();
    PMU.disableBLDO1();
    PMU.disableBLDO2();
    PMU.disableCPUSLDO();
    PMU.disableDLDO1();
    PMU.disableDLDO2();

    //DCDC1
    PMU.setDC1Voltage(3300);
    
    //DCDC3
    PMU.setDC3Voltage(3300);
    delay(1);
    targetVol = PMU.getDC3Voltage();
    
    //ALDO1 IMAX=300mA
    //500~3500mV, 100mV/step,31steps
    PMU.setALDO1Voltage(3300);
    delay(1);
    targetVol = PMU.getALDO1Voltage();
        
    //ALDO2 IMAX=300mA
    //500~3500mV, 100mV/step,31steps
    PMU.setALDO2Voltage(3300);
    delay(1);
    targetVol = PMU.getALDO2Voltage();
    
    //ALDO3 IMAX=300mA
    //500~3500mV, 100mV/step,31steps

    PMU.setALDO3Voltage(3300);
    delay(1);
    targetVol = PMU.getALDO3Voltage();
    
    //ALDO4 IMAX=300mA
    //500~3500mV, 100mV/step,31steps
    PMU.setALDO4Voltage(3300);
    delay(1);
    targetVol = PMU.getALDO4Voltage();
    
    //BLDO1 IMAX=300mA
    //500~3500mV, 100mV/step,31steps
    PMU.setBLDO1Voltage(3300);
    delay(1);
    targetVol = PMU.getBLDO1Voltage();
    
    PMU.enableDC1();
    PMU.enableDC3();

    PMU.enableALDO1();
    PMU.enableALDO2();
    PMU.enableALDO3();
    PMU.enableALDO4();
    PMU.enableBLDO1();
}
/////////////////////////////////////////////////////////////
void loop()
{
    delay(100);
}

Small charge current in constant charge(CC)! Please help me!

20:48:50.186 -> AXP2101 Started Successful.
20:48:50.186 -> DCDC1 :ENABLE Voltage:3100 mV
20:48:50.218 -> DCDC3 :DISABLE Voltage:3300 mV
20:48:50.218 -> ALDO1 :DISABLE Voltage:3300 mV
20:48:50.218 -> ALDO2 :DISABLE Voltage:3100 mV
20:48:50.218 -> ALDO3 :DISABLE Voltage:3100 mV
20:48:50.218 -> ALDO4 :DISABLE Voltage:3100 mV
20:48:50.218 -> BLDO1 :DISABLE Voltage:3300 mV
20:48:50.218 -> -> getSysPowerDownVoltage:2600
20:48:50.218 -> DISABLE - HEX:0xffffffff
20:48:50.218 -> ENABLE - HEX:0x18fcc0
20:48:50.259 -> Setting Charge Target Current : 1000
20:48:50.259 -> Setting Charge Target Voltage : 4200
20:48:50.259 ->
20:48:55.248 -> ---------------------------------------------------------------------------------------------------------
20:48:55.248 -> Satus1 Satus2 CHARG DISC STBY VBUSIN VGOOD VBAT VBUS VSYS Percentage CHG_STATUS
20:48:55.248 -> (Bin) (Bin) (bool) (bool) (bool) (bool) (bool) (mV) (mV) (mV) (%) (str)
20:48:55.248 -> ---------------------------------------------------------------------------------------------------------
20:48:55.294 -> 0b11000 0b10010 YES NO NO YES YES 3774 4771 4765 49 constant charge(CC)

20:49:06.297 -> =====================================================================
20:49:06.297 -> BatVoltage: 3772(49%)
20:49:06.297 -> >>>>>>register 0x0: 0b111000
20:49:06.297 -> >>>>>>register 0x1: 0b110010
20:49:06.297 -> >>>>>>register 0x67: 0b11100110
20:49:06.340 -> charge_status: 0b10

The charging current is only about 3-5mA, so the charging time exceeds 12H (set by reg67H[5:4]), and thus also interrupts the charging process. I can't fix this problem, please help me!

Equivalent of AXP202 library

Is there an equivalent library for a battery powered ESP32-S3 to the AXP202 library for the TTGO T-Watch.
Currant usage could be measured without a device, such as an INA219 module.
The getBattChargeCurrent() and getBattDischargeCurrent() function are very useful.

The AXP2021 chip shutdown by itself

Hello Dear,

May be this issue is not related to the library.
But i have no any other support sources.

The new boards arrived. All 50 are having strange behavier.
It is eather electrical connection issue or AXP2101 are faulty.

I am receiving this IRQ's in a raw and after that MPU shutdown:
isVbusRemove
isBatInsert
isBatRemove
isPekeyShortPress
isPekeyLongPress

This issue can happen during charging or during normal operations.
This issue can happen 1 hour after start or even 40 hours after start.
And i can not find any links to anything. It is just random shutdowns...

I am using
DCDC1 as ESP32 + Radio module power supply (max 0.6A total)
DCDC3 as GPS power supply (max 0.3A)
ALDO1 as gyro power supply (little load)
ALDO2 as spare power supply.

Kindly help with your expirience.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.