#ifndef EIS_H #define EIS_H #include "ad5940.h" #include #define EIS_MAX_POINTS 100 typedef enum { RTIA_200 = 0, RTIA_1K, RTIA_5K, RTIA_10K, RTIA_20K, RTIA_40K, RTIA_80K, RTIA_160K, RTIA_EXT_DE0, RTIA_COUNT } EISRtia; typedef enum { RCAL_200R = 0, /* RCAL0 ↔ RCAL1 */ RCAL_3K, /* RCAL0 ↔ AIN0 */ RCAL_COUNT } EISRcal; typedef enum { ELEC_4WIRE = 0, /* AIN3 drive, AIN0 return, AIN2/AIN1 sense */ ELEC_3WIRE, /* CE0 drive, RE0 sense+, SE0 sense-/TIA */ ELEC_COUNT } EISElectrode; typedef struct { float freq_start_hz; float freq_stop_hz; uint16_t points_per_decade; EISRtia rtia; EISRcal rcal; EISElectrode electrode; uint32_t pga; uint32_t excit_amp; } EISConfig; typedef struct { float freq_hz; float mag_ohms; float phase_deg; float z_real; float z_imag; float rtia_mag_before; float rtia_mag_after; float rev_mag; float rev_phase; float pct_err; } EISPoint; typedef int (*eis_point_cb_t)(uint16_t idx, const EISPoint *pt); void eis_default_config(EISConfig *cfg); void eis_init(const EISConfig *cfg); void eis_reconfigure(const EISConfig *cfg); int eis_measure_point(float freq_hz, EISPoint *out); int eis_sweep(EISPoint *out, uint32_t max_points, eis_point_cb_t cb); uint32_t eis_calc_num_points(const EISConfig *cfg); int eis_open_cal(EISPoint *buf, uint32_t max_points, eis_point_cb_t cb); void eis_clear_open_cal(void); int eis_has_open_cal(void); void eis_load_open_cal(void); void eis_set_cell_k(float k); float eis_get_cell_k(void); void eis_load_cell_k(void); void eis_set_cl_factor(float f); float eis_get_cl_factor(void); void eis_load_cl_factor(void); float eis_get_ph_slope(void); float eis_get_ph_offset(void); float eis_get_ph_temp_slope_cold(void); float eis_get_ph_temp_slope_hot(void); void eis_load_ph_cal(void); #define PH_CAL_BUFFERS 3 #define PH_CAL_TEMPS 3 #define PH_TEMP_BELOW 0 #define PH_TEMP_BASE 1 #define PH_TEMP_ABOVE 2 int eis_ph_cal_set_point(uint8_t buf, uint8_t tslot, float ocp_mv, float temp_c); int eis_ph_cal_clear_point(uint8_t buf, uint8_t tslot); void eis_ph_cal_clear_all(void); bool eis_ph_cal_get_point(uint8_t buf, uint8_t tslot, float *ocp_mv, float *temp_c); int eis_ph_cal_count(void); float eis_ph_cal_buffer_ph(uint8_t buf); #endif