Added very basic support for Heltec V3 battery voltage

This commit is contained in:
macvenez 2024-09-02 18:14:44 +02:00
parent 06b4683993
commit a73bdad9fd
2 changed files with 1180 additions and 1096 deletions

View File

@ -122,8 +122,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_TBEAM #elif BOARD_MODEL == BOARD_TBEAM
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -163,8 +162,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_HUZZAH32 #elif BOARD_MODEL == BOARD_HUZZAH32
#define HAS_BLUETOOTH true #define HAS_BLUETOOTH true
@ -196,8 +194,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_LORA32_V1_0 #elif BOARD_MODEL == BOARD_LORA32_V1_0
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -240,8 +237,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_LORA32_V2_0 #elif BOARD_MODEL == BOARD_LORA32_V2_0
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -262,7 +258,6 @@
const int pin_led_tx = 22; const int pin_led_tx = 22;
#endif #endif
const uint8_t interfaces[INTERFACE_COUNT] = {SX127X}; const uint8_t interfaces[INTERFACE_COUNT] = {SX127X};
const bool interface_cfg[INTERFACE_COUNT][3] = { const bool interface_cfg[INTERFACE_COUNT][3] = {
// SX127X // SX127X
@ -285,8 +280,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_LORA32_V2_1 #elif BOARD_MODEL == BOARD_LORA32_V2_1
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -321,8 +315,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
33 // pin_tcxo_enable 33 // pin_tcxo_enable
} }};
};
#endif #endif
#if defined(EXTERNAL_LEDS) #if defined(EXTERNAL_LEDS)
const int pin_led_rx = 15; const int pin_led_rx = 15;
@ -355,8 +348,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#endif #endif
#elif BOARD_MODEL == BOARD_HELTEC32_V2 #elif BOARD_MODEL == BOARD_HELTEC32_V2
@ -396,8 +388,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_HELTEC32_V3 #elif BOARD_MODEL == BOARD_HELTEC32_V3
#define IS_ESP32S3 true #define IS_ESP32S3 true
@ -411,6 +402,7 @@
#define PIN_WAKEUP GPIO_NUM_0 #define PIN_WAKEUP GPIO_NUM_0
#define WAKEUP_LEVEL 0 #define WAKEUP_LEVEL 0
#define INTERFACE_COUNT 1 #define INTERFACE_COUNT 1
#define HAS_PMU true
const int pin_btn_usr1 = 0; const int pin_btn_usr1 = 0;
@ -444,8 +436,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_RNODE_NG_20 #elif BOARD_MODEL == BOARD_RNODE_NG_20
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -469,7 +460,6 @@
#endif #endif
#endif #endif
const uint8_t interfaces[INTERFACE_COUNT] = {SX1276}; const uint8_t interfaces[INTERFACE_COUNT] = {SX1276};
const bool interface_cfg[INTERFACE_COUNT][3] = { const bool interface_cfg[INTERFACE_COUNT][3] = {
// SX1276 // SX1276
@ -492,8 +482,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_RNODE_NG_21 #elif BOARD_MODEL == BOARD_RNODE_NG_21
#define HAS_DISPLAY true #define HAS_DISPLAY true
@ -522,7 +511,6 @@
#endif #endif
#endif #endif
const uint8_t interfaces[INTERFACE_COUNT] = {SX127X}; const uint8_t interfaces[INTERFACE_COUNT] = {SX127X};
const bool interface_cfg[INTERFACE_COUNT][3] = { const bool interface_cfg[INTERFACE_COUNT][3] = {
// SX127X // SX127X
@ -545,8 +533,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_MODEL == BOARD_T3S3 #elif BOARD_MODEL == BOARD_T3S3
#define IS_ESP32S3 true #define IS_ESP32S3 true
@ -622,8 +609,7 @@
-1, // pin_txen -1, // pin_txen
-1, // pin_rxen -1, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#else #else
#error An unsupported ESP32 board was selected. Cannot compile RNode firmware. #error An unsupported ESP32 board was selected. Cannot compile RNode firmware.
#endif #endif
@ -658,8 +644,7 @@
false, // DEFAULT_SPI false, // DEFAULT_SPI
true, // HAS_TCXO true, // HAS_TCXO
true // DIO2_AS_RF_SWITCH true // DIO2_AS_RF_SWITCH
} }};
};
const int8_t interface_pins[INTERFACE_COUNT][10] = { const int8_t interface_pins[INTERFACE_COUNT][10] = {
// SX1262 // SX1262
{ {
@ -673,8 +658,7 @@
-1, // pin_txen -1, // pin_txen
37, // pin_rxen 37, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#elif BOARD_VARIANT == MODEL_13 || BOARD_VARIANT == MODEL_14 || BOARD_VARIANT == MODEL_21 #elif BOARD_VARIANT == MODEL_13 || BOARD_VARIANT == MODEL_14 || BOARD_VARIANT == MODEL_21
#define INTERFACE_COUNT 2 #define INTERFACE_COUNT 2
@ -694,8 +678,7 @@
true, // DEFAULT_SPI true, // DEFAULT_SPI
false, // HAS_TCXO false, // HAS_TCXO
false // DIO2_AS_RF_SWITCH false // DIO2_AS_RF_SWITCH
} }};
};
const int8_t interface_pins[INTERFACE_COUNT][10] = { const int8_t interface_pins[INTERFACE_COUNT][10] = {
// SX1262 // SX1262
{ {
@ -722,11 +705,9 @@
20, // pin_txen 20, // pin_txen
19, // pin_rxen 19, // pin_rxen
-1 // pin_tcxo_enable -1 // pin_tcxo_enable
} }};
};
#endif #endif
const int pin_disp_cs = SS; const int pin_disp_cs = SS;
const int pin_disp_dc = WB_IO1; const int pin_disp_dc = WB_IO1;
const int pin_disp_reset = -1; const int pin_disp_reset = -1;

