Skip to content
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

Add ability to re-configure SPI. #42

Closed
davidlenfesty opened this issue Aug 9, 2020 · 2 comments · Fixed by #112
Closed

Add ability to re-configure SPI. #42

davidlenfesty opened this issue Aug 9, 2020 · 2 comments · Fixed by #112
Labels
good first issue Things that aren't too difficult to implement/fix and might be a great way to start contributing hal-api API design for the different components of avr-hal hal-generic Related to MCU generic parts of avr-hal help wanted Extra attention is needed

Comments

@davidlenfesty
Copy link

I'm trying to use SPI to read off an SD card, and part of the requirements of an SD card is that it needs to initialize at 100-400kHz, but then you can run it faster afterwards.

I'm using embedded-sdmmc, and it allows you to reconfigure the peripheral after initializing through a function. However as this HAL currently exists, there is no way to do that other than releasing the existing instance and creating a new one.

I have tested the following and it seems to work (haven't built the hardware to test yet):

impl $Spi {
    [...]
    /// Reconfigure SPI peripheral without releasing pins.
    pub fn reconfigure(&mut self, settings: Settings) {
        self.settings = settings;
        self.setup();
    }
    [...]
}
@Rahix Rahix added the hal-impl label Aug 9, 2020
@Rahix
Copy link
Owner

Rahix commented Aug 9, 2020

cc @jonahbron, what do you think?

@couchand
Copy link
Contributor

couchand commented Aug 14, 2020

Presumably you'd want to wait for any in-flight writes to complete, so perhaps the implementation would be:

pub fn reconfigure(&mut self, settings: Settings) -> nb::Result<(), Void> {
    self.flush()?;
    self.settings = settings;
    self.setup();
    Ok(())
}

@Rahix Rahix added the good first issue Things that aren't too difficult to implement/fix and might be a great way to start contributing label Sep 21, 2020
@Rahix Rahix added hal-api API design for the different components of avr-hal help wanted Extra attention is needed and removed hal-impl labels Oct 4, 2020
@Rahix Rahix added the hal-generic Related to MCU generic parts of avr-hal label Dec 3, 2020
@Rahix Rahix linked a pull request Dec 4, 2020 that will close this issue
@Rahix Rahix closed this as completed in #112 Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Things that aren't too difficult to implement/fix and might be a great way to start contributing hal-api API design for the different components of avr-hal hal-generic Related to MCU generic parts of avr-hal help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants