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/sai | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/sai')
| -rw-r--r-- | embassy-stm32/src/sai/mod.rs | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 39ed44712..0c9c27797 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::PeripheralType; |
| 8 | 8 | ||
| 9 | pub use crate::dma::word; | 9 | pub use crate::dma::word; |
| 10 | #[cfg(not(gpdma))] | 10 | #[cfg(not(gpdma))] |
| @@ -12,7 +12,7 @@ use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptio | |||
| 12 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; | 12 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; |
| 13 | use crate::pac::sai::{vals, Sai as Regs}; | 13 | use crate::pac::sai::{vals, Sai as Regs}; |
| 14 | use crate::rcc::{self, RccPeripheral}; | 14 | use crate::rcc::{self, RccPeripheral}; |
| 15 | use crate::{peripherals, Peripheral}; | 15 | use crate::{peripherals, Peri}; |
| 16 | 16 | ||
| 17 | /// SAI error | 17 | /// SAI error |
| 18 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 18 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| @@ -679,7 +679,7 @@ fn get_af_types(mode: Mode, tx_rx: TxRx) -> (AfType, AfType) { | |||
| 679 | 679 | ||
| 680 | #[cfg(not(gpdma))] | 680 | #[cfg(not(gpdma))] |
| 681 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( | 681 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( |
| 682 | dma: impl Peripheral<P = impl Channel> + 'd, | 682 | dma: Peri<'d, impl Channel>, |
| 683 | dma_buf: &'d mut [W], | 683 | dma_buf: &'d mut [W], |
| 684 | request: Request, | 684 | request: Request, |
| 685 | sub_block: WhichSubBlock, | 685 | sub_block: WhichSubBlock, |
| @@ -718,16 +718,15 @@ fn update_synchronous_config(config: &mut Config) { | |||
| 718 | } | 718 | } |
| 719 | 719 | ||
| 720 | /// SAI subblock instance. | 720 | /// SAI subblock instance. |
| 721 | pub struct SubBlock<'d, T, S: SubBlockInstance> { | 721 | pub struct SubBlock<'d, T: Instance, S: SubBlockInstance> { |
| 722 | peri: PeripheralRef<'d, T>, | 722 | peri: Peri<'d, T>, |
| 723 | _phantom: PhantomData<S>, | 723 | _phantom: PhantomData<S>, |
| 724 | } | 724 | } |
| 725 | 725 | ||
| 726 | /// Split the main SAIx peripheral into the two subblocks. | 726 | /// Split the main SAIx peripheral into the two subblocks. |
| 727 | /// | 727 | /// |
| 728 | /// You can then create a [`Sai`] driver for each each half. | 728 | /// You can then create a [`Sai`] driver for each each half. |
| 729 | pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { | 729 | pub fn split_subblocks<'d, T: Instance>(peri: Peri<'d, T>) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { |
| 730 | into_ref!(peri); | ||
| 731 | rcc::enable_and_reset::<T>(); | 730 | rcc::enable_and_reset::<T>(); |
| 732 | 731 | ||
| 733 | ( | 732 | ( |
| @@ -744,11 +743,11 @@ pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (S | |||
| 744 | 743 | ||
| 745 | /// SAI sub-block driver. | 744 | /// SAI sub-block driver. |
| 746 | pub struct Sai<'d, T: Instance, W: word::Word> { | 745 | pub struct Sai<'d, T: Instance, W: word::Word> { |
| 747 | _peri: PeripheralRef<'d, T>, | 746 | _peri: Peri<'d, T>, |
| 748 | sd: Option<PeripheralRef<'d, AnyPin>>, | 747 | sd: Option<Peri<'d, AnyPin>>, |
| 749 | fs: Option<PeripheralRef<'d, AnyPin>>, | 748 | fs: Option<Peri<'d, AnyPin>>, |
| 750 | sck: Option<PeripheralRef<'d, AnyPin>>, | 749 | sck: Option<Peri<'d, AnyPin>>, |
| 751 | mclk: Option<PeripheralRef<'d, AnyPin>>, | 750 | mclk: Option<Peri<'d, AnyPin>>, |
| 752 | #[cfg(gpdma)] | 751 | #[cfg(gpdma)] |
| 753 | ring_buffer: PhantomData<W>, | 752 | ring_buffer: PhantomData<W>, |
| 754 | #[cfg(not(gpdma))] | 753 | #[cfg(not(gpdma))] |
| @@ -763,16 +762,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 763 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 762 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 764 | pub fn new_asynchronous_with_mclk<S: SubBlockInstance>( | 763 | pub fn new_asynchronous_with_mclk<S: SubBlockInstance>( |
| 765 | peri: SubBlock<'d, T, S>, | 764 | peri: SubBlock<'d, T, S>, |
| 766 | sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, | 765 | sck: Peri<'d, impl SckPin<T, S>>, |
| 767 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 766 | sd: Peri<'d, impl SdPin<T, S>>, |
| 768 | fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, | 767 | fs: Peri<'d, impl FsPin<T, S>>, |
| 769 | mclk: impl Peripheral<P = impl MclkPin<T, S>> + 'd, | 768 | mclk: Peri<'d, impl MclkPin<T, S>>, |
| 770 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 769 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 771 | dma_buf: &'d mut [W], | 770 | dma_buf: &'d mut [W], |
| 772 | mut config: Config, | 771 | mut config: Config, |
| 773 | ) -> Self { | 772 | ) -> Self { |
| 774 | into_ref!(mclk); | ||
| 775 | |||
| 776 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 773 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 777 | mclk.set_as_af(mclk.af_num(), ck_af_type); | 774 | mclk.set_as_af(mclk.af_num(), ck_af_type); |
| 778 | 775 | ||
| @@ -788,15 +785,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 788 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 785 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 789 | pub fn new_asynchronous<S: SubBlockInstance>( | 786 | pub fn new_asynchronous<S: SubBlockInstance>( |
| 790 | peri: SubBlock<'d, T, S>, | 787 | peri: SubBlock<'d, T, S>, |
| 791 | sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, | 788 | sck: Peri<'d, impl SckPin<T, S>>, |
| 792 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 789 | sd: Peri<'d, impl SdPin<T, S>>, |
| 793 | fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, | 790 | fs: Peri<'d, impl FsPin<T, S>>, |
| 794 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 791 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 795 | dma_buf: &'d mut [W], | 792 | dma_buf: &'d mut [W], |
| 796 | config: Config, | 793 | config: Config, |
| 797 | ) -> Self { | 794 | ) -> Self { |
| 798 | let peri = peri.peri; | 795 | let peri = peri.peri; |
| 799 | into_ref!(peri, dma, sck, sd, fs); | ||
| 800 | 796 | ||
| 801 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 797 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 802 | sd.set_as_af(sd.af_num(), sd_af_type); | 798 | sd.set_as_af(sd.af_num(), sd_af_type); |
| @@ -809,10 +805,10 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 809 | Self::new_inner( | 805 | Self::new_inner( |
| 810 | peri, | 806 | peri, |
| 811 | sub_block, | 807 | sub_block, |
| 812 | Some(sck.map_into()), | 808 | Some(sck.into()), |
| 813 | None, | 809 | None, |
| 814 | Some(sd.map_into()), | 810 | Some(sd.into()), |
| 815 | Some(fs.map_into()), | 811 | Some(fs.into()), |
| 816 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), | 812 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), |
| 817 | config, | 813 | config, |
| 818 | ) | 814 | ) |
| @@ -823,15 +819,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 823 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 819 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 824 | pub fn new_synchronous<S: SubBlockInstance>( | 820 | pub fn new_synchronous<S: SubBlockInstance>( |
| 825 | peri: SubBlock<'d, T, S>, | 821 | peri: SubBlock<'d, T, S>, |
| 826 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 822 | sd: Peri<'d, impl SdPin<T, S>>, |
| 827 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 823 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 828 | dma_buf: &'d mut [W], | 824 | dma_buf: &'d mut [W], |
| 829 | mut config: Config, | 825 | mut config: Config, |
| 830 | ) -> Self { | 826 | ) -> Self { |
| 831 | update_synchronous_config(&mut config); | 827 | update_synchronous_config(&mut config); |
| 832 | 828 | ||
| 833 | let peri = peri.peri; | 829 | let peri = peri.peri; |
| 834 | into_ref!(dma, peri, sd); | ||
| 835 | 830 | ||
| 836 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); | 831 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 837 | sd.set_as_af(sd.af_num(), sd_af_type); | 832 | sd.set_as_af(sd.af_num(), sd_af_type); |
| @@ -844,7 +839,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 844 | sub_block, | 839 | sub_block, |
| 845 | None, | 840 | None, |
| 846 | None, | 841 | None, |
| 847 | Some(sd.map_into()), | 842 | Some(sd.into()), |
| 848 | None, | 843 | None, |
| 849 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), | 844 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), |
| 850 | config, | 845 | config, |
| @@ -852,12 +847,12 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 852 | } | 847 | } |
| 853 | 848 | ||
| 854 | fn new_inner( | 849 | fn new_inner( |
| 855 | peri: impl Peripheral<P = T> + 'd, | 850 | peri: Peri<'d, T>, |
| 856 | sub_block: WhichSubBlock, | 851 | sub_block: WhichSubBlock, |
| 857 | sck: Option<PeripheralRef<'d, AnyPin>>, | 852 | sck: Option<Peri<'d, AnyPin>>, |
| 858 | mclk: Option<PeripheralRef<'d, AnyPin>>, | 853 | mclk: Option<Peri<'d, AnyPin>>, |
| 859 | sd: Option<PeripheralRef<'d, AnyPin>>, | 854 | sd: Option<Peri<'d, AnyPin>>, |
| 860 | fs: Option<PeripheralRef<'d, AnyPin>>, | 855 | fs: Option<Peri<'d, AnyPin>>, |
| 861 | ring_buffer: RingBuffer<'d, W>, | 856 | ring_buffer: RingBuffer<'d, W>, |
| 862 | config: Config, | 857 | config: Config, |
| 863 | ) -> Self { | 858 | ) -> Self { |
| @@ -947,7 +942,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 947 | } | 942 | } |
| 948 | 943 | ||
| 949 | Self { | 944 | Self { |
| 950 | _peri: peri.into_ref(), | 945 | _peri: peri, |
| 951 | sub_block, | 946 | sub_block, |
| 952 | sck, | 947 | sck, |
| 953 | mclk, | 948 | mclk, |
| @@ -1106,7 +1101,7 @@ impl SubBlockInstance for B {} | |||
| 1106 | 1101 | ||
| 1107 | /// SAI instance trait. | 1102 | /// SAI instance trait. |
| 1108 | #[allow(private_bounds)] | 1103 | #[allow(private_bounds)] |
| 1109 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} | 1104 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {} |
| 1110 | 1105 | ||
| 1111 | pin_trait!(SckPin, Instance, SubBlockInstance); | 1106 | pin_trait!(SckPin, Instance, SubBlockInstance); |
| 1112 | pin_trait!(FsPin, Instance, SubBlockInstance); | 1107 | pin_trait!(FsPin, Instance, SubBlockInstance); |
