Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c70a0d42c9 | |||
| eda7c3701c | |||
| dcefe939a6 | |||
| 3666de2d55 | |||
| 89315fb288 | |||
| 39960f7725 | |||
| 95975447dc | |||
| 2b147d2199 | |||
| 0c92a36bf8 | |||
| cf30a62011 | |||
| 67d9db9c7a |
@@ -1,7 +1,10 @@
|
||||
#include "axp2101.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
#include <Esp.h>
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_PMU_SDA
|
||||
#define CONFIG_PMU_SDA 21
|
||||
@@ -18,9 +21,12 @@
|
||||
bool pmu_flag = 0;
|
||||
XPowersPMU PMU;
|
||||
|
||||
const uint8_t i2c_sda = CONFIG_PMU_SDA;
|
||||
const uint8_t i2c_scl = CONFIG_PMU_SCL;
|
||||
//const uint8_t i2c_sda = CONFIG_PMU_SDA;
|
||||
//const uint8_t i2c_scl = CONFIG_PMU_SCL;
|
||||
#ifdef USE_ARDUINO
|
||||
// TODO: Use esphome APIs (to allow I/O expanders, etc)
|
||||
const uint8_t pmu_irq_pin = CONFIG_PMU_IRQ;
|
||||
#endif
|
||||
|
||||
void setFlag(void)
|
||||
{
|
||||
@@ -34,6 +40,11 @@ static const char *TAG = "axp2101.sensor";
|
||||
|
||||
void AXP2101Component::setup()
|
||||
{
|
||||
ESP_LOGI(TAG, "AXP2101Component::setup invoked");
|
||||
PMU.init();
|
||||
|
||||
#warning "axp2101.sensor basically disabled XXX"
|
||||
#if 0
|
||||
ESP_LOGCONFIG(TAG, "getID:0x%x", PMU.getChipID());
|
||||
|
||||
// Set the minimum common working voltage of the PMU VBUS input,
|
||||
@@ -124,17 +135,17 @@ void AXP2101Component::setup()
|
||||
|
||||
|
||||
// PMU.enableDC1();
|
||||
PMU.enableDC2();
|
||||
PMU.enableDC3();
|
||||
PMU.enableDC4();
|
||||
PMU.enableDC5();
|
||||
PMU.enableALDO1();
|
||||
PMU.enableALDO2();
|
||||
// PMU.enableALDO3(); // This is the speaker
|
||||
PMU.enableALDO4();
|
||||
PMU.enableBLDO1();
|
||||
PMU.enableBLDO2();
|
||||
PMU.enableCPUSLDO();
|
||||
// PMU.enableDC2();
|
||||
// PMU.enableDC3();
|
||||
// PMU.enableDC4();
|
||||
// PMU.enableDC5();
|
||||
// PMU.enableALDO1();
|
||||
// PMU.enableALDO2();
|
||||
// // PMU.enableALDO3(); // This is the speaker
|
||||
// PMU.enableALDO4();
|
||||
// PMU.enableBLDO1();
|
||||
// PMU.enableBLDO2();
|
||||
// PMU.enableCPUSLDO();
|
||||
// PMU.enableDLDO1(); // This is the vibration motor
|
||||
// PMU.enableDLDO2();
|
||||
|
||||
@@ -196,30 +207,30 @@ void AXP2101Component::setup()
|
||||
bool en;
|
||||
|
||||
// DCDC 120%(130%) high voltage turn off PMIC function
|
||||
en = PMU.getDCHighVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDCHighVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDCHighVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDCHighVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
// DCDC1 85% low voltage turn off PMIC function
|
||||
en = PMU.getDC1LowVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC1LowVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDC1LowVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC1LowVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
// DCDC2 85% low voltage turn off PMIC function
|
||||
en = PMU.getDC2LowVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC2LowVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDC2LowVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC2LowVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
// DCDC3 85% low voltage turn off PMIC function
|
||||
en = PMU.getDC3LowVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC3LowVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDC3LowVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC3LowVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
// DCDC4 85% low voltage turn off PMIC function
|
||||
en = PMU.getDC4LowVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC4LowVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDC4LowVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC4LowVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
// DCDC5 85% low voltage turn off PMIC function
|
||||
en = PMU.getDC5LowVoltagePowerDowmEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC5LowVoltagePowerDowmEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
en = PMU.getDC5LowVoltagePowerDownEn();
|
||||
ESP_LOGCONFIG(TAG, "getDC5LowVoltagePowerDownEn: %s", en ? "ENABLE" : "DISABLE");
|
||||
|
||||
// PMU.setDCHighVoltagePowerDowm(true);
|
||||
// PMU.setDC1LowVoltagePowerDowm(true);
|
||||
// PMU.setDC2LowVoltagePowerDowm(true);
|
||||
// PMU.setDC3LowVoltagePowerDowm(true);
|
||||
// PMU.setDC4LowVoltagePowerDowm(true);
|
||||
// PMU.setDC5LowVoltagePowerDowm(true);
|
||||
// PMU.setDCHighVoltagePowerDown(true);
|
||||
// PMU.setDC1LowVoltagePowerDown(true);
|
||||
// PMU.setDC2LowVoltagePowerDown(true);
|
||||
// PMU.setDC3LowVoltagePowerDown(true);
|
||||
// PMU.setDC4LowVoltagePowerDown(true);
|
||||
// PMU.setDC5LowVoltagePowerDown(true);
|
||||
|
||||
// It is necessary to disable the detection function of the TS pin on the board
|
||||
// without the battery temperature detection function, otherwise it will cause abnormal charging
|
||||
@@ -246,8 +257,12 @@ void AXP2101Component::setup()
|
||||
|
||||
|
||||
// Force add pull-up
|
||||
#ifdef USE_ARDUINO
|
||||
pinMode(pmu_irq_pin, INPUT_PULLUP);
|
||||
attachInterrupt(pmu_irq_pin, setFlag, FALLING);
|
||||
#else
|
||||
#warning "IRQ support not ready in ESP-IDF" // TODO
|
||||
#endif
|
||||
|
||||
|
||||
// Disable all interrupts
|
||||
@@ -287,20 +302,21 @@ void AXP2101Component::setup()
|
||||
|
||||
// Set Button Battery charge voltage
|
||||
PMU.setButtonBatteryChargeVoltage(3300);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AXP2101Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "AXP2101:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
LOG_SENSOR(" ", "Battery Voltage", this->batteryvoltage_sensor_);
|
||||
LOG_SENSOR(" ", "Battery Level", this->batterylevel_sensor_);
|
||||
LOG_BINARY_SENSOR(" ", "Battery Charging", this->batterycharging_bsensor_);
|
||||
//LOG_I2C_DEVICE(this);
|
||||
//LOG_SENSOR(" ", "Battery Voltage", this->batteryvoltage_sensor_);
|
||||
//LOG_SENSOR(" ", "Battery Level", this->batterylevel_sensor_);
|
||||
//LOG_BINARY_SENSOR(" ", "Battery Charging", this->batterycharging_bsensor_);
|
||||
}
|
||||
|
||||
float AXP2101Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
//float AXP2101Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
void AXP2101Component::update() {
|
||||
|
||||
#if 0
|
||||
if (this->batterylevel_sensor_ != nullptr) {
|
||||
float vbat = PMU.getBattVoltage();
|
||||
ESP_LOGD(TAG, "Got Battery Voltage=%f", vbat);
|
||||
@@ -329,10 +345,15 @@ void AXP2101Component::update() {
|
||||
ESP_LOGD(TAG, "Got Battery Charging=%s", vcharging ? "true" : "false");
|
||||
this->batterycharging_bsensor_->publish_state(vcharging);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
UpdateBrightness();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
void AXP2101Component::Write1Byte( uint8_t Addr , uint8_t Data )
|
||||
{
|
||||
this->write_byte(Addr, Data);
|
||||
@@ -817,6 +838,7 @@ std::string AXP2101Component::GetStartupReason() {
|
||||
return "ESP_RST_SDIO";
|
||||
return std::string{"RESET_UNKNOWN_REASON"};
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
// (In most use cases you won't need these)
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
//float get_setup_priority() const override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
@@ -61,65 +61,65 @@ protected:
|
||||
* LD03: Vibration Motor
|
||||
*/
|
||||
|
||||
void UpdateBrightness();
|
||||
bool GetBatState();
|
||||
uint8_t GetBatData();
|
||||
|
||||
void EnableCoulombcounter(void);
|
||||
void DisableCoulombcounter(void);
|
||||
void StopCoulombcounter(void);
|
||||
void ClearCoulombcounter(void);
|
||||
uint32_t GetCoulombchargeData(void);
|
||||
uint32_t GetCoulombdischargeData(void);
|
||||
float GetCoulombData(void);
|
||||
|
||||
uint16_t GetVbatData(void) __attribute__((deprecated));
|
||||
uint16_t GetIchargeData(void) __attribute__((deprecated));
|
||||
uint16_t GetIdischargeData(void) __attribute__((deprecated));
|
||||
uint16_t GetTempData(void) __attribute__((deprecated));
|
||||
uint32_t GetPowerbatData(void) __attribute__((deprecated));
|
||||
uint16_t GetVinData(void) __attribute__((deprecated));
|
||||
uint16_t GetIinData(void) __attribute__((deprecated));
|
||||
uint16_t GetVusbinData(void) __attribute__((deprecated));
|
||||
uint16_t GetIusbinData(void) __attribute__((deprecated));
|
||||
uint16_t GetVapsData(void) __attribute__((deprecated));
|
||||
uint8_t GetBtnPress(void);
|
||||
|
||||
// -- sleep
|
||||
void SetSleep(void);
|
||||
void DeepSleep(uint64_t time_in_us = 0);
|
||||
void LightSleep(uint64_t time_in_us = 0);
|
||||
|
||||
// void SetChargeVoltage( uint8_t );
|
||||
void SetChargeCurrent( uint8_t );
|
||||
float GetBatCurrent();
|
||||
float GetVinVoltage();
|
||||
float GetVinCurrent();
|
||||
float GetVBusVoltage();
|
||||
float GetVBusCurrent();
|
||||
float GetTempInAXP2101();
|
||||
float GetBatPower();
|
||||
float GetBatChargeCurrent();
|
||||
float GetAPSVoltage();
|
||||
float GetBatCoulombInput();
|
||||
float GetBatCoulombOut();
|
||||
uint8_t GetWarningLevel(void);
|
||||
void SetCoulombClear();
|
||||
void SetLDO2( bool State );
|
||||
void SetLDO3( bool State );
|
||||
void SetAdcState(bool State);
|
||||
|
||||
void PowerOff();
|
||||
|
||||
|
||||
void Write1Byte( uint8_t Addr , uint8_t Data );
|
||||
uint8_t Read8bit( uint8_t Addr );
|
||||
uint16_t Read12Bit( uint8_t Addr);
|
||||
uint16_t Read13Bit( uint8_t Addr);
|
||||
uint16_t Read16bit( uint8_t Addr );
|
||||
uint32_t Read24bit( uint8_t Addr );
|
||||
uint32_t Read32bit( uint8_t Addr );
|
||||
void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff );
|
||||
// void UpdateBrightness();
|
||||
// bool GetBatState();
|
||||
// uint8_t GetBatData();
|
||||
//
|
||||
// void EnableCoulombcounter(void);
|
||||
// void DisableCoulombcounter(void);
|
||||
// void StopCoulombcounter(void);
|
||||
// void ClearCoulombcounter(void);
|
||||
// uint32_t GetCoulombchargeData(void);
|
||||
// uint32_t GetCoulombdischargeData(void);
|
||||
// float GetCoulombData(void);
|
||||
//
|
||||
// uint16_t GetVbatData(void) __attribute__((deprecated));
|
||||
// uint16_t GetIchargeData(void) __attribute__((deprecated));
|
||||
// uint16_t GetIdischargeData(void) __attribute__((deprecated));
|
||||
// uint16_t GetTempData(void) __attribute__((deprecated));
|
||||
// uint32_t GetPowerbatData(void) __attribute__((deprecated));
|
||||
// uint16_t GetVinData(void) __attribute__((deprecated));
|
||||
// uint16_t GetIinData(void) __attribute__((deprecated));
|
||||
// uint16_t GetVusbinData(void) __attribute__((deprecated));
|
||||
// uint16_t GetIusbinData(void) __attribute__((deprecated));
|
||||
// uint16_t GetVapsData(void) __attribute__((deprecated));
|
||||
// uint8_t GetBtnPress(void);
|
||||
//
|
||||
// // -- sleep
|
||||
// void SetSleep(void);
|
||||
// void DeepSleep(uint64_t time_in_us = 0);
|
||||
// void LightSleep(uint64_t time_in_us = 0);
|
||||
//
|
||||
// // void SetChargeVoltage( uint8_t );
|
||||
// void SetChargeCurrent( uint8_t );
|
||||
// float GetBatCurrent();
|
||||
// float GetVinVoltage();
|
||||
// float GetVinCurrent();
|
||||
// float GetVBusVoltage();
|
||||
// float GetVBusCurrent();
|
||||
// float GetTempInAXP2101();
|
||||
// float GetBatPower();
|
||||
// float GetBatChargeCurrent();
|
||||
// float GetAPSVoltage();
|
||||
// float GetBatCoulombInput();
|
||||
// float GetBatCoulombOut();
|
||||
// uint8_t GetWarningLevel(void);
|
||||
// void SetCoulombClear();
|
||||
// void SetLDO2( bool State );
|
||||
// void SetLDO3( bool State );
|
||||
// void SetAdcState(bool State);
|
||||
//
|
||||
// void PowerOff();
|
||||
//
|
||||
//
|
||||
// void Write1Byte( uint8_t Addr , uint8_t Data );
|
||||
// uint8_t Read8bit( uint8_t Addr );
|
||||
// uint16_t Read12Bit( uint8_t Addr);
|
||||
// uint16_t Read13Bit( uint8_t Addr);
|
||||
// uint16_t Read16bit( uint8_t Addr );
|
||||
// uint32_t Read24bit( uint8_t Addr );
|
||||
// uint32_t Read32bit( uint8_t Addr );
|
||||
// void ReadBuff( uint8_t Addr , uint8_t Size , uint8_t *Buff );
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ def to_code(config):
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
|
||||
cg.add_library("lewisxhe/XPowersLib", "0.2.1")
|
||||
cg.add_library("lewisxhe/XPowersLib", "0.3.1")
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user