diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src/spi | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/spi')
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index a43da1b5a..6578aa1aa 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -6,7 +6,6 @@ use core::ptr; | |||
| 6 | 6 | ||
| 7 | use embassy_embedded_hal::SetConfig; | 7 | use embassy_embedded_hal::SetConfig; |
| 8 | use embassy_futures::join::join; | 8 | use embassy_futures::join::join; |
| 9 | use embassy_hal_internal::PeripheralRef; | ||
| 10 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 9 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 11 | 10 | ||
| 12 | use crate::dma::{word, ChannelAndRequest}; | 11 | use crate::dma::{word, ChannelAndRequest}; |
| @@ -15,7 +14,7 @@ use crate::mode::{Async, Blocking, Mode as PeriMode}; | |||
| 15 | use crate::pac::spi::{regs, vals, Spi as Regs}; | 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; |
| 16 | use crate::rcc::{RccInfo, SealedRccPeripheral}; | 15 | use crate::rcc::{RccInfo, SealedRccPeripheral}; |
| 17 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 18 | use crate::Peripheral; | 17 | use crate::Peri; |
| 19 | 18 | ||
| 20 | /// SPI error. | 19 | /// SPI error. |
| 21 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 20 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| @@ -130,9 +129,9 @@ impl Config { | |||
| 130 | pub struct Spi<'d, M: PeriMode> { | 129 | pub struct Spi<'d, M: PeriMode> { |
| 131 | pub(crate) info: &'static Info, | 130 | pub(crate) info: &'static Info, |
| 132 | kernel_clock: Hertz, | 131 | kernel_clock: Hertz, |
| 133 | sck: Option<PeripheralRef<'d, AnyPin>>, | 132 | sck: Option<Peri<'d, AnyPin>>, |
| 134 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 133 | mosi: Option<Peri<'d, AnyPin>>, |
| 135 | miso: Option<PeripheralRef<'d, AnyPin>>, | 134 | miso: Option<Peri<'d, AnyPin>>, |
| 136 | tx_dma: Option<ChannelAndRequest<'d>>, | 135 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 137 | rx_dma: Option<ChannelAndRequest<'d>>, | 136 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 138 | _phantom: PhantomData<M>, | 137 | _phantom: PhantomData<M>, |
| @@ -142,10 +141,10 @@ pub struct Spi<'d, M: PeriMode> { | |||
| 142 | 141 | ||
| 143 | impl<'d, M: PeriMode> Spi<'d, M> { | 142 | impl<'d, M: PeriMode> Spi<'d, M> { |
| 144 | fn new_inner<T: Instance>( | 143 | fn new_inner<T: Instance>( |
| 145 | _peri: impl Peripheral<P = T> + 'd, | 144 | _peri: Peri<'d, T>, |
| 146 | sck: Option<PeripheralRef<'d, AnyPin>>, | 145 | sck: Option<Peri<'d, AnyPin>>, |
| 147 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 146 | mosi: Option<Peri<'d, AnyPin>>, |
| 148 | miso: Option<PeripheralRef<'d, AnyPin>>, | 147 | miso: Option<Peri<'d, AnyPin>>, |
| 149 | tx_dma: Option<ChannelAndRequest<'d>>, | 148 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 150 | rx_dma: Option<ChannelAndRequest<'d>>, | 149 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 151 | config: Config, | 150 | config: Config, |
| @@ -465,10 +464,10 @@ impl<'d, M: PeriMode> Spi<'d, M> { | |||
| 465 | impl<'d> Spi<'d, Blocking> { | 464 | impl<'d> Spi<'d, Blocking> { |
| 466 | /// Create a new blocking SPI driver. | 465 | /// Create a new blocking SPI driver. |
| 467 | pub fn new_blocking<T: Instance>( | 466 | pub fn new_blocking<T: Instance>( |
| 468 | peri: impl Peripheral<P = T> + 'd, | 467 | peri: Peri<'d, T>, |
| 469 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 468 | sck: Peri<'d, impl SckPin<T>>, |
| 470 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 469 | mosi: Peri<'d, impl MosiPin<T>>, |
| 471 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 470 | miso: Peri<'d, impl MisoPin<T>>, |
| 472 | config: Config, | 471 | config: Config, |
| 473 | ) -> Self { | 472 | ) -> Self { |
| 474 | Self::new_inner( | 473 | Self::new_inner( |
| @@ -484,9 +483,9 @@ impl<'d> Spi<'d, Blocking> { | |||
| 484 | 483 | ||
| 485 | /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI). | 484 | /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI). |
| 486 | pub fn new_blocking_rxonly<T: Instance>( | 485 | pub fn new_blocking_rxonly<T: Instance>( |
| 487 | peri: impl Peripheral<P = T> + 'd, | 486 | peri: Peri<'d, T>, |
| 488 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 487 | sck: Peri<'d, impl SckPin<T>>, |
| 489 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 488 | miso: Peri<'d, impl MisoPin<T>>, |
| 490 | config: Config, | 489 | config: Config, |
| 491 | ) -> Self { | 490 | ) -> Self { |
| 492 | Self::new_inner( | 491 | Self::new_inner( |
| @@ -502,9 +501,9 @@ impl<'d> Spi<'d, Blocking> { | |||
| 502 | 501 | ||
| 503 | /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO). | 502 | /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO). |
| 504 | pub fn new_blocking_txonly<T: Instance>( | 503 | pub fn new_blocking_txonly<T: Instance>( |
| 505 | peri: impl Peripheral<P = T> + 'd, | 504 | peri: Peri<'d, T>, |
| 506 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 505 | sck: Peri<'d, impl SckPin<T>>, |
| 507 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 506 | mosi: Peri<'d, impl MosiPin<T>>, |
| 508 | config: Config, | 507 | config: Config, |
| 509 | ) -> Self { | 508 | ) -> Self { |
| 510 | Self::new_inner( | 509 | Self::new_inner( |
| @@ -522,8 +521,8 @@ impl<'d> Spi<'d, Blocking> { | |||
| 522 | /// | 521 | /// |
| 523 | /// This can be useful for bit-banging non-SPI protocols. | 522 | /// This can be useful for bit-banging non-SPI protocols. |
| 524 | pub fn new_blocking_txonly_nosck<T: Instance>( | 523 | pub fn new_blocking_txonly_nosck<T: Instance>( |
| 525 | peri: impl Peripheral<P = T> + 'd, | 524 | peri: Peri<'d, T>, |
| 526 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 525 | mosi: Peri<'d, impl MosiPin<T>>, |
| 527 | config: Config, | 526 | config: Config, |
| 528 | ) -> Self { | 527 | ) -> Self { |
| 529 | Self::new_inner( | 528 | Self::new_inner( |
| @@ -541,12 +540,12 @@ impl<'d> Spi<'d, Blocking> { | |||
| 541 | impl<'d> Spi<'d, Async> { | 540 | impl<'d> Spi<'d, Async> { |
| 542 | /// Create a new SPI driver. | 541 | /// Create a new SPI driver. |
| 543 | pub fn new<T: Instance>( | 542 | pub fn new<T: Instance>( |
| 544 | peri: impl Peripheral<P = T> + 'd, | 543 | peri: Peri<'d, T>, |
| 545 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 544 | sck: Peri<'d, impl SckPin<T>>, |
| 546 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 545 | mosi: Peri<'d, impl MosiPin<T>>, |
| 547 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 546 | miso: Peri<'d, impl MisoPin<T>>, |
| 548 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 547 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 549 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 548 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 550 | config: Config, | 549 | config: Config, |
| 551 | ) -> Self { | 550 | ) -> Self { |
| 552 | Self::new_inner( | 551 | Self::new_inner( |
| @@ -562,11 +561,11 @@ impl<'d> Spi<'d, Async> { | |||
| 562 | 561 | ||
| 563 | /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). | 562 | /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). |
| 564 | pub fn new_rxonly<T: Instance>( | 563 | pub fn new_rxonly<T: Instance>( |
| 565 | peri: impl Peripheral<P = T> + 'd, | 564 | peri: Peri<'d, T>, |
| 566 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 565 | sck: Peri<'d, impl SckPin<T>>, |
| 567 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 566 | miso: Peri<'d, impl MisoPin<T>>, |
| 568 | #[cfg(any(spi_v1, spi_f1, spi_v2))] tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 567 | #[cfg(any(spi_v1, spi_f1, spi_v2))] tx_dma: Peri<'d, impl TxDma<T>>, |
| 569 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 568 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 570 | config: Config, | 569 | config: Config, |
| 571 | ) -> Self { | 570 | ) -> Self { |
| 572 | Self::new_inner( | 571 | Self::new_inner( |
| @@ -585,10 +584,10 @@ impl<'d> Spi<'d, Async> { | |||
| 585 | 584 | ||
| 586 | /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). | 585 | /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). |
| 587 | pub fn new_txonly<T: Instance>( | 586 | pub fn new_txonly<T: Instance>( |
| 588 | peri: impl Peripheral<P = T> + 'd, | 587 | peri: Peri<'d, T>, |
| 589 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 588 | sck: Peri<'d, impl SckPin<T>>, |
| 590 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 589 | mosi: Peri<'d, impl MosiPin<T>>, |
| 591 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 590 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 592 | config: Config, | 591 | config: Config, |
| 593 | ) -> Self { | 592 | ) -> Self { |
| 594 | Self::new_inner( | 593 | Self::new_inner( |
| @@ -606,9 +605,9 @@ impl<'d> Spi<'d, Async> { | |||
| 606 | /// | 605 | /// |
| 607 | /// This can be useful for bit-banging non-SPI protocols. | 606 | /// This can be useful for bit-banging non-SPI protocols. |
| 608 | pub fn new_txonly_nosck<T: Instance>( | 607 | pub fn new_txonly_nosck<T: Instance>( |
| 609 | peri: impl Peripheral<P = T> + 'd, | 608 | peri: Peri<'d, T>, |
| 610 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 609 | mosi: Peri<'d, impl MosiPin<T>>, |
| 611 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 610 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 612 | config: Config, | 611 | config: Config, |
| 613 | ) -> Self { | 612 | ) -> Self { |
| 614 | Self::new_inner( | 613 | Self::new_inner( |
| @@ -625,9 +624,9 @@ impl<'d> Spi<'d, Async> { | |||
| 625 | #[cfg(stm32wl)] | 624 | #[cfg(stm32wl)] |
| 626 | /// Useful for on chip peripherals like SUBGHZ which are hardwired. | 625 | /// Useful for on chip peripherals like SUBGHZ which are hardwired. |
| 627 | pub fn new_subghz<T: Instance>( | 626 | pub fn new_subghz<T: Instance>( |
| 628 | peri: impl Peripheral<P = T> + 'd, | 627 | peri: Peri<'d, T>, |
| 629 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 628 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 630 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 629 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 631 | ) -> Self { | 630 | ) -> Self { |
| 632 | // see RM0453 rev 1 section 7.2.13 page 291 | 631 | // see RM0453 rev 1 section 7.2.13 page 291 |
| 633 | // The SUBGHZSPI_SCK frequency is obtained by PCLK3 divided by two. | 632 | // The SUBGHZSPI_SCK frequency is obtained by PCLK3 divided by two. |
| @@ -644,7 +643,7 @@ impl<'d> Spi<'d, Async> { | |||
| 644 | 643 | ||
| 645 | #[allow(dead_code)] | 644 | #[allow(dead_code)] |
| 646 | pub(crate) fn new_internal<T: Instance>( | 645 | pub(crate) fn new_internal<T: Instance>( |
| 647 | peri: impl Peripheral<P = T> + 'd, | 646 | peri: Peri<'d, T>, |
| 648 | tx_dma: Option<ChannelAndRequest<'d>>, | 647 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 649 | rx_dma: Option<ChannelAndRequest<'d>>, | 648 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 650 | config: Config, | 649 | config: Config, |
