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.
2 parents c10ddae + 6eeb8c4 commit d9e2ca0Copy full SHA for d9e2ca0
embedded-hal/src/pwm.rs
@@ -95,8 +95,15 @@ 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!(denom != 0);
99
+ debug_assert!(num <= denom);
100
let duty = u32::from(num) * u32::from(self.get_max_duty_cycle()) / u32::from(denom);
- self.set_duty_cycle(duty as u16)
101
+
102
+ // This is safe because we know that `num <= denom`, so `duty <= self.get_max_duty_cycle()` (u16)
103
+ #[allow(clippy::cast_possible_truncation)]
104
+ {
105
+ self.set_duty_cycle(duty as u16)
106
+ }
107
}
108
109
/// Set the duty cycle to `percent / 100`
0 commit comments