/*
 * adc_buffers.h
 *
 *  Created on: Sep 5, 2024
 *      Author: jakubski
 */

#ifndef INC_ADC_BUFFERS_H_
#define INC_ADC_BUFFERS_H_

#include "stdint.h"
#include "stm32h7xx_hal.h"

#define EXT_VREF_mV 3000
#define U_CHANNEL_CONST 7.59
#define I_CHANNEL_CONST 7.5758
#define deltaADC 3.0/65535

enum _ADC1_DataInfo {
    UL1 = 0,
    UL2,
    UL3,
	IL1Ref,
	IL2Ref,
	IL3Ref,
	FanFB,
    ADC1LastData,
};
typedef enum _ADC1_DataInfo ADC1_DataInfo;

struct _ADC1_Data {
    uint16_t adcDataBuffer[ADC1LastData];
    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC1LastData];
};

enum _ADC2_DataInfo { IL1 = 0, IL2, IL3, ADC2LastData };
typedef enum _ADC2_DataInfo ADC2_DataInfo;

struct _ADC2_Data {
    uint16_t adcDataBuffer[ADC2LastData];
    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC2LastData];
};

enum _ADC3_DataInfo { pvTemp1 = 0, pvTemp2, motorXSense, motorYSense, VrefInt, ADC3LastData };
typedef enum _ADC3_DataInfo ADC3_DataInfo;

struct _ADC3_Data {
    uint16_t adcDataBuffer[ADC3LastData];
    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC3LastData];
};

typedef struct _ADC1_Data ADC1_Data;
typedef struct _ADC2_Data ADC2_Data;
typedef struct _ADC3_Data ADC3_Data;

extern ADC1_Data adc1Data;
extern ADC2_Data adc2Data;
extern ADC3_Data adc3Data;

#define DEFAULT_U_GAIN 1.0
#define DEFAULT_U_OFFSET 0.0
#define DEFAULT_I_GAIN 1.0
#define DEFAULT_I_OFFSET 0.0

struct _EletricalMeasCorrectionData
{
	float gain;
	float offset;
};
typedef struct _EletricalMeasCorrectionData EletricalMeasCorrectionData;

extern EletricalMeasCorrectionData U_MeasCorrectionData[3];
extern EletricalMeasCorrectionData I_MeasCorrectionData[3];

#endif /* INC_ADC_BUFFERS_H_ */
