#pragma once

// Library defines
#define ADS1256_SPI_ALREADY_STARTED

// Device Libraries
#include <ADS1256.h>
#include <AD5292.h>
#include <PCA95x5.h>

// ADC Channel mapping
#define ADC_CH_PEAK_12P_IN      SING_0
#define ADC_CH_PEAK_12N_IN      SING_1
#define ADC_CH_PEAK_34P_IN      SING_2
#define ADC_CH_PEAK_34N_IN      SING_3
#define ADC_CH_PEAK_12P_OUT     SING_4
#define ADC_CH_PEAK_12N_OUT     SING_5
#define ADC_CH_PEAK_34P_OUT     SING_6
#define ADC_CH_PEAK_34N_OUT     SING_7

// Device Pointer structs for tasks
struct Devices {
  AD5292 *pot_a = NULL, *pot_b = NULL;
  ADS1256 *adc_a = NULL, *adc_b = NULL; 
  PCA9555* io = NULL;
};

// Adc read channel wrapper to selet mux before reading
inline float adcReadChannel(ADS1256* adc, const uint8_t ch){
    adc->setMUX(ch);
    // scarta 3 conversioni
    for (int i = 0; i < 3; i++) {
        adc->readSingle();
    }
    // ora lettura valida a 30kSPS → ~100 µs di settling
    return adc->convertToVoltage(adc->readSingle());
}
