3333
3434#![ allow( unused_braces) ]
3535
36- use core:: marker:: PhantomData ;
36+ use core:: { marker:: PhantomData , ptr :: NonNull } ;
3737
3838use atsamd_hal_macros:: { hal_cfg, hal_macro_helper} ;
3939
@@ -342,9 +342,9 @@ impl<Id: ChId, S: Status> Channel<Id, S> {
342342 // SAFETY This is safe as we are only reading the descriptor's address,
343343 // and not actually writing any data to it. We also assume the descriptor
344344 // will never be moved.
345- descriptor as * mut _
345+ NonNull :: new ( descriptor)
346346 } else {
347- core :: ptr :: null_mut ( )
347+ None
348348 } ;
349349
350350 unsafe {
@@ -842,7 +842,7 @@ pub(crate) unsafe fn write_descriptor<Src: Buffer, Dst: Buffer<Beat = Src::Beat>
842842 descriptor : & mut DmacDescriptor ,
843843 source : & mut Src ,
844844 destination : & mut Dst ,
845- next : * mut DmacDescriptor ,
845+ next : Option < NonNull < DmacDescriptor > > ,
846846) {
847847 let src_ptr = source. dma_ptr ( ) ;
848848 let src_inc = source. incrementing ( ) ;
@@ -864,7 +864,7 @@ pub(crate) unsafe fn write_descriptor<Src: Buffer, Dst: Buffer<Beat = Src::Beat>
864864 . with_beatsize ( Src :: Beat :: BEATSIZE )
865865 . with_valid ( true ) ;
866866
867- // Seems like we need a fence before the buffer pointer escaped the current
867+ // Seems like we need a fence before the buffer pointer "escapes" the current
868868 // function. I don't claim to fully understand why, or what the gnarly LLVM
869869 // optimization details might be. But seems like the buffer pointers must be
870870 // written somewhere with a _volatile_ access, _after_ an (asm) compiler
@@ -875,7 +875,7 @@ pub(crate) unsafe fn write_descriptor<Src: Buffer, Dst: Buffer<Beat = Src::Beat>
875875 core:: ptr:: from_mut ( descriptor) . write_volatile ( DmacDescriptor {
876876 // Next descriptor address: 0x0 terminates the transaction (no linked list),
877877 // any other address points to the next block descriptor
878- descaddr : next,
878+ descaddr : next. map ( |n| n . as_ptr ( ) ) . unwrap_or ( core :: ptr :: null_mut ( ) ) ,
879879 // Source address: address of the last beat transfer source in block
880880 srcaddr : src_ptr as * mut _ ,
881881 // Destination address: address of the last beat transfer destination in block
0 commit comments