aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-11-13 17:50:11 +0100
committerJames Munns <[email protected]>2025-11-13 18:02:50 +0100
commit357a538e8d5f69c8c0aeacfd416f1ad99b0907d3 (patch)
treeaa209bf8dc7d3869f06bd6d5a3368771ee155b68 /src
parent9387d3352a39a903757860568e41890b022c990f (diff)
autofix clippy lints
Diffstat (limited to 'src')
-rw-r--r--src/adc.rs4
-rw-r--r--src/lpuart/buffered.rs22
-rw-r--r--src/lpuart/mod.rs18
-rw-r--r--src/ostimer.rs6
-rw-r--r--src/rtc.rs4
-rw-r--r--src/uart.rs8
6 files changed, 37 insertions, 25 deletions
diff --git a/src/adc.rs b/src/adc.rs
index d456971f7..655bf934f 100644
--- a/src/adc.rs
+++ b/src/adc.rs
@@ -228,7 +228,7 @@ impl<I: Instance> Adc<I> {
228 let step = 1.0 / (1u32 << shift) as f32; 228 let step = 1.0 / (1u32 << shift) as f32;
229 let tmp = (gain_adjustment / step) as u32; 229 let tmp = (gain_adjustment / step) as u32;
230 gcra_array[i - 1] = tmp; 230 gcra_array[i - 1] = tmp;
231 gain_adjustment = gain_adjustment - tmp as f32 * step; 231 gain_adjustment -= tmp as f32 * step;
232 } 232 }
233 233
234 for i in (1..=17).rev() { 234 for i in (1..=17).rev() {
@@ -244,7 +244,7 @@ impl<I: Instance> Adc<I> {
244 while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} 244 while adc.gcc0().read().rdy().is_gain_cal_not_valid() {}
245 245
246 let mut gcca = adc.gcc0().read().gain_cal().bits() as u32; 246 let mut gcca = adc.gcc0().read().gain_cal().bits() as u32;
247 if gcca & (((0xFFFF >> 0) + 1) >> 1) != 0 { 247 if gcca & ((0xFFFF + 1) >> 1) != 0 {
248 gcca |= !0xFFFF; 248 gcca |= !0xFFFF;
249 } 249 }
250 250
diff --git a/src/lpuart/buffered.rs b/src/lpuart/buffered.rs
index 0413fed8e..21b86ada9 100644
--- a/src/lpuart/buffered.rs
+++ b/src/lpuart/buffered.rs
@@ -24,6 +24,12 @@ pub struct State {
24 initialized: AtomicBool, 24 initialized: AtomicBool,
25} 25}
26 26
27impl Default for State {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
27impl State { 33impl State {
28 /// Create a new state instance 34 /// Create a new state instance
29 pub const fn new() -> Self { 35 pub const fn new() -> Self {
@@ -612,16 +618,14 @@ impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> for Buffere
612 } 618 }
613 619
614 // Handle transmission complete 620 // Handle transmission complete
615 if ctrl.tcie().is_enabled() { 621 if ctrl.tcie().is_enabled() && regs.stat().read().tc().is_complete() {
616 if regs.stat().read().tc().is_complete() { 622 state.tx_done.store(true, Ordering::Release);
617 state.tx_done.store(true, Ordering::Release); 623 state.tx_waker.wake();
618 state.tx_waker.wake();
619 624
620 // Disable TC interrupt 625 // Disable TC interrupt
621 cortex_m::interrupt::free(|_| { 626 cortex_m::interrupt::free(|_| {
622 regs.ctrl().modify(|_, w| w.tcie().disabled()); 627 regs.ctrl().modify(|_, w| w.tcie().disabled());
623 }); 628 });
624 }
625 } 629 }
626 } 630 }
627} 631}
diff --git a/src/lpuart/mod.rs b/src/lpuart/mod.rs
index bed10bdb0..854136144 100644
--- a/src/lpuart/mod.rs
+++ b/src/lpuart/mod.rs
@@ -105,8 +105,8 @@ mod gpio {
105 105
106 impl GpioPin for super::lib::peripherals::$pin {} 106 impl GpioPin for super::lib::peripherals::$pin {}
107 107
108 impl Into<AnyPin> for super::lib::peripherals::$pin { 108 impl From<super::lib::peripherals::$pin> for AnyPin {
109 fn into(self) -> AnyPin { 109 fn from(val: super::lib::peripherals::$pin) -> Self {
110 AnyPin 110 AnyPin
111 } 111 }
112 } 112 }
@@ -242,7 +242,7 @@ pub fn configure_baudrate(regs: Regs, baudrate_bps: u32, clock: Clock) -> Result
242 // Configure BAUD register 242 // Configure BAUD register
243 regs.baud().modify(|_, w| unsafe { 243 regs.baud().modify(|_, w| unsafe {
244 // Clear and set OSR 244 // Clear and set OSR
245 w.osr().bits((osr - 1) as u8); 245 w.osr().bits((osr - 1));
246 // Clear and set SBR 246 // Clear and set SBR
247 w.sbr().bits(sbr); 247 w.sbr().bits(sbr);
248 // Set BOTHEDGE if OSR is between 4 and 7 248 // Set BOTHEDGE if OSR is between 4 and 7
@@ -305,9 +305,9 @@ pub fn configure_fifo(regs: Regs, config: &Config) {
305 // Configure WATER register for FIFO watermarks 305 // Configure WATER register for FIFO watermarks
306 regs.water().write(|w| unsafe { 306 regs.water().write(|w| unsafe {
307 w.rxwater() 307 w.rxwater()
308 .bits(config.rx_fifo_watermark as u8) 308 .bits(config.rx_fifo_watermark)
309 .txwater() 309 .txwater()
310 .bits(config.tx_fifo_watermark as u8) 310 .bits(config.tx_fifo_watermark)
311 }); 311 });
312 312
313 // Enable TX/RX FIFOs 313 // Enable TX/RX FIFOs
@@ -377,7 +377,7 @@ pub fn calculate_baudrate(baudrate: u32, src_clock_hz: u32) -> Result<(u8, u16)>
377 // Try OSR values from 4 to 32 377 // Try OSR values from 4 to 32
378 for osr_temp in 4u8..=32u8 { 378 for osr_temp in 4u8..=32u8 {
379 // Calculate SBR: (srcClock_Hz * 2 / (baudRate * osr) + 1) / 2 379 // Calculate SBR: (srcClock_Hz * 2 / (baudRate * osr) + 1) / 2
380 let sbr_calc = ((src_clock_hz * 2) / (baudrate * osr_temp as u32) + 1) / 2; 380 let sbr_calc = ((src_clock_hz * 2) / (baudrate * osr_temp as u32)).div_ceil(2);
381 381
382 let sbr_temp = if sbr_calc == 0 { 382 let sbr_temp = if sbr_calc == 0 {
383 1 383 1
@@ -390,11 +390,7 @@ pub fn calculate_baudrate(baudrate: u32, src_clock_hz: u32) -> Result<(u8, u16)>
390 // Calculate actual baud rate 390 // Calculate actual baud rate
391 let calculated_baud = src_clock_hz / (osr_temp as u32 * sbr_temp as u32); 391 let calculated_baud = src_clock_hz / (osr_temp as u32 * sbr_temp as u32);
392 392
393 let temp_diff = if calculated_baud > baudrate { 393 let temp_diff = calculated_baud.abs_diff(baudrate);
394 calculated_baud - baudrate
395 } else {
396 baudrate - calculated_baud
397 };
398 394
399 if temp_diff <= baud_diff { 395 if temp_diff <= baud_diff {
400 baud_diff = temp_diff; 396 baud_diff = temp_diff;
diff --git a/src/ostimer.rs b/src/ostimer.rs
index a4cab6970..8bc68389a 100644
--- a/src/ostimer.rs
+++ b/src/ostimer.rs
@@ -151,6 +151,12 @@ pub struct Alarm<'d> {
151 _phantom: core::marker::PhantomData<&'d mut ()>, 151 _phantom: core::marker::PhantomData<&'d mut ()>,
152} 152}
153 153
154impl<'d> Default for Alarm<'d> {
155 fn default() -> Self {
156 Self::new()
157 }
158}
159
154impl<'d> Alarm<'d> { 160impl<'d> Alarm<'d> {
155 /// Create a new alarm instance 161 /// Create a new alarm instance
156 pub fn new() -> Self { 162 pub fn new() -> Self {
diff --git a/src/rtc.rs b/src/rtc.rs
index d62da1f0a..afd46610e 100644
--- a/src/rtc.rs
+++ b/src/rtc.rs
@@ -102,7 +102,7 @@ pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime {
102 days -= days_in_year; 102 days -= days_in_year;
103 year += 1; 103 year += 1;
104 104
105 days_in_year = if year % 4 == 0 { 105 days_in_year = if year.is_multiple_of(4) {
106 DAYS_IN_A_YEAR + 1 106 DAYS_IN_A_YEAR + 1
107 } else { 107 } else {
108 DAYS_IN_A_YEAR 108 DAYS_IN_A_YEAR
@@ -110,7 +110,7 @@ pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime {
110 } 110 }
111 111
112 let mut days_per_month = [0u8, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 112 let mut days_per_month = [0u8, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
113 if year % 4 == 0 { 113 if year.is_multiple_of(4) {
114 days_per_month[2] = 29; 114 days_per_month[2] = 29;
115 } 115 }
116 116
diff --git a/src/uart.rs b/src/uart.rs
index 3209a318d..cd504a6c6 100644
--- a/src/uart.rs
+++ b/src/uart.rs
@@ -118,7 +118,7 @@ impl<I: Instance> Uart<I> {
118 StopBits::Two => w.sbns().two(), 118 StopBits::Two => w.sbns().two(),
119 }; 119 };
120 // OSR field encodes (osr-1); use raw bits to avoid a long match on all variants 120 // OSR field encodes (osr-1); use raw bits to avoid a long match on all variants
121 let raw_osr = osr.saturating_sub(1) as u8; 121 let raw_osr = osr.saturating_sub(1);
122 unsafe { w.osr().bits(raw_osr).sbr().bits(sbr) } 122 unsafe { w.osr().bits(raw_osr).sbr().bits(sbr) }
123 }); 123 });
124 // 3) CTRL baseline and parity 124 // 3) CTRL baseline and parity
@@ -195,6 +195,12 @@ pub struct RingBuffer {
195 count: usize, 195 count: usize,
196} 196}
197 197
198impl Default for RingBuffer {
199 fn default() -> Self {
200 Self::new()
201 }
202}
203
198impl RingBuffer { 204impl RingBuffer {
199 pub const fn new() -> Self { 205 pub const fn new() -> Self {
200 Self { 206 Self {