Very basic Heltec V3 battery support

This commit is contained in:
macvenez 2024-09-03 00:14:11 +02:00
parent 06b4683993
commit 2e25092e1d
2 changed files with 39 additions and 0 deletions

View File

@ -411,6 +411,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;

38
Power.h
View File

@ -64,6 +64,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;
@ -134,6 +137,35 @@ 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;
@ -294,6 +326,12 @@ 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);