From 6bf03f63a9bb6ee558913fcef5392a3048e91b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 25 Oct 2024 15:07:43 +0200 Subject: [PATCH] Small SPI slave cleanup (#2405) --- esp-hal/src/spi/slave.rs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 1cb3a5305..97315ab6f 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -104,14 +104,14 @@ impl<'d> Spi<'d> { MISO: PeripheralOutput, CS: PeripheralInput, >( - spi: impl Peripheral

+ 'd> + 'd, + spi: impl Peripheral

+ 'd, sclk: impl Peripheral

+ 'd, mosi: impl Peripheral

+ 'd, miso: impl Peripheral

+ 'd, cs: impl Peripheral

+ 'd, mode: SpiMode, ) -> Spi<'d> { - Self::new_typed(spi, sclk, mosi, miso, cs, mode) + Self::new_typed(spi.map_into(), sclk, mosi, miso, cs, mode) } } @@ -126,7 +126,7 @@ where MISO: PeripheralOutput, CS: PeripheralInput, >( - spi: impl Peripheral

+ 'd> + 'd, + spi: impl Peripheral

+ 'd, sclk: impl Peripheral

+ 'd, mosi: impl Peripheral

+ 'd, miso: impl Peripheral

+ 'd, @@ -153,18 +153,17 @@ where this } - pub(crate) fn new_internal( - spi: impl Peripheral

+ 'd> + 'd, - mode: SpiMode, - ) -> Spi<'d, T> { + pub(crate) fn new_internal(spi: impl Peripheral

+ 'd, mode: SpiMode) -> Spi<'d, T> { crate::into_ref!(spi); let mut spi = Spi { - spi: spi.map_into(), + spi, data_mode: mode, }; - spi.spi.reset_peripheral(); - spi.spi.enable_peripheral(); + + PeripheralClockControl::reset(spi.spi.peripheral()); + PeripheralClockControl::enable(spi.spi.peripheral()); + spi.spi.init(); spi.spi.set_data_mode(mode, false); @@ -570,27 +569,14 @@ impl InstanceDma for crate::peripherals::SPI2 {} impl InstanceDma for crate::peripherals::SPI3 {} #[doc(hidden)] -pub trait Instance: private::Sealed + PeripheralMarker { +pub trait Instance: Peripheral

+ Into + PeripheralMarker + 'static { fn register_block(&self) -> &RegisterBlock; fn sclk_signal(&self) -> InputSignal; - fn mosi_signal(&self) -> InputSignal; - fn miso_signal(&self) -> OutputSignal; - fn cs_signal(&self) -> InputSignal; - #[inline(always)] - fn reset_peripheral(&self) { - PeripheralClockControl::reset(self.peripheral()); - } - - #[inline(always)] - fn enable_peripheral(&self) { - PeripheralClockControl::enable(self.peripheral()); - } - #[cfg(esp32)] fn prepare_length_and_lines(&self, rx_len: usize, tx_len: usize) { let reg_block = self.register_block();