-
Notifications
You must be signed in to change notification settings - Fork 2k
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
driver/bme680: add I2C/SPI driver for BME680 device #12717
Conversation
I will review and test it tomorrow. |
A comment on the naming of the package. If the number of packages imported in this way increases, it might be better to order them by category for readability. If not in separate directories then at least by starting the name with the category as we already do for test applications. Therefore, I would suggest to call the package What do you think about it? |
I am not against and I'll apply this change unless someone is opposed to such naming scheme.
Agreed, but let's wait for some time if new drivers/pkgs appears in the future. I think I dedicated name with a category is better than a subfolder which will increase build complexity. |
#endif /* BME680_SPI_MODE */ | ||
|
||
#ifndef BME680_NSS_PIN | ||
#define BME680_NSS_PIN GPIO_PIN(PA, 5) |
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.
Please use a platform independent port identifier here to ensure that it is is compilable on all platforms.
#define BME680_NSS_PIN GPIO_PIN(PA, 5) | |
#define BME680_NSS_PIN GPIO_PIN(0, 5) |
tests/driver_bme680/main.c
Outdated
ret = bme680_get_sensor_data(&data, &(dev.dev)); | ||
if(!ret) { | ||
#ifndef BME680_FLOAT_POINT_COMPENSATION | ||
printf("[bme680]: T %d degC, P %ld hPa, H %ld ", data.temperature, |
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.
Please use platform independent format defines here:
printf("[bme680]: T %d degC, P %ld hPa, H %ld ", data.temperature, | |
printf("[bme680]: T %" PRIi16 " degC, P %" PRIu32 " hPa, H %" PRIu32, data.temperature, |
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.
Fixed, I also enforce display formatting. Tell me if it's wrong.
Tested with I2C and it works as expected 👍 |
Many moons ago I did a implementation for Contiki IMO the Bosch lib was to bloated so I just rewrote from user manual code examples to keep the code compact, readable and with few dependencies. But I don't the implementation is very tested. |
Also I bit disappointing to see there still no mapping between the resistance and the indoor Air Quality. Bosch is to blame. |
@MrKevinWeiss is this a poster child for SPI HIL testing? |
I don't know if this is a good candidate as this is a driver. If there are problems with the CPU implementations of the SPI than the HiL could assist with debugging. |
@herjulf I did exactly the same two years ago for ESP-IDF which could be easily ported to RIOT and probably would have done it already 😉 This PR is the result of the review of PR #9909 which provided a driver that based on the vendor code but had only required parts of the code. At that time, we decided to try to use the original vendor driver as a package, see also #10502. If code size is your concern, it may be interesting to know what code size PR #9909 and what code size this PR has. |
@gschorcht . Thanks for this history and background and seems like we have similar experiences with drivers w/o Bosch API. Code size is of course interesting but my concerns is more about control and avoiding dependencies for long time maintainability. Anyway current work is now based on the Bosch library. |
@gschorcht I pushed a couple of changes, especially the interface selection in the bme680_params.h file. Would you mind have another look please ? |
pkg/bme680_driver/README.md
Outdated
In addition, this driver can use floating point if available on your MCU. By default, this package do not use it. | ||
|
||
## Usage | ||
Add `USEPKG += bme680_driver` in your Makefile and `#include "bme680_hal.h"` to your code. Refer to the code documentation for more information on the API. |
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.
Please remove USEPKG += bme680_driver
from documentation. It isn't necessary to add it to the application's makefile.
Even more, if you move
#include "bme680_hal.h"
#include "bme680_defs.h"
to bme680.h
, the application has not to include them. Then it is enough to include bme680.h
and bme680_params.h
by the application. This makes the usage easier.
Add `USEPKG += bme680_driver` in your Makefile and `#include "bme680_hal.h"` to your code. Refer to the code documentation for more information on the API. | |
Refer to the code documentation for more information on the API. |
What about this suggested change? I just want to have a naming that allows us to sort the large amount of different package types a bit. As the number of driver packages increases, they could all be called |
Thanks for testing. Sounds good. |
We should get it merged in near future, there is already a conflict with master again 😟 May I rebase and squash? |
Yes, please do so. Will give the code a final review. Testing should be complete at this point. Thanks @janschlicht |
I still wrap my head around this. Is it safe to just switch from ohm to kilo ohm? Can there be a double meaning of a value? |
Hm, there is no other chance. Since the |
Add the vendor driver implementation from Bosch Sensortech as a package.
Oh I see now. So you still know if you read the value, if it is in ohms or kilo ohms, you just have to look at the scale then. Nevermind my comment then :) |
Add the support for BME680 based on the BME680 vendor driver package.
d367276
to
a1e2f36
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.
@janschlicht and I tested some more cases. I2C, SPI, SPI + I2C and two I2C devices -> works like expected!
ACK from my side.
Wow that's nice ! |
Yes! Even though adding the second set of I2C Parameters wasn't too easy. But I don't see a neat way of changing it. I suggest leaving the driver as is for now, until (when/if) this becomes an issue! |
@gschorcht I think some of your requested changes prevent merge? |
@MichelRottleuthner @gschorcht @PeterKietzmann We can merge?! |
@roberthartung yes sure go ahead! |
Awesome ! Thanks for merging @roberthartung |
Thank you all for contributing, reviewing, testing and for merging. The merge of this PR is an important milestone, as it is a good example of how a vendor driver can be used package. There are other PRs that do this in the same way, for example #10363. With our Arduino compatibility layer in |
data->val[0] = _gas[dev_index]; | ||
data->scale = 0; | ||
} | ||
data->unit = UNIT_OHM; |
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.
Ohm?
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.
Yep, the gas measurement is returned as the resistance of the gas sensitive layer. What ever it means. Unfortunately, the datasheet gives no explanation or hints on how the value has to be interpreted 😟
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.
They just recommend to use the BSEC to get IAQ.
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.
I have the import of the BSEC as package on my ToDo list.
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.
@boschsensortec: Care to help out here? Could you give a formula how to convert that value into something useful?
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.
The biggest chalange will be that each user of the BSCE has to accept the license before it is downloadable.
Contribution description
This PR provides support for BME680 sensor using the vendor driver from Bosch Sensortech as package.
The sensor provides measurement for temperature, humidity, pressure and VOC gas concentration. It can be connected either via I2C or via SPI. The driver supports multiple BME680 sensor and mixed I2C/SPI configurations.
The driver supports SAUL.
Testing procedure
Apply the parameters you want in the
bme680_params.h
file runtests/driver_bme680
with one I2C device
with one SPI device
or with one I2C and one SPI device
SAUL can be tested with
tests/saul
. The used interface(s) has/have to be defined withUSEMODULE
, for exampleIssues/PRs references
Replaces #10502