Skip to content

resolve all warnings and clippy lints #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ impl From<u8> for Sequence {
}
}

impl Into<u8> for Sequence {
fn into(self) -> u8 {
match self {
impl From<Sequence> for u8 {
fn from(seq: Sequence) -> u8 {
match seq {
Sequence::One => 0,
Sequence::Two => 1,
Sequence::Three => 2,
Expand Down Expand Up @@ -592,7 +592,7 @@ impl Default for Resolution {
}

impl Resolution {
fn to_max_count(&self) -> u32 {
fn to_max_count(self) -> u32 {
match self {
Resolution::Bits12 => (1 << 12) - 1,
Resolution::Bits10 => (1 << 10) - 1,
Expand Down
2 changes: 1 addition & 1 deletion src/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a> WriteErase for FlashProgramming<'a> {

let mut chunks = aligned_data.chunks_exact(mem::size_of::<Self::NativeType>());

while let Some(exact_chunk) = chunks.next() {
for exact_chunk in chunks.by_ref() {
// Write chunks
let native = &[Self::NativeType::from_ne_bytes(
exact_chunk.try_into().unwrap(),
Expand Down
12 changes: 6 additions & 6 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ where
w.start()
.set_bit()
.sadd()
.bits(u16(addr << 1 | 0))
.bits(u16(addr << 1))
.add10()
.clear_bit()
.rd_wrn()
Expand Down Expand Up @@ -357,7 +357,7 @@ where

fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
// TODO support transfers of more than 255 bytes
assert!(buffer.len() < 256 && buffer.len() > 0);
assert!(buffer.len() < 256 && !buffer.is_empty());

// Wait for any previous address sequence to end
// automatically. This could be up to 50% of a bus
Expand All @@ -369,7 +369,7 @@ where
// is BUSY or I2C is in slave mode.
self.i2c.cr2.write(|w| {
w.sadd()
.bits((addr << 1 | 0) as u16)
.bits((addr << 1) as u16)
.rd_wrn()
.read()
.nbytes()
Expand Down Expand Up @@ -402,8 +402,8 @@ where

fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> {
// TODO support transfers of more than 255 bytes
assert!(bytes.len() < 256 && bytes.len() > 0);
assert!(buffer.len() < 256 && buffer.len() > 0);
assert!(bytes.len() < 256 && !bytes.is_empty());
assert!(buffer.len() < 256 && !buffer.is_empty());

// Wait for any previous address sequence to end
// automatically. This could be up to 50% of a bus
Expand All @@ -417,7 +417,7 @@ where
w.start()
.set_bit()
.sadd()
.bits(u16(addr << 1 | 0))
.bits(u16(addr << 1))
.add10()
.clear_bit()
.rd_wrn()
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! the STM32L432KC microcontroller. Participation is of course very welcome!

#![no_std]
#![allow(clippy::upper_case_acronyms)]
Copy link
Contributor Author

@Crzyrndm Crzyrndm Mar 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing peripheral / register defines to raise clippy warnings. It was only in a single module IIRC, so could move this to only the scope of that module potentially?


#[cfg(not(any(
feature = "stm32l431",
Expand Down
2 changes: 1 addition & 1 deletion src/lptimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ macro_rules! hal {
// This operation is sound, as it is an atomic memory access
// that does not modify the memory/read value
ClockSource::HSI16 => {
assert!(unsafe { (&*RCC::ptr()).cr.read().hsion().bit_is_set() })
assert!(unsafe { (*RCC::ptr()).cr.read().hsion().bit_is_set() })
}
_ => {}
}
Expand Down
3 changes: 2 additions & 1 deletion src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ impl RngCore for Rng {
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
Ok(self.fill_bytes(dest))
self.fill_bytes(dest);
Ok(())
}
}

Expand Down
19 changes: 14 additions & 5 deletions src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,24 @@ impl RtcConfig {
}

impl Rtc {
#[allow(clippy::self_named_constructors)]
#[deprecated = "use `new()` instead"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially controversial. Opinions?
Also has conflicts with #297 (whichever is merged last will need modifications to suppress the deprecation warnings assuming this remains)

pub fn rtc(
rtc: RTC,
apb1r1: &mut APB1R1,
bdcr: &mut BDCR,
pwrcr1: &mut pwr::CR1,
rtc_config: RtcConfig,
) -> Self {
Self::new(rtc, apb1r1, bdcr, pwrcr1, rtc_config)
}

pub fn new(
rtc: RTC,
apb1r1: &mut APB1R1,
bdcr: &mut BDCR,
pwrcr1: &mut pwr::CR1,
rtc_config: RtcConfig,
) -> Self {
// assert_eq!(clocks.lsi(), true); // make sure LSI is enabled
// enable peripheral clock for communication
Expand All @@ -178,9 +190,6 @@ impl Rtc {

/// Get date and time touple
pub fn get_date_time(&self) -> (Date, Time) {
let time;
let date;

let sync_p = self.rtc_config.sync_prescaler as u32;
let micros =
1_000_000u32 / (sync_p + 1) * (sync_p - self.rtc.ssr.read().ss().bits() as u32);
Expand All @@ -191,15 +200,15 @@ impl Rtc {
// calendar shadow registers until RTC_DR is read.
let dater = self.rtc.dr.read();

time = Time::new(
let time = Time::new(
(bcd2_to_byte((timer.ht().bits(), timer.hu().bits())) as u32).hours(),
(bcd2_to_byte((timer.mnt().bits(), timer.mnu().bits())) as u32).minutes(),
(bcd2_to_byte((timer.st().bits(), timer.su().bits())) as u32).secs(),
micros.micros(),
cr.bkp().bit(),
);

date = Date::new(
let date = Date::new(
dater.wdu().bits().into(),
bcd2_to_byte((dater.dt().bits(), dater.du().bits())).into(),
bcd2_to_byte((dater.mt().bit() as u8, dater.mu().bits())).into(),
Expand Down
4 changes: 2 additions & 2 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ macro_rules! hal {
// SSI: set nss high = master mode
// CRCEN: hardware CRC calculation disabled
// BIDIMODE: 2 line unidirectional (full duplex)
spi.cr1.write(|w| unsafe {
spi.cr1.write(|w| {
w.cpha()
.bit(mode.phase == Phase::CaptureOnSecondTransition)
.cpol()
Expand Down Expand Up @@ -191,7 +191,7 @@ macro_rules! hal {
/// Change the baud rate of the SPI
pub fn reclock(&mut self, freq: Hertz, clocks: Clocks) {
self.spi.cr1.modify(|_, w| w.spe().clear_bit());
self.spi.cr1.modify(|_, w| unsafe {
self.spi.cr1.modify(|_, w| {
w.br().bits(Self::compute_baud_rate(clocks.$pclkX(), freq));
w.spe().set_bit()
});
Expand Down
4 changes: 2 additions & 2 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl MonoTimer {
/// Returns an `Instant` corresponding to "now"
pub fn now(&self) -> Instant {
Instant {
now: DWT::get_cycle_count(),
now: DWT::cycle_count(),
}
}
}
Expand All @@ -65,6 +65,6 @@ pub struct Instant {
impl Instant {
/// Ticks elapsed since the `Instant` was created
pub fn elapsed(&self) -> u32 {
DWT::get_cycle_count().wrapping_sub(self.now)
DWT::cycle_count().wrapping_sub(self.now)
}
}
9 changes: 9 additions & 0 deletions src/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ pub enum ChargeDischargeTime {
}

impl<SPIN> Tsc<SPIN> {
#[allow(clippy::self_named_constructors)]
#[deprecated = "use `new()` instead"]
pub fn tsc(tsc: TSC, sample_pin: SPIN, ahb: &mut AHB1, cfg: Option<Config>) -> Self
where
SPIN: SamplePin<TSC>,
{
Self::new(tsc, sample_pin, ahb, cfg)
}

pub fn new(tsc: TSC, sample_pin: SPIN, ahb: &mut AHB1, cfg: Option<Config>) -> Self
where
SPIN: SamplePin<TSC>,
{
Expand Down