Files
MeshCore/variants/heltec_rc32/HeltecRC32Board.cpp
T
mikecarper ab6412e73c Add persistent battery ADC calibration across boards
Add meter-reference calibration with saved ADC corrections, checked persistence and rollback. Preserve existing board coefficients and nRF52 voltage policy, and merge the Mini Repeater feature gates.

Validation: 69 focused tests, hosted documentation checks, and four firmware builds passed. Mini Repeater retains calibration and its existing filesystem with 376 flash bytes free; earlier Mini Sensor size failures remain documented.
2026-10-22 18:56:32 -07:00

90 lines
2.4 KiB
C++

#include "HeltecRC32Board.h"
#include <helpers/ESP32GpioHold.h>
void HeltecRC32Board::begin() {
ESP32Board::begin();
pinMode(PIN_ADC_CTRL, OUTPUT);
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
#ifdef SENSOR_RST_PIN
pinMode(SENSOR_RST_PIN, OUTPUT);
digitalWrite(SENSOR_RST_PIN, HIGH);
#endif
#ifdef LED_POWER
pinMode(LED_POWER, OUTPUT);
digitalWrite(LED_POWER, LOW);
#endif
periph_power.begin();
periph_power.claim();
#ifdef RC32_PERIPHERAL_WARMUP_MS
delay(RC32_PERIPHERAL_WARMUP_MS);
#endif
esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1L << P_LORA_DIO_1)) {
startup_reason = BD_STARTUP_RX_PACKET;
}
mesh::esp32::releaseRtcGpioIfSupported((gpio_num_t)P_LORA_NSS);
mesh::esp32::deinitRtcGpioIfSupported((gpio_num_t)P_LORA_DIO_1);
}
}
void HeltecRC32Board::onBootComplete() {
#ifdef ESP32_POST_BOOT_CPU_FREQ
const uint32_t current_mhz = getCpuFrequencyMhz();
if (current_mhz > ESP32_POST_BOOT_CPU_FREQ) {
if (setCpuFrequencyMhz(ESP32_POST_BOOT_CPU_FREQ)) {
MESH_DEBUG_PRINTLN("RC32 startup complete; CPU reduced from %lu to %u MHz",
(unsigned long)current_mhz,
(unsigned)ESP32_POST_BOOT_CPU_FREQ);
} else {
MESH_DEBUG_PRINTLN("RC32 could not set post-boot CPU frequency to %u MHz",
(unsigned)ESP32_POST_BOOT_CPU_FREQ);
}
}
#endif
}
void HeltecRC32Board::powerOff() {
enterDeepSleep(0);
}
void HeltecRC32Board::onBeforeTransmit() {
if (mesh::leds::enabled()) digitalWrite(P_LORA_TX_LED, HIGH);
}
void HeltecRC32Board::onAfterTransmit() {
digitalWrite(P_LORA_TX_LED, LOW);
}
uint16_t HeltecRC32Board::getBattMilliVolts() {
analogReadResolution(12);
analogSetAttenuation(ADC_2_5db);
digitalWrite(PIN_ADC_CTRL, ADC_CTRL_ENABLED);
delay(10);
uint32_t raw = 0;
for (int i = 0; i < 8; i++) {
raw += analogReadMilliVolts(PIN_VBAT_READ);
}
raw = raw / 8;
digitalWrite(PIN_ADC_CTRL, !ADC_CTRL_ENABLED);
return (adc_mult * raw);
}
bool HeltecRC32Board::setAdcMultiplier(float multiplier) {
if (!isfinite(multiplier) || multiplier < 0.0f || multiplier > 10.0f) return false;
adc_mult = multiplier == 0.0f ? ADC_MULTIPLIER : multiplier;
return true;
}
const char* HeltecRC32Board::getManufacturerName() const {
return "Heltec RC32";
}