Skip to content

Add new adapter layer#2

Open
jfaeh wants to merge 2 commits into
sensirion-commonfrom
LKD-901-implement-adapter-layer
Open

Add new adapter layer#2
jfaeh wants to merge 2 commits into
sensirion-commonfrom
LKD-901-implement-adapter-layer

Conversation

@jfaeh
Copy link
Copy Markdown

@jfaeh jfaeh commented Jun 3, 2026

This Pull Request adds an adapter layer and updates the sts4x sensor driver for the new adapter layer.

Renamade from old sensirion_common to sensirion_conversions
@jfaeh jfaeh changed the title Renamed prefixes in conversions Add new adapter layer Jun 3, 2026

// 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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we have to consider the byte order of the host. In case the host has the same byte order (BE) this code is wrong.
I'm aware that his is also the case for the code we have in sensirion_common :-(

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];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how about of doing a memcpy?

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*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if we consistently use the i2c_packet_add_ there is no need to add a crc again. I also think the i2c_packet* should be the first arguement and the i2c_spec the last one!

}
packet->data[j++] = packet->data[i];
packet->data[j++] = packet->data[i + 1];
i2c_packet->data[j++] = i2c_packet->data[i];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also here we may use a memcpy

* @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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in fact we may use a const i2c_packet_t* const

* @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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in fact we may use a const i2c_packet_t* const

*/
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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do you think it is better to have the first argument the i2c_spec?

*/
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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do you think it is better to have the first argument the i2c_spec?

* @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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could also be const uint8_t const*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants