drivers: dac: stm32: add dac value range check
Compare value and DAC resolution in `dac_write_value` and return -EINVAL if the value is above supported resolution. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This commit is contained in:
parent
004b307206
commit
398d297519
|
@ -68,6 +68,11 @@ static int dac_stm32_write_value(const struct device *dev,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value >= BIT(data->resolution)) {
|
||||||
|
LOG_ERR("Value %d is out of range", value);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (data->resolution == 8) {
|
if (data->resolution == 8) {
|
||||||
LL_DAC_ConvertData8RightAligned(cfg->base,
|
LL_DAC_ConvertData8RightAligned(cfg->base,
|
||||||
table_channels[channel - STM32_FIRST_CHANNEL], value);
|
table_channels[channel - STM32_FIRST_CHANNEL], value);
|
||||||
|
|
Loading…
Reference in a new issue