File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,24 @@ where
4141 type Error = Error ;
4242
4343 fn transfer < ' w > ( & mut self , words : & ' w mut [ u8 ] ) -> Result < & ' w [ u8 ] , Error > {
44- // If the slice isn't in RAM, we can't write back to it at all
45- slice_in_ram_or ( words, Error :: DMABufferNotInDataMemory ) ?;
46-
47- words. chunks ( EASY_DMA_SIZE ) . try_for_each ( |chunk| {
48- self . do_spi_dma_transfer ( DmaSlice :: from_slice ( chunk) , DmaSlice :: from_slice ( chunk) )
49- } ) ?;
50-
44+ if slice_in_ram ( words) {
45+ words. chunks ( EASY_DMA_SIZE ) . try_for_each ( |chunk| {
46+ self . do_spi_dma_transfer ( DmaSlice :: from_slice ( chunk) , DmaSlice :: from_slice ( chunk) )
47+ } ) ?;
48+ } else {
49+ words
50+ . chunks_mut ( FORCE_COPY_BUFFER_SIZE )
51+ . try_for_each ( |chunk| {
52+ let mut buf = [ 0u8 ; FORCE_COPY_BUFFER_SIZE ] ;
53+ buf[ ..chunk. len ( ) ] . copy_from_slice ( chunk) ;
54+ self . do_spi_dma_transfer (
55+ DmaSlice :: from_slice ( & buf[ ..chunk. len ( ) ] ) ,
56+ DmaSlice :: from_slice ( & buf[ ..chunk. len ( ) ] ) ,
57+ ) ?;
58+ chunk. copy_from_slice ( & buf[ ..chunk. len ( ) ] ) ;
59+ Ok ( ( ) )
60+ } ) ?;
61+ }
5162 Ok ( words)
5263 }
5364}
You can’t perform that action at this time.
0 commit comments