Skip to content

Commit 6bf03f6

Browse files
authored
Small SPI slave cleanup (#2405)
1 parent 681f4ef commit 6bf03f6

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

esp-hal/src/spi/slave.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ impl<'d> Spi<'d> {
104104
MISO: PeripheralOutput,
105105
CS: PeripheralInput,
106106
>(
107-
spi: impl Peripheral<P = impl Into<AnySpi> + 'd> + 'd,
107+
spi: impl Peripheral<P = impl Instance> + 'd,
108108
sclk: impl Peripheral<P = SCK> + 'd,
109109
mosi: impl Peripheral<P = MOSI> + 'd,
110110
miso: impl Peripheral<P = MISO> + 'd,
111111
cs: impl Peripheral<P = CS> + 'd,
112112
mode: SpiMode,
113113
) -> Spi<'d> {
114-
Self::new_typed(spi, sclk, mosi, miso, cs, mode)
114+
Self::new_typed(spi.map_into(), sclk, mosi, miso, cs, mode)
115115
}
116116
}
117117

@@ -126,7 +126,7 @@ where
126126
MISO: PeripheralOutput,
127127
CS: PeripheralInput,
128128
>(
129-
spi: impl Peripheral<P = impl Into<T> + 'd> + 'd,
129+
spi: impl Peripheral<P = T> + 'd,
130130
sclk: impl Peripheral<P = SCK> + 'd,
131131
mosi: impl Peripheral<P = MOSI> + 'd,
132132
miso: impl Peripheral<P = MISO> + 'd,
@@ -153,18 +153,17 @@ where
153153
this
154154
}
155155

156-
pub(crate) fn new_internal(
157-
spi: impl Peripheral<P = impl Into<T> + 'd> + 'd,
158-
mode: SpiMode,
159-
) -> Spi<'d, T> {
156+
pub(crate) fn new_internal(spi: impl Peripheral<P = T> + 'd, mode: SpiMode) -> Spi<'d, T> {
160157
crate::into_ref!(spi);
161158

162159
let mut spi = Spi {
163-
spi: spi.map_into(),
160+
spi,
164161
data_mode: mode,
165162
};
166-
spi.spi.reset_peripheral();
167-
spi.spi.enable_peripheral();
163+
164+
PeripheralClockControl::reset(spi.spi.peripheral());
165+
PeripheralClockControl::enable(spi.spi.peripheral());
166+
168167
spi.spi.init();
169168
spi.spi.set_data_mode(mode, false);
170169

@@ -570,27 +569,14 @@ impl InstanceDma for crate::peripherals::SPI2 {}
570569
impl InstanceDma for crate::peripherals::SPI3 {}
571570

572571
#[doc(hidden)]
573-
pub trait Instance: private::Sealed + PeripheralMarker {
572+
pub trait Instance: Peripheral<P = Self> + Into<AnySpi> + PeripheralMarker + 'static {
574573
fn register_block(&self) -> &RegisterBlock;
575574

576575
fn sclk_signal(&self) -> InputSignal;
577-
578576
fn mosi_signal(&self) -> InputSignal;
579-
580577
fn miso_signal(&self) -> OutputSignal;
581-
582578
fn cs_signal(&self) -> InputSignal;
583579

584-
#[inline(always)]
585-
fn reset_peripheral(&self) {
586-
PeripheralClockControl::reset(self.peripheral());
587-
}
588-
589-
#[inline(always)]
590-
fn enable_peripheral(&self) {
591-
PeripheralClockControl::enable(self.peripheral());
592-
}
593-
594580
#[cfg(esp32)]
595581
fn prepare_length_and_lines(&self, rx_len: usize, tx_len: usize) {
596582
let reg_block = self.register_block();

0 commit comments

Comments
 (0)