diff options
| -rw-r--r-- | embassy-stm32/src/i2s.rs | 27 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/i2s_dma.rs | 1 |
2 files changed, 12 insertions, 16 deletions
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 5005a5cdb..a51d21bb0 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -155,6 +155,10 @@ impl ClockPolarity { | |||
| 155 | #[non_exhaustive] | 155 | #[non_exhaustive] |
| 156 | #[derive(Copy, Clone)] | 156 | #[derive(Copy, Clone)] |
| 157 | pub struct Config { | 157 | pub struct Config { |
| 158 | /// Frequency | ||
| 159 | pub frequency: Hertz, | ||
| 160 | /// GPIO Speed | ||
| 161 | pub gpio_speed: Speed, | ||
| 158 | /// Mode | 162 | /// Mode |
| 159 | pub mode: Mode, | 163 | pub mode: Mode, |
| 160 | /// Which I2S standard to use. | 164 | /// Which I2S standard to use. |
| @@ -170,6 +174,8 @@ pub struct Config { | |||
| 170 | impl Default for Config { | 174 | impl Default for Config { |
| 171 | fn default() -> Self { | 175 | fn default() -> Self { |
| 172 | Self { | 176 | Self { |
| 177 | frequency: Hertz::khz(48), | ||
| 178 | gpio_speed: Speed::VeryHigh, | ||
| 173 | mode: Mode::Master, | 179 | mode: Mode::Master, |
| 174 | standard: Standard::Philips, | 180 | standard: Standard::Philips, |
| 175 | format: Format::Data16Channel16, | 181 | format: Format::Data16Channel16, |
| @@ -243,7 +249,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 243 | mck: Peri<'d, impl MckPin<T>>, | 249 | mck: Peri<'d, impl MckPin<T>>, |
| 244 | txdma: Peri<'d, impl TxDma<T>>, | 250 | txdma: Peri<'d, impl TxDma<T>>, |
| 245 | txdma_buf: &'d mut [W], | 251 | txdma_buf: &'d mut [W], |
| 246 | freq: Hertz, | ||
| 247 | config: Config, | 252 | config: Config, |
| 248 | ) -> Self { | 253 | ) -> Self { |
| 249 | Self::new_inner( | 254 | Self::new_inner( |
| @@ -255,7 +260,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 255 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 260 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 256 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 261 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 257 | None, | 262 | None, |
| 258 | freq, | ||
| 259 | config, | 263 | config, |
| 260 | Function::Transmit, | 264 | Function::Transmit, |
| 261 | ) | 265 | ) |
| @@ -269,7 +273,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 269 | ck: Peri<'d, impl CkPin<T>>, | 273 | ck: Peri<'d, impl CkPin<T>>, |
| 270 | txdma: Peri<'d, impl TxDma<T>>, | 274 | txdma: Peri<'d, impl TxDma<T>>, |
| 271 | txdma_buf: &'d mut [W], | 275 | txdma_buf: &'d mut [W], |
| 272 | freq: Hertz, | ||
| 273 | config: Config, | 276 | config: Config, |
| 274 | ) -> Self { | 277 | ) -> Self { |
| 275 | Self::new_inner( | 278 | Self::new_inner( |
| @@ -281,7 +284,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 281 | None, | 284 | None, |
| 282 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 285 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 283 | None, | 286 | None, |
| 284 | freq, | ||
| 285 | config, | 287 | config, |
| 286 | Function::Transmit, | 288 | Function::Transmit, |
| 287 | ) | 289 | ) |
| @@ -296,7 +298,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 296 | mck: Peri<'d, impl MckPin<T>>, | 298 | mck: Peri<'d, impl MckPin<T>>, |
| 297 | rxdma: Peri<'d, impl RxDma<T>>, | 299 | rxdma: Peri<'d, impl RxDma<T>>, |
| 298 | rxdma_buf: &'d mut [W], | 300 | rxdma_buf: &'d mut [W], |
| 299 | freq: Hertz, | ||
| 300 | config: Config, | 301 | config: Config, |
| 301 | ) -> Self { | 302 | ) -> Self { |
| 302 | Self::new_inner( | 303 | Self::new_inner( |
| @@ -308,7 +309,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 308 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 309 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 309 | None, | 310 | None, |
| 310 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), | 311 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), |
| 311 | freq, | ||
| 312 | config, | 312 | config, |
| 313 | Function::Receive, | 313 | Function::Receive, |
| 314 | ) | 314 | ) |
| @@ -327,7 +327,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 327 | txdma_buf: &'d mut [W], | 327 | txdma_buf: &'d mut [W], |
| 328 | rxdma: Peri<'d, impl RxDma<T>>, | 328 | rxdma: Peri<'d, impl RxDma<T>>, |
| 329 | rxdma_buf: &'d mut [W], | 329 | rxdma_buf: &'d mut [W], |
| 330 | freq: Hertz, | ||
| 331 | config: Config, | 330 | config: Config, |
| 332 | ) -> Self { | 331 | ) -> Self { |
| 333 | Self::new_inner( | 332 | Self::new_inner( |
| @@ -339,7 +338,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 339 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 338 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 340 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 339 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 341 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), | 340 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), |
| 342 | freq, | ||
| 343 | config, | 341 | config, |
| 344 | Function::FullDuplex, | 342 | Function::FullDuplex, |
| 345 | ) | 343 | ) |
| @@ -473,17 +471,16 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 473 | mck: Option<Peri<'d, AnyPin>>, | 471 | mck: Option<Peri<'d, AnyPin>>, |
| 474 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 472 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 475 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 473 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 476 | freq: Hertz, | ||
| 477 | config: Config, | 474 | config: Config, |
| 478 | function: Function, | 475 | function: Function, |
| 479 | ) -> Self { | 476 | ) -> Self { |
| 480 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 477 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 481 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 478 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 482 | 479 | ||
| 483 | let spi = Spi::new_internal(peri, None, None, { | 480 | let spi = Spi::new_internal(peri, None, None, { |
| 484 | let mut config = SpiConfig::default(); | 481 | let mut spi_config = SpiConfig::default(); |
| 485 | config.frequency = freq; | 482 | spi_config.frequency = config.frequency; |
| 486 | config | 483 | spi_config |
| 487 | }); | 484 | }); |
| 488 | 485 | ||
| 489 | let regs = T::info().regs; | 486 | let regs = T::info().regs; |
| @@ -493,7 +490,7 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 493 | #[cfg(not(all(rcc_f4, not(stm32f410))))] | 490 | #[cfg(not(all(rcc_f4, not(stm32f410))))] |
| 494 | let pclk = T::frequency(); | 491 | let pclk = T::frequency(); |
| 495 | 492 | ||
| 496 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); | 493 | let (odd, div) = compute_baud_rate(pclk, config.frequency, config.master_clock, config.format); |
| 497 | 494 | ||
| 498 | #[cfg(any(spi_v1, spi_v3, spi_f1))] | 495 | #[cfg(any(spi_v1, spi_v3, spi_f1))] |
| 499 | { | 496 | { |
diff --git a/examples/stm32f4/src/bin/i2s_dma.rs b/examples/stm32f4/src/bin/i2s_dma.rs index db5103d0f..6051a3c5a 100644 --- a/examples/stm32f4/src/bin/i2s_dma.rs +++ b/examples/stm32f4/src/bin/i2s_dma.rs | |||
| @@ -72,7 +72,6 @@ async fn main(_spawner: Spawner) { | |||
| 72 | p.PB3, // ck | 72 | p.PB3, // ck |
| 73 | p.DMA1_CH7, | 73 | p.DMA1_CH7, |
| 74 | &mut dma_buffer, | 74 | &mut dma_buffer, |
| 75 | Hertz(48_000), | ||
| 76 | i2s_config, | 75 | i2s_config, |
| 77 | ); | 76 | ); |
| 78 | i2s.start(); | 77 | i2s.start(); |
