@@ -19,6 +19,7 @@ use crate::{
19
19
target_constants:: { SRAM_LOWER , SRAM_UPPER } ,
20
20
time:: * ,
21
21
} ;
22
+ use embedded_dma:: * ;
22
23
23
24
/// A safe wrapper around the raw peripheral.
24
25
#[ derive( Debug ) ]
@@ -473,37 +474,29 @@ where
473
474
474
475
/// Loads a sequence buffer.
475
476
/// NOTE: `buf` must live until the sequence is done playing, or it might play a corrupted sequence.
476
- pub fn load_seq ( & self , seq : Seq , buf : & [ u16 ] ) -> Result < ( ) , Error > {
477
- if ( buf. as_ptr ( ) as usize ) < SRAM_LOWER || ( buf. as_ptr ( ) as usize ) > SRAM_UPPER {
477
+ pub fn load_seq < W , B > ( & self , seq : Seq , buf : B ) -> Result < ( ) , Error >
478
+ where
479
+ B : ReadBuffer < Word = W > ,
480
+ {
481
+ let ( ptr, len) = unsafe { buf. read_buffer ( ) } ;
482
+ if ( ptr as usize ) < SRAM_LOWER || ( ptr as usize ) > SRAM_UPPER {
478
483
return Err ( Error :: DMABufferNotInDataMemory ) ;
479
484
}
480
485
481
- if buf . len ( ) > 32_768 {
486
+ if len > ( 1 << 15 ) / core :: mem :: size_of :: < W > ( ) {
482
487
return Err ( Error :: BufferTooLong ) ;
483
488
}
484
489
485
490
compiler_fence ( Ordering :: SeqCst ) ;
486
491
487
492
match seq {
488
493
Seq :: Seq0 => {
489
- self . pwm
490
- . seq0
491
- . ptr
492
- . write ( |w| unsafe { w. bits ( buf. as_ptr ( ) as u32 ) } ) ;
493
- self . pwm
494
- . seq0
495
- . cnt
496
- . write ( |w| unsafe { w. bits ( buf. len ( ) as u32 ) } ) ;
494
+ self . pwm . seq0 . ptr . write ( |w| unsafe { w. bits ( ptr as u32 ) } ) ;
495
+ self . pwm . seq0 . cnt . write ( |w| unsafe { w. bits ( len as u32 ) } ) ;
497
496
}
498
497
Seq :: Seq1 => {
499
- self . pwm
500
- . seq1
501
- . ptr
502
- . write ( |w| unsafe { w. bits ( buf. as_ptr ( ) as u32 ) } ) ;
503
- self . pwm
504
- . seq1
505
- . cnt
506
- . write ( |w| unsafe { w. bits ( buf. len ( ) as u32 ) } ) ;
498
+ self . pwm . seq1 . ptr . write ( |w| unsafe { w. bits ( ptr as u32 ) } ) ;
499
+ self . pwm . seq1 . cnt . write ( |w| unsafe { w. bits ( len as u32 ) } ) ;
507
500
}
508
501
}
509
502
Ok ( ( ) )
0 commit comments