@@ -3,7 +3,7 @@ use core::ops::Deref;
33
44use crate :: {
55 gpio:: { Floating , Input , Output , Pin , PushPull } ,
6- pac:: { spi0, SPI0 , SPI1 } ,
6+ pac:: { spi0, SPI0 } ,
77} ;
88
99pub use embedded_hal:: {
7171{
7272 pub fn new ( spi : T , pins : Pins , frequency : Frequency , mode : Mode ) -> Self {
7373 // Select pins.
74- spi. pselsck
75- . write ( |w| unsafe { w. bits ( pins. sck . pin ( ) . into ( ) ) } ) ;
76-
77- // Optional pins.
78- if let Some ( ref pin) = pins. mosi {
79- spi. pselmosi . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
80- }
81- if let Some ( ref pin) = pins. miso {
82- spi. pselmiso . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
83- }
74+ let mut spi = spi;
75+ Self :: set_pins ( & mut spi, pins) ;
8476
8577 // Enable SPI instance.
8678 spi. enable . write ( |w| w. enable ( ) . enabled ( ) ) ;
9991 Self ( spi)
10092 }
10193
94+ #[ cfg( feature = "51" ) ]
95+ fn set_pins ( spi : & mut T , pins : Pins ) {
96+ spi. pselsck
97+ . write ( |w| unsafe { w. bits ( pins. sck . pin ( ) . into ( ) ) } ) ;
98+
99+ // Optional pins.
100+ if let Some ( ref pin) = pins. mosi {
101+ spi. pselmosi . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
102+ }
103+ if let Some ( ref pin) = pins. miso {
104+ spi. pselmiso . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
105+ }
106+ }
107+
108+ #[ cfg( not( feature = "51" ) ) ]
109+ fn set_pins ( spi : & mut T , pins : Pins ) {
110+ spi. psel
111+ . sck
112+ . write ( |w| unsafe { w. bits ( pins. sck . pin ( ) . into ( ) ) } ) ;
113+
114+ // Optional pins.
115+ if let Some ( ref pin) = pins. mosi {
116+ spi. psel . mosi . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
117+ }
118+ if let Some ( ref pin) = pins. miso {
119+ spi. psel . miso . write ( |w| unsafe { w. bits ( pin. pin ( ) . into ( ) ) } ) ;
120+ }
121+ }
122+
102123 /// Return the raw interface to the underlying SPI peripheral.
103124 pub fn free ( self ) -> T {
104125 self . 0
@@ -137,5 +158,12 @@ mod sealed {
137158impl sealed:: Sealed for SPI0 { }
138159impl Instance for SPI0 { }
139160
140- impl sealed:: Sealed for SPI1 { }
141- impl Instance for SPI1 { }
161+ #[ cfg( not( feature = "52810" ) ) ]
162+ impl sealed:: Sealed for crate :: pac:: SPI1 { }
163+ #[ cfg( not( feature = "52810" ) ) ]
164+ impl Instance for crate :: pac:: SPI1 { }
165+
166+ #[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
167+ impl sealed:: Sealed for crate :: pac:: SPI2 { }
168+ #[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
169+ impl Instance for crate :: pac:: SPI2 { }
0 commit comments