drivers: regulator: improve regulator_get_current_limit
- Function returns now the value by reference, similar to voltage counterparts. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
8db7e046c5
commit
2bd6d50934
3 changed files with 15 additions and 9 deletions
|
@ -308,16 +308,19 @@ static int regulator_pca9420_get_voltage(const struct device *dev,
|
|||
* Part of the extended regulator consumer API
|
||||
* Gets the set current limit for the regulator
|
||||
*/
|
||||
static int regulator_pca9420_get_current_limit(const struct device *dev)
|
||||
static int regulator_pca9420_get_current_limit(const struct device *dev,
|
||||
int32_t *curr_ua)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
||||
|
||||
if (cconfig->vin_ilim_ua == 0U) {
|
||||
return config->max_ua;
|
||||
*curr_ua = config->max_ua;
|
||||
} else {
|
||||
*curr_ua = MIN(config->max_ua, cconfig->vin_ilim_ua);
|
||||
}
|
||||
|
||||
return MIN(config->max_ua, cconfig->vin_ilim_ua);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int regulator_pca9420_set_mode(const struct device *dev, uint32_t mode)
|
||||
|
|
|
@ -85,6 +85,7 @@ static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
|||
static int cmd_set_ilim(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
int lcur, ucur, ret;
|
||||
int32_t curr_ua;
|
||||
const struct device *reg_dev;
|
||||
|
||||
reg_dev = device_get_binding(argv[1]);
|
||||
|
@ -101,12 +102,12 @@ static int cmd_set_ilim(const struct shell *sh, size_t argc, char **argv)
|
|||
shell_error(sh, "failed to set current, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = regulator_get_current_limit(reg_dev);
|
||||
ret = regulator_get_current_limit(reg_dev, &curr_ua);
|
||||
if (ret < 0) {
|
||||
shell_error(sh, "failed to read current, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
shell_print(sh, "set current limit to %d uA", ret);
|
||||
shell_print(sh, "set current limit to %d uA", curr_ua);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue