Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion embassy-stm32/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ fn main() {
(("spi", "I2S_SD"), quote!(crate::spi::I2sSdPin)),
(("spi", "I2S_SDI"), quote!(crate::spi::I2sSdPin)),
(("spi", "I2S_SDO"), quote!(crate::spi::I2sSdPin)),
(("spi", "I2S_ext_SD"), quote!(crate::i2s::SdExtPin)),
(("i2c", "SDA"), quote!(crate::i2c::SdaPin)),
(("i2c", "SCL"), quote!(crate::i2c::SclPin)),
(("rcc", "MCO_1"), quote!(crate::rcc::McoPin)),
Expand Down Expand Up @@ -1794,6 +1795,7 @@ fn main() {
(("sai", "B"), quote!(crate::sai::Dma<B>)),
(("spi", "RX"), quote!(crate::spi::RxDma)),
(("spi", "TX"), quote!(crate::spi::TxDma)),
(("spi", "EXT"), quote!(crate::i2s::RxDmaExt)),
(("spdifrx", "RX"), quote!(crate::spdifrx::Dma)),
(("i2c", "RX"), quote!(crate::i2c::RxDma)),
(("i2c", "TX"), quote!(crate::i2c::TxDma)),
Expand Down Expand Up @@ -1857,6 +1859,10 @@ fn main() {

for p in METADATA.peripherals {
if let Some(regs) = &p.registers {
if p.name.starts_with("I2S") {
continue;
}

for trigger in p.triggers {
let matches = trigger_expr.captures(trigger.signal).unwrap();
let signal = &matches[1];
Expand All @@ -1876,7 +1882,15 @@ fn main() {
}

let mut dupe = HashSet::new();
for ch in p.dma_channels {
let mut dma_channels = vec![p.dma_channels.iter()];

if let Some(peri) = p.name.strip_prefix("SPI")
&& let Some(i2s_peri) = peripheral_map.get(format!("I2S{}", peri).as_str())
{
dma_channels.push(i2s_peri.dma_channels.iter());
}

for ch in dma_channels.iter_mut().flatten() {
if let Some(tr) = signals.get(&(regs.kind, ch.signal)) {
let peri = format_ident!("{}", p.name);

Expand Down
42 changes: 40 additions & 2 deletions embassy-stm32/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ enum Function {
Transmit,
/// Receive audio data
Receive,
#[cfg(any(spi_v4, spi_v5))]

#[cfg(any(spi_v4, spi_v5, spi_v2_i2s))]
/// Transmit and Receive audio data
FullDuplex,
}
Expand Down Expand Up @@ -349,6 +348,38 @@ impl<'d, W: Word> I2S<'d, W> {
)
}

#[cfg(spi_v2_i2s)]
/// Create a transmitter driver.
pub fn new_full_duplex<T: I2sSExtInstance, D1: TxDma<T>, D2: RxDmaExt<T>, #[cfg(afio)] A>(
peri: Peri<'d, T>,
txsd: Peri<'d, if_afio!(impl MosiPin<T, A>)>,
rxsd: Peri<'d, if_afio!(impl SdExtPin<T, A>)>,
ws: Peri<'d, if_afio!(impl WsPin<T, A>)>,
ck: Peri<'d, if_afio!(impl CkPin<T, A>)>,
mck: Peri<'d, if_afio!(impl MckPin<T, A>)>,
txdma: Peri<'d, D1>,
txdma_buf: &'d mut [W],
rxdma: Peri<'d, D2>,
rxdma_buf: &'d mut [W],
_irq: impl crate::interrupt::typelevel::Binding<D1::Interrupt, crate::dma::InterruptHandler<D1>>
+ crate::interrupt::typelevel::Binding<D2::Interrupt, crate::dma::InterruptHandler<D2>>
+ 'd,
config: Config,
) -> Self {
Self::new_inner(
peri,
new_pin!(txsd, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
new_pin!(rxsd, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
ws,
ck,
new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)),
new_dma!(txdma, _irq).map(|d| (d, txdma_buf)),
new_dma!(rxdma, _irq).map(|d| (d, rxdma_buf)),
config,
Function::FullDuplex,
)
}

#[cfg(any(spi_v4, spi_v5))]
/// Create a full duplex driver.
pub fn new_full_duplex<T: Instance, D1: TxDma<T>, D2: RxDma<T>, #[cfg(afio)] A>(
Expand Down Expand Up @@ -644,6 +675,10 @@ impl<'d, W: Word> I2S<'d, W> {
(Mode::Slave, Function::Receive) => I2scfg::SLAVE_RX,
#[cfg(any(spi_v4, spi_v5))]
(Mode::Slave, Function::FullDuplex) => I2scfg::SLAVE_FULL_DUPLEX,
#[cfg(spi_v2_i2s)]
(Mode::Master, Function::FullDuplex) => todo!(),
#[cfg(spi_v2_i2s)]
(Mode::Slave, Function::FullDuplex) => todo!(),
});
});

Expand Down Expand Up @@ -782,6 +817,9 @@ fn reset_incompatible_bitfields<T: Instance>() {
regs.udrdr().write(|w| w.0 = 0);
}

dma_trait!(RxDmaExt, I2sSExtInstance);
pin_trait!(SdExtPin, I2sSExtInstance);

/// Full-Duplex I2s Instance
pub trait I2sSExtInstance: spi::Instance {
/// Ext regs
Expand Down
7 changes: 7 additions & 0 deletions embassy-stm32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ pub mod wdg;
#[cfg(xspi)]
pub mod xspi;

#[cfg(all(spi, not(any(spi_v1_i2s, spi_v2_i2s, spi_v3_i2s, spi_v4_i2s, spi_v5_i2s))))]
/// Stub module for I2S
pub mod i2s {
dma_trait!(RxDmaExt, crate::spi::Instance);
pin_trait!(SdExtPin, crate::spi::Instance);
}

#[cfg(feature = "_executor")]
pub mod executor;

Expand Down