embedded-sdmmc-rs icon indicating copy to clipboard operation
embedded-sdmmc-rs copied to clipboard

SdMmcSpi::acquire should consume self, not use &mut ref

Open ceigel opened this issue 3 years ago • 2 comments

Currently SdMmcSpi::acquire returns a BlockSpi object which contains a mutable reference to the SdMmcSpi. This is a construct that is very hard to work with. I'm reading parts of a file inside an interrupt, so I have to keep alive both a SdMmcSpi and a BlockSpi. Moreover the SdMmcSpi has to be placed in a static variable so that it is not moved once the BlockSpi is constructed. This is quite hard to use. I believe it would be easier if the SdMmcSpi would be moved inside BlockSpi.

ceigel avatar Jun 17 '22 08:06 ceigel

Honestly, reading from a filesystem in an interrupt sounds like a nightmare. Personally I would set a flag and deal with that in the main loop. But aside from that, dealing with ownership transfer is not necessarily easier than handling mutable references - it just changes things.

Freel free to propose a PR to change how it works, or you could fork the library to better suit your needs.

thejpster avatar Jul 06 '22 10:07 thejpster

This would make it hard to re-acquire the BlockDeviceSPI in case of some error. I've wrapped the BlockDeviceSpi in a handle which makes it a bit easier to work with: https://github.com/gauteh/sfy/blob/main/sfy-buoy/src/storage/mod.rs#L204, depends on #63 .

gauteh avatar Oct 01 '22 16:10 gauteh

Closed by #80

thejpster avatar May 06 '23 20:05 thejpster