223
Power.h
View File

@ -9,8 +9,10 @@
#define BAT_V_MIN 3.15 #define BAT_V_MIN 3.15
#define BAT_V_MAX 4.14 #define BAT_V_MAX 4.14
void disablePeripherals() { void disablePeripherals()
if (PMU) { {
if (PMU)
{
// GNSS RTC PowerVDD // GNSS RTC PowerVDD
PMU->enablePowerOutput(XPOWERS_VBACKUP); PMU->enablePowerOutput(XPOWERS_VBACKUP);
@ -64,6 +66,9 @@ int bat_charging_samples = 0;
int bat_charged_samples = 0; int bat_charged_samples = 0;
bool bat_voltage_dropping = false; bool bat_voltage_dropping = false;
float bat_delay_v = 0; float bat_delay_v = 0;
#elif BOARD_MODEL == BOARD_HELTEC32_V3
#define PIN_VBAT 1
#define VBAT_READ_CNTRL_PIN 37
#endif #endif
uint32_t last_pmu_update = 0; uint32_t last_pmu_update = 0;
@ -73,7 +78,8 @@ uint8_t pmu_rc = 0;
#define PMU_R_INTERVAL 5 #define PMU_R_INTERVAL 5
void kiss_indicate_battery(); void kiss_indicate_battery();
void measure_battery() { void measure_battery()
{
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1
battery_installed = true; battery_installed = true;
battery_indeterminate = true; battery_indeterminate = true;
@ -81,40 +87,54 @@ void measure_battery() {
bat_p_samples[bat_samples_count % BAT_SAMPLES] = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0; bat_p_samples[bat_samples_count % BAT_SAMPLES] = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0;
bat_samples_count++; bat_samples_count++;
if (!battery_ready && bat_samples_count >= BAT_SAMPLES) { if (!battery_ready && bat_samples_count >= BAT_SAMPLES)
{
battery_ready = true; battery_ready = true;
} }
if (battery_ready) { if (battery_ready)
{
battery_percent = 0; battery_percent = 0;
for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++) { for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++)
{
battery_percent += bat_p_samples[bi]; battery_percent += bat_p_samples[bi];
} }
battery_percent = battery_percent / BAT_SAMPLES; battery_percent = battery_percent / BAT_SAMPLES;
battery_voltage = 0; battery_voltage = 0;
for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++) { for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++)
{
battery_voltage += bat_v_samples[bi]; battery_voltage += bat_v_samples[bi];
} }
battery_voltage = battery_voltage / BAT_SAMPLES; battery_voltage = battery_voltage / BAT_SAMPLES;
if (bat_delay_v == 0) bat_delay_v = battery_voltage; if (bat_delay_v == 0)
if (battery_percent > 100.0) battery_percent = 100.0; bat_delay_v = battery_voltage;
if (battery_percent < 0.0) battery_percent = 0.0; if (battery_percent > 100.0)
battery_percent = 100.0;
if (battery_percent < 0.0)
battery_percent = 0.0;
if (bat_samples_count%BAT_SAMPLES == 0) { if (bat_samples_count % BAT_SAMPLES == 0)
if (battery_voltage < bat_delay_v && battery_voltage < BAT_V_FLOAT) { {
if (battery_voltage < bat_delay_v && battery_voltage < BAT_V_FLOAT)
{
bat_voltage_dropping = true; bat_voltage_dropping = true;
} else { }
else
{
bat_voltage_dropping = false; bat_voltage_dropping = false;
} }
bat_samples_count = 0; bat_samples_count = 0;
} }
if (bat_voltage_dropping && battery_voltage < BAT_V_FLOAT) { if (bat_voltage_dropping && battery_voltage < BAT_V_FLOAT)
{
battery_state = BATTERY_STATE_DISCHARGING; battery_state = BATTERY_STATE_DISCHARGING;
} else { }
else
{
#if BOARD_MODEL == BOARD_RNODE_NG_21 #if BOARD_MODEL == BOARD_RNODE_NG_21
battery_state = BATTERY_STATE_CHARGING; battery_state = BATTERY_STATE_CHARGING;
#else #else
@ -122,8 +142,6 @@ void measure_battery() {
#endif #endif
} }
// if (bt_state == BT_STATE_CONNECTED) { // if (bt_state == BT_STATE_CONNECTED) {
// SerialBT.printf("Bus voltage %.3fv. Unfiltered %.3fv.", battery_voltage, bat_v_samples[BAT_SAMPLES-1]); // SerialBT.printf("Bus voltage %.3fv. Unfiltered %.3fv.", battery_voltage, bat_v_samples[BAT_SAMPLES-1]);
// if (bat_voltage_dropping) { // if (bat_voltage_dropping) {
@ -134,13 +152,44 @@ void measure_battery() {
// } // }
} }
#elif BOARD_MODEL == BOARD_HELTEC32_V3
battery_installed = true;
battery_indeterminate = false;
battery_state = BATTERY_STATE_DISCHARGING;
battery_ready = true;
digitalWrite(VBAT_READ_CNTRL_PIN, LOW);
analogSetPinAttenuation(PIN_VBAT, ADC_2_5db);
delay(50);
analogRead(PIN_VBAT); // to clear out potential wrong reads on first read
int analogValue = 0;
for (int i = 0; i < 5; i++)
{
analogValue += analogRead(PIN_VBAT); // reading value to make an average over 5 values
delay(10);
}
analogValue /= 5; // calculate average value
digitalWrite(VBAT_READ_CNTRL_PIN, HIGH);
battery_voltage = (float(analogValue) / 4095.0) * 1.25 * (4.9); // at 2.5db attenuation range is 0-1250mV, 4.9 is voltage divider ratio
battery_percent = (battery_voltage - 3.4) * 125.0;
if (battery_percent > 100.0)
{
battery_percent = 100.0;
}
if (battery_percent < 0.0)
{
battery_percent = 0.0;
}
#elif BOARD_MODEL == BOARD_TBEAM #elif BOARD_MODEL == BOARD_TBEAM
if (PMU) { if (PMU)
{
float discharge_current = 0; float discharge_current = 0;
float charge_current = 0; float charge_current = 0;
float ext_voltage = 0; float ext_voltage = 0;
float ext_current = 0; float ext_current = 0;
if (PMU->getChipModel() == XPOWERS_AXP192) { if (PMU->getChipModel() == XPOWERS_AXP192)
{
discharge_current = ((XPowersAXP192 *)PMU)->getBattDischargeCurrent(); discharge_current = ((XPowersAXP192 *)PMU)->getBattDischargeCurrent();
charge_current = ((XPowersAXP192 *)PMU)->getBatteryChargeCurrent(); charge_current = ((XPowersAXP192 *)PMU)->getBatteryChargeCurrent();
battery_voltage = PMU->getBattVoltage() / 1000.0; battery_voltage = PMU->getBattVoltage() / 1000.0;
@ -150,7 +199,8 @@ void measure_battery() {
ext_voltage = PMU->getVbusVoltage() / 1000.0; ext_voltage = PMU->getVbusVoltage() / 1000.0;
ext_current = ((XPowersAXP192 *)PMU)->getVbusCurrent(); ext_current = ((XPowersAXP192 *)PMU)->getVbusCurrent();
} }
else if (PMU->getChipModel() == XPOWERS_AXP2101) { else if (PMU->getChipModel() == XPOWERS_AXP2101)
{
battery_voltage = PMU->getBattVoltage() / 1000.0; battery_voltage = PMU->getBattVoltage() / 1000.0;
// battery_percent = PMU->getBattPercentage()*1.0; // battery_percent = PMU->getBattPercentage()*1.0;
battery_installed = PMU->isBatteryConnect(); battery_installed = PMU->isBatteryConnect();
@ -158,27 +208,38 @@ void measure_battery() {
ext_voltage = PMU->getVbusVoltage() / 1000.0; ext_voltage = PMU->getVbusVoltage() / 1000.0;
} }
if (battery_installed) { if (battery_installed)
if (PMU->isCharging()) { {
if (PMU->isCharging())
{
battery_state = BATTERY_STATE_CHARGING; battery_state = BATTERY_STATE_CHARGING;
battery_percent = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0; battery_percent = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0;
} else { }
if (PMU->isDischarge()) { else
{
if (PMU->isDischarge())
{
battery_state = BATTERY_STATE_DISCHARGING; battery_state = BATTERY_STATE_DISCHARGING;
battery_percent = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0; battery_percent = ((battery_voltage - BAT_V_MIN) / (BAT_V_MAX - BAT_V_MIN)) * 100.0;
} else { }
else
{
battery_state = BATTERY_STATE_CHARGED; battery_state = BATTERY_STATE_CHARGED;
battery_percent = 100.0; battery_percent = 100.0;
} }
} }
} else { }
else
{
battery_state = BATTERY_STATE_DISCHARGING; battery_state = BATTERY_STATE_DISCHARGING;
battery_percent = 0.0; battery_percent = 0.0;
battery_voltage = 0.0; battery_voltage = 0.0;
} }
if (battery_percent > 100.0) battery_percent = 100.0; if (battery_percent > 100.0)
if (battery_percent < 0.0) battery_percent = 0.0; battery_percent = 100.0;
if (battery_percent < 0.0)
battery_percent = 0.0;
float charge_watts = battery_voltage * (charge_current / 1000.0); float charge_watts = battery_voltage * (charge_current / 1000.0);
float discharge_watts = battery_voltage * (discharge_current / 1000.0); float discharge_watts = battery_voltage * (discharge_current / 1000.0);
@ -210,7 +271,8 @@ void measure_battery() {
// SerialBT.println(""); // SerialBT.println("");
// } // }
} }
else { else
{
battery_ready = false; battery_ready = false;
} }
@ -220,106 +282,147 @@ void measure_battery() {
bat_v_samples[bat_samples_count % BAT_SAMPLES] = (float)(analogRead(PIN_VBAT)) * VBAT_MV_PER_LSB_FIN; bat_v_samples[bat_samples_count % BAT_SAMPLES] = (float)(analogRead(PIN_VBAT)) * VBAT_MV_PER_LSB_FIN;
if (bat_v_samples[bat_samples_count%BAT_SAMPLES] < 3300) { if (bat_v_samples[bat_samples_count % BAT_SAMPLES] < 3300)
{
bat_p_samples[bat_samples_count % BAT_SAMPLES] = 0; bat_p_samples[bat_samples_count % BAT_SAMPLES] = 0;
} }
else if (bat_v_samples[bat_samples_count % BAT_SAMPLES] < 3600) else if (bat_v_samples[bat_samples_count % BAT_SAMPLES] < 3600)
{ {
bat_v_samples[bat_samples_count % BAT_SAMPLES] -= 3300; bat_v_samples[bat_samples_count % BAT_SAMPLES] -= 3300;
bat_p_samples[bat_samples_count % BAT_SAMPLES] = bat_v_samples[bat_samples_count % BAT_SAMPLES] / 30; bat_p_samples[bat_samples_count % BAT_SAMPLES] = bat_v_samples[bat_samples_count % BAT_SAMPLES] / 30;
} else { }
else
{
bat_v_samples[bat_samples_count % BAT_SAMPLES] -= 3600; bat_v_samples[bat_samples_count % BAT_SAMPLES] -= 3600;
} }
bat_p_samples[bat_samples_count % BAT_SAMPLES] = 10 + (bat_v_samples[bat_samples_count % BAT_SAMPLES] * 0.15F); bat_p_samples[bat_samples_count % BAT_SAMPLES] = 10 + (bat_v_samples[bat_samples_count % BAT_SAMPLES] * 0.15F);
bat_samples_count++; bat_samples_count++;
if (!battery_ready && bat_samples_count >= BAT_SAMPLES) { if (!battery_ready && bat_samples_count >= BAT_SAMPLES)
{
battery_ready = true; battery_ready = true;
} }
battery_percent = 0; battery_percent = 0;
for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++) { for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++)
{
battery_percent += bat_p_samples[bi]; battery_percent += bat_p_samples[bi];
} }
battery_percent = battery_percent / BAT_SAMPLES; battery_percent = battery_percent / BAT_SAMPLES;
battery_voltage = 0; battery_voltage = 0;
for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++) { for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++)
{
battery_voltage += bat_v_samples[bi]; battery_voltage += bat_v_samples[bi];
} }
battery_voltage = battery_voltage / BAT_SAMPLES; battery_voltage = battery_voltage / BAT_SAMPLES;
if (bat_delay_v == 0) bat_delay_v = battery_voltage; if (bat_delay_v == 0)
if (battery_percent > 100.0) battery_percent = 100.0; bat_delay_v = battery_voltage;
if (battery_percent < 0.0) battery_percent = 0.0; if (battery_percent > 100.0)
battery_percent = 100.0;
if (battery_percent < 0.0)
battery_percent = 0.0;
if (bat_samples_count%BAT_SAMPLES == 0) { if (bat_samples_count % BAT_SAMPLES == 0)
if (battery_voltage < bat_delay_v && battery_voltage < BAT_V_FLOAT) { {
if (battery_voltage < bat_delay_v && battery_voltage < BAT_V_FLOAT)
{
bat_voltage_dropping = true; bat_voltage_dropping = true;
} else { }
else
{
bat_voltage_dropping = false; bat_voltage_dropping = false;
} }
bat_samples_count = 0; bat_samples_count = 0;
} }
nrfx_power_usb_state_t usbstate = nrfx_power_usbstatus_get(); nrfx_power_usb_state_t usbstate = nrfx_power_usbstatus_get();
if (usbstate == NRFX_POWER_USB_STATE_CONNECTED || usbstate == NRFX_POWER_USB_STATE_READY) { if (usbstate == NRFX_POWER_USB_STATE_CONNECTED || usbstate == NRFX_POWER_USB_STATE_READY)
{
// charging // charging
battery_state = BATTERY_STATE_CHARGING; battery_state = BATTERY_STATE_CHARGING;
} else { }
else
{
battery_state = BATTERY_STATE_DISCHARGING; battery_state = BATTERY_STATE_DISCHARGING;
} }
if (battery_percent >= 98) { if (battery_percent >= 98)
{
battery_state = BATTERY_STATE_CHARGED; battery_state = BATTERY_STATE_CHARGED;
} }
#endif #endif
if (battery_ready) { if (battery_ready)
{
pmu_rc++; pmu_rc++;
if (pmu_rc%PMU_R_INTERVAL == 0) { if (pmu_rc % PMU_R_INTERVAL == 0)
{
kiss_indicate_battery(); kiss_indicate_battery();
} }
} }
} }
void update_pmu() { void update_pmu()
if (millis()-last_pmu_update >= pmu_update_interval) { {
if (millis() - last_pmu_update >= pmu_update_interval)
{
measure_battery(); measure_battery();
last_pmu_update = millis(); last_pmu_update = millis();
} }
} }
bool init_pmu() { bool init_pmu()
{
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1
pinMode(pin_vbat, INPUT); pinMode(pin_vbat, INPUT);
return true; return true;
#elif BOARD_MODEL == BOARD_HELTEC32_V3
pinMode(PIN_VBAT, INPUT);
pinMode(VBAT_READ_CNTRL_PIN, OUTPUT);
adcAttachPin(PIN_VBAT);
analogReadResolution(12);
return true;
#elif BOARD_MODEL == BOARD_TBEAM #elif BOARD_MODEL == BOARD_TBEAM
Wire.begin(I2C_SDA, I2C_SCL); Wire.begin(I2C_SDA, I2C_SCL);
if (!PMU) { if (!PMU)
{
PMU = new XPowersAXP2101(PMU_WIRE_PORT); PMU = new XPowersAXP2101(PMU_WIRE_PORT);
if (!PMU->init()) { if (!PMU->init())
{
Serial.println("Warning: Failed to find AXP2101 power management"); Serial.println("Warning: Failed to find AXP2101 power management");
delete PMU; delete PMU;
PMU = NULL; PMU = NULL;
} else { }
else
{
Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU"); Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU");
} }
} }
if (!PMU) { if (!PMU)
{
PMU = new XPowersAXP192(PMU_WIRE_PORT); PMU = new XPowersAXP192(PMU_WIRE_PORT);
if (!PMU->init()) { if (!PMU->init())
{
Serial.println("Warning: Failed to find AXP192 power management"); Serial.println("Warning: Failed to find AXP192 power management");
delete PMU; delete PMU;
PMU = NULL; PMU = NULL;
} else { }
else
{
Serial.println("AXP192 PMU init succeeded, using AXP192 PMU"); Serial.println("AXP192 PMU init succeeded, using AXP192 PMU");
} }
} }
if (!PMU) { if (!PMU)
{
return false; return false;
} }
@ -329,7 +432,8 @@ bool init_pmu() {
pinMode(PMU_IRQ, INPUT_PULLUP); pinMode(PMU_IRQ, INPUT_PULLUP);
attachInterrupt(PMU_IRQ, setPmuFlag, FALLING); attachInterrupt(PMU_IRQ, setPmuFlag, FALLING);
if (PMU->getChipModel() == XPOWERS_AXP192) { if (PMU->getChipModel() == XPOWERS_AXP192)
{
// Turn off unused power sources to save power // Turn off unused power sources to save power
PMU->disablePowerOutput(XPOWERS_DCDC1); PMU->disablePowerOutput(XPOWERS_DCDC1);
@ -366,11 +470,10 @@ bool init_pmu() {
XPOWERS_AXP192_BAT_CHG_START_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ |
XPOWERS_AXP192_BAT_REMOVE_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ |
XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_INSERT_IRQ |
XPOWERS_AXP192_PKEY_SHORT_IRQ XPOWERS_AXP192_PKEY_SHORT_IRQ);
);
} }
else if (PMU->getChipModel() == XPOWERS_AXP2101) { else if (PMU->getChipModel() == XPOWERS_AXP2101)
{
// Turn off unused power sources to save power // Turn off unused power sources to save power
PMU->disablePowerOutput(XPOWERS_DCDC2); PMU->disablePowerOutput(XPOWERS_DCDC2);