Skip to content

Commit

Permalink
Remove SPI slave prelude (#2260)
Browse files Browse the repository at this point in the history
* Remove SPI slave prelude

* Changelog

* Update esp-hal/src/spi/slave.rs
  • Loading branch information
bugadani authored Oct 2, 2024
1 parent 8e9f6b5 commit f5b8e4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 67 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `uart::{DefaultRxPin, DefaultTxPin}` (#2132)
- Removed `PcntSource` and `PcntInputConfig`. (#2134)
- Removed the `place-spi-driver-in-ram` feature, this is now enabled via [esp-config](https://docs.rs/esp-config) (#2156)
- Removed `esp_hal::spi::slave::prelude` (#2260)
- Removed `esp_hal::spi::slave::WithDmaSpiN` traits (#2260)

## [0.20.1] - 2024-08-30

Expand Down
82 changes: 19 additions & 63 deletions esp-hal/src/spi/slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! # use esp_hal::dma::DmaPriority;
//! # use esp_hal::dma_buffers;
//! # use esp_hal::spi::SpiMode;
//! # use esp_hal::spi::slave::{prelude::*, Spi};
//! # use esp_hal::spi::slave::Spi;
//! # use esp_hal::dma::Dma;
//! # use esp_hal::gpio::Io;
//! let dma = Dma::new(peripherals.DMA);
Expand Down Expand Up @@ -80,17 +80,6 @@ use crate::{
system::PeripheralClockControl,
};

/// Prelude for the SPI (Slave) driver
pub mod prelude {
#[cfg(spi3)]
pub use super::dma::WithDmaSpi3 as _esp_hal_spi_slave_dma_WithDmaSpi3;
pub use super::{
dma::WithDmaSpi2 as _esp_hal_spi_slave_dma_WithDmaSpi2,
Instance as _esp_hal_spi_slave_Instance,
InstanceDma as _esp_hal_spi_slave_InstanceDma,
};
}

const MAX_DMA_SIZE: usize = 32768 - 32;

/// SPI peripheral driver
Expand Down Expand Up @@ -181,54 +170,20 @@ pub mod dma {
Mode,
};

/// Trait for configuring DMA with SPI2 peripherals in slave mode.
pub trait WithDmaSpi2<'d, C, DmaMode>
where
C: DmaChannel,
C::P: SpiPeripheral,
DmaMode: Mode,
{
/// Configures the SPI2 peripheral with the provided DMA channel and
/// descriptors.
fn with_dma(
self,
channel: Channel<'d, C, DmaMode>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> SpiDma<'d, crate::peripherals::SPI2, C, DmaMode>;
}

/// Trait for configuring DMA with SPI3 peripherals in slave mode.
#[cfg(spi3)]
pub trait WithDmaSpi3<'d, C, DmaMode>
where
C: DmaChannel,
C::P: SpiPeripheral,
DmaMode: Mode,
{
impl<'d> Spi<'d, crate::peripherals::SPI2, FullDuplexMode> {
/// Configures the SPI3 peripheral with the provided DMA channel and
/// descriptors.
fn with_dma(
self,
channel: Channel<'d, C, DmaMode>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> SpiDma<'d, crate::peripherals::SPI3, C, DmaMode>;
}

impl<'d, C, DmaMode> WithDmaSpi2<'d, C, DmaMode>
for Spi<'d, crate::peripherals::SPI2, FullDuplexMode>
where
C: DmaChannel,
C::P: SpiPeripheral + Spi2Peripheral,
DmaMode: Mode,
{
fn with_dma(
pub fn with_dma<C, DmaMode>(
self,
channel: Channel<'d, C, DmaMode>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> SpiDma<'d, crate::peripherals::SPI2, C, DmaMode> {
) -> SpiDma<'d, crate::peripherals::SPI2, C, DmaMode>
where
C: DmaChannel,
C::P: SpiPeripheral + Spi2Peripheral,
DmaMode: Mode,
{
SpiDma {
spi: self.spi,
channel,
Expand All @@ -239,19 +194,20 @@ pub mod dma {
}

#[cfg(spi3)]
impl<'d, C, DmaMode> WithDmaSpi3<'d, C, DmaMode>
for Spi<'d, crate::peripherals::SPI3, FullDuplexMode>
where
C: DmaChannel,
C::P: SpiPeripheral + Spi3Peripheral,
DmaMode: Mode,
{
fn with_dma(
impl<'d> Spi<'d, crate::peripherals::SPI3, FullDuplexMode> {
/// Configures the SPI3 peripheral with the provided DMA channel and
/// descriptors.
pub fn with_dma<C, DmaMode>(
self,
channel: Channel<'d, C, DmaMode>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> SpiDma<'d, crate::peripherals::SPI3, C, DmaMode> {
) -> SpiDma<'d, crate::peripherals::SPI3, C, DmaMode>
where
C: DmaChannel,
C::P: SpiPeripheral + Spi3Peripheral,
DmaMode: Mode,
{
SpiDma {
spi: self.spi,
channel,
Expand Down
5 changes: 1 addition & 4 deletions examples/src/bin/spi_slave_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ use esp_hal::{
dma_buffers,
gpio::{Input, Io, Level, Output, Pull},
prelude::*,
spi::{
slave::{prelude::*, Spi},
SpiMode,
},
spi::{slave::Spi, SpiMode},
};
use esp_println::println;

Expand Down

0 comments on commit f5b8e4b

Please sign in to comment.