ad7172: doc, style

This commit is contained in:
Astro 2019-08-29 23:55:45 +02:00
parent 6e02b2c4f6
commit 574b96187a
1 changed files with 7 additions and 5 deletions

View File

@ -34,6 +34,9 @@ pub enum Register {
Gain3 = 0x3B, Gain3 = 0x3B,
} }
/// AD7172-2 implementation
///
/// [Manual](https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf)
pub struct Adc<SPI: Transfer<u8>, NSS: OutputPin> { pub struct Adc<SPI: Transfer<u8>, NSS: OutputPin> {
spi: SPI, spi: SPI,
nss: NSS, nss: NSS,
@ -56,16 +59,15 @@ impl<SPI: Transfer<u8>, NSS: OutputPin> Adc<SPI, NSS> {
/// Returns the channel the data is from /// Returns the channel the data is from
pub fn data_ready(&mut self) -> Option<u8> { pub fn data_ready(&mut self) -> Option<u8> {
let mut buf = [0u8; 2]; let mut buf = [0u8; 2];
match self.read_reg(Register::Status, &mut buf) { self.read_reg(Register::Status, &mut buf)
Err(_) => None, .ok()
Ok(()) => { .and_then(|()| {
if buf[1] & 0x80 == 0 { if buf[1] & 0x80 == 0 {
None None
} else { } else {
Some(buf[1] & 0x3) Some(buf[1] & 0x3)
} }
} })
}
} }
/// Get data /// Get data