Add new adapter layer#2
Conversation
Renamade from old sensirion_common to sensirion_conversions
|
|
||
| // 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, |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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*/ |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
could also be const uint8_t const*
This Pull Request adds an adapter layer and updates the sts4x sensor driver for the new adapter layer.