I am working on a 769 bit shift register that receives data using Spi. Multiple IC’s are chained together so that you now have a n * 769 bit register. I am trying to send data using Spi DMA. One of the problem I am facing is that since the register length is not a multiple of 8, the data here (RGB 3 * 8bit) needs to either packed together or I need to split the dma transfers such that I write 768 bits using
(DMA for 768 bits + convert Spi pins to IO + toggle bit) * Number of IC’s.

You can’t pass ownership of a part of an array (that’s because ownership is tied to where allocations and deallocations are inserted into the code, and it’s the same problem as trying to split one malloc() into multiple blocks that are free()d).

You could use Option.take() to pass ownership of the whole object and pass a range separately. Or if dma() doesn’t absolutely require ownership, then keep it using slices. You can use &buffer[…] and split_at_mut() to get multiple slices out of a single array.

&'static mut [u8] means you’re borrowing the slice for the life of the program, which is unlikely what you want. Instead, you’re really looking for something like &'a mut &'static mut [u8], which is a temporary borrow of a mutable slice that lives forever, roughly:

The a binding has a lifetime itself now, and you could treat it like a value - borrow it mutably for some shorter scope, and prevent multiple borrows at the same time.

However, you have native code that’s async and ultimately you’ll need to use unsafe code anyway. Maybe you could build a future-like API that you could use to gate access to subsequent dma calls. Or build some mutex-like abstraction that blocks the caller until in-flight dma completes. Just throwing out random ideas