@@ -743,29 +743,38 @@ int adxl367_get_accel_data(const struct device *dev,
743
743
}
744
744
745
745
/**
746
- * @brief Reads the raw temperature of the device. If ADXL367_TEMP_EN is not
747
- * set, use adxl367_temp_read_en() first to enable temperature reading.
746
+ * @brief Reads the raw temperature of the device.
748
747
*
749
- * @param dev - The device structure.
750
- * @param raw_temp - Raw value of temperature.
748
+ * If ADXL367_TEMP_EN is not set, use adxl367_temp_read_en() first to enable temperature reading.
749
+ * Optionally checks the data ready status before reading temperature.
750
+ *
751
+ * @param dev - The device structure.
752
+ * @param raw_temp - Raw value of temperature.
753
+ * @param check_data_rdy - If true, waits for data ready status before reading temperature.
754
+ * If false, reads temperature directly. Note: The DATA_READY bit is
755
+ * cleared when data is read; set this flag to false if temperature from
756
+ * the same sample frame is needed after performing an axis(x,y,z) read.
751
757
*
752
758
* @return 0 in case of success, negative error code otherwise.
753
759
*/
754
- int adxl367_get_temp_data (const struct device * dev , int16_t * raw_temp )
760
+ int adxl367_get_temp_data (const struct device * dev , int16_t * raw_temp , bool check_data_rdy )
755
761
{
756
762
int ret ;
757
763
uint8_t temp [2 ] = { 0 };
758
- uint8_t reg_data , nready = 1U ;
759
764
struct adxl367_data * data = dev -> data ;
760
765
761
- while (nready != 0 ) {
762
- ret = data -> hw_tf -> read_reg (dev , ADXL367_STATUS , & reg_data );
763
- if (ret != 0 ) {
764
- return ret ;
765
- }
766
+ if (check_data_rdy ) {
767
+ uint8_t reg_data , nready = 1U ;
766
768
767
- if ((reg_data & ADXL367_STATUS_DATA_RDY ) != 0 ) {
768
- nready = 0U ;
769
+ while (nready != 0 ) {
770
+ ret = data -> hw_tf -> read_reg (dev , ADXL367_STATUS , & reg_data );
771
+ if (ret != 0 ) {
772
+ return ret ;
773
+ }
774
+
775
+ if ((reg_data & ADXL367_STATUS_DATA_RDY ) != 0 ) {
776
+ nready = 0U ;
777
+ }
769
778
}
770
779
}
771
780
@@ -879,8 +888,14 @@ static int adxl367_sample_fetch(const struct device *dev,
879
888
if (ret != 0 ) {
880
889
return ret ;
881
890
}
891
+ const struct adxl367_dev_config * cfg = dev -> config ;
892
+ bool check_temp_data_ready = false;
882
893
883
- return adxl367_get_temp_data (dev , & data -> temp_val );
894
+ if (cfg -> temp_en ) {
895
+ ret = adxl367_get_temp_data (dev , & data -> temp_val , check_temp_data_ready );
896
+ }
897
+
898
+ return ret ;
884
899
}
885
900
#ifdef CONFIG_SENSOR_ASYNC_API
886
901
void adxl367_accel_convert (struct sensor_value * val , int16_t value ,
0 commit comments