-
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
drivers/sht11: Major refactoring #9317
Conversation
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 refactoring this sensor @maribu ! It's already much better than before.
I think the shell commands could be kept and I have some comments to improve the module organisation (using pseudomodules) and also regarding the way the sensor is initialized/configured.
drivers/Makefile.dep
Outdated
@@ -302,7 +302,7 @@ ifneq (,$(filter servo,$(USEMODULE))) | |||
FEATURES_REQUIRED += periph_pwm | |||
endif | |||
|
|||
ifneq (,$(filter sht11,$(USEMODULE))) | |||
ifneq (,$(filter sht1x,$(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.
it's better to use pseudomodule for specific version of the sensor (sht10, sht11, sht15) and to load the generic module when the specific one is loaded.
You can declare the pseudomodules in RIOTBASE/makefiles/pseudomodules.inc.mk
(see sx1272, sx1276 as example) and here use the following makefile rule:
ifneq (,$(filter sht1%,$(USEMODULE)))
USEMODULE += sht1x
USEMODULE += xtimer
endif
your Makefile needs to contain these lines: | ||
|
||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk} | ||
USEMODULE += sht11 | ||
USEMODULE += sht1x |
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.
use the pseudomodule related to the concrete version of the sensor (sht10,11,15)
drivers/include/sht1x.h
Outdated
*/ | ||
|
||
/** | ||
* @defgroup drivers_sht1x SHT10/SHT1X/SHT15 Humidity and Temperature Sensors |
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 be SHT10/SHT11/SHT15
drivers/include/sht1x.h
Outdated
/** | ||
* @defgroup drivers_sht1x SHT10/SHT1X/SHT15 Humidity and Temperature Sensors | ||
* @ingroup drivers_sensors | ||
* @brief Driver for Sensirion SHT10/SHT1/SHT15 Humidity and 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.
typo on SHT11
drivers/include/sht1x.h
Outdated
* @file | ||
* @brief SHT1X Device Driver | ||
* | ||
* @author Freie Universität Berlin, Computer Systems & Telematics |
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 author is invalid, maybe it was already like this ?
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.
Yes, I could remove the author tag and keep them in the copyright declaration. The author tag does not provide additional information compared to the copyright declaration.
sys/auto_init/saul/auto_init_sht1x.c
Outdated
saul_entries[(i * 3) + 2].dev = &(sht1x_devs[i]); | ||
saul_entries[(i * 3) ].name = "SHT1X temperature"; | ||
saul_entries[(i * 3) + 1].name = "SHT1X humidity"; | ||
saul_entries[(i * 3) + 2].name = "SHT1X config (Low resolution | " |
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 think the calibration should be passed in the driver params.
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 was not actually calibrating the sensor - the calibration data is stored inside the sensor. But the sensor can be configured to not use them, which speeds up measurements about 10 ms. So this should be a runtime option, as this trade-off between speed and precision depends on the situation.
But the configuration was removed from SAUL anyway (as suggested), so that comment no longer applies.
@@ -8,9 +8,6 @@ endif | |||
ifneq (,$(filter ps,$(USEMODULE))) | |||
SRC += sc_ps.c | |||
endif | |||
ifneq (,$(filter sht11,$(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.
I would keep the shell commands
tests/driver_sht1x/Makefile
Outdated
BOARD ?= native | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += sht1x |
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.
Same comment about the version of sensor, better use the pseudomodule which will implicitly load the common concrete module.
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.
Sure the device specific pseudo modules should be used for unit tests that are not device specific? I would prefer to keep sht1x here, otherwise it is not obvious that is applies to all variants.
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.
Sure the device specific pseudo modules should be used for unit tests that are not device specific?
Ok, I initially missed that subtlety. If you want to test conversion functions in a unit test way then I would recommend that you add this in a real unittest under the unittests application.
The driver_sht1x
should be a helper application for testing real hardware. Instead of native, the default board could msba2 or msp430 since they embed one of this sensor. This application could either call the driver initialization, use a default configuration and then periodically read the sensor values or, just use the shell commands to give full control on the device.
tests/driver_sht1x/main.c
Outdated
continue; | ||
} | ||
int16_t got_hum = sht1x_humidity(&dev, raw_hum, temp); | ||
if ( |
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 file needs to be uncrustified
tests/driver_sht1x/main.c
Outdated
const char *res_temp[] = {"12", "14"}; | ||
const char *res_hum[] = {"8", "12"}; | ||
const char *voltages[] = {"5.0", "4.0", "3.5", "3.0", "2.5"}; | ||
sht1x_dev_t dev = {.conf = 0}; |
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 sht1x_init
with the default params ? This is the common usage for other sensors.
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.
Because this would require an actual sensor to be present, but the unit tests are intended to run on "native" without any hardware. The unit tests verify that the integer arithmetic still gives the same results as the floating point arithmetic given in the data sheet. Because these tests are computationally expensive, it makes no sense to run them on embedded hardware.
Also, using default parameters would dramatically decrease test coverage. The unit tests iterate over all possible configuration states in the for loops and verify that the calculations are correct for all of them - including the configuration that was chosen to be the default one.
8ba8ff3
to
7685085
Compare
@aabadie: Thanks for your review. Unless I have overlooked anything, I have addressed all issues you pointed out with the exception of the issues for the unit tests I commented on. Please review again and give feedback if the two points with the unit tests can remain as they are for the reasons I stated in the comments above, or whether I should address them somehow. Kind regards, |
Hmm, coccinelle wants me to cast implicitly from |
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 addressing the initial comments.
I found other small issues with typos and doxygen. See below.
I also have comments related to the unittests: if you want to test the conversion functions under different parameters and independently of the platform, I think it's better to create a new unittest under the unittests application.
The driver_sht1x application should be testable on real hardware.
The last big comment is about the way you split the auto_init from the saul registry initialization. I think the implementation files could be merged, using conditional macros.
Maybe I missed some subtlety, so forgive me it's the case.
@@ -302,7 +302,8 @@ ifneq (,$(filter servo,$(USEMODULE))) | |||
FEATURES_REQUIRED += periph_pwm | |||
endif | |||
|
|||
ifneq (,$(filter sht11,$(USEMODULE))) | |||
ifneq (,$(filter sht1%,$(USEMODULE))) | |||
USEMODULE += sht1x |
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 module also depends on periph_gpio
so you should also add here FEATURES_REQUIRED += periph_gpio
drivers/include/sht1x.h
Outdated
} sht1x_dev_t; | ||
|
||
/** | ||
* @brief Parameters requried to set up the SHT1X device driver |
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.
typo requried
drivers/include/sht1x.h
Outdated
* @brief Parameters requried to set up the SHT1X device driver | ||
*/ | ||
typedef struct { | ||
gpio_t clk; /**< GPIO conntected to the clock pin of the SHT1X */ |
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.
typo conntected
drivers/include/sht1x.h
Outdated
|
||
/** | ||
* @brief Calculate the temperature from the raw input | ||
* @note This internal funciton is exposed for unit tests |
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.
typo funciton
drivers/include/sht1x.h
Outdated
* | ||
* @param dev SHT1X sensor to read | ||
* @param temp Store the measured temperature in E-02 °C here | ||
* @param hum Store the measured relative humidit in E-02 % here |
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.
typo humidit
sys/auto_init/auto_init.c
Outdated
@@ -307,8 +304,8 @@ void auto_init(void) | |||
auto_init_lis3dh(); | |||
#endif | |||
#ifdef MODULE_LIS3MDL | |||
extern void auto_init_lis3mdl(void); | |||
auto_init_lis3mdl(); | |||
extern void auto_init_lis3mdl(void); |
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.
unrelated
tests/driver_sht1x/Makefile
Outdated
BOARD ?= native | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += sht1x |
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.
Sure the device specific pseudo modules should be used for unit tests that are not device specific?
Ok, I initially missed that subtlety. If you want to test conversion functions in a unit test way then I would recommend that you add this in a real unittest under the unittests application.
The driver_sht1x
should be a helper application for testing real hardware. Instead of native, the default board could msba2 or msp430 since they embed one of this sensor. This application could either call the driver initialization, use a default configuration and then periodically read the sensor values or, just use the shell commands to give full control on the device.
sys/shell/commands/sc_sht1x.c
Outdated
case 1: | ||
return &sht1x_devs[0]; | ||
case 2: | ||
if ((argv[1][0] >= '0') && (argv[1][0] <= '9') && (!argv[1][1])) { |
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.
Just use int dev_idx = atoi(argv[1]);
, easier to read.
const sht1x_dev_t *dev = get_dev(argc, argv); | ||
|
||
if (!dev) { | ||
return -1; |
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.
Maybe add an error message.
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 error message is printed by get_dev()
:-)
extern const saul_driver_t sht1x_saul_hum_driver; | ||
/** @} */ | ||
|
||
void auto_init_sht1x_saul(void) |
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.
No need for a saul specific function, you could add it to auto_init_sht1x
but guard it with an #ifdef
if the saul module is loaded. If you do this, auto_init_sht1x_saul.c
can be removed. And the auto_init_sht1x.c
could be with the other saul devices auto init files.
166d36b
to
22485ee
Compare
@aabadie: Thanks for the review and for pointing me to the unit tests app. This is much better now :-) |
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.
SAUL integration and unittests looks good now. Thanks!
Please address the remaining minor comments (doxygen, typos). It would also be nice to have a test application in tests/driver_sht1x
: it could a simple application that load the auto_init
, sht1x
and shell_commands
and start a shell. This way one can play on real hardware using shell commands. What do you think ?
drivers/include/sht1x.h
Outdated
* | ||
* @param dev Device from which the raw value was received | ||
* @param raw The raw (unprocessed) temperature value | ||
* @param temp The temperate at which the humidity was measure in E-02 °C |
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.
typo 'temperature'
sys/auto_init/auto_init.c
Outdated
#ifdef MODULE_SHT11 | ||
#include "sht11.h" | ||
#ifdef MODULE_SHT1X | ||
void auto_init_sht1x(void); |
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.
No need to declare this function here. Just use extern
before the call to the function.
sys/auto_init/auto_init.c
Outdated
#ifdef MODULE_SHT11 | ||
DEBUG("Auto init SHT11 module.\n"); | ||
sht11_init(); | ||
#ifdef MODULE_SHT1X |
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 would move this just before the #ifdef MODULE_AUTO_INIT_SAUL
.
82446a1
to
d2289b7
Compare
Unless I have overlooked anything, I have address all open issues and also added an on-device test for the driver. This test will read both temperature and humidity value three times for each configuration and then drop to the shell for manual testing. I added the MSBA2 as default board, because I tested on that. Please note that the driver does only work on the MSBA2 after the gpio driver bugs addressed by this PR are fixed. |
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 updating again @maribu. It's getting closer.
Found another typo in the new test application.
By the way, some of my previous comments are not addressed.
tests/driver_sht1x/main.c
Outdated
@@ -0,0 +1,172 @@ | |||
/* | |||
* Copyright (C) 2018 2018 Otto-von-Guericke-Universität Magdeburg |
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.
2018 appears twice
In case you wonder why I put thumbs up on every comment: I in fact missed some and would like to tick them with a check mark. As there is no check mark, the thumbs up is what comes nearest to it. So it is just for me to check that I actually applied every comment |
Done :-) |
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 like. I wanted to ACK but found 2 minor things remaining. See below.
makefiles/pseudomodules.inc.mk
Outdated
@@ -105,6 +106,10 @@ PSEUDOMODULES += si7013 | |||
PSEUDOMODULES += si7020 | |||
PSEUDOMODULES += si7021 | |||
|
|||
# include variants of SX127X drivers as pseudo modules |
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.
Ok, I understand. This block should be moved to its original place (before the si1145 pseudo modules). Normally only changes related to sht11/10/15 should appear.
/** @} */ | ||
|
||
/** | ||
* @name Commands that can be send to the SHT1X driver |
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.
s/send/sent/
Just triggered Murdock, maybe some other things will raise. |
Done. I believe I still have to add some boards to BOARD_INSUFFICIENT_MEMORY for the test, but lets wait for Murdock to complete |
Murdock is still failing, I think you have to remove the |
The default pin configuration is invalid on telosb, wsn430-v1_3b, wsn430-v1_4 and z1. How should I handle that? |
I just changed the way the SAUL info texts are added. The new way is a bit more clever and matches the strategy other drivers use |
No idea, this is related to 16bit platform but the error is weird. Maybe @cladmi has an idea ? |
Hi,
typedef uint16_t gpio_t;
[...]
#define GPIO_PIN(x, y) ((gpio_t)(((x & 0xff) << 8) | (1 << (y & 0xff)))) so for #define GPIO_PIN(x, y) ((gpio_t)(((x & 0xff) << 8) | (1 << (y & 0x0f)))) would make the result valid again. But maybe it is desired that the compilation fails for invalid pin specifications? PS: I'm checking that right now with a dummy commit added on top of the PR. So please don't merge until I remove that again. |
The sensor family SHT10, SHT11 and SHT15 only differ in their accuracy (as in calibration, not as in resolution). Thus, the same driver can be used for all. The new driver name better reflects this fact.
- Use RIOT's GPIO interface to access the sensor to increase portability - Changed API to allow more than one sensor per board - Added `sht1x_params.h` that specifies how the sensors is connected - each board can overwrite default settings by #defining SHT1X_PARAM_CLK and SHT1X_PARAM_DATA - Changed arithmetic to use integer calculations only instead of floating point arithmetic - Added support for checking the CRC sum - Allow optional skipping of the CRC check to speed up measuring - Added support for advanced features like reducing the resolution and skipping calibration to speed up measuring - Allow specifying the supply voltage of sensor which heavily influences the temperature result (and use that information to calculate the correct temperature) - Reset sensor on initialization to bring it in a well known state - Support for the obscure heater feature. (Can be useful to check the temperature sensor?) - Updated old SHT11 shell commands to the new driver interface, thus allowing more than one SHT10/11/15 sensor to be used - Added new shell command to allow full configuration of all attached SHT1x sensors - Removed old command for setting the SHT11 temperature offset, as this feature is implemented in the new configuration command
- Added unit tests for new integer only arithmetic - Temperature conversion differs at most 0.01°C from double arithmetic - Humidity conversions differs at most 0.1% from double arithmetic
@aabadie: I just rebased the PR against current master (and removed the testing commit). The issue with compilation on msp430fxyz boards is now fixed :-) |
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.
Looks good now.
Untested-ACK
sht1x_params.h
that specifies how the sensors is connected - each board can overwrite default settings by #defining SHT1X_PARAM_CLK and SHT1X_PARAM_DATAHint: Before testing on the MSBA2 or other lpc2387 based boards, please apply this PR containing various bugfixes for the gpio driver.