-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a generic Transport
trait to support multiple SD card protocols
#170
base: develop
Are you sure you want to change the base?
Introduce a generic Transport
trait to support multiple SD card protocols
#170
Conversation
Signed-off-by: Zhouqi Jiang <[email protected]>
…rapper around an implementation of `Transport` Signed-off-by: Zhouqi Jiang <[email protected]>
…tions` Signed-off-by: Zhouqi Jiang <[email protected]>
Signed-off-by: Zhouqi Jiang <[email protected]>
This looks really interesting - thank you for the PR! Did you have a specific SD Host Controller you wanted to implement |
Currently most of the user-facing types inside |
Reading through this, I think a bunch of the implementation detail in the
For example, I believe this method would be exactly the same regardless of which SD Card transport was used: /// Read the 'card specific data' block.
fn read_csd(&mut self) -> Result<Csd, Error> {
match self.card_type {
Some(CardType::SD1) => {
let mut csd = CsdV1::new();
if self.card_command(CMD9, 0)? != 0 {
return Err(Error::RegisterReadError);
}
self.read_data(&mut csd.data)?;
Ok(Csd::V1(csd))
}
Some(CardType::SD2 | CardType::SDHC) => {
let mut csd = CsdV2::new();
if self.card_command(CMD9, 0)? != 0 {
return Err(Error::RegisterReadError);
}
self.read_data(&mut csd.data)?;
Ok(Csd::V2(csd))
}
None => Err(Error::CardNotFound),
}
} But, I'd probably want to implement the |
I pushed a few comment fixes to better track where things now are. |
@thejpster: Thanks for your feedback! I'm currently working on the following:
Several community members are also interested in adding SD protocol support for chips like STM32, ESP32, and others.
Yes, I'd love to!
I like the idea of reusing code from the SPI implementation. However, before proceeding, we should carefully review the SD card specification. There are notable differences between the SD and SPI protocols, such as variations in command reply types and initialization processes. In fact, I attempted to provide a command-level abstraction in this branch. However, I found that while it decouples SPI and SD protocols to some extent, it also makes it harder to create a unified abstraction for both. Further exploration of the full SD Host Controller Specification might be necessary, especially for implementing the
Thank you! |
@thejpster: If we're unsure which functions to include in this trait, could we mark the entire trait as experimental or unstable for now? We can stabilize it later once we've finalized the functions to retain in |
Are you planning on making Transport implementations outside this crate? I guess we could merge an experimental trait. I see that embassy-stm32 has a working SD Host Controller driver. I looked at it briefly but I might dig into it a more. The Pico SDK also has an experimental driver that uses a custom PIO program. |
@thejpster: Yes, I am planning to implement |
Is a git dependency pointing at this branch sufficient? |
I’d suggest merging it into the upstream instead. While it would still require a Git dependency until a new version is published, merging into upstream ensures the changes are more visible and accessible to the community, encouraging broader testing and feedback. This can help refine the |
OK. How do you want to mark the trait as 'unstable' then? |
@thejpster: Can we introduce an
This approach would allow experimental features to be gated while keeping the stable API intact. |
Sounds OK to me. I guess the examples will tell us if we broke the API by doing this. |
Currently, the
embedded-sdmmc
library only supports SPI-based SD card access. However, certain MCUs and SoC chips feature dedicated SD protocol peripherals that can provide faster and more efficient access. This PR abstracts various SD card protocols into a newTransport
trait, enabling future extensions and custom transports by third-party libraries.This pull request includes:
SdCard
to hold a mutable reference to aTransport
implementor, renames constructors tonew_spi
andnew_spi_with_options
(breaking) to clarify SPI usage.These changes pave the way for supporting more advanced SD interfaces in hardware, improving performance and enabling community-driven protocol expansions.
r? @thejpster