-
Notifications
You must be signed in to change notification settings - Fork 8.4k
drivers: sensor: STCC4 Add Driver #98434
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
base: main
Are you sure you want to change the base?
Conversation
2c0be47 to
729e16d
Compare
|
@MaureenHelm Have you had a chance to take a look at this pull request? |
2a70286 to
f40a06c
Compare
216099a to
a7b6ea6
Compare
|
Can someone please have a look? |
|
Hi @jfaeh . |
8a0ed58 to
452ba30
Compare
|
@jeppenodgaard Tests are now successfull |
jeppenodgaard
left a comment
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 you for this PR!
I did not do a full review as it seems like usage of any zephyr helper functions absent.
I think a lot of code can be removed and some be more concise by becoming familiar and using zephyr functions.
|
|
||
| #include <stdint.h> | ||
|
|
||
| #define NO_ERROR 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 just use standard errnos?
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.
Isn't 0 the errno for no error?
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.
A define is not required. Please use errno directly without wrapping them in another define.
|
Related: |
|
Hi @jeppenodgaard |
This adds support for Sensirion's STCC4 co2 sensor. Signed-off-by: Jan Faeh <[email protected]>
|
|
Hi @jeppenodgaard I wanted to ask if you have already had a chance to look at my changes. |
jeppenodgaard
left a comment
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.
After reading the issue I think I understand what is desired:
A driver that is OS agnostic. I do not think sensiron_core does or can do that.
I was not part of #71374 but I think it could be used as a guideline. See #71374 (review).
Again I did not do a full review - I think we need another input, maybe from @teburd ?
| return local_error; | ||
| } | ||
| *product_id = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]); | ||
| sensirion_common_to_integer(&buffer_ptr[4], (uint8_t *)serial_number, LONG_INTEGER, 8); |
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 prefer memcpy, since it is faster, should use less memory and is a non-custom function.
| sensirion_common_to_integer(&buffer_ptr[4], (uint8_t *)serial_number, LONG_INTEGER, 8); | |
| memcpy(serial_number, &buffer_ptr[4], 8); |
|
|
||
| #include <stdint.h> | ||
|
|
||
| #define NO_ERROR 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.
A define is not required. Please use errno directly without wrapping them in another define.
|
|
||
| #define SENSIRION_COMMAND_SIZE 2 | ||
| #define SENSIRION_WORD_SIZE 2 | ||
| #define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE) |
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.
Not used
| * @param count: Number of bytes in the data buffer (excluding checksum). | ||
| * @param checksum: The expected CRC checksum byte received from the sensor. | ||
| * | ||
| * @return 0 if the checksum is valid, a negative error code otherwise. |
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.
Consider using boolean instead:
https://www.kernel.org/doc/html/latest/process/coding-style.html#function-return-values-and-names
If it can return multiple types of errors it should return type int and return an errno.
| /** | ||
| * Enum to describe the type of an integer | ||
| */ | ||
| typedef enum { |
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.
Remove this:
- An integer is not always 4 bytes
- Names might clash with other defines since they are very generic.
- Seems like only
LONG_INTEGERis used.
|
Hello @jeppenodgaard Thank you again for your review, and sorry that I didn’t explain our goal more clearly. Our intention is to make the standard drivers of Sensirion available on Zephyr. These standard drivers are automatically generated by a code generator. We generate these drivers for various other platforms, like, e.g., Raspberry Pi. The drivers are published on GitHub. Since this generated code depends on the interface of the adapter layer, we cannot change this interface. This would break the generated driver. Furthermore, we also cannot narrow the interface, as further drivers with other features will not work. What you see in the PR is one driver instance that may not access all functions and features of the adapter layer. While we can easily change the implementation of the adapter layer, we cannot easily change the interface of the adapter layer. That's also why we initially proposed to provide the adapter layer as a module. |
|
Thank you for the thorough explanation. The goal makes a lot of sense and it must be possible to achieve somehow. Some thoughts:
Please await another review before continuing - and sorry for the delays. |



This adds support for Sensirion's STCC4 co2 sensor.
In addition to the driver, we would like to add a driver core that handles basic functions relevant to Sensirion sensors. With the help of this core, we will be able to add and unify many new drivers quickly and easily in the near future.