Skip to content

Commit

Permalink
Fix missing parentheses in sign extension shifting
Browse files Browse the repository at this point in the history
  • Loading branch information
brghena authored and alevy committed Jun 6, 2024
1 parent 2861299 commit 7d3dff2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions capsules/extra/src/bme280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ impl<'a, I: I2CDevice> I2CClient for Bme280<'a, I> {
let calib = self.calibration.get();

// note: per datasheet, measurement is 20-bit two's complement
let adc_temperature: i32 = (((buffer[0] as usize) << 12
let adc_temperature: i32 = ((((buffer[0] as usize) << 12
| (buffer[1] as usize) << 4
| (((buffer[2] as usize) >> 4) & 0x0F) << 12)
as i32)
| (((buffer[2] as usize) >> 4) & 0x0F))
<< 12) as i32)
>> 12; // ensure sign extension

if adc_temperature == 0 {
Expand Down
3 changes: 1 addition & 2 deletions capsules/extra/src/bmp280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl CalibrationData {
}
}

fn temp_from_raw(&self, raw_temp: i32) -> i32 {
let temp = raw_temp as i32; // guaranteed to succeed because raw temp has only 20 significant bits maximum.
fn temp_from_raw(&self, temp: i32) -> i32 {
let dig_t1 = self.dig_t1 as i32; // same, 16-bits
let dig_t2 = self.dig_t2 as i32; // same, 16-bits
let dig_t3 = self.dig_t3 as i32; // same, 16-bits
Expand Down

0 comments on commit 7d3dff2

Please sign in to comment.