main
TylerK Replace discrete-analog board with MCU/IC redesign: STM32G031 P&O MPPT + CC/CV firmware, LM5175 buck-boost, INA180 curr… e48ba30 1mo ago
/*
 * adc_sense.h -- reads VBATT_SENSE/IIN_SENSE/ICHG_SENSE (PA0/PA1/PA2,
 * ADC1 channels 0/1/2) and returns an engineering-unit sensor_frame_t.
 * Assumes STM32CubeMX/HAL has configured ADC1 for a 3-channel scan
 * sequence (rank 1=IN0, rank 2=IN1, rank 3=IN2) triggered by software or a
 * timer, plus GPIO inputs for MPPT_PGOOD/BIAS_PGOOD.
 */
#ifndef ADC_SENSE_H
#define ADC_SENSE_H

#include "charge_control.h"

/* Simple exponential moving average -- enough to tame shunt/ADC noise
 * without adding phase lag that would fight the (much slower) control
 * loop cadence. alpha in (0,1], smaller = more filtering. */
typedef struct {
    float vbatt_f, iin_f, ichg_f;
    uint8_t initialized;
} adc_filter_state_t;

void adc_sense_init(adc_filter_state_t *filt);

/* Blocking read of all 3 ADC channels + the 2 PGOOD GPIOs, filtered.
 * Call HAL_ADC_Start / poll-for-conversion internally. */
void adc_sense_read(adc_filter_state_t *filt, sensor_frame_t *out);

#endif /* ADC_SENSE_H */