96 lines
2.0 KiB
C
96 lines
2.0 KiB
C
#include "adc_drv.h"
|
|
|
|
#if (DEF_ADS8691_ENABLED)
|
|
#include "ads8691.h"
|
|
extern const adc_drv_if_t ads8691;
|
|
static const adc_drv_if_t *p_inst = &ads8691;
|
|
#else
|
|
#include "builtin_saadc.h"
|
|
static const adc_drv_if_t *p_inst = &builtin_saadc;
|
|
#endif
|
|
|
|
#if (DEF_ADC_DRV_ENABLED)
|
|
|
|
int adc_init(void)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->init();
|
|
}
|
|
|
|
int adc_reset(void)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->reset();
|
|
}
|
|
|
|
int adc_gain(adc_gain_t gain)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->gain(gain);
|
|
}
|
|
|
|
int adc_read(uint32_t channel, int32_t *adc_val)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read(channel, adc_val);
|
|
}
|
|
|
|
int adc_read_mutiple_channels(uint32_t *p_channel, int32_t *p_adc_val, uint32_t cnt)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read_multiple_channels(p_channel, p_adc_val, cnt);
|
|
}
|
|
|
|
int adc_read_mutiple_channels_ex(uint32_t *p_channel, int32_t *p_adc_val, uint32_t cnt, void (*preliminary_action)(void))
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read_multiple_channels_ex(p_channel, p_adc_val, cnt, preliminary_action);
|
|
}
|
|
|
|
int adc_read_multiple_milivolt_ex(uint32_t *p_channel, float *p_val, uint32_t cnt, void (*preliminary_action)(void))
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read_multiple_milivolt_ex(p_channel, p_val, cnt, preliminary_action);
|
|
}
|
|
|
|
int adc_read_milivolt(uint32_t channel, float *mv)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read_milivolt(channel, mv);
|
|
}
|
|
|
|
int adc_read_mutiple_channels_convert_milivolt(int32_t *p_val_14bit, float *p_val_f, uint32_t count)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->adc_convert_multiple_milivolt(p_val_14bit, p_val_f, count);
|
|
}
|
|
|
|
#endif /* ! DEF_ADC_DRV_ENABLED */
|