We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84dfc74 commit 8ce43e5Copy full SHA for 8ce43e5
embedded-hal/src/pwm.rs
@@ -95,8 +95,14 @@ pub trait SetDutyCycle: ErrorType {
95
/// and that `denom` is not zero.
96
#[inline]
97
fn set_duty_cycle_fraction(&mut self, num: u16, denom: u16) -> Result<(), Self::Error> {
98
+ debug_assert!(num <= denom);
99
let duty = u32::from(num) * u32::from(self.get_max_duty_cycle()) / u32::from(denom);
- self.set_duty_cycle(duty as u16)
100
+
101
+ // This is safe because we know that `num <= denom`, so `duty <= self.get_max_duty_cycle()` (u16)
102
+ #[allow(clippy::cast_possible_truncation)]
103
+ {
104
+ self.set_duty_cycle(duty as u16)
105
+ }
106
}
107
108
/// Set the duty cycle to `percent / 100`
0 commit comments