-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/bmx280: reworked driver and added SPI mode #8383
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
e9c73e4
to
1f06485
Compare
rebased and fixed initialization and init_master order for the i2c mode (according to #8446). |
1f06485
to
f75590e
Compare
rebased. Anyone willing to review? |
drivers/Makefile.dep
Outdated
@@ -47,14 +47,27 @@ ifneq (,$(filter bmp180,$(USEMODULE))) | |||
USEMODULE += xtimer | |||
endif | |||
|
|||
ifneq (,$(filter bmx055,$(USEMODULE))) | |||
FEATURES_REQUIRED += periph_i2c | |||
ifneq (,$(filter bme280_spi,$(USEMODULE))) |
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 use the wildcard %
and merge this one with the block under ? I think the wildcard could also be used in the block below that handles the distinction between spi and i2c.
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 this block and the one below include different base modules (bme vs bmp).
But for the last block of this module I could actually use wildcards, will give this a try.
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.
Simplified the dependencies a little bit, better now?
drivers/bmx280/bmx280.c
Outdated
|
||
#ifdef MODULE_BME280 | ||
/* ctrl_hum must be written before ctrl_meas for changes to become | ||
* effective ... */ |
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 3 dots are superfluous IMHO
tests/driver_bmx280/main.c
Outdated
|
||
#define MAINLOOP_DELAY (2 * 1000 * 1000u) /* 2 seconds delay between printf's */ | ||
#define MAINLOOP_DELAY (2 * US_PER_SEC) /* read sensor every 2 seconds */ |
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.
We could just use xtimer_sleep(2) below and drop this line I think
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 already added some comments but looking more in depth, I find it difficult to make the distinction between what is related to new spi feature and what is pure refactoring.
So I would recommend splitting this PR in 2: a first one only containing the refactoring and a second one with the new SPI feature.
Otherwise, I would also recommend avoiding comments like this: While adding this mode, I found the driver was in a very bad state
. It's very subjective and initial authors/contributors/reviewers may not appreciate that.
Maybe @dylad is interested by this. |
Sorry for the subjective grading, there was a high level of frustration involved when working on this driver so I got in a bad mood... I know that splitting this PR would make a lot of sense from a reviewing perspective, but unfortunately this is not so easy. Adding the new SPI feature and reworking the driver's structure is highly correlated, so that splitting the changes would probably take another 1-2 days on top, which is not feasible for me to do. Do you guys think we could get this in somehow in the current state? |
f75590e
to
d98c63b
Compare
addressed the so far open comments. |
Yes, on my side. But we need to wait for the I2C embargo first. |
awesome, thanks! Then lets get back to this PR once the I2C stuff is merged. |
It is! |
Will try to find the time and rebase this during the next days, stay tuned :-) (and sorry for the delay!) |
|
@haukepetersen are you aware of #12772? |
bugs fixed: - move global variables into device descriptor - guard bus access (use acquire and release) added functionality: - enable SPI mode structural improvements: - reduce stack usage - simplify the driver's structure - centralize bus access code - use assertions - cleanup includes - use shortcuts for bus access style changes: - fix line length - cleanup and improve doxygen - unify pointer notation (char *var over char* var) - unify (error) return messages - use `#ifdef MODULE_BME280` instead of `#if defined(BME..)` - unify debug messages -> using `[bmx28] x: msg` scheme
functional changes: - enable test to test the driver in SPI mode style changes and code simplification: - enable SPI mode - fixed typos in doxygen - fixed line length issues - simplified code - use fmt for formatting numbers - use US_PER_SEC instead of magic value - use named return values provided by driver - use puts where ever applicable
fe8f7bb
to
5e51030
Compare
@herjulf thanks! I took the freedom to squash again... |
Yea but I thought when you are editing the file anyway it would be trivial to add those lines. Or maybe just have a general But that could also be done in a separate PR. |
But then I get in trouble for not keeping authorship for selected contributions :-) |
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 don't want this to go in without a proper discussion about the architecture of the driver. I'll add reasons later.
Are you serious? Please open a separate issue, you are always welcome to rework this driver, but please lets get it merged for now! |
@haukepetersen: Out of all people working on RIOT, you're the single person that really just should not complain if a PR is blocked last minute. |
I also think that an iterative approach is sensible here. |
Its not about the last minute, its about the reasoning. The architecture of this driver as proposed in this PR is in line with the driver design as of now. I think we can all agree, that this PR makes the situation better than it was before the PR, so it does not hurt. Also it does not introduce anything architecturally weird that breaks with design practices, so again, IMO no blocker there. Now starting a more generic discussion on how to design drivers in general is something we can always have, but please in a generic context! |
#if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C) | ||
/* ctrl_hum must be written before ctrl_meas for changes to become | ||
* effective */ | ||
reg = dev->params.humid_oversample; | ||
if (_write_reg(dev, BME280_CTRL_HUM_REG, reg) != BMX280_OK) { | ||
goto err; | ||
} | ||
#endif |
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.
It is not even possible to have a BMP280 and a BME280 using the same interface.
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.
Nope, it is not. BUT
a) it is an extremely rare use case to have both connected concurrently
b) you might just use the bme280
driver config with both devices as a workaround
c) the convention in RIOT we always used to follow is not to over complicate things for the last 1% of exotic use cases
d) this has nothing to do with the content of this PR
+1. @benpicco #12772 is a distinct change and should be seperate, if it eases reviewing. This PR's review is basically done, so adding changes will certainly not ease reviewing. Actually, at this point it is against procedures. Also, the other change is from a different author and came months after this PR. Let's not force re-opening this PR on @haukepetersen, integrate #12772 mentally, ... @maribu IIRC this PR doesn't change the driver's architecture by much, but improves the current implementation. The architecture discussion should be kept seperate. |
It was a deliberate design choice to implement bus support as different driver modes. And this design choice is what I challenge.
It is not really my intent to start a discussion, but rather enforce general design goals already agreed upon. Citing RIOT's driver guide:
The wording of the sentence is not super clear, but to me this clearly means that a driver should not prevent a user from using multiple devices of the same kind even though attached to different buses. Also there is a broad consensus on the use if Not properly factoring out yields to such cases. This is clearly not the worst, e.g. when looking at the https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx.c#L51-58 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx.c#L63-L71 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx.c#L76-L87 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx.c#L127-L136 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx_getset.c#L232-L240 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx_internal.c#L147-L154 https://github.com/RIOT-OS/RIOT/blob/master/drivers/at86rf2xx/at86rf2xx_netdev.c#L218-L226 Someone starts to go the lazy route to just hack in "flavors" of the driver using |
Agreed. And maybe it makes sense to migrate the driver guideline to github, so this is more visible and content changes in there are properly reviewed. |
The architecture can be fixed in a separte PR
It happens that I know that paragraph quite well :-) In general the state of the But don't get me wrong, I am not against discussing and adapting the design guide lines and best practices in driver design for RIOT - after all circumstances change, we all gain experience, and hence we assess decisions differently now. I think we should just keep those generic discussions should not per default block everything in its path... |
Issues/PRs references
For supporting the
ruuvitag
it is needed to interface thebmx280
sensor in SPI mode. While adding this mode, I found the driver was in a very bad state. This PR adds the possibility to use the driver in SPI mode and it significantly improves the drivers structure and style:bugs fixed (I wonder how these were able to go by previous reviews...):
added functionality:
structural improvements:
style changes:
#ifdef MODULE_BME280
instead of#if defined(BME..)
[bmx28] x: msg
schemeThis PR also adapts and improves the test application accordingly and also add the
bme280_spi
module as default SAUL module to theruuvitag
.Note on commits: as it was impossible to cleanly split the rework and cleanup efforts from the SPI mode addition to the driver, I put all changes into a single commit...
Testing:
The changes are tested and verified for the
bmx280_spi
andbmp280_spi
on theruuvitag
. I don't have access to any board having these sensors connected via I2C, so the I2C mode still needs to be tested.