// Copyright (c) 2026 Oleg Kalachev // Repository: https://github.com/okalachev/flix // Power management #include #include #include "lpf.h" #include "util.h" float voltage = NAN; LowPassFilter voltageFilter(0.2); int voltagePin = -1; float voltageScale = 2; void setupPower() { REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA); // disable reset on low voltage if (digitalPinToAnalogChannel(voltagePin) == -1) voltagePin = -1; // test ADC pin } void readVoltage() { if (voltagePin < 0) return; static Rate rate(10); if (!rate) return; float v = analogReadMilliVolts(voltagePin) * voltageScale / 1000.0f; voltage = voltageFilter.update(v); }