From ebf0a1516ba700f3aed3856a4e525ca801f6bff2 Mon Sep 17 00:00:00 2001 From: Vitaly Domnikov Date: Sun, 17 Mar 2024 11:08:16 -0700 Subject: [PATCH] make clippy happy --- src/crc.rs | 8 ++++++-- src/rtc.rs | 18 +++++++++--------- src/spi.rs | 7 ++++--- src/timer/pwm.rs | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/crc.rs b/src/crc.rs index ff1a9f9..fa1bd68 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -173,8 +173,12 @@ impl Crc { pub fn feed(&mut self, data: &[u8]) { let crc = unsafe { &(*CRC::ptr()) }; for byte in data { - let ptr = &crc.dr as *const _; - unsafe { core::ptr::write_volatile(ptr as *mut u8, *byte) }; + unsafe { + core::ptr::write_volatile( + core::cell::UnsafeCell::raw_get(&crc.dr as *const _ as _), + byte, + ) + } } } diff --git a/src/rtc.rs b/src/rtc.rs index 1b4bf35..32a1e3c 100644 --- a/src/rtc.rs +++ b/src/rtc.rs @@ -193,10 +193,10 @@ impl Rtc { pub fn set_alarm_a(&mut self, alarm: impl Into) { let alarm = alarm.into(); - let (dt, du) = bcd2_encode(alarm.day.unwrap_or_default() as u32); - let (ht, hu) = bcd2_encode(alarm.hours.unwrap_or_default() as u32); - let (mt, mu) = bcd2_encode(alarm.minutes.unwrap_or_default() as u32); - let (st, su) = bcd2_encode(alarm.seconds.unwrap_or_default() as u32); + let (dt, du) = bcd2_encode(alarm.day.unwrap_or_default()); + let (ht, hu) = bcd2_encode(alarm.hours.unwrap_or_default()); + let (mt, mu) = bcd2_encode(alarm.minutes.unwrap_or_default()); + let (st, su) = bcd2_encode(alarm.seconds.unwrap_or_default()); self.modify(|rb| { rb.alrmassr.write(|w| unsafe { @@ -226,10 +226,10 @@ impl Rtc { } pub fn set_alarm_b(&mut self, alarm: Alarm) { - let (dt, du) = bcd2_encode(alarm.day.unwrap_or_default() as u32); - let (ht, hu) = bcd2_encode(alarm.hours.unwrap_or_default() as u32); - let (mt, mu) = bcd2_encode(alarm.minutes.unwrap_or_default() as u32); - let (st, su) = bcd2_encode(alarm.seconds.unwrap_or_default() as u32); + let (dt, du) = bcd2_encode(alarm.day.unwrap_or_default()); + let (ht, hu) = bcd2_encode(alarm.hours.unwrap_or_default()); + let (mt, mu) = bcd2_encode(alarm.minutes.unwrap_or_default()); + let (st, su) = bcd2_encode(alarm.seconds.unwrap_or_default()); self.modify(|rb| { rb.alrmbssr.write(|w| unsafe { @@ -387,7 +387,7 @@ fn bcd2_encode(word: u32) -> (u8, u8) { bcd_high += 1; value -= 10; } - let bcd_low = ((bcd_high << 4) | value) as u8; + let bcd_low = (bcd_high << 4) | value; (bcd_high, bcd_low) } diff --git a/src/spi.rs b/src/spi.rs index 69290c7..099194b 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -2,7 +2,7 @@ use crate::gpio::*; use crate::rcc::*; use crate::stm32::{SPI1, SPI2}; use crate::time::Hertz; -use core::ptr; +use core::{cell, ptr}; pub use hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; /// SPI error @@ -264,8 +264,9 @@ macro_rules! spi { } else if sr.crcerr().bit_is_set() { nb::Error::Other(Error::Crc) } else if sr.txe().bit_is_set() { - let ptr = &self.spi.dr as *const _; - unsafe { core::ptr::write_volatile(ptr as *mut u8, byte) }; + unsafe { + ptr::write_volatile(cell::UnsafeCell::raw_get(&self.spi.dr as *const _ as _), byte) + } return Ok(()); } else { nb::Error::WouldBlock diff --git a/src/timer/pwm.rs b/src/timer/pwm.rs index fe5ecfa..8bfd362 100644 --- a/src/timer/pwm.rs +++ b/src/timer/pwm.rs @@ -269,7 +269,7 @@ pwm_advanced_hal! { TIM17: (Channel1, cc1e: cc1ne, ccmr1_output, oc1pe, oc1m, ccr1, moe), } -#[cfg(any(feature = "stm32g070"))] +#[cfg(feature = "stm32g070")] pwm_advanced_hal! { TIM15: (Channel1, cc1e: cc1ne, ccmr1_output, oc1pe, oc1m1, ccr1, moe), }