drivers: adc: adc_ad559x: fix 5593 adc read
The AD5593 conversion result also contains the channel read and not just a value: | adc channel (3 bits) | adc value (12 bits) | This value was not removed from the result before using it as an adc value. Reuse the AD5592 code to fix the issue. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This commit is contained in:
parent
7c3b66eac8
commit
052eb6180d
1 changed files with 23 additions and 26 deletions
|
@ -130,9 +130,6 @@ static int adc_ad559x_read_channel(const struct device *dev, uint8_t channel, ui
|
|||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*result = sys_get_be16((uint8_t *)&val);
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Invalid data:
|
||||
|
@ -145,31 +142,31 @@ static int adc_ad559x_read_channel(const struct device *dev, uint8_t channel, ui
|
|||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
val = sys_be16_to_cpu(val);
|
||||
|
||||
/*
|
||||
* Invalid data:
|
||||
* See "ADC section" in "Theory of operation" chapter.
|
||||
* Valid ADC result has MSB bit set to 0.
|
||||
*/
|
||||
if ((val & AD559X_ADC_RES_IND_BIT) != 0) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/*
|
||||
* Invalid channel converted:
|
||||
* See "ADC section" in "Theory of operation" chapter.
|
||||
* Conversion result contains channel number which should match requested channel.
|
||||
*/
|
||||
conv_channel = FIELD_GET(AD559X_ADC_RES_CHAN_MASK, val);
|
||||
if (conv_channel != channel) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*result = val & AD559X_ADC_RES_VAL_MASK;
|
||||
}
|
||||
|
||||
val = sys_be16_to_cpu(val);
|
||||
|
||||
/*
|
||||
* Invalid data:
|
||||
* See AD5592 "ADC section" in "Theory of operation" chapter.
|
||||
* Valid ADC result has MSB bit set to 0.
|
||||
*/
|
||||
if ((val & AD559X_ADC_RES_IND_BIT) != 0) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/*
|
||||
* Invalid channel converted:
|
||||
* See AD5592 "ADC section" in "Theory of operation" chapter.
|
||||
* Conversion result contains channel number which should match requested channel.
|
||||
*/
|
||||
conv_channel = FIELD_GET(AD559X_ADC_RES_CHAN_MASK, val);
|
||||
if (conv_channel != channel) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*result = val & AD559X_ADC_RES_VAL_MASK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue