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

detect if SPI bus has been initialized (IDFGH-7142) #8745

Open
morganrallen opened this issue Apr 7, 2022 · 9 comments
Open

detect if SPI bus has been initialized (IDFGH-7142) #8745

morganrallen opened this issue Apr 7, 2022 · 9 comments
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF

Comments

@morganrallen
Copy link

This is a followup on #8642
If a method was provided to detect if the bus was already initialized a decision could be made on calling spi_bus_free before reinitializing. In my situation I have a driver that supports multiple devices that all might not be initialized at the same time. I need a way to see if the bus need initializing (for the first device) or not (for the rest of them).

Describe the solution you'd like
Some function call like bool spi_bus_initialized(spi_host_device_t host_id, spi_bus_config_t *bus_config) or spi_bus_is_initialized for better clarity.

@morganrallen morganrallen added the Type: Feature Request Feature request for IDF label Apr 7, 2022
@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 7, 2022
@github-actions github-actions bot changed the title detect if SPI bus has been initialized detect if SPI bus has been initialized (IDFGH-7142) Apr 7, 2022
@KaeLL
Copy link
Contributor

KaeLL commented Apr 7, 2022

I think that's a trivial change, and there may even be an argument for creating an esp_err_t define specifically for denoting that something's already been initialized.
Question, though: are you trying to have each peripheral's driver do all SPI initialization completely independent from one another?

@rtborg
Copy link

rtborg commented Apr 19, 2022

I'd also appreciate such functionality - for the reason above, each peripheral driver does SPI initialization independent from the others.

@abobija
Copy link

abobija commented Aug 25, 2022

Bump 👀

@MassimilianoMontagni
Copy link

+1

@morganrallen
Copy link
Author

As a workaround I've settled on this method....

  if(spi_bus_get_attr(spi_host) == NULL) {
    err = spi_bus_initialize(spi_host, &buscfg, 2);
  }

It seems to work consistently, but would still be very helpful to have a method that we know will continue to work in the future.

@MassimilianoMontagni
Copy link

MassimilianoMontagni commented Oct 18, 2022

I'm using idf v 4.4.2 and I don't find any spi_bus_get_attr do I have to import some header or it is no longer available?

@morganrallen
Copy link
Author

Also using ~4.4.2, you'll need to include driver/spi_common_internal.h

@MassimilianoMontagni
Copy link

Thanks a lot @morganrallen but I still have the issue reported here

@abobija
Copy link

abobija commented Oct 12, 2023

Is this resolved? Is there a way to check if SPI is initialized or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

6 participants