Skip to content

Conversation

MichelRottleuthner
Copy link
Contributor

@MichelRottleuthner MichelRottleuthner commented Jan 31, 2020

Contribution description

This PR provides a sensor driver for the Sensirion SPS30 particulate matter sensor.
I added the WIP label for now because I'm still planning to add SAUL support and improve the test application a bit. [edit:] done
For now I only implemented I2C support but the sensor could also be used via UART.
Any opinions on whether I should add that too? If yes, how (i.e. runtime vs. compiletime selection) ?

Testing procedure

Check the documentation of sps30.h to see if it is sufficient to get it running and run the test application under tests/driver_sps30.
[edit:]
SAUL adaption is now included so the generic saul example can also be used for testing:
USEMODULE="sps30" BOARD=<your_board_name> make -C examples/saul all flash term

[edit 2:]
Keep in mind that the I2C bus must be running in standard mode speed. You might need to change that in your boards periph_conf.h

Issues/PRs references

Might be a good candidate for discussing about drivers with support for multiple interfaces (i.e. #13208).

@MichelRottleuthner MichelRottleuthner added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers labels Jan 31, 2020
* @brief SPS30 device parameters
*/
typedef struct {
i2c_t i2c_dev; /**< I2C dev the sensor is connected to */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the above this could later be changed to union to allow for I2C and UART support.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow

@MichelRottleuthner
Copy link
Contributor Author

Since the WIP label is still set I allowed myself to squash and rebase directly..

@MichelRottleuthner MichelRottleuthner added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Feb 7, 2020
@MichelRottleuthner
Copy link
Contributor Author

@smlng want to give it another look?

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some more comments, and suggestions. No serious blockers though.

@smlng
Copy link
Member

smlng commented Feb 15, 2020

finally got it working - after changing cables twice, the device seems to be very sensible 😦 However, driver test and saul test are working as expected.

Please fix CI erros and squash afterwards. Then I'll make a final review round.

@MichelRottleuthner
Copy link
Contributor Author

@smlng thanks for testing! Can you explain what exactly was sensible and which board you used? Was it that the sensor required stronger pull-ups, didn't work with long wires, or something like that?

@smlng
Copy link
Member

smlng commented Feb 17, 2020

For testing I used a bluepill board, and yes I think the wires were too long and/or didn't make good connection - not sure I first tried a "nice" wiring on a bread board with these u-shaped jumper bridges/wires (?), these didn't work.

Finally I used short (10cm) jumper wires, I also used the pull-ups you provided, which worked.

@MichelRottleuthner MichelRottleuthner force-pushed the pr_sps30 branch 2 times, most recently from ac6be65 to 80bd08f Compare February 18, 2020 12:34
@MichelRottleuthner
Copy link
Contributor Author

fixed CI errors and some typos reported by travis and directly squashed to avoid repeated CI builds. Travis also complains about the line containing the datasheet link being to long but there seems to be no nice way to break the url and keep the link working...

Comment on lines 25 to 28
#define TEST_START_DELAY_US (2 * US_PER_SEC)
#define SENSOR_RESET_DELAY_US (10 * US_PER_SEC)
#define SENSOR_STARTUP_DELAY_US (10 * US_PER_SEC)
#define POLL_FOR_READY_US (1000000U)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you could go for seconds and use xtimer_sleep instead of xtimer_usleep?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the latter should be 1 * US_PER_SEC otherwise?

@smlng
Copy link
Member

smlng commented Feb 18, 2020

mhm, maybe we need to adjust the vera++ settings @jia200x

  • 100 chars per line to error seems a bit harsh, maybe try 120
  • what about links in markdown?

@MichelRottleuthner
Copy link
Contributor Author

what about links in markdown?

tried that, nothing seems to be working. I took the lazy way out using an url shortener.

@smlng
Copy link
Member

smlng commented Feb 18, 2020

I took the lazy way out using an url shortener.

lets hope that one is stable enough in the long run 🤞

@MichelRottleuthner
Copy link
Contributor Author

yeah my first thought was also against that but practically there is no difference between the URL shortener quitting service and the manufacturer breaking the links. Actually I encountered the latter more often :P ...and we need to update the link anyway then. Maybe a custom url shortener under riot-os.org would be a nice thing for stuff like that 🤔

@@ -148,41 +148,76 @@ enum {
* and the SAUL intra-category ID (six least significant bits).
*/
enum {
SAUL_ACT_ANY = SAUL_CAT_ACT | SAUL_ACT_ID_ANY, /**< any actuator - wildcard */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we really want to change it this way, maybe its better to relax vera++ settings to allow 120 chars per line before error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah damn coding conventions are strict for 100 char tops, and I don't want to start a lengthy discussion (now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we leave it as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah for now, maybe we should discuss the 100 char line limit in our coding conventions and argue for 120. IIRC Python has 120 max, bc 80 is nice to have but often a bit to strict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just compiled the doc, still looks good - so let's go for it, regardless of the 100 - 120 chars discussion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing I don't like about this change is that now there are two different styles of documentation for enums in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but I still favor same-line-comments if possible.

@smlng
Copy link
Member

smlng commented Feb 18, 2020

Maybe a custom url shortener under riot-os.org would be a nice thing for stuff like that

yep thought the same

*
* @return #SPS30_OK on success, negative #sps30_error_code_t on error
*/
int sps30_start_fan_clean(const sps30_t *dev);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit picky: there is no sps30_stop_fan_clean 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep because that is not a feature documented by the manufacturer. It could be possible to implement that via the reset command (not tested) but then this is a very unlikely thing to be needed. The clean will be done after a fixed time of 10 seconds anyway. And what kind of firmware would first trigger the clean and then decide it is better to stop it now?^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure, was just bike-shedding 😄

If any I would change this to: sps30_clean_fan or even a simple sps30_clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I leave it as is. I actually chose the name like that because directly maps to how the command is named in the datasheet.

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are good here 😄

@smlng smlng added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Feb 20, 2020
@benpicco benpicco merged commit aa00191 into RIOT-OS:master Feb 21, 2020
@leandrolanzieri leandrolanzieri added this to the Release 2020.04 milestone Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants