drivers: regulator: improve regulator_get_voltage
- Function now returns error, value is obtained by reference. This allows to propagate potential bus errors. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
b909d0e560
commit
3d47b6dfba
3 changed files with 15 additions and 12 deletions
|
@ -295,15 +295,13 @@ static int regulator_pca9420_set_voltage(const struct device *dev,
|
|||
* Part of the extended regulator consumer API
|
||||
* Gets the current output voltage in uV
|
||||
*/
|
||||
static int32_t regulator_pca9420_get_voltage(const struct device *dev)
|
||||
static int regulator_pca9420_get_voltage(const struct device *dev,
|
||||
int32_t *volt_uv)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
struct regulator_pca9420_common_data *cdata = config->parent->data;
|
||||
int32_t voltage = 0;
|
||||
|
||||
(void)regulator_pca9420_get_voltage_mode(dev, cdata->mode, &voltage);
|
||||
|
||||
return voltage;
|
||||
return regulator_pca9420_get_voltage_mode(dev, cdata->mode, volt_uv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,7 @@ static int cmd_reg_dis(const struct shell *sh, size_t argc, char **argv)
|
|||
static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
int lvol, uvol, ret;
|
||||
int32_t volt_uv;
|
||||
const struct device *reg_dev;
|
||||
|
||||
reg_dev = device_get_binding(argv[1]);
|
||||
|
@ -72,12 +73,12 @@ static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
|||
shell_error(sh, "failed to set voltage, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = regulator_get_voltage(reg_dev);
|
||||
ret = regulator_get_voltage(reg_dev, &volt_uv);
|
||||
if (ret < 0) {
|
||||
shell_error(sh, "failed to read voltage, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
shell_print(sh, "set voltage to %d uV", ret);
|
||||
shell_print(sh, "set voltage to %d uV", volt_uv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue