5892bffd3c
1. 實作 Dev mode 2. 實作 cis_version 3. ADC_DRV 新增 adc_read_mutiple_channels()/adc_read_mutiple_channels_ex(), 連續轉換多個 ADC channel 備註: 目前設定使用 adc_read_mutiple_channels()/adc_read_mutiple_channels_ex() 每筆 ADC 需要 sample 40us
79 lines
1.5 KiB
C
79 lines
1.5 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_milivolt(uint32_t channel, float *mv)
|
|
{
|
|
if (p_inst == NULL)
|
|
{
|
|
return ADC_DRV_ERROR;
|
|
}
|
|
return p_inst->read_milivolt(channel, mv);
|
|
}
|
|
|
|
#endif /* ! DEF_ADC_DRV_ENABLED */
|