88//! enabled.
99
1010use crate :: {
11- element:: Element ,
12- ral:: { self , dma, dmamux, tcd:: BandwidthControl , Static } ,
1311 Error ,
12+ element:: Element ,
13+ ral:: { self , Static , dma, dmamux, tcd:: BandwidthControl } ,
1414} ;
1515
1616impl < const CHANNELS : usize > super :: Dma < CHANNELS > {
@@ -465,10 +465,12 @@ impl Configuration {
465465/// Caller must ensure that `hardware_source` is valid for the lifetime of the transfer,
466466/// and valid for all subsequent transfers performed by this DMA channel with this address.
467467pub unsafe fn set_source_hardware < E : Element > ( chan : & mut Channel , hardware_source : * const E ) {
468- chan. set_source_address ( hardware_source) ;
469- chan. set_source_offset ( 0 ) ;
470- chan. set_source_attributes :: < E > ( 0 ) ;
471- chan. set_source_last_address_adjustment ( 0 ) ;
468+ unsafe {
469+ chan. set_source_address ( hardware_source) ;
470+ chan. set_source_offset ( 0 ) ;
471+ chan. set_source_attributes :: < E > ( 0 ) ;
472+ chan. set_source_last_address_adjustment ( 0 ) ;
473+ }
472474}
473475
474476/// Set a hardware peripheral as the destination for a DMA transfer
@@ -485,10 +487,12 @@ pub unsafe fn set_destination_hardware<E: Element>(
485487 chan : & mut Channel ,
486488 hardware_destination : * const E ,
487489) {
488- chan. set_destination_address ( hardware_destination) ;
489- chan. set_destination_offset ( 0 ) ;
490- chan. set_destination_attributes :: < E > ( 0 ) ;
491- chan. set_destination_last_address_adjustment ( 0 ) ;
490+ unsafe {
491+ chan. set_destination_address ( hardware_destination) ;
492+ chan. set_destination_offset ( 0 ) ;
493+ chan. set_destination_attributes :: < E > ( 0 ) ;
494+ chan. set_destination_last_address_adjustment ( 0 ) ;
495+ }
492496}
493497
494498/// Set a linear buffer as the source for a DMA transfer
@@ -501,10 +505,14 @@ pub unsafe fn set_destination_hardware<E: Element>(
501505/// Caller must ensure that the source is valid for the lifetime of the transfer,
502506/// and valid for all subsequent transfers performed by this DMA channel with this buffer.
503507pub unsafe fn set_source_linear_buffer < E : Element > ( chan : & mut Channel , source : & [ E ] ) {
504- chan. set_source_address ( source. as_ptr ( ) ) ;
505- chan. set_source_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
506- chan. set_source_attributes :: < E > ( 0 ) ;
507- chan. set_source_last_address_adjustment ( ( core:: mem:: size_of_val ( source) as i32 ) . wrapping_neg ( ) ) ;
508+ unsafe {
509+ chan. set_source_address ( source. as_ptr ( ) ) ;
510+ chan. set_source_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
511+ chan. set_source_attributes :: < E > ( 0 ) ;
512+ chan. set_source_last_address_adjustment (
513+ ( core:: mem:: size_of_val ( source) as i32 ) . wrapping_neg ( ) ,
514+ ) ;
515+ }
508516}
509517
510518/// Set a linear buffer as the destination for a DMA transfer
@@ -517,12 +525,14 @@ pub unsafe fn set_source_linear_buffer<E: Element>(chan: &mut Channel, source: &
517525/// Caller must ensure that the destination is valid for the lifetime of the transfer,
518526/// and valid for all subsequent transfers performed by this DMA channel with this buffer.
519527pub unsafe fn set_destination_linear_buffer < E : Element > ( chan : & mut Channel , destination : & mut [ E ] ) {
520- chan. set_destination_address ( destination. as_ptr ( ) ) ;
521- chan. set_destination_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
522- chan. set_destination_attributes :: < E > ( 0 ) ;
523- chan. set_destination_last_address_adjustment (
524- ( core:: mem:: size_of_val ( destination) as i32 ) . wrapping_neg ( ) ,
525- ) ;
528+ unsafe {
529+ chan. set_destination_address ( destination. as_ptr ( ) ) ;
530+ chan. set_destination_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
531+ chan. set_destination_attributes :: < E > ( 0 ) ;
532+ chan. set_destination_last_address_adjustment (
533+ ( core:: mem:: size_of_val ( destination) as i32 ) . wrapping_neg ( ) ,
534+ ) ;
535+ }
526536}
527537
528538/// Assert properties about the circular buffer
@@ -535,7 +545,7 @@ fn circular_buffer_asserts<E>(buffer: &[E]) {
535545 let start = buffer. as_ptr ( ) ;
536546 let size = core:: mem:: size_of_val ( buffer) ;
537547 assert ! (
538- ( start as usize ) % size == 0 ,
548+ ( start as usize ) . is_multiple_of ( size) ,
539549 "DMA circular buffer is not properly aligned"
540550 ) ;
541551}
@@ -565,10 +575,12 @@ pub unsafe fn set_source_circular_buffer<E: Element>(chan: &mut Channel, source:
565575 circular_buffer_asserts ( source) ;
566576 let modulo = circular_buffer_modulo ( source) ;
567577
568- chan. set_source_address ( source. as_ptr ( ) ) ;
569- chan. set_source_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
570- chan. set_source_attributes :: < E > ( modulo as u8 ) ;
571- chan. set_source_last_address_adjustment ( 0 ) ;
578+ unsafe {
579+ chan. set_source_address ( source. as_ptr ( ) ) ;
580+ chan. set_source_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
581+ chan. set_source_attributes :: < E > ( modulo as u8 ) ;
582+ chan. set_source_last_address_adjustment ( 0 ) ;
583+ }
572584}
573585
574586/// Set a circular buffer as the destination for a DMA transfer
@@ -594,8 +606,10 @@ pub unsafe fn set_destination_circular_buffer<E: Element>(
594606 circular_buffer_asserts ( destination) ;
595607 let modulo = circular_buffer_modulo ( destination) ;
596608
597- chan. set_destination_address ( destination. as_ptr ( ) ) ;
598- chan. set_destination_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
599- chan. set_destination_attributes :: < E > ( modulo as u8 ) ;
600- chan. set_destination_last_address_adjustment ( 0 ) ;
609+ unsafe {
610+ chan. set_destination_address ( destination. as_ptr ( ) ) ;
611+ chan. set_destination_offset ( core:: mem:: size_of :: < E > ( ) as i16 ) ;
612+ chan. set_destination_attributes :: < E > ( modulo as u8 ) ;
613+ chan. set_destination_last_address_adjustment ( 0 ) ;
614+ }
601615}
0 commit comments