@@ -3,7 +3,7 @@ use core::ops::Deref;
3
3
4
4
use crate :: {
5
5
gpio:: { Floating , Input , Output , Pin , PushPull } ,
6
- pac:: { spi0, SPI0 , SPI1 } ,
6
+ pac:: { spi0, SPI0 } ,
7
7
} ;
8
8
9
9
pub use embedded_hal:: {
71
71
{
72
72
pub fn new ( spi : T , pins : Pins , frequency : Frequency , mode : Mode ) -> Self {
73
73
// 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) ;
84
76
85
77
// Enable SPI instance.
86
78
spi. enable . write ( |w| w. enable ( ) . enabled ( ) ) ;
99
91
Self ( spi)
100
92
}
101
93
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
+
102
123
/// Return the raw interface to the underlying SPI peripheral.
103
124
pub fn free ( self ) -> T {
104
125
self . 0
@@ -137,5 +158,12 @@ mod sealed {
137
158
impl sealed:: Sealed for SPI0 { }
138
159
impl Instance for SPI0 { }
139
160
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