drivers/lpsxxx: refactor lps331ap and add support for lps25hb + lps22hb#10695
drivers/lpsxxx: refactor lps331ap and add support for lps25hb + lps22hb#10695aabadie merged 7 commits intoRIOT-OS:masterfrom
Conversation
MrKevinWeiss
left a comment
There was a problem hiding this comment.
Looks pretty good. Maybe take a look at the comments and I can start the testing once you have made the decision how to handle them (either ignore or implement). I would also like to wait for @smlng or someone else to take a look at but that can come after testing.
| float res = TEMP_BASE; /* reference value -> see datasheet */ | ||
|
|
||
| i2c_acquire(DEV_I2C); | ||
| if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPSXXX_REG_TEMP_OUT_L, &tmp, 0) < 0) { |
There was a problem hiding this comment.
Less lines if you read 16 bits and only swap if big endian?
There was a problem hiding this comment.
I was done this way initially. Reading multiple bytes in one go requires extra play with BDU bit in CTRL_REG1 register. Otherwise it doesn't work with lps25h/lps22h.
There was a problem hiding this comment.
Hmmm I see the point...
I am now curious if there is either a problem with an update that could occur after reading the lsb or if updates just don't work if only reading temperature since
1. To guarantee the correct behavior of BDU feature, PRESS_OUT_H (2Ah) must be the last address read.
There was a problem hiding this comment.
@MrKevinWeiss, I have just tested it and there's no problem on both lps25hb and lps22hb.
There was a problem hiding this comment.
even if I don't read the pressure measure at all.
There was a problem hiding this comment.
Hmm OK, then do we worry about the MSB updating after the LSB read?
There was a problem hiding this comment.
Or can we assume the BDU takes care of that? If so I suppose I am happy and can start testing with iotlabs
There was a problem hiding this comment.
can we assume the BDU takes care of that?
I would say so.
|
|
||
| i2c_acquire(DEV_I2C); | ||
|
|
||
| if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPSXXX_REG_PRESS_OUT_XL, &tmp, 0) < 0) { |
There was a problem hiding this comment.
Same as above but with 3 bytes.
| lpsxxx_enable(&dev); | ||
| xtimer_sleep(1); /* wait a bit for the measurements to complete */ | ||
|
|
||
| lpsxxx_read_temp(&dev, &temp); |
There was a problem hiding this comment.
Maybe it would be interesting to read/print several temperatures in a row to see if a change occurs then read the pressures. This can expose the update problem I am thinking of.
There was a problem hiding this comment.
Good idea, I'll try this.
|
@MrKevinWeiss, still interested in testing this ? |
|
Yup, starting soon! |
|
Wow, it seems like it is pretty hot in saclay 😆 |
It may look a bit weird indeed ! |
|
So no beach sand and sun glasses? |
Unfortunately no... 😎 |
|
Testing is good, ran all the tests described above as well as manually reading multiple temperatures with saul to ensure the temperature gets updated without having to read pressure. I would like to wait for @smlng before continuing. I will ACK the testing side though. |
|
@MrKevinWeiss, I don't think the |
|
I second that. |
|
"Impact: major" should always be read like: might require more than one reviewer (i.e. also at least two ACKs) to be merged. |
|
I was told any API change should be major, I agree though that this doesn't seem like a major change. |
ef522ec to
794a5e1
Compare
done ! |
| * @brief The sensors default output data rate (ODR) | ||
| */ | ||
| #if MODULE_LPS331AP || MODULE_LPS25HB | ||
| #define LPSXXX_DEFAULT_RATE (LPSXXX_RATE_7HZ) |
There was a problem hiding this comment.
why not simply use LPSXXX_RATE_1HZ as default for all?
|
looks good in general, untested ACK. |
794a5e1 to
a4fa24a
Compare
|
I fixed the small issue in the test README that was reported by codacy. And directly squashed. Now the green merge button is very tempting ;) |
| * @brief Read a temperature value from the given sensor, returned in m°C | ||
| * | ||
| * @param[in] dev device descriptor of sensor to read from | ||
| * @param[out] temp temperature value in c°C |
| res += ((float)val) / TEMP_DIVIDER; | ||
|
|
||
| /* return temperature in c°C */ | ||
| *temp = (int16_t)(res * 100); |
There was a problem hiding this comment.
I think you can get rid of the float conversion & division:
(TEMP_BASE + (val / TEMP_DIVIDER)) * 100 == (TEMP_BASE * 100) + (val * 100 / TEMP_DIVIDER)
So this should be equivalent:
#define TEMP_BASE=4250U;
#define TEMP_DIVIDER=480U;
uint32_t res = TEMP_BASE;
uint32_t val = 0;
// ...
res += (val * 100) / TEMP_DIVIDER;
*temp = (int16_t)res;
(maybe use signed int).
There was a problem hiding this comment.
I tried but that doesn't work on lps331ap/lps25hb.
a4fa24a to
51d3f00
Compare
51d3f00 to
db6463d
Compare
The default address is the same one
db6463d to
a218bc6
Compare
|
Any chance to get this merged ? It's all green for quite some time now. |
|
I give Murdock another spin, if it still holds green, I'd hit it. |
|
Thanks @smlng :) |
|
It's all green @smlng |
Contribution description
This PR is a rework of the initial ST lps331ap atmospheric pressure and temperature sensor. It does several things:
0x44to0x5D(why was it0x44initially, I don't know). The default address depends on the SDO/SA0 pad: when connected to ground it is0x5D, when connected to power supply, it is0x5C. On STx-nucleo-iks01a2(lps22hb) andx-nucleo-iks01a1(lps25hb) extensions, the pad is connected to ground, thus using0x5Dby default, makes more sense (to me)For simplicity, only basic polling mode with continuous measurements is provided by the driver. It should be possible to implement the other modes: One shot, Interrupt (with data ready) or FIFO in an extend version. Maybe a good candidate for a follow-up ? (Note that it might become a bit messy because of
#ifdefs).Testing procedure
This PR can be fully tested using the IoT-LAB testbed, because some boards provides the 3 types of sensors:
tests/driver_lpsxxxtest application on the different nodes and verify that it works:examples/defaultwith the right driver module loaded (not needed on iotlab-m3 and b-l475e-iot01a as lps331ap and lps22hb are automatically provided):Issues/PRs references
closes #7267 (quite an old one, isn't it?), tick an item of #7585