ad7172: perform data sign checks
This commit is contained in:
parent
12c2be0a03
commit
83117db8c5
@ -114,7 +114,7 @@ impl<SPI: Transfer<u8>, NSS: OutputPin> Adc<SPI, NSS> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get data
|
/// Get data
|
||||||
pub fn read_data(&mut self) -> Result<u32, AdcError<SPI::Error>> {
|
pub fn read_data(&mut self) -> Result<i32, AdcError<SPI::Error>> {
|
||||||
self.read_reg(®s::Data)
|
self.read_reg(®s::Data)
|
||||||
.map(|data| data.data())
|
.map(|data| data.data())
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,16 @@ impl if_mode::Data {
|
|||||||
|
|
||||||
def_reg!(Data, data, 0x04, 3);
|
def_reg!(Data, data, 0x04, 3);
|
||||||
impl data::Data {
|
impl data::Data {
|
||||||
pub fn data(&self) -> u32 {
|
pub fn data(&self) -> i32 {
|
||||||
|
let raw =
|
||||||
(u32::from(self.0[0]) << 16) |
|
(u32::from(self.0[0]) << 16) |
|
||||||
(u32::from(self.0[1]) << 8) |
|
(u32::from(self.0[1]) << 8) |
|
||||||
u32::from(self.0[2])
|
u32::from(self.0[2]);
|
||||||
|
if raw & 0x80_0000 != 0 {
|
||||||
|
((raw & 0x7F_FFFF) | 0x8000_0000) as i32
|
||||||
|
} else {
|
||||||
|
raw as i32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user