diff --git a/src/spi.rs b/src/spi.rs index f7626e0..52b04a9 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -118,14 +118,28 @@ where /// let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A")?; /// let hal = hal::FtHal::init_freq(device, 3_000_000)?; /// let mut spi = hal.spi()?; - /// spi.set_clock_polarity(Polarity::IdleLow); + /// spi.set_clock_polarity(Polarity::IdleLow)?; /// # } /// # Ok::<(), std::boxed::Box>(()) /// ``` /// /// [SPI mode]: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface#Mode_numbers - pub fn set_clock_polarity>(&mut self, cpol: P) { - self.pol = cpol.into() + pub fn set_clock_polarity>(&mut self, cpol: P) -> Result<(), Error> { + self.pol = cpol.into(); + let mut lock = self.mtx.lock().unwrap(); + match self.pol.clk { + ClockData::MsbNegIn | ClockData::LsbNegIn => { + lock.lower.value |= 1; + } + ClockData::MsbPosIn | ClockData::LsbPosIn => { + lock.lower.value &= !1; + } + } + let cmd: MpsseCmdBuilder = MpsseCmdBuilder::new() + .set_gpio_lower(lock.value, lock.direction) + .send_immediate(); + lock.ft.send(cmd.as_slice())?; + Ok(()) } }