Commit cf5d4de0 authored by Federico Vaga's avatar Federico Vaga

lib: sw_avg remove nsample attr, get from cfg

Get the total number of samples directly from the applied configuration
instead of asking the user to provide this value.

It is true that this can be redundant, but it is more reliable
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent b9ff1cff
......@@ -114,13 +114,15 @@ uint64_t adc_get_capabilities(struct adc_dev *dev,
*/
int adc_offset_auto_clear_sw_avg(struct adc_dev *dev,
unsigned int chan,
unsigned int nsamples,
unsigned long flags,
int32_t *offset)
{
struct adc_conf cfg;
struct adc_buffer *buf;
struct timeval tv = {0, 0};
int err, err_stop;
uint32_t pre, post;
unsigned int nsamples;
if (!(flags & ADC_OFFSET_AC_F_SOFTWARE)) {
errno = EINVAL;
......@@ -132,6 +134,17 @@ int adc_offset_auto_clear_sw_avg(struct adc_dev *dev,
return -1;
}
memset(&cfg, 0, sizeof(struct adc_conf));
cfg.type = ADC_CONF_TYPE_ACQ;
adc_set_conf_mask(&cfg, ADC_CONF_ACQ_PRE_SAMP);
adc_set_conf_mask(&cfg, ADC_CONF_ACQ_POST_SAMP);
err = adc_retrieve_config(dev, &cfg);
if (err)
return err;
adc_get_conf(&cfg, ADC_CONF_ACQ_PRE_SAMP, &pre);
adc_get_conf(&cfg, ADC_CONF_ACQ_POST_SAMP, &post);
nsamples = pre + post;
buf = adc_request_buffer(dev, nsamples, NULL, 0);
if (!buf)
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment