adafruit_seesaw/modules/
touch.rs

1use crate::{devices::SeesawDevice, Driver, DriverExt, SeesawError};
2
3use super::{Modules, Reg};
4
5// https://github.com/adafruit/Adafruit_Seesaw/blob/master/Adafruit_seesaw.cpp#L363
6// Delay of 3,000 us is used to read from the touch sensor. They also read the
7// value in a retry loop but I haven't seen that be necessary to get data.
8const TOUCH_READ_DELAY: u32 = 3_000;
9
10const TOUCH: &Reg = &[Modules::Touch.into_u8(), 0x10];
11
12pub trait TouchModule<D: Driver>: SeesawDevice<Driver = D> {
13    fn read_touch_capacitance(&mut self) -> Result<u16, SeesawError<D::Error>> {
14        let addr = self.addr();
15        self.driver()
16            .read_u16_with_delay(addr, TOUCH, TOUCH_READ_DELAY)
17            .map_err(SeesawError::I2c)
18    }
19}