mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
Merge pull request #20112 from maribu/drivers/lpsxxx
drivers/lpsxxx: add missing sign extension
This commit is contained in:
commit
31224b4d2d
@ -131,7 +131,7 @@ int lpsxxx_init(lpsxxx_t *dev, const lpsxxx_params_t * params)
|
|||||||
int lpsxxx_read_temp(const lpsxxx_t *dev, int16_t *temp)
|
int lpsxxx_read_temp(const lpsxxx_t *dev, int16_t *temp)
|
||||||
{
|
{
|
||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
int32_t val = 0;
|
int16_t val;
|
||||||
uint16_t res = TEMP_BASE; /* reference value -> see datasheet */
|
uint16_t res = TEMP_BASE; /* reference value -> see datasheet */
|
||||||
|
|
||||||
i2c_acquire(DEV_I2C);
|
i2c_acquire(DEV_I2C);
|
||||||
@ -140,7 +140,7 @@ int lpsxxx_read_temp(const lpsxxx_t *dev, int16_t *temp)
|
|||||||
DEBUG("[lpsxxx] read_temp: cannot read TEMP_OUT_L register\n");
|
DEBUG("[lpsxxx] read_temp: cannot read TEMP_OUT_L register\n");
|
||||||
return -LPSXXX_ERR_I2C;
|
return -LPSXXX_ERR_I2C;
|
||||||
}
|
}
|
||||||
val |= tmp;
|
val = tmp;
|
||||||
|
|
||||||
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPSXXX_REG_TEMP_OUT_H, &tmp, 0) < 0) {
|
if (i2c_read_reg(DEV_I2C, DEV_ADDR, LPSXXX_REG_TEMP_OUT_H, &tmp, 0) < 0) {
|
||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
@ -150,13 +150,10 @@ int lpsxxx_read_temp(const lpsxxx_t *dev, int16_t *temp)
|
|||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
val |= ((uint16_t)tmp << 8);
|
val |= ((uint16_t)tmp << 8);
|
||||||
|
|
||||||
DEBUG("[lpsxxx] read_temp: raw data %08" PRIx32 "\n", val);
|
DEBUG("[lpsxxx] read_temp: raw data %08" PRIx16 "\n", val);
|
||||||
|
|
||||||
/* convert val to c°C */
|
|
||||||
val *= 100;
|
|
||||||
|
|
||||||
/* compute actual temperature value in c°C */
|
/* compute actual temperature value in c°C */
|
||||||
res += DIV_ROUND(val, TEMP_DIVIDER);
|
res += DIV_ROUND((int32_t)val * 100, TEMP_DIVIDER);
|
||||||
|
|
||||||
*temp = res;
|
*temp = res;
|
||||||
return LPSXXX_OK;
|
return LPSXXX_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user