drivers/sensor: lps22hh: Fix the raw to kPa sample conversion
The lps22hh 24 bit raw sample is left aligned, which means that it needs to be right-shifted by 8 before applying conversion. Moreover the conversion has been simplified for clarity. Fix #35871 Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
92afba6278
commit
4e8c809d74
1 changed files with 6 additions and 4 deletions
|
@ -56,11 +56,13 @@ static int lps22hh_sample_fetch(const struct device *dev,
|
||||||
static inline void lps22hh_press_convert(struct sensor_value *val,
|
static inline void lps22hh_press_convert(struct sensor_value *val,
|
||||||
int32_t raw_val)
|
int32_t raw_val)
|
||||||
{
|
{
|
||||||
|
int32_t press_tmp = raw_val >> 8; /* raw value is left aligned (24 msb) */
|
||||||
|
|
||||||
/* Pressure sensitivity is 4096 LSB/hPa */
|
/* Pressure sensitivity is 4096 LSB/hPa */
|
||||||
/* Convert raw_val to val in kPa */
|
/* Also convert hPa into kPa */
|
||||||
val->val1 = (raw_val >> 12) / 10;
|
|
||||||
val->val2 = (raw_val >> 12) % 10 * 100000 +
|
val->val1 = press_tmp / 40960;
|
||||||
(((int32_t)((raw_val) & 0x0FFF) * 100000L) >> 12);
|
val->val2 = (press_tmp % 40960) * 1000000 / 40960;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void lps22hh_temp_convert(struct sensor_value *val,
|
static inline void lps22hh_temp_convert(struct sensor_value *val,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue