diff --git a/inc/mlx90632_depends.h b/inc/mlx90632_depends.h index 28af8ac..623fed4 100644 --- a/inc/mlx90632_depends.h +++ b/inc/mlx90632_depends.h @@ -48,6 +48,21 @@ */ extern int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value); +/** Read from two addresses from the mlx90632 + * + * i2c read is processor specific and this function expects to have address of mlx90632 known, as it operates purely on + * register addresses. + * + * @note Needs to be implemented externally + * @param[in] register_address Address of the register to be read from + * @param[out] *value32 pointer to uint16_t array where read data can be written + + * @retval 0 for success + * @retval <0 for failure + * + */ +extern int32_t mlx90632_i2c_read32(int16_t register_address, uint16_t* value32); + /** Write value to register_address of the mlx90632 * * i2c write is processor specific and this function expects to have address of mlx90632 known, as it operates purely diff --git a/src/mlx90632.c b/src/mlx90632.c index 35223f7..f5048af 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -188,7 +188,7 @@ STATIC int32_t mlx90632_read_temp_object_raw(int32_t channel_position, int16_t *object_new_raw, int16_t *object_old_raw) { int32_t ret; - uint16_t read_tmp; + uint16_t read_temp[2]; int16_t read; uint8_t channel, channel_old; @@ -196,26 +196,19 @@ STATIC int32_t mlx90632_read_temp_object_raw(int32_t channel_position, if (ret != 0) return -EINVAL; - ret = mlx90632_i2c_read(MLX90632_RAM_2(channel), &read_tmp); + ret = mlx90632_i2c_read32(MLX90632_RAM_1(channel), read_temp); if (ret < 0) - return ret; + return ret; - read = (int16_t)read_tmp; - - ret = mlx90632_i2c_read(MLX90632_RAM_1(channel), &read_tmp); - if (ret < 0) - return ret; - *object_new_raw = (read + (int16_t)read_tmp) / 2; + read = (int16_t)read_temp[1]; + *object_new_raw = (read + (int16_t)read_temp[0]) >> 1; - ret = mlx90632_i2c_read(MLX90632_RAM_2(channel_old), &read_tmp); + ret = mlx90632_i2c_read32(MLX90632_RAM_1(channel_old), read_temp); if (ret < 0) - return ret; - read = (int16_t)read_tmp; + return ret; - ret = mlx90632_i2c_read(MLX90632_RAM_1(channel_old), &read_tmp); - if (ret < 0) - return ret; - *object_old_raw = (read + (int16_t)read_tmp) / 2; + read = (int16_t)read_temp[1]; + *object_old_raw = (read + (int16_t)read_temp[0]) >> 1; return ret; }