-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
sensors: BME280: obtain device pointers directly #30536
sensors: BME280: obtain device pointers directly #30536
Conversation
516bff1
to
51365a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, pending actually trying it which I'll do soon. Hopefully other drivers won't require so much prep.
51365a3
to
d9c121e
Compare
d9c121e
to
52d5183
Compare
That's sweet! |
52d5183
to
a446deb
Compare
Rebased and addressed review feedback. I suppose this could be merged for Zephyr 2.5, but I'm not in a rush. |
a446deb
to
ba974f3
Compare
Adjust the documentation and devicetree overlays so the sample can be built for any board with an Arduino I2C and SPI pinout, defaulting I2C and SPI to y to make it easier to switch between the two without requiring a pristine build. The user has to choose an appropriate overlay or have a sensor built in to the board. Use the newly introduced DEVICE_DT_GET_ANY() in main.c to ask for a bosch,bme280 without worrying over the details or exposing DT_DRV_COMPAT-based functionality that is really meant for drivers. Remove the no-longer-needed board specific overlay for nRF52840 DK; this is covered by the generic Arduino overlays now. Fix the datasheet link while we're here. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
4f3ddfe
to
bb98ba9
Compare
Missed this comment in my above reply. Yes, this is the crux of the issue. I've rebased and pushed a version with these macros ifdef'ed out on C++. No other changes. |
@avisconti please review, you may want to do this in the ST sensor drivers |
@MaureenHelm he is waiting for it to go in before updating one of his PRs actually; see: #31775 (comment) |
@mbolivar-nordic Thanks for the reminder. I'd seen that comment earlier, but forgot about it. |
Yes, sorry for not reviewing it. I was busy with other stuff as well |
This commit simplifies the Device Tree configuration by using the new helpers introduced in zephyrproject-rtos#30536. In particular: - get bus devices with DEVICE_DT_GET - get SPI information with SPI_CONFIG_DT_INST Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit simplifies the Device Tree configuration by using the new helpers introduced in #30536. In particular: - get bus devices with DEVICE_DT_GET - get SPI information with SPI_CONFIG_DT_INST Signed-off-by: Armando Visconti <armando.visconti@st.com>
Make this driver multi-instance and use the new API. This commit makes use of the new helpers introduced in zephyrproject-rtos#30536. In particular: - get bus devices with DEVICE_DT_GET - get SPI information with SPI_CONFIG_DT_INST - get drdy gpios with GPIO_DT_SPEC_GET Signed-off-by: Armando Visconti <armando.visconti@st.com>
Make this driver multi-instance and use the new API. This commit makes use of the new helpers introduced in zephyrproject-rtos#30536. In particular: - get bus devices with DEVICE_DT_GET - get SPI information with SPI_CONFIG_DT_INST - get drdy gpios with GPIO_DT_SPEC_GET Signed-off-by: Armando Visconti <armando.visconti@st.com>
Make this driver multi-instance and use the new API. This commit makes use of the new helpers introduced in #30536. In particular: - get bus devices with DEVICE_DT_GET - get SPI information with SPI_CONFIG_DT_INST - get drdy gpios with GPIO_DT_SPEC_GET Signed-off-by: Armando Visconti <armando.visconti@st.com>
The main point of this pull request is to show the advantage of declaring device structures using the DEVICE_DT_DEFINE() and DEVICE_DT_DEFINE_INST() macros introduced in e643ee26a71and 3a83f0e.
I'm using the BME280 sensor driver as a proof of concept. We used the same driver as a testing ground for the new DT API when that was introduced in zephyr v2.3.
Avoid calling
device_get_binding()
at boot time to grab the device. Instead, the BME280 driver can just useDEVICE_DT_GET()
anddevice_is_ready()
to make sure the relevant SPI, I2C, and GPIO devices it may depend on are available instead. This saves RAM by moving astruct device*
and astruct spi_cs_control
from the driver data to its config structure since all the devices are known at build time, and avoids error-prone boilerplate by reusing common macros from drivers/spi.h.A secondary goal of this PR is to add more helper macros to the SPI API for initializing SPI device configuration data from devicetree nodes. This eliminates boilerplate in the BME280 driver in a way that could be reused elsewhere.
Update the sample likewise to use DEVICE_DT_GET to get the BME280 device instead of calling device_get_binding(). I re-worked the sample a bit as well so that it works on any board that has Arduino SPI and I2C pins while we're here, in hopes that makes this PR easier for others to try out.