Files
MeshCore/variants/heltec_rc32/HeltecRC32Board.cpp
T
9d52b1fd68 Add saved LED controls across supported boards
Add get leds and set leds on|off for Companion, repeater, room server and
sensor builds. Preserve the setting across reboots and cover GPIO, RGB,
Bluetooth, notification and expander indicators without changing radio
amplifier controls or screen backlights.

RAK Companions blink while advertising and keep the Bluetooth LED off once
connected, including late timer callbacks.

Adapted from meshcore-dev/MeshCore#3605 and #2694.
Validated with host regressions and firmware builds for SenseCAP Solar,
RAK4631, T096, Heltec V4, T-Beam, Xiao S3, Pico W and Wio E5 Mini.

Co-authored-by: R0ck <develop@hectospark.co.uk>
Co-authored-by: Nick Dunklee <nick@dunklee.org>
2026-10-20 08:59:39 -07:00

89 lines
2.3 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) {
adc_mult = multiplier == 0.0f ? ADC_MULTIPLIER : multiplier;
return true;
}
const char* HeltecRC32Board::getManufacturerName() const {
return "Heltec RC32";
}