Skip to content

Commit 1c76cbe

Browse files
bors[bot]Dirbaio
andauthored
Merge #313
313: Fix PWM EasyDMA max length r=Yatekii a=Dirbaio 1. The max length is 0x7FFF, not 0x8000 (1<<15). The latter already doesn't fit in 15 bits. 2. The max length is in duty value count, not in bytes, so there's no need to divide by sizeof(u16) I have verified the max length is 15 bits on all chips. Co-authored-by: Dario Nieuwenhuis <[email protected]>
2 parents 053dc54 + ea3af5b commit 1c76cbe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

nrf-hal-common/src/pwm.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use core::{
2020
};
2121
use embedded_dma::*;
2222

23+
const MAX_SEQ_LEN: usize = 0x7FFF;
24+
2325
/// A safe wrapper around the raw peripheral.
2426
#[derive(Debug)]
2527
pub struct Pwm<T: Instance> {
@@ -507,7 +509,7 @@ where
507509
seq1_buffer,
508510
));
509511
}
510-
if len > (1 << 15) / core::mem::size_of::<u16>() {
512+
if len > MAX_SEQ_LEN {
511513
return Err((Error::BufferTooLong, self, seq0_buffer, seq1_buffer));
512514
}
513515
compiler_fence(Ordering::SeqCst);
@@ -530,7 +532,7 @@ where
530532
seq1_buffer,
531533
));
532534
}
533-
if len > (1 << 15) / core::mem::size_of::<u16>() {
535+
if len > MAX_SEQ_LEN {
534536
return Err((Error::BufferTooLong, self, seq0_buffer, seq1_buffer));
535537
}
536538
compiler_fence(Ordering::SeqCst);

0 commit comments

Comments
 (0)