-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) 2025 Sensirion | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| zephyr_library() | ||
|
|
||
| zephyr_library_sources(sensirion_common.c) | ||
| zephyr_library_sources(sensirion_i2c.c) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright (c) 2025 Sensirion | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include "sensirion_common.h" | ||
|
|
||
| float sensirion_common_bytes_to_float(const uint8_t *bytes) | ||
| { | ||
| union { | ||
| uint32_t u32_value; | ||
| float float32; | ||
| } tmp; | ||
|
|
||
| tmp.u32_value = sys_get_be32(bytes); | ||
| return tmp.float32; | ||
| } | ||
|
|
||
| void sensirion_common_float_to_bytes(const float value, uint8_t *bytes) | ||
| { | ||
| union { | ||
| uint32_t u32_value; | ||
| float float32; | ||
| } tmp; | ||
| tmp.float32 = value; | ||
| sys_put_be32(tmp.u32_value, bytes); | ||
| } | ||
|
|
||
| void sensirion_common_to_integer(const uint8_t *source, uint8_t *destination, INT_TYPE int_type, | ||
| uint8_t data_length) | ||
| { | ||
| if (data_length > int_type) { | ||
| data_length = 0; | ||
| } | ||
|
|
||
| uint8_t offset = int_type - data_length; | ||
|
|
||
| for (uint8_t i = 0; i < offset; i++) { | ||
| destination[int_type - i - 1] = 0; | ||
| } | ||
|
|
||
| for (uint8_t i = 1; i <= data_length; i++) { | ||
| destination[int_type - offset - i] = source[i - 1]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright (c) 2025 Sensirion | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef SENSIRION_COMMON_H | ||
| #define SENSIRION_COMMON_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #include <stdint.h> | ||
| #include <zephyr/sys/byteorder.h> | ||
|
|
||
| #define NO_ERROR 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just use standard
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. A define is not required. Please use |
||
| #define NOT_IMPLEMENTED_ERROR ENOSYS | ||
|
|
||
| #define SENSIRION_COMMAND_SIZE 2 | ||
| #define SENSIRION_WORD_SIZE 2 | ||
| #define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE) | ||
| #define SENSIRION_MAX_BUFFER_WORDS 32 | ||
|
|
||
| #define sensirion_common_bytes_to_int16_t(src) ((int16_t)sys_get_be16((src))) | ||
jeppenodgaard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define sensirion_common_bytes_to_uint16_t(src) (sys_get_be16((src))) | ||
| #define sensirion_common_bytes_to_int32_t(src) ((int32_t)sys_get_be32((src))) | ||
| #define sensirion_common_bytes_to_uint32_t(src) (sys_get_be32((src))) | ||
|
|
||
| #define sensirion_common_uint32_t_to_bytes(val, dst) (sys_put_be32((val), (dst))) | ||
| #define sensirion_common_int32_t_to_bytes(val, dst) (sys_put_be32((uint32_t)(val), (dst))) | ||
| #define sensirion_common_uint16_t_to_bytes(val, dst) (sys_put_be16((val), (dst))) | ||
| #define sensirion_common_int16_t_to_bytes(val, dst) (sys_put_be16((uint16_t)(val), (dst))) | ||
| #define sensirion_common_copy_bytes(src, dst, len) (memcpy((dst), (src), (len))) | ||
|
|
||
| /** | ||
| * Enum to describe the type of an integer | ||
| */ | ||
| typedef enum { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this:
|
||
| BYTE = 1, | ||
| SHORT = 2, | ||
| INTEGER = 4, | ||
| LONG_INTEGER = 8 | ||
| } INT_TYPE; | ||
|
|
||
| /** | ||
| * Convert an array of bytes to a float | ||
| * | ||
| * Convert an array of bytes received from the sensor in big-endian/MSB-first | ||
| * format to an float value in the correct system-endianness. | ||
| * | ||
| * @param bytes An array of at least four bytes (MSB first) | ||
| * @return The byte array represented as float | ||
| */ | ||
| float sensirion_common_bytes_to_float(const uint8_t *bytes); | ||
|
|
||
| /** | ||
| * Convert an float to an array of bytes | ||
| * | ||
| * Convert an float value in system-endianness to big-endian/MBS-first | ||
| * format to send to the sensor. | ||
| * | ||
| * @param value Value to convert | ||
| * @param bytes An array of at least four bytes | ||
| */ | ||
| void sensirion_common_float_to_bytes(const float value, uint8_t *bytes); | ||
|
|
||
| /** | ||
| * Copy bytes from byte array to integer. | ||
| * | ||
| * @param source Array of bytes to be copied. | ||
| * @param int_value Pointer to integer of bytes to be copied to. | ||
| * @param int_type Type (size) of the integer to be copied. | ||
| * @param data_length Number of bytes to copy. | ||
| */ | ||
| void sensirion_common_to_integer(const uint8_t *source, uint8_t *destination, INT_TYPE int_type, | ||
| uint8_t data_length); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* SENSIRION_COMMON_H */ | ||
Uh oh!
There was an error while loading. Please reload this page.