You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2018/12/20 08:59:49 UTC
[mynewt-core] 02/02: hw/drivers/lps33[t]hw: Simplify 24 to 32 bits
conversion
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit cfa2cd0b7bc8ea702c47a09863f834d63c81a45f
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Dec 18 16:21:42 2018 +0100
hw/drivers/lps33[t]hw: Simplify 24 to 32 bits conversion
Casting used for creating int value from uin8_t array resulted
in non optimal code that required additional manual sign extension.
If work is left to compiler instead code is more compact.
---
hw/drivers/sensors/lps33hw/src/lps33hw.c | 7 +------
hw/drivers/sensors/lps33thw/src/lps33thw.c | 7 +------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw.c b/hw/drivers/sensors/lps33hw/src/lps33hw.c
index 5eebf6e..a55a7a6 100644
--- a/hw/drivers/sensors/lps33hw/src/lps33hw.c
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw.c
@@ -510,12 +510,7 @@ lps33hw_get_pressure_regs(struct sensor_itf *itf, uint8_t reg, float *pressure)
return rc;
}
- int_press = (((int32_t)payload[2] << 16) |
- ((int32_t)payload[1] << 8) | payload[0]);
-
- if (int_press & 0x00800000) {
- int_press |= 0xff000000;
- }
+ int_press = (((int8_t)payload[2] << 16) | (payload[1] << 8) | payload[0]);
*pressure = lps33hw_reg_to_pa(int_press);
diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index b136ae6..a7347a7 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -517,12 +517,7 @@ lps33thw_get_pressure_regs(struct sensor_itf *itf, uint8_t reg, float *pressure)
return rc;
}
- int_press = (((int32_t)payload[2] << 16) |
- ((int32_t)payload[1] << 8) | payload[0]);
-
- if (int_press & 0x00800000) {
- int_press |= 0xff000000;
- }
+ int_press = ((int8_t)payload[2] << 16) | (payload[1] << 8) | payload[0];
*pressure = lps33thw_reg_to_pa(int_press);