@@ -62,14 +62,17 @@ impl<USB: UsbPeripheral> EndpointBuffer<USB> {
6262 }
6363 }
6464
65+ /// # Safety
66+ ///
67+ /// Caller must ensure that while the returned reference exists, no mutable references to the section of EP memory covered by this slice exist.
6568 #[ inline( always) ]
66- fn get_mem_slice < T > ( & self ) -> & mut [ VolatileCell < T > ] {
67- unsafe { slice:: from_raw_parts_mut ( self . mem_ptr . cast ( ) , self . mem_len ) }
69+ unsafe fn get_mem_slice < T > ( & self ) -> & [ VolatileCell < T > ] {
70+ unsafe { slice:: from_raw_parts ( self . mem_ptr . cast ( ) , self . mem_len ) }
6871 }
6972
7073 pub fn read ( & self , mut buf : & mut [ u8 ] ) {
7174 if USB :: EP_MEMORY_ACCESS == MemoryAccess :: Word32x1 {
72- let mem = self . get_mem_slice :: < u32 > ( ) ;
75+ let mem = unsafe { self . get_mem_slice :: < u32 > ( ) } ;
7376
7477 let mut index = 0 ;
7578
@@ -86,7 +89,7 @@ impl<USB: UsbPeripheral> EndpointBuffer<USB> {
8689 buf. copy_from_slice ( & value[ 0 ..buf. len ( ) ] ) ;
8790 }
8891 } else {
89- let mem = self . get_mem_slice :: < u16 > ( ) ;
92+ let mem = unsafe { self . get_mem_slice :: < u16 > ( ) } ;
9093
9194 let mut index = 0 ;
9295
@@ -107,15 +110,15 @@ impl<USB: UsbPeripheral> EndpointBuffer<USB> {
107110
108111 pub fn write ( & self , mut buf : & [ u8 ] ) {
109112 if USB :: EP_MEMORY_ACCESS == MemoryAccess :: Word32x1 {
110- let mem = self . get_mem_slice :: < u32 > ( ) ;
113+ let mem = unsafe { self . get_mem_slice :: < u32 > ( ) } ;
111114
112115 let mut index = 0 ;
113116
114117 while buf. len ( ) >= 4 {
115118 let mut value = [ 0 ; 4 ] ;
116119 value. copy_from_slice ( & buf[ 0 ..4 ] ) ;
117120 buf = & buf[ 4 ..] ;
118-
121+
119122 mem[ index] . set ( u32:: from_ne_bytes ( value) ) ;
120123 index += USB :: EP_MEMORY_ACCESS . offset_multiplier ( ) ;
121124 }
@@ -126,7 +129,7 @@ impl<USB: UsbPeripheral> EndpointBuffer<USB> {
126129 mem[ index] . set ( u32:: from_ne_bytes ( value) ) ;
127130 }
128131 } else {
129- let mem = self . get_mem_slice :: < u16 > ( ) ;
132+ let mem = unsafe { self . get_mem_slice :: < u16 > ( ) } ;
130133
131134 let mut index = 0 ;
132135
0 commit comments