Commit 4b79f254 authored by Federico Vaga's avatar Federico Vaga

lib: add function to set/get more configurations in one call

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 372263f1
......@@ -185,6 +185,11 @@ Following an example from the ``example.c`` code available under ``tools``
:language: c
:lines: 186-203
There are also the correspondent functions to set/get more than one
configuration at time:
:cpp:func:`adc_apply_config_n()`, :cpp:func:`adc_retrieve_config_n()`.
To handle the exceptional cases where parameters are actually *strings*
(``char *``) or the library does not support them (e.g. board-specific
parameter), the library added the support to single access parameters.
......
......@@ -394,8 +394,13 @@ extern int adc_reset_conf(struct adc_dev *dev, unsigned int flags,
struct adc_conf *conf);
extern int adc_apply_config(struct adc_dev *dev, unsigned int flags,
struct adc_conf *conf);
extern int adc_apply_config_n(struct adc_dev *dev, unsigned int flags,
struct adc_conf *conf, unsigned int n);
extern int adc_retrieve_config(struct adc_dev *dev,
struct adc_conf *conf);
extern int adc_retrieve_config_n(struct adc_dev *dev,
struct adc_conf *conf,
unsigned int n);
extern uint64_t adc_get_capabilities(struct adc_dev *dev,
enum adc_configuration_type type);
extern int adc_get_param(struct adc_dev *dev, char *name,
......
......@@ -295,6 +295,33 @@ int adc_apply_config(struct adc_dev *dev, unsigned int flags,
}
/**
* It applies the given configuration to the device
* @param[in] dev ADC device token
* @param[in] flags
* @param[in] conf list of configurations to apply
* @param[in] n number of valid configurations in conf
* @return 0 on success, -1 on error and errno is set appropriately
*
* If a configuration cannot be applied entirely, then this function
* will set ADC_CONF_F_ERROR in conf[i].flags
*/
int adc_apply_config_n(struct adc_dev *dev, unsigned int flags,
struct adc_conf *conf, unsigned int n)
{
unsigned int i;
int err_last = 0;
for (i = 0; i < n; ++i) {
int err = adc_apply_config(dev, flags, &conf[i]);
if (err) {
err_last = err;
continue;
}
}
return err_last;
}
/**
* It retrieve the current device configuration
......@@ -341,6 +368,33 @@ int adc_retrieve_config(struct adc_dev *dev, struct adc_conf *conf)
return err;
}
/**
* It retrieve the current device configuration
* @param[in] dev ADC device token
* @param[in,out] conf configuration descriptor to fill with configuration
* values.
* @param[in] n number of valid configurations in conf
* @return 0 on success, -1 on error and errno is set appropriately
*
* If a configuration cannot be retrieved entirely, then this function
* will set ADC_CONF_F_ERROR in conf[i].flags
*/
int adc_retrieve_config_n(struct adc_dev *dev, struct adc_conf *conf,
unsigned int n)
{
unsigned int i;
int err_last = 0;
for (i = 0; i < n; ++i) {
int err = adc_retrieve_config(dev, &conf[i]);
if (err) {
err_last = err;
continue;
}
}
return err_last;
}
/**
* It get a single parameter from the device
......
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