-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add support for BME680 SPI Interface #38854
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
Conversation
2968cf7 to
14b344d
Compare
14b344d to
4d5750d
Compare
drivers/sensor/bme680/bme680.c
Outdated
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.
Should this be a condition of the device instance? i.e., would this work if you had a SPI instance and an I2C instance in your application?
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.
Good question. It probably won't work..
I could add a new member to the bme680_config (e.g. bus_type) and then check for that.
Do you think that would make sense?
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.
Why not fold this into the individual bus_io->read routines as needed instead?
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 is roughly what I ended up doing.
I made a separate function that does the mem page switching and I am also calling it from the bus_io->write routine.
teburd
left a comment
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.
As mentioned the compile ifdef for setting the mem page when using SPI seems an issue to me as well, everything else looks great
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
|
Sorry for shelving this for so long without notice. |
17783e0 to
8de7551
Compare
|
I've updated the PR and tested it with I2C and SPI instance enabled simultaneously. |
5eedfb4 to
a12865e
Compare
|
I split the pull request into 4 commits as suggested by @mbolivar-nordic. |
mbolivar-nordic
left a comment
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.
Thank you, that was indeed easier to review
drivers/sensor/bme680/bme680.c
Outdated
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.
Thanks for explaining. In that case I think it would be a little better to write it something like this:
static inline bool bme680_is_on_spi(struct device *dev)
{
const struct bme680_config *config = dev->config;
return config->bus_io == &bme680_bus_io_spi;
}
/* ... */
#if BME680_BUS_SPI
if (bme680_is_on_spi(dev)) {
err = ...;
if (err < 0) {
return err;
}
}
#endifIMO it is a bit better to have the I2C devices initialize the same way always, regardless of whether a SPI device happens to be in the same system. It may ease debugging in some cases and it definitely enhances consistency.
But it's not a blocking request; just please consider it.
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.
Thanks for taking another look at it and giving some more insight on that matter.
To have it consistent across all possible configurations wouldn't it make sense to
remove the #if BME680_BUS_SPI directive aswell?
I have prepared the change as suggested by you (without the #if). If that makes sense to you I can push them.
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.
That's a fair point -- if it's safe to do regardless of bus type, might as well be consistent on all of them. Given the ifdef, I was assuming there was a reason to prefer not to do it on I2C, but if there isn't, then I'm fine either way.
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.
Well, it was probably me just over-complicating things -.-;
I pushed the changes, this way it is definitely easier on the eyes.
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.
...disregard that.. the directives are needed or else it won't build for I2C, obviously..
Sorry for the noise.
7779014 to
a4606a4
Compare
|
@teburd would you take another look? |
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
|
I think this PR got lost in the shuffle while the merge window was closed for the 3.0 release. @leonardp will you please rebase and resolve the merge conflict? |
This fixes the constant for the mem page and replaces a magic number with the already defined `BME680_LEN_COEFF2` constant. Signed-off-by: Leonard Pollak <[email protected]>
Consolidate the initialization routines and change the include guard to conform with the coding guidelines as a preparation for the following commits which add support for the SPI interface. Signed-off-by: Leonard Pollak <[email protected]>
This enables the SPI interface for the BME680 sensor driver. Signed-off-by: Leonard Pollak <[email protected]>
Add BME680 (SPI) sensor driver to build_all tests. Signed-off-by: Leonard Pollak <[email protected]>
9548c78
|
@MaureenHelm @mbolivar-nordic I rebased this, please re-ack. |
|
I tested bme680 sample with SPI and I got the following error bme680: Bad BME680 chip id: 0x0. I used the following prj.conf settings I did some additional tests and I found out that if both bme 680 chips were connected to the board none of them was detected. If only one bme 680 chip is connected to the board, the address is figured out successfully. Based on this observation I assumed that something was wrong with the implementation details of the bme 680 library. I will appreciate for help! |
This Pull request adds support for the BME680 SPI Interface.
It is mostly analogous to the BME280.
Signed-off-by: Leonard Pollak [email protected]