4
4
use core:: ops:: Deref ;
5
5
use core:: sync:: atomic:: { compiler_fence, Ordering :: SeqCst } ;
6
6
use core:: cmp:: min;
7
+ pub use crate :: target:: spim0:: frequency:: FREQUENCYW as Frequency ;
7
8
pub use embedded_hal:: spi:: { Mode , Phase , Polarity , MODE_0 , MODE_1 , MODE_2 , MODE_3 } ;
8
9
9
10
use crate :: target:: { spim0, SPIM0 } ;
@@ -158,7 +159,7 @@ impl<T> Spim<T> where T: SpimExt {
158
159
159
160
// Configure mode
160
161
spim. config . write ( |w| {
161
- // Can't match on `mode` as embedded_hal::spi::Mode only derives PartialEq, not Eq
162
+ // Can't match on `mode` due to embedded-hal, see https://github.com/rust-embedded/embedded-hal/pull/126
162
163
if mode == MODE_0 {
163
164
w. order ( ) . msb_first ( ) . cpol ( ) . active_high ( ) . cpha ( ) . leading ( )
164
165
} else if mode == MODE_1 {
@@ -171,37 +172,9 @@ impl<T> Spim<T> where T: SpimExt {
171
172
} ) ;
172
173
173
174
// Configure frequency
174
- spim. frequency . write ( |w| match frequency {
175
- Frequency :: K125 => {
176
- w. frequency ( ) . k125 ( ) // 125 kHz
177
- }
178
- Frequency :: K250 => {
179
- w. frequency ( ) . k250 ( ) // 250 kHz
180
- }
181
- Frequency :: K500 => {
182
- w. frequency ( ) . k500 ( ) // 500 kHz
183
- }
184
- Frequency :: M1 => {
185
- w. frequency ( ) . m1 ( ) // 1 MHz
186
- }
187
- Frequency :: M2 => {
188
- w. frequency ( ) . m2 ( ) // 2 MHz
189
- }
190
- Frequency :: M4 => {
191
- w. frequency ( ) . m4 ( ) // 4 MHz
192
- }
193
- Frequency :: M8 => {
194
- w. frequency ( ) . m8 ( ) // 8 MHz
195
- }
196
- #[ cfg( feature = "52840" ) ]
197
- Frequency :: M16 => {
198
- w. frequency ( ) . m16 ( ) // 16 MHz
199
- }
200
- #[ cfg( feature = "52840" ) ]
201
- Frequency :: M32 => {
202
- w. frequency ( ) . m32 ( ) // 32 MHz
203
- }
204
- } ) ;
175
+ spim. frequency . write ( |w|
176
+ w. frequency ( ) . variant ( frequency)
177
+ ) ;
205
178
206
179
// Set over-read character to `0`
207
180
spim. orc . write ( |w|
@@ -418,23 +391,6 @@ pub struct Pins {
418
391
pub miso : Option < Pin < Input < Floating > > > ,
419
392
}
420
393
421
- /// Frequencies for SPIM interface
422
- pub enum Frequency {
423
- K125 ,
424
- K250 ,
425
- K500 ,
426
- M1 ,
427
- M2 ,
428
- M4 ,
429
- M8 ,
430
- /// (only the 52840 can operate at 16M and 32M)
431
- #[ cfg( feature = "52840" ) ]
432
- M16 ,
433
- /// (only the 52840 can operate at 16M and 32M)
434
- #[ cfg( feature = "52840" ) ]
435
- M32 ,
436
- }
437
-
438
394
#[ derive( Debug ) ]
439
395
pub enum Error {
440
396
TxBufferTooLong ,
0 commit comments