From 31abeda76053fea62e4a9c23b900536b629caaeb Mon Sep 17 00:00:00 2001 From: Jan Faeh Date: Wed, 3 Jun 2026 16:07:33 +0200 Subject: [PATCH 1/2] Renamed prefixes in conversions Renamade from old sensirion_common to sensirion_conversions --- drivers/sensor/sensirion/common/conversions.c | 6 +++--- drivers/sensor/sensirion/common/conversions.h | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/sensor/sensirion/common/conversions.c b/drivers/sensor/sensirion/common/conversions.c index b2799d93f14b7..44a5b2eb3048b 100644 --- a/drivers/sensor/sensirion/common/conversions.c +++ b/drivers/sensor/sensirion/common/conversions.c @@ -6,7 +6,7 @@ #include "conversions.h" -float sensirion_common_bytes_to_float(const uint8_t *bytes) +float sensirion_conversions_bytes_to_float(const uint8_t *bytes) { union { uint32_t u32_value; @@ -17,7 +17,7 @@ float sensirion_common_bytes_to_float(const uint8_t *bytes) return tmp.float32; } -void sensirion_common_float_to_bytes(const float value, uint8_t *bytes) +void sensirion_conversions_float_to_bytes(const float value, uint8_t *bytes) { union { uint32_t u32_value; @@ -27,7 +27,7 @@ void sensirion_common_float_to_bytes(const float value, uint8_t *bytes) sys_put_be32(tmp.u32_value, bytes); } -void sensirion_common_to_integer(const uint8_t *source, uint8_t *destination, INT_TYPE int_type, +void sensirion_conversions_to_integer(const uint8_t *source, uint8_t *destination, INT_TYPE int_type, uint8_t data_length) { if (data_length > int_type) { diff --git a/drivers/sensor/sensirion/common/conversions.h b/drivers/sensor/sensirion/common/conversions.h index a6a52297ee1c9..c9559dc155f08 100644 --- a/drivers/sensor/sensirion/common/conversions.h +++ b/drivers/sensor/sensirion/common/conversions.h @@ -29,11 +29,11 @@ extern "C" { * conversions from byte arrays to basic data types. * Since Zephyr does not provide a function for converting big-endian * (MSB-first) byte arrays to floating-point values, the function - * sensirion_common_bytes_to_float() is + * sensirion_conversions_bytes_to_float() is * provided for this purpose. * To maintain a consistent naming scheme for all functions that convert byte * arrays to basic types, the functions - * sensirion_common_bytes_to_() are also provided, + * sensirion_conversions_bytes_to_() are also provided, * even in cases where Zephyr already provides equivalent functions for * specific integer * types. @@ -49,14 +49,14 @@ extern "C" { * @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); +float sensirion_conversions_bytes_to_float(const uint8_t *bytes); -#define sensirion_common_bytes_to_int16_t(bytes) ((int16_t)sys_get_be16(bytes)) -#define sensirion_common_bytes_to_uint16_t(bytes) ((uint16_t)sys_get_be16(bytes)) -#define sensirion_common_bytes_to_int32_t(bytes) ((int32_t)sys_get_be32(bytes)) -#define sensirion_common_bytes_to_uint32_t(bytes) ((uint32_t)sys_get_be32(bytes)) -#define sensirion_common_bytes_to_int64_t(bytes) ((int64_t)sys_get_be64(bytes)) -#define sensirion_common_bytes_to_uint64_t(bytes) ((uint64_t)sys_get_be64(bytes)) +#define sensirion_conversions_bytes_to_int16_t(bytes) ((int16_t)sys_get_be16(bytes)) +#define sensirion_conversions_bytes_to_uint16_t(bytes) ((uint16_t)sys_get_be16(bytes)) +#define sensirion_conversions_bytes_to_int32_t(bytes) ((int32_t)sys_get_be32(bytes)) +#define sensirion_conversions_bytes_to_uint32_t(bytes) ((uint32_t)sys_get_be32(bytes)) +#define sensirion_conversions_bytes_to_int64_t(bytes) ((int64_t)sys_get_be64(bytes)) +#define sensirion_conversions_bytes_to_uint64_t(bytes) ((uint64_t)sys_get_be64(bytes)) /** @} */ @@ -77,7 +77,7 @@ float sensirion_common_bytes_to_float(const uint8_t *bytes); * @param destination_size Size of the destination integer in bytes. * @param data_length Number of available bytes in source to copy. */ -void sensirion_common_to_integer(const uint8_t *source, uint8_t *destination, +void sensirion_conversions_to_integer(const uint8_t *source, uint8_t *destination, size_t destination_size, uint8_t data_length); #ifdef __cplusplus From e29d8c428bf9b0efea3f29c2706f3f756fc358fc Mon Sep 17 00:00:00 2001 From: Jan Faeh Date: Thu, 4 Jun 2026 12:36:59 +0200 Subject: [PATCH 2/2] Finished i2c adapter layer --- drivers/sensor/sensirion/CMakeLists.txt | 1 + .../sensor/sensirion/common/CMakeLists.txt | 2 +- drivers/sensor/sensirion/common/conversions.c | 22 ++-- drivers/sensor/sensirion/common/conversions.h | 4 +- .../sensirion/common/i2c_general_call_reset.c | 9 ++ drivers/sensor/sensirion/common/i2c_packet.c | 124 ++++++++++-------- drivers/sensor/sensirion/common/i2c_packet.h | 70 +++++----- 7 files changed, 134 insertions(+), 98 deletions(-) diff --git a/drivers/sensor/sensirion/CMakeLists.txt b/drivers/sensor/sensirion/CMakeLists.txt index 8d131d626046e..577a930382afe 100644 --- a/drivers/sensor/sensirion/CMakeLists.txt +++ b/drivers/sensor/sensirion/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # zephyr-keep-sorted-start +add_subdirectory(common) add_subdirectory_ifdef(CONFIG_SCD4X scd4x) add_subdirectory_ifdef(CONFIG_SGP40 sgp40) add_subdirectory_ifdef(CONFIG_SHT3XD sht3xd) diff --git a/drivers/sensor/sensirion/common/CMakeLists.txt b/drivers/sensor/sensirion/common/CMakeLists.txt index 2566061a5b978..bab020db73de4 100644 --- a/drivers/sensor/sensirion/common/CMakeLists.txt +++ b/drivers/sensor/sensirion/common/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2025 Sensirion +# Copyright (c) 2026 Sensirion # # SPDX-License-Identifier: Apache-2.0 # diff --git a/drivers/sensor/sensirion/common/conversions.c b/drivers/sensor/sensirion/common/conversions.c index 44a5b2eb3048b..a8cb7c5c59c17 100644 --- a/drivers/sensor/sensirion/common/conversions.c +++ b/drivers/sensor/sensirion/common/conversions.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Sensirion + * Copyright (c) 2026 Sensirion * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,19 +27,21 @@ void sensirion_conversions_float_to_bytes(const float value, uint8_t *bytes) sys_put_be32(tmp.u32_value, bytes); } -void sensirion_conversions_to_integer(const uint8_t *source, uint8_t *destination, INT_TYPE int_type, - uint8_t data_length) +void sensirion_conversions_to_integer(const uint8_t *source, uint8_t *destination, + size_t destination_size, uint8_t data_length) { - if (data_length > int_type) { - data_length = int_type; + if (data_length > destination_size) { + data_length = destination_size; } - // set all bytes in destination to 0 to make sure that the value is correct even if the data_length is smaller than the size of the integer type + /* set all bytes in destination to 0 to make sure that the value is correct even if the + * data_length is smaller than the size of the integer type */ memset(destination, 0, data_length); - uint8_t offset = int_type - data_length; - // copy the bytes from source to destination. The source is in big-endian/MSB-first format, so the first byte of the source is the most significant byte. - // The destination should be filled in the correct order for the system endianness. + /* copy the bytes from source to destination. The source is in big-endian/MSB-first format, + * so the first byte of the source is the most significant byte. The destination should be + * filled in the correct order for the system endianness. + */ for (uint8_t i = 1; i <= data_length; i++) { - destination[int_type - offset - i] = source[i - 1]; + destination[data_length - i] = source[i - 1]; } } diff --git a/drivers/sensor/sensirion/common/conversions.h b/drivers/sensor/sensirion/common/conversions.h index c9559dc155f08..0d76b786e3ef0 100644 --- a/drivers/sensor/sensirion/common/conversions.h +++ b/drivers/sensor/sensirion/common/conversions.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Sensirion + * Copyright (c) 2026 Sensirion * * SPDX-License-Identifier: Apache-2.0 */ @@ -78,7 +78,7 @@ float sensirion_conversions_bytes_to_float(const uint8_t *bytes); * @param data_length Number of available bytes in source to copy. */ void sensirion_conversions_to_integer(const uint8_t *source, uint8_t *destination, - size_t destination_size, uint8_t data_length); + size_t destination_size, uint8_t data_length); #ifdef __cplusplus } diff --git a/drivers/sensor/sensirion/common/i2c_general_call_reset.c b/drivers/sensor/sensirion/common/i2c_general_call_reset.c index 477afd24b6240..9cb9c75333c66 100644 --- a/drivers/sensor/sensirion/common/i2c_general_call_reset.c +++ b/drivers/sensor/sensirion/common/i2c_general_call_reset.c @@ -1,3 +1,12 @@ +/* + * Copyright (c) 2026 Sensirion + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "i2c_general_call_reset.h" +#include + int sensirion_i2c_general_call_reset(const struct i2c_dt_spec *i2c_spec) { const uint8_t data = 0x06; diff --git a/drivers/sensor/sensirion/common/i2c_packet.c b/drivers/sensor/sensirion/common/i2c_packet.c index 50f7662a7bb0f..4d1f099c1fce1 100644 --- a/drivers/sensor/sensirion/common/i2c_packet.c +++ b/drivers/sensor/sensirion/common/i2c_packet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Sensirion + * Copyright (c) 2026 Sensirion * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,82 +10,82 @@ #include #include +#define SENSIRION_WORD_SIZE 2u +#define SENSIRION_CRC8_LEN 1u -#define SENSIRION_WORD_SIZE 2 -#define SENSIRION_CRC8_LEN 1 - - -uint8_t sensirion_i2c_packet_get_crc(const i2c_packet *packet, uint16_t index) +uint8_t sensirion_i2c_packet_get_crc(const i2c_packet_t *i2c_packet, uint16_t index) { - return crc8(&packet->data[index], SENSIRION_WORD_SIZE, - packet->crc8_poly, packet->crc8_init, false); + return crc8(&i2c_packet->data[index], SENSIRION_WORD_SIZE, i2c_packet->crc8_poly, + i2c_packet->crc8_init, false); } -bool sensirion_i2c_packet_check_crc(const i2c_packet *packet, uint16_t index) +bool sensirion_i2c_packet_check_crc(const i2c_packet_t *i2c_packet, uint16_t index) { - if (sensirion_i2c_packet_get_crc(packet, index) != packet->data[index + SENSIRION_WORD_SIZE]) { + if (sensirion_i2c_packet_get_crc(i2c_packet, index) != + i2c_packet->data[index + SENSIRION_WORD_SIZE]) { return false; } return true; } - - -uint16_t sensirion_i2c_packet_add_command16(i2c_packet *packet, uint16_t offset, uint16_t command) +uint16_t sensirion_i2c_packet_add_command16(i2c_packet_t *i2c_packet, uint16_t offset, + uint16_t command) { - sys_put_be16(command, &packet->data[offset]); + sys_put_be16(command, &i2c_packet->data[offset]); offset += 2; return offset; } -uint16_t sensirion_i2c_packet_add_command8(i2c_packet *packet, uint16_t offset, uint8_t command) +uint16_t sensirion_i2c_packet_add_command8(i2c_packet_t *i2c_packet, uint16_t offset, + uint8_t command) { - packet->data[offset++] = command; + i2c_packet->data[offset++] = command; return offset; } -uint16_t sensirion_i2c_packet_add_uint64_t(i2c_packet *packet, uint16_t offset, uint64_t data) +uint16_t sensirion_i2c_packet_add_uint64_t(i2c_packet_t *i2c_packet, uint16_t offset, uint64_t data) { - offset = sensirion_i2c_packet_add_uint32_t(packet, offset, data >> 32); - offset = sensirion_i2c_packet_add_uint32_t(packet, offset, data & 0xFFFFFFFF); + offset = sensirion_i2c_packet_add_uint32_t(i2c_packet, offset, data >> 32u); + offset = sensirion_i2c_packet_add_uint32_t(i2c_packet, offset, data & 0xFFFFFFFFu); return offset; } -uint16_t sensirion_i2c_packet_add_int64_t(i2c_packet *packet, uint16_t offset, int64_t data) +uint16_t sensirion_i2c_packet_add_int64_t(i2c_packet_t *i2c_packet, uint16_t offset, int64_t data) { - return sensirion_i2c_packet_add_uint64_t(packet, offset, (uint64_t)data); + return sensirion_i2c_packet_add_uint64_t(i2c_packet, offset, (uint64_t)data); } -uint16_t sensirion_i2c_packet_add_uint32_t(i2c_packet *packet, uint16_t offset, uint32_t data) +uint16_t sensirion_i2c_packet_add_uint32_t(i2c_packet_t *i2c_packet, uint16_t offset, uint32_t data) { - offset = sensirion_i2c_packet_add_uint16_t(packet, offset, data >> 16); - offset = sensirion_i2c_packet_add_uint16_t(packet, offset, data & 0xFFFF); + offset = sensirion_i2c_packet_add_uint16_t(i2c_packet, offset, data >> 16u); + offset = sensirion_i2c_packet_add_uint16_t(i2c_packet, offset, data & 0xFFFFu); return offset; } -uint16_t sensirion_i2c_packet_add_int32_t(i2c_packet *packet, uint16_t offset, int32_t data) +uint16_t sensirion_i2c_packet_add_int32_t(i2c_packet_t *i2c_packet, uint16_t offset, int32_t data) { - return sensirion_i2c_packet_add_uint32_t(packet, offset, (uint32_t)data); + return sensirion_i2c_packet_add_uint32_t(i2c_packet, offset, (uint32_t)data); } -uint16_t sensirion_i2c_packet_add_uint16_t(i2c_packet *packet, uint16_t offset, uint16_t data) +uint16_t sensirion_i2c_packet_add_uint16_t(i2c_packet_t *i2c_packet, uint16_t offset, uint16_t data) { - sys_put_be16(data, &packet->data[offset]); + sys_put_be16(data, &i2c_packet->data[offset]); offset += 2; - if (packet->crc8_poly != 0) { - packet->data[offset] = sensirion_i2c_packet_get_crc(packet, offset - SENSIRION_WORD_SIZE); + if (i2c_packet->crc8_poly != 0) { + i2c_packet->data[offset] = + sensirion_i2c_packet_get_crc(i2c_packet, offset - SENSIRION_WORD_SIZE); offset++; } return offset; } -uint16_t sensirion_i2c_packet_add_int16_t(i2c_packet *packet, uint16_t offset, int16_t data) +uint16_t sensirion_i2c_packet_add_int16_t(i2c_packet_t *i2c_packet, uint16_t offset, int16_t data) { - return sensirion_i2c_packet_add_uint16_t(packet, offset, (uint16_t)data); + return sensirion_i2c_packet_add_uint16_t(i2c_packet, offset, (uint16_t)data); } -uint16_t sensirion_i2c_packet_add_float(i2c_packet *packet, uint16_t offset, float data) +uint16_t sensirion_i2c_packet_add_float(i2c_packet_t *i2c_packet, uint16_t offset, float data) { union { uint32_t uint32_data; @@ -93,57 +93,77 @@ uint16_t sensirion_i2c_packet_add_float(i2c_packet *packet, uint16_t offset, flo } convert; convert.float_data = data; - return sensirion_i2c_packet_add_uint32_t(packet, offset, convert.uint32_data); + return sensirion_i2c_packet_add_uint32_t(i2c_packet, offset, convert.uint32_data); } -uint16_t sensirion_i2c_packet_add_bytes(i2c_packet *packet, uint16_t offset, const uint8_t *data, - uint16_t data_length) +uint16_t sensirion_i2c_packet_add_bytes(i2c_packet_t *i2c_packet, uint16_t offset, + const uint8_t *data, uint16_t data_length) { uint16_t i; - if (data_length % SENSIRION_WORD_SIZE != 0) { + if (data_length % SENSIRION_WORD_SIZE != 0u) { return -EINVAL; } - for (i = 0; i < data_length; i += 2) { - packet->data[offset++] = data[i]; - packet->data[offset++] = data[i + 1]; - if (packet->crc8_poly != 0) { - packet->data[offset] = sensirion_i2c_packet_get_crc(packet, offset - SENSIRION_WORD_SIZE); + for (i = 0; i < data_length; i += 2u) { + i2c_packet->data[offset++] = data[i]; + i2c_packet->data[offset++] = data[i + 1u]; + if (i2c_packet->crc8_poly != 0u) { + i2c_packet->data[offset] = sensirion_i2c_packet_get_crc( + i2c_packet, offset - SENSIRION_WORD_SIZE); offset++; } } return offset; } +int sensirion_i2c_packet_write(const struct i2c_dt_spec *i2c_spec, const i2c_packet_t *i2c_packet, + uint16_t data_length) +{ + uint8_t has_8bit_command = (float)(data_length / 2.0f) != 0.0f; + uint16_t num_words = (data_length + has_8bit_command) / SENSIRION_WORD_SIZE; + uint8_t tx_buffer[SENSIRION_WORD_SIZE * num_words + SENSIRION_CRC8_LEN * num_words]; + + /*skips the first word (command) because the command does not have a CRC*/ + for (uint16_t i = 1; i < num_words; i++) { + tx_buffer[i * (SENSIRION_WORD_SIZE + SENSIRION_CRC8_LEN)] = + i2c_packet->data[i * SENSIRION_WORD_SIZE]; + tx_buffer[i * (SENSIRION_WORD_SIZE + SENSIRION_CRC8_LEN) + 1] = + i2c_packet->data[i * SENSIRION_WORD_SIZE + 1]; + tx_buffer[i * (SENSIRION_WORD_SIZE + SENSIRION_CRC8_LEN) + 2] = + sensirion_i2c_packet_get_crc(i2c_packet, i * SENSIRION_WORD_SIZE); + } + + return i2c_write_dt(i2c_spec, tx_buffer, sizeof(tx_buffer)); +} -int sensirion_i2c_packet_read(const struct i2c_dt_spec *i2c_spec, i2c_packet *packet, - uint16_t expected_data_length) +int sensirion_i2c_packet_read(const struct i2c_dt_spec *i2c_spec, i2c_packet_t *i2c_packet, + uint16_t expected_data_length) { int ret; uint16_t i, j; - uint16_t crc_len = (packet->crc8_poly != 0) ? SENSIRION_CRC8_LEN : 0; - uint16_t size = (expected_data_length / SENSIRION_WORD_SIZE) * - (SENSIRION_WORD_SIZE + crc_len); + uint16_t crc_len = (i2c_packet->crc8_poly != 0) ? SENSIRION_CRC8_LEN : 0; + uint16_t size = + (expected_data_length / SENSIRION_WORD_SIZE) * (SENSIRION_WORD_SIZE + crc_len); if (expected_data_length % SENSIRION_WORD_SIZE != 0) { return -EINVAL; } - ret = i2c_read_dt(i2c_spec, packet->data, size); + ret = i2c_read_dt(i2c_spec, i2c_packet->data, size); if (ret != 0) { return ret; } for (i = 0, j = 0; i < size; i += SENSIRION_WORD_SIZE + crc_len) { - if (packet->crc8_poly != 0) { - if (!sensirion_i2c_packet_check_crc(packet, i)) { + if (i2c_packet->crc8_poly != 0) { + if (!sensirion_i2c_packet_check_crc(i2c_packet, i)) { return -EIO; } } - packet->data[j++] = packet->data[i]; - packet->data[j++] = packet->data[i + 1]; + i2c_packet->data[j++] = i2c_packet->data[i]; + i2c_packet->data[j++] = i2c_packet->data[i + 1]; } return 0; diff --git a/drivers/sensor/sensirion/common/i2c_packet.h b/drivers/sensor/sensirion/common/i2c_packet.h index ffab4440e9b2a..2cfd90420b4e6 100644 --- a/drivers/sensor/sensirion/common/i2c_packet.h +++ b/drivers/sensor/sensirion/common/i2c_packet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Sensirion + * Copyright (c) 2026 Sensirion * * SPDX-License-Identifier: Apache-2.0 */ @@ -36,30 +36,30 @@ typedef struct { /** Pointer to the data buffer */ uint8_t *data; //< Pointer to the data array. -} i2c_packet; +} i2c_packet_t; /** * @brief Calculate the CRC8 for a word in the i2c_packet at position . * - * @param packet Pointer to the i2c_packet containing the data for which the - * CRC8 will be calculated. - * @param index Index of the word in the data array for which the CRC8 will - * be calculated. + * @param i2c_packet Pointer to the i2c_packet containing the data for which the + * CRC8 will be calculated. + * @param index Index of the word in the data array for which the CRC8 will + * be calculated. * @return uint8_t Calculated CRC8 value. */ -uint8_t sensirion_i2c_packet_get_crc(const i2c_packet *packet, uint16_t index); +uint8_t sensirion_i2c_packet_get_crc(const i2c_packet_t *i2c_packet, uint16_t index); /** * @brief Check the CRC8 for a word in the i2c_packet at position . * - * @param packet Pointer to the i2c_packet containing the data for which the + * @param i2c_packet Pointer to the i2c_packet containing the data for which the * CRC8 will be checked. * @param index Index of the word in the data array for which the CRC8 will * be checked. * @return true If the CRC8 is valid. * @return false If the CRC8 is invalid. */ -bool sensirion_i2c_packet_check_crc(const i2c_packet *packet, uint16_t index); +bool sensirion_i2c_packet_check_crc(const i2c_packet_t *i2c_packet, uint16_t index); /** * Add a command to the i2c_packet at the specified offset. @@ -67,7 +67,7 @@ bool sensirion_i2c_packet_check_crc(const i2c_packet *packet, uint16_t index); * Most sensirion Sensors use 16 bit commands. This function adds a 2 bytes * to the i2c_packet. * - * @param packet Pointer to i2c_packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -75,7 +75,8 @@ bool sensirion_i2c_packet_check_crc(const i2c_packet *packet, uint16_t index); * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_command16(i2c_packet *packet, uint16_t offset, uint16_t command); +uint16_t sensirion_i2c_packet_add_command16(i2c_packet_t *i2c_packet, uint16_t offset, + uint16_t command); /** * Add a command to the i2c_packet at the specified offset. @@ -83,7 +84,7 @@ uint16_t sensirion_i2c_packet_add_command16(i2c_packet *packet, uint16_t offset, * Adds one byte command to the i2c_packet. * This is used for sensors that only take one command byte such as SHT. * - * @param packet Pointer to i2c_packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -91,14 +92,15 @@ uint16_t sensirion_i2c_packet_add_command16(i2c_packet *packet, uint16_t offset, * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_command8(i2c_packet *packet, uint16_t offset, uint8_t command); +uint16_t sensirion_i2c_packet_add_command8(i2c_packet_t *i2c_packet, uint16_t offset, + uint8_t command); /** * Add a uint64_t to the i2c_packet at the specified offset. * * Adds 12 bytes to the i2c_packet. * - * @param packet Pointer to i2c_packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -106,14 +108,15 @@ uint16_t sensirion_i2c_packet_add_command8(i2c_packet *packet, uint16_t offset, * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_uint64_t(i2c_packet *packet, uint16_t offset, uint64_t data); +uint16_t sensirion_i2c_packet_add_uint64_t(i2c_packet_t *i2c_packet, uint16_t offset, + uint64_t data); /** * Add a uint32_t to the i2c_packet at the specified offset. * * Adds 6 bytes to the i2c_packet. * - * @param packet Pointer to i2c_packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -121,14 +124,15 @@ uint16_t sensirion_i2c_packet_add_uint64_t(i2c_packet *packet, uint16_t offset, * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_uint32_t(i2c_packet *packet, uint16_t offset, uint32_t data); +uint16_t sensirion_i2c_packet_add_uint32_t(i2c_packet_t *i2c_packet, uint16_t offset, + uint32_t data); /** * Add a int32_t to the i2c_packet at the specified offset. * * Adds 6 bytes to the i2c_packet. * - * @param packet Pointer to packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -136,12 +140,12 @@ uint16_t sensirion_i2c_packet_add_uint32_t(i2c_packet *packet, uint16_t offset, * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_int32_t(i2c_packet *packet, uint16_t offset, int32_t data); +uint16_t sensirion_i2c_packet_add_int32_t(i2c_packet_t *i2c_packet, uint16_t offset, int32_t data); /** * Add a uint16_t to the i2c_packet at the specified offset. Adds 3 bytes to the i2c_packet. * - * @param packet Pointer to packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -149,12 +153,13 @@ uint16_t sensirion_i2c_packet_add_int32_t(i2c_packet *packet, uint16_t offset, i * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_uint16_t(i2c_packet *packet, uint16_t offset, uint16_t data); +uint16_t sensirion_i2c_packet_add_uint16_t(i2c_packet_t *i2c_packet, uint16_t offset, + uint16_t data); /** * Add a int16_t to the i2c_packet at the specified offset. Adds 3 bytes to the i2c_packet. * - * @param packet Pointer to packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -162,12 +167,12 @@ uint16_t sensirion_i2c_packet_add_uint16_t(i2c_packet *packet, uint16_t offset, * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_int16_t(i2c_packet *packet, uint16_t offset, int16_t data); +uint16_t sensirion_i2c_packet_add_int16_t(i2c_packet_t *i2c_packet, uint16_t offset, int16_t data); /** * Add a float to the i2c_packet at the specified offset. Adds 6 bytes to the i2c_packet. * - * @param packet Pointer to packet in which the write frame will be prepared. + * @param i2c_packet Pointer to i2c_packet in which the write frame will be prepared. * Caller needs to make sure that there is enough space after * offset left to write the data into the i2c_packet. * @param offset Offset of the next free byte in the i2c_packet. @@ -175,12 +180,12 @@ uint16_t sensirion_i2c_packet_add_int16_t(i2c_packet *packet, uint16_t offset, i * * @return Offset of next free byte in the i2c_packet after writing the data. */ -uint16_t sensirion_i2c_packet_add_float(i2c_packet *packet, uint16_t offset, float data); +uint16_t sensirion_i2c_packet_add_float(i2c_packet_t *i2c_packet, uint16_t offset, float data); /** * Add a byte array to the i2c_packet at the specified offset. * - * @param packet Pointer to i2c_packet in which the write frame will be + * @param i2c_packet Pointer to i2c_packet in which the write frame will be * prepared. Caller needs to make sure that there is * enough space after offset left to write the data * into the i2c_packet. @@ -193,21 +198,20 @@ uint16_t sensirion_i2c_packet_add_float(i2c_packet *packet, uint16_t offset, flo * @return Offset of next free byte in the i2c_packet after writing the * data. */ -uint16_t sensirion_i2c_packet_add_bytes(i2c_packet *packet, uint16_t offset, const uint8_t *data, - uint16_t data_length); +uint16_t sensirion_i2c_packet_add_bytes(i2c_packet_t *i2c_packet, uint16_t offset, + const uint8_t *data, uint16_t data_length); /** * Writes the i2c_packet to the Sensor. * - * * @param i2c_packet Pointer to the i2c_packet containing the data to write. * @param data_length Number of bytes to send to the Sensor. * @param i2c_spec Sensor I2C specification * * @return 0 on success, error code otherwise */ -int sensirion_i2c_packet_write(const i2c_packet const *packet, uint16_t data_length, - const struct i2c_dt_spec *i2c_spec); +int sensirion_i2c_packet_write(const struct i2c_dt_spec *i2c_spec, const i2c_packet_t *i2c_packet, + uint16_t data_length); /** * Reads data from the Sensor. @@ -223,8 +227,8 @@ int sensirion_i2c_packet_write(const i2c_packet const *packet, uint16_t data_len * * @return 0 on success, an error code otherwise */ -int sensirion_i2c_packet_read(const i2c_packet *i2c_packet, uint16_t expected_data_length, - const struct i2c_dt_spec *i2c_spec); +int sensirion_i2c_packet_read(const struct i2c_dt_spec *i2c_spec, const i2c_packet_t *i2c_packet, + uint16_t expected_data_length); #ifdef __cplusplus }