Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed Nov 22, 2023
1 parent 3e93493 commit a272fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
25 changes: 10 additions & 15 deletions src/analog/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub struct Adc {
sample_time: SampleTime,
align: Align,
precision: Precision,
vdda_mv: Option<u32>,
vref: Option<u32>,
}

/// Contains the calibration factors for the ADC which can be reused with [`Adc::set_calibration()`]
Expand All @@ -125,7 +125,7 @@ impl Adc {
sample_time: SampleTime::T_2,
align: Align::Right,
precision: Precision::B_12,
vdda_mv: None,
vref: None,
}
}

Expand Down Expand Up @@ -232,9 +232,11 @@ impl Adc {
&mut self,
pin: &mut PIN,
) -> nb::Result<u16, ()> {
let vdda_mv = if let Some(vdda_mv) = self.vdda_mv {
vdda_mv
let vref = if let Some(vref) = &self.vref {
*vref
} else {
let vref_cal: u32 = unsafe { ptr::read_volatile(0x1FFF_75AA as *const u16) as u32 };

let mut vref = VRef::new();
let vref_val: u32 = if vref.enabled(self) {
self.read(&mut vref)?
Expand All @@ -245,20 +247,13 @@ impl Adc {
vref_val
};

let vref_cal: u32 = unsafe {
// DS12766 3.13.2
ptr::read_volatile(0x1FFF_75AA as *const u16) as u32
};

// RM0454 14.9 Calculating the actual VDDA voltage using the internal reference voltage
// V_DDA = 3 V x VREFINT_CAL / VREFINT_DATA
let vdda_mv = vref_cal * 3_000_u32 / vref_val;
self.vdda_mv = Some(vdda_mv);
vdda_mv
let vref = (3_000_u32 * vref_cal) / vref_val;
self.vref = Some(vref);
vref
};

self.read(pin).map(|raw: u32| {
let adc_mv = (vdda_mv * raw) >> 12;
let adc_mv = (vref as u32 * raw) >> 16;

Check warning on line 256 in src/analog/adc.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`u32` -> `u32`)

warning: casting to the same type is unnecessary (`u32` -> `u32`) --> src/analog/adc.rs:256:27 | 256 | let adc_mv = (vref as u32 * raw) >> 16; | ^^^^^^^^^^^ help: try: `vref` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `#[warn(clippy::unnecessary_cast)]` on by default
adc_mv as u16
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ macro_rules! gpio {
let _ = &(*$GPIOX::ptr()).pupdr.modify(|r, w| {
w.bits(r.bits() & !(0b11 << offset))
});
&(*$GPIOX::ptr()).moder.modify(|r, w| {
let _ = &(*$GPIOX::ptr()).moder.modify(|r, w| {
w.bits(r.bits() & !(0b11 << offset))
})
});
};
let offset = ($i % 4) * 8;
let mask = $Pxn << offset;
Expand Down Expand Up @@ -483,9 +483,9 @@ macro_rules! gpio {
pub fn set_speed(self, speed: Speed) -> Self {
let offset = 2 * $i;
unsafe {
&(*$GPIOX::ptr()).ospeedr.modify(|r, w| {
let _ = &(*$GPIOX::ptr()).ospeedr.modify(|r, w| {
w.bits((r.bits() & !(0b11 << offset)) | ((speed as u32) << offset))
})
});
};
self
}
Expand Down

0 comments on commit a272fa0

Please sign in to comment.