Files
microchip-application-bmd38…/edc.h
T
2024-06-27 21:29:19 +08:00

136 lines
2.9 KiB
C

#pragma once
#ifndef __EDC_H__
#define __EDC_H__
#include "dac_drv.h"
#include "elite_def.h"
#include <stdbool.h>
#include <stdint.h>
/** Iin, Vin, Vout **/
#define RIS_ADC_IIN 0x00
#define RIS_ADC_VIN 0x01
#define RIS_DAC_VOUT 0x02
#define RIS_HIGH_Z 0x03
#define RIS_ADC_VOUT 0x04
#define RIS_ADC_BAT 0x05
// ADC Iin gain level !!! move to ADC.h in future
#define I_GAIN_3M 0x00 // lv0,largest gain
#define I_GAIN_100K 0x01 // lv1
#define I_GAIN_3K 0x02 // lv2
#define I_GAIN_100R 0x03 // lv3,the least gain
#define I_GAIN_AUTO 0x04
// ADC Vin gain level !!! move to ADC.h in future
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
// DAC Vout gain level !!! move to DAC.h in future
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000 // DAC_ZERO is about 0V
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
typedef struct
{
void (*init)(void);
elite_instance_t *p_elite_instance;
struct
{
uint32_t chip_id;
uint32_t eliteFxn;
// time relation
uint32_t VsetRateIndex;
uint32_t VsetRate;
uint32_t sampleRate;
uint32_t notifyRate;
uint32_t period;
int32_t Vset;
uint32_t VoltConstant;
uint32_t directionInit;
uint32_t step;
uint32_t Ve1;
uint32_t Ve2;
int32_t Vinit;
int32_t Vmax;
int32_t Vmin;
uint32_t steptime;
uint32_t IinADCAutoGainEn;
uint32_t VinADCAutoGainEn;
uint32_t VoutAutoGainEn;
uint32_t IinADCGainLv;
uint32_t VinADCGainLv;
uint32_t VoutGainLv;
uint32_t gain_switch_on;
uint32_t AdcChannel;
bool hign_z_en;
uint32_t cycleNumber;
uint32_t charge;
int32_t constantCurrent;
// uint32_t cc_resistance;
uint32_t cc_cp_speed;
// uni pulse mode
int32_t v0;
uint32_t t_pulse[4];
int32_t v_initial[4];
int32_t v_slope[4];
int32_t v_step[4];
uint32_t t_pulse_min[4];
uint32_t t_pulse_max[4];
int32_t v_stop;
int32_t v_up;
int32_t v_low;
bool v_invert_option;
bool v_stop_direction;
int32_t v_1;
int32_t v_2;
int32_t Vout;
// not use
int32_t Currentmax;
uint32_t VoViSwitch;
} instru;
} edc20_t;
typedef struct
{
float coeff;
float offset;
} edc20_cal_data_t;
typedef struct
{
struct
{
float coeff;
float offset;
} dac_c;
struct
{
float coeff;
float offset;
float Voffset;
} dac_f[3];
} edc20_dac_cal_data_t;
extern edc20_t edc;
#endif // !__EDC_H__