aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/ospi
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src/ospi
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/ospi')
-rw-r--r--embassy-stm32/src/ospi/mod.rs224
1 files changed, 111 insertions, 113 deletions
diff --git a/embassy-stm32/src/ospi/mod.rs b/embassy-stm32/src/ospi/mod.rs
index 5dff3c4c3..74edfd5e4 100644
--- a/embassy-stm32/src/ospi/mod.rs
+++ b/embassy-stm32/src/ospi/mod.rs
@@ -8,7 +8,7 @@ pub mod enums;
8use core::marker::PhantomData; 8use core::marker::PhantomData;
9 9
10use embassy_embedded_hal::{GetConfig, SetConfig}; 10use embassy_embedded_hal::{GetConfig, SetConfig};
11use embassy_hal_internal::{into_ref, PeripheralRef}; 11use embassy_hal_internal::PeripheralType;
12pub use enums::*; 12pub use enums::*;
13use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits}; 13use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits};
14 14
@@ -19,7 +19,7 @@ use crate::pac::octospi::{vals, Octospi as Regs};
19#[cfg(octospim_v1)] 19#[cfg(octospim_v1)]
20use crate::pac::octospim::Octospim; 20use crate::pac::octospim::Octospim;
21use crate::rcc::{self, RccPeripheral}; 21use crate::rcc::{self, RccPeripheral};
22use crate::{peripherals, Peripheral}; 22use crate::{peripherals, Peri};
23 23
24/// OPSI driver config. 24/// OPSI driver config.
25#[derive(Clone, Copy)] 25#[derive(Clone, Copy)]
@@ -160,18 +160,18 @@ pub enum OspiError {
160 160
161/// OSPI driver. 161/// OSPI driver.
162pub struct Ospi<'d, T: Instance, M: PeriMode> { 162pub struct Ospi<'d, T: Instance, M: PeriMode> {
163 _peri: PeripheralRef<'d, T>, 163 _peri: Peri<'d, T>,
164 sck: Option<PeripheralRef<'d, AnyPin>>, 164 sck: Option<Peri<'d, AnyPin>>,
165 d0: Option<PeripheralRef<'d, AnyPin>>, 165 d0: Option<Peri<'d, AnyPin>>,
166 d1: Option<PeripheralRef<'d, AnyPin>>, 166 d1: Option<Peri<'d, AnyPin>>,
167 d2: Option<PeripheralRef<'d, AnyPin>>, 167 d2: Option<Peri<'d, AnyPin>>,
168 d3: Option<PeripheralRef<'d, AnyPin>>, 168 d3: Option<Peri<'d, AnyPin>>,
169 d4: Option<PeripheralRef<'d, AnyPin>>, 169 d4: Option<Peri<'d, AnyPin>>,
170 d5: Option<PeripheralRef<'d, AnyPin>>, 170 d5: Option<Peri<'d, AnyPin>>,
171 d6: Option<PeripheralRef<'d, AnyPin>>, 171 d6: Option<Peri<'d, AnyPin>>,
172 d7: Option<PeripheralRef<'d, AnyPin>>, 172 d7: Option<Peri<'d, AnyPin>>,
173 nss: Option<PeripheralRef<'d, AnyPin>>, 173 nss: Option<Peri<'d, AnyPin>>,
174 dqs: Option<PeripheralRef<'d, AnyPin>>, 174 dqs: Option<Peri<'d, AnyPin>>,
175 dma: Option<ChannelAndRequest<'d>>, 175 dma: Option<ChannelAndRequest<'d>>,
176 _phantom: PhantomData<M>, 176 _phantom: PhantomData<M>,
177 config: Config, 177 config: Config,
@@ -245,25 +245,23 @@ impl<'d, T: Instance, M: PeriMode> Ospi<'d, T, M> {
245 } 245 }
246 246
247 fn new_inner( 247 fn new_inner(
248 peri: impl Peripheral<P = T> + 'd, 248 peri: Peri<'d, T>,
249 d0: Option<PeripheralRef<'d, AnyPin>>, 249 d0: Option<Peri<'d, AnyPin>>,
250 d1: Option<PeripheralRef<'d, AnyPin>>, 250 d1: Option<Peri<'d, AnyPin>>,
251 d2: Option<PeripheralRef<'d, AnyPin>>, 251 d2: Option<Peri<'d, AnyPin>>,
252 d3: Option<PeripheralRef<'d, AnyPin>>, 252 d3: Option<Peri<'d, AnyPin>>,
253 d4: Option<PeripheralRef<'d, AnyPin>>, 253 d4: Option<Peri<'d, AnyPin>>,
254 d5: Option<PeripheralRef<'d, AnyPin>>, 254 d5: Option<Peri<'d, AnyPin>>,
255 d6: Option<PeripheralRef<'d, AnyPin>>, 255 d6: Option<Peri<'d, AnyPin>>,
256 d7: Option<PeripheralRef<'d, AnyPin>>, 256 d7: Option<Peri<'d, AnyPin>>,
257 sck: Option<PeripheralRef<'d, AnyPin>>, 257 sck: Option<Peri<'d, AnyPin>>,
258 nss: Option<PeripheralRef<'d, AnyPin>>, 258 nss: Option<Peri<'d, AnyPin>>,
259 dqs: Option<PeripheralRef<'d, AnyPin>>, 259 dqs: Option<Peri<'d, AnyPin>>,
260 dma: Option<ChannelAndRequest<'d>>, 260 dma: Option<ChannelAndRequest<'d>>,
261 config: Config, 261 config: Config,
262 width: OspiWidth, 262 width: OspiWidth,
263 dual_quad: bool, 263 dual_quad: bool,
264 ) -> Self { 264 ) -> Self {
265 into_ref!(peri);
266
267 #[cfg(octospim_v1)] 265 #[cfg(octospim_v1)]
268 { 266 {
269 // RCC for octospim should be enabled before writing register 267 // RCC for octospim should be enabled before writing register
@@ -685,11 +683,11 @@ impl<'d, T: Instance, M: PeriMode> Ospi<'d, T, M> {
685impl<'d, T: Instance> Ospi<'d, T, Blocking> { 683impl<'d, T: Instance> Ospi<'d, T, Blocking> {
686 /// Create new blocking OSPI driver for a single spi external chip 684 /// Create new blocking OSPI driver for a single spi external chip
687 pub fn new_blocking_singlespi( 685 pub fn new_blocking_singlespi(
688 peri: impl Peripheral<P = T> + 'd, 686 peri: Peri<'d, T>,
689 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 687 sck: Peri<'d, impl SckPin<T>>,
690 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 688 d0: Peri<'d, impl D0Pin<T>>,
691 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 689 d1: Peri<'d, impl D1Pin<T>>,
692 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 690 nss: Peri<'d, impl NSSPin<T>>,
693 config: Config, 691 config: Config,
694 ) -> Self { 692 ) -> Self {
695 Self::new_inner( 693 Self::new_inner(
@@ -717,11 +715,11 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> {
717 715
718 /// Create new blocking OSPI driver for a dualspi external chip 716 /// Create new blocking OSPI driver for a dualspi external chip
719 pub fn new_blocking_dualspi( 717 pub fn new_blocking_dualspi(
720 peri: impl Peripheral<P = T> + 'd, 718 peri: Peri<'d, T>,
721 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 719 sck: Peri<'d, impl SckPin<T>>,
722 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 720 d0: Peri<'d, impl D0Pin<T>>,
723 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 721 d1: Peri<'d, impl D1Pin<T>>,
724 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 722 nss: Peri<'d, impl NSSPin<T>>,
725 config: Config, 723 config: Config,
726 ) -> Self { 724 ) -> Self {
727 Self::new_inner( 725 Self::new_inner(
@@ -749,13 +747,13 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> {
749 747
750 /// Create new blocking OSPI driver for a quadspi external chip 748 /// Create new blocking OSPI driver for a quadspi external chip
751 pub fn new_blocking_quadspi( 749 pub fn new_blocking_quadspi(
752 peri: impl Peripheral<P = T> + 'd, 750 peri: Peri<'d, T>,
753 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 751 sck: Peri<'d, impl SckPin<T>>,
754 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 752 d0: Peri<'d, impl D0Pin<T>>,
755 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 753 d1: Peri<'d, impl D1Pin<T>>,
756 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 754 d2: Peri<'d, impl D2Pin<T>>,
757 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 755 d3: Peri<'d, impl D3Pin<T>>,
758 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 756 nss: Peri<'d, impl NSSPin<T>>,
759 config: Config, 757 config: Config,
760 ) -> Self { 758 ) -> Self {
761 Self::new_inner( 759 Self::new_inner(
@@ -783,17 +781,17 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> {
783 781
784 /// Create new blocking OSPI driver for two quadspi external chips 782 /// Create new blocking OSPI driver for two quadspi external chips
785 pub fn new_blocking_dualquadspi( 783 pub fn new_blocking_dualquadspi(
786 peri: impl Peripheral<P = T> + 'd, 784 peri: Peri<'d, T>,
787 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 785 sck: Peri<'d, impl SckPin<T>>,
788 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 786 d0: Peri<'d, impl D0Pin<T>>,
789 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 787 d1: Peri<'d, impl D1Pin<T>>,
790 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 788 d2: Peri<'d, impl D2Pin<T>>,
791 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 789 d3: Peri<'d, impl D3Pin<T>>,
792 d4: impl Peripheral<P = impl D4Pin<T>> + 'd, 790 d4: Peri<'d, impl D4Pin<T>>,
793 d5: impl Peripheral<P = impl D5Pin<T>> + 'd, 791 d5: Peri<'d, impl D5Pin<T>>,
794 d6: impl Peripheral<P = impl D6Pin<T>> + 'd, 792 d6: Peri<'d, impl D6Pin<T>>,
795 d7: impl Peripheral<P = impl D7Pin<T>> + 'd, 793 d7: Peri<'d, impl D7Pin<T>>,
796 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 794 nss: Peri<'d, impl NSSPin<T>>,
797 config: Config, 795 config: Config,
798 ) -> Self { 796 ) -> Self {
799 Self::new_inner( 797 Self::new_inner(
@@ -821,17 +819,17 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> {
821 819
822 /// Create new blocking OSPI driver for octospi external chips 820 /// Create new blocking OSPI driver for octospi external chips
823 pub fn new_blocking_octospi( 821 pub fn new_blocking_octospi(
824 peri: impl Peripheral<P = T> + 'd, 822 peri: Peri<'d, T>,
825 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 823 sck: Peri<'d, impl SckPin<T>>,
826 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 824 d0: Peri<'d, impl D0Pin<T>>,
827 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 825 d1: Peri<'d, impl D1Pin<T>>,
828 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 826 d2: Peri<'d, impl D2Pin<T>>,
829 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 827 d3: Peri<'d, impl D3Pin<T>>,
830 d4: impl Peripheral<P = impl D4Pin<T>> + 'd, 828 d4: Peri<'d, impl D4Pin<T>>,
831 d5: impl Peripheral<P = impl D5Pin<T>> + 'd, 829 d5: Peri<'d, impl D5Pin<T>>,
832 d6: impl Peripheral<P = impl D6Pin<T>> + 'd, 830 d6: Peri<'d, impl D6Pin<T>>,
833 d7: impl Peripheral<P = impl D7Pin<T>> + 'd, 831 d7: Peri<'d, impl D7Pin<T>>,
834 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 832 nss: Peri<'d, impl NSSPin<T>>,
835 config: Config, 833 config: Config,
836 ) -> Self { 834 ) -> Self {
837 Self::new_inner( 835 Self::new_inner(
@@ -861,12 +859,12 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> {
861impl<'d, T: Instance> Ospi<'d, T, Async> { 859impl<'d, T: Instance> Ospi<'d, T, Async> {
862 /// Create new blocking OSPI driver for a single spi external chip 860 /// Create new blocking OSPI driver for a single spi external chip
863 pub fn new_singlespi( 861 pub fn new_singlespi(
864 peri: impl Peripheral<P = T> + 'd, 862 peri: Peri<'d, T>,
865 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 863 sck: Peri<'d, impl SckPin<T>>,
866 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 864 d0: Peri<'d, impl D0Pin<T>>,
867 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 865 d1: Peri<'d, impl D1Pin<T>>,
868 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 866 nss: Peri<'d, impl NSSPin<T>>,
869 dma: impl Peripheral<P = impl OctoDma<T>> + 'd, 867 dma: Peri<'d, impl OctoDma<T>>,
870 config: Config, 868 config: Config,
871 ) -> Self { 869 ) -> Self {
872 Self::new_inner( 870 Self::new_inner(
@@ -894,12 +892,12 @@ impl<'d, T: Instance> Ospi<'d, T, Async> {
894 892
895 /// Create new blocking OSPI driver for a dualspi external chip 893 /// Create new blocking OSPI driver for a dualspi external chip
896 pub fn new_dualspi( 894 pub fn new_dualspi(
897 peri: impl Peripheral<P = T> + 'd, 895 peri: Peri<'d, T>,
898 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 896 sck: Peri<'d, impl SckPin<T>>,
899 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 897 d0: Peri<'d, impl D0Pin<T>>,
900 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 898 d1: Peri<'d, impl D1Pin<T>>,
901 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 899 nss: Peri<'d, impl NSSPin<T>>,
902 dma: impl Peripheral<P = impl OctoDma<T>> + 'd, 900 dma: Peri<'d, impl OctoDma<T>>,
903 config: Config, 901 config: Config,
904 ) -> Self { 902 ) -> Self {
905 Self::new_inner( 903 Self::new_inner(
@@ -927,14 +925,14 @@ impl<'d, T: Instance> Ospi<'d, T, Async> {
927 925
928 /// Create new blocking OSPI driver for a quadspi external chip 926 /// Create new blocking OSPI driver for a quadspi external chip
929 pub fn new_quadspi( 927 pub fn new_quadspi(
930 peri: impl Peripheral<P = T> + 'd, 928 peri: Peri<'d, T>,
931 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 929 sck: Peri<'d, impl SckPin<T>>,
932 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 930 d0: Peri<'d, impl D0Pin<T>>,
933 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 931 d1: Peri<'d, impl D1Pin<T>>,
934 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 932 d2: Peri<'d, impl D2Pin<T>>,
935 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 933 d3: Peri<'d, impl D3Pin<T>>,
936 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 934 nss: Peri<'d, impl NSSPin<T>>,
937 dma: impl Peripheral<P = impl OctoDma<T>> + 'd, 935 dma: Peri<'d, impl OctoDma<T>>,
938 config: Config, 936 config: Config,
939 ) -> Self { 937 ) -> Self {
940 Self::new_inner( 938 Self::new_inner(
@@ -962,18 +960,18 @@ impl<'d, T: Instance> Ospi<'d, T, Async> {
962 960
963 /// Create new blocking OSPI driver for two quadspi external chips 961 /// Create new blocking OSPI driver for two quadspi external chips
964 pub fn new_dualquadspi( 962 pub fn new_dualquadspi(
965 peri: impl Peripheral<P = T> + 'd, 963 peri: Peri<'d, T>,
966 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 964 sck: Peri<'d, impl SckPin<T>>,
967 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 965 d0: Peri<'d, impl D0Pin<T>>,
968 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 966 d1: Peri<'d, impl D1Pin<T>>,
969 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 967 d2: Peri<'d, impl D2Pin<T>>,
970 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 968 d3: Peri<'d, impl D3Pin<T>>,
971 d4: impl Peripheral<P = impl D4Pin<T>> + 'd, 969 d4: Peri<'d, impl D4Pin<T>>,
972 d5: impl Peripheral<P = impl D5Pin<T>> + 'd, 970 d5: Peri<'d, impl D5Pin<T>>,
973 d6: impl Peripheral<P = impl D6Pin<T>> + 'd, 971 d6: Peri<'d, impl D6Pin<T>>,
974 d7: impl Peripheral<P = impl D7Pin<T>> + 'd, 972 d7: Peri<'d, impl D7Pin<T>>,
975 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 973 nss: Peri<'d, impl NSSPin<T>>,
976 dma: impl Peripheral<P = impl OctoDma<T>> + 'd, 974 dma: Peri<'d, impl OctoDma<T>>,
977 config: Config, 975 config: Config,
978 ) -> Self { 976 ) -> Self {
979 Self::new_inner( 977 Self::new_inner(
@@ -1001,18 +999,18 @@ impl<'d, T: Instance> Ospi<'d, T, Async> {
1001 999
1002 /// Create new blocking OSPI driver for octospi external chips 1000 /// Create new blocking OSPI driver for octospi external chips
1003 pub fn new_octospi( 1001 pub fn new_octospi(
1004 peri: impl Peripheral<P = T> + 'd, 1002 peri: Peri<'d, T>,
1005 sck: impl Peripheral<P = impl SckPin<T>> + 'd, 1003 sck: Peri<'d, impl SckPin<T>>,
1006 d0: impl Peripheral<P = impl D0Pin<T>> + 'd, 1004 d0: Peri<'d, impl D0Pin<T>>,
1007 d1: impl Peripheral<P = impl D1Pin<T>> + 'd, 1005 d1: Peri<'d, impl D1Pin<T>>,
1008 d2: impl Peripheral<P = impl D2Pin<T>> + 'd, 1006 d2: Peri<'d, impl D2Pin<T>>,
1009 d3: impl Peripheral<P = impl D3Pin<T>> + 'd, 1007 d3: Peri<'d, impl D3Pin<T>>,
1010 d4: impl Peripheral<P = impl D4Pin<T>> + 'd, 1008 d4: Peri<'d, impl D4Pin<T>>,
1011 d5: impl Peripheral<P = impl D5Pin<T>> + 'd, 1009 d5: Peri<'d, impl D5Pin<T>>,
1012 d6: impl Peripheral<P = impl D6Pin<T>> + 'd, 1010 d6: Peri<'d, impl D6Pin<T>>,
1013 d7: impl Peripheral<P = impl D7Pin<T>> + 'd, 1011 d7: Peri<'d, impl D7Pin<T>>,
1014 nss: impl Peripheral<P = impl NSSPin<T>> + 'd, 1012 nss: Peri<'d, impl NSSPin<T>>,
1015 dma: impl Peripheral<P = impl OctoDma<T>> + 'd, 1013 dma: Peri<'d, impl OctoDma<T>>,
1016 config: Config, 1014 config: Config,
1017 ) -> Self { 1015 ) -> Self {
1018 Self::new_inner( 1016 Self::new_inner(
@@ -1221,12 +1219,12 @@ pub(crate) trait SealedInstance {
1221/// OSPI instance trait. 1219/// OSPI instance trait.
1222#[cfg(octospim_v1)] 1220#[cfg(octospim_v1)]
1223#[allow(private_bounds)] 1221#[allow(private_bounds)]
1224pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral + SealedOctospimInstance {} 1222pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + SealedOctospimInstance {}
1225 1223
1226/// OSPI instance trait. 1224/// OSPI instance trait.
1227#[cfg(not(octospim_v1))] 1225#[cfg(not(octospim_v1))]
1228#[allow(private_bounds)] 1226#[allow(private_bounds)]
1229pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} 1227pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {}
1230 1228
1231pin_trait!(SckPin, Instance); 1229pin_trait!(SckPin, Instance);
1232pin_trait!(NckPin, Instance); 1230pin_trait!(NckPin, Instance);