#ifndef __CALIBRATION_H
#define __CALIBRATION_H 

#ifdef __cplusplus
extern "C" {
#endif

/////constant///////////
#include "hc32_ll.h"
#include "math.h"
/////////////////////////
#define MODE_SEL_DELAY_THRESHOLD     10

////calibration parameters
#define IFB2_GAIN_IDEAL                 0.0161172f
#define IFB2_OFFSET_IDEAL               0.0f
#define IFB1_GAIN_IDEAL                 0.0161172f
#define IFB1_OFFSET_IDEAL               0.0f
#define IGL_GAIN_IDEAL                  0.001184059f
#define IGL_OFFSET_IDEAL                -5.0f
#define IGR_GAIN_IDEAL                  0.001184059f
#define IGR_OFFSET_IDEAL                -5.0f
#define IPV_GAIN_IDEAL                  0.005352f
#define IPV_OFFSET_IDEAL                -14.5796f
#define ZCD_CAL_GAIN_IDEAL              29.54f

#define VPV_GAIN_IDEAL                  0.01635734f
#define VPV_OFFSET_IDEAL                0.0f
#define VGRID_GAIN_IDEAL                0.21537715f
#define VGRID_OFFSET_IDEAL              -2074.36f

/////enum
typedef enum{
  START,	
	STEP_1,
	STEP_2,
	CALC,
	DONE
} CALIBRATION_STATE_TYPE;

typedef enum{
  IDLE,	
	GRIDVOL_CALIB,
	PVVOL_CALIB,
	ACCUR_CALIB,
	PARA_INIT,
} SYSTEM_CALIBMODE_TYPE;

extern uint8_t SysCali_Cmd;

extern float_t	IFB2_GAIN;
extern float_t	IFB2_OFFSET;
extern float_t	IFB1_GAIN;
extern float_t  IFB1_OFFSET;
extern float_t  IGL_GAIN;
extern float_t  IGL_OFFSET;
extern float_t  IGR_GAIN;
extern float_t  IGR_OFFSET;
extern float_t  IPV_GAIN;
extern float_t  IPV_OFFSET;
extern float_t  ZCD_CAL_GAIN;

extern float_t  VPV_GAIN;
extern float_t  VPV_OFFSET;
extern float_t  VGRID_GAIN;
extern float_t  VGRID_OFFSET;



extern uint8_t comm_uart_cal(void);
extern void System_Calib_Statemachine(void);
extern void CalPara_Init(void);

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */



