Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
richardeoin committed Dec 26, 2024
1 parent efa5636 commit b92a4ad
Showing 12 changed files with 64 additions and 66 deletions.
24 changes: 11 additions & 13 deletions examples/blinky-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
@@ -48,18 +48,16 @@ fn main() -> ! {
let mut delay = cp.SYST.delay(ccdr.clocks);

loop {
loop {
led1.set_high();
led2.set_low();
led3.set_high();
led4.set_low();
delay.delay_ms(500_u16);

led1.set_low();
led2.set_high();
led3.set_low();
led4.set_high();
delay.delay_ms(500_u16);
}
led1.set_high();
led2.set_low();
led3.set_high();
led4.set_low();
delay.delay_ms(500_u16);

led1.set_low();
led2.set_high();
led3.set_low();
led4.set_high();
delay.delay_ms(500_u16);
}
}
17 changes: 8 additions & 9 deletions examples/can-echo.rs
Original file line number Diff line number Diff line change
@@ -131,14 +131,13 @@ fn main() -> ! {
block!(can.transmit(header, &buffer)).unwrap();

loop {
if let Ok(rxheader) = block!(can.receive0(&mut buffer)) {
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
}
let Ok(rxheader) = block!(can.receive0(&mut buffer));
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
}
}
17 changes: 8 additions & 9 deletions examples/can-fd.rs
Original file line number Diff line number Diff line change
@@ -163,14 +163,13 @@ fn main() -> ! {
block!(can.transmit(header, &buffer)).unwrap();

loop {
if let Ok(rxheader) = block!(can.receive0(&mut buffer)) {
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
}
let Ok(rxheader) = block!(can.receive0(&mut buffer));
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
}
}
2 changes: 1 addition & 1 deletion examples/display-dsi-command-teartest-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ fn main() -> ! {
let mut buf = WriteTo::new(&mut buf);
write!(&mut buf, "f: {frame}").unwrap();
frame += 1;
colored_label(buf.as_str().unwrap(), 50, 20, Rgb888::RED, draw)
colored_label(buf.into_str().unwrap(), 50, 20, Rgb888::RED, draw)
.unwrap();

display_test(draw).unwrap();
4 changes: 2 additions & 2 deletions examples/display-dsi-video-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
@@ -331,7 +331,7 @@ fn main() -> ! {
time_circuit(
NaiveDateTime::new(
NaiveDate::from_ymd_opt(1985, 10, 26).unwrap(),
NaiveTime::from_hms_opt(01, 21, 0).unwrap(),
NaiveTime::from_hms_opt(1, 21, 0).unwrap(),
),
tc_x,
100,
@@ -355,7 +355,7 @@ fn main() -> ! {
time_circuit(
NaiveDateTime::new(
NaiveDate::from_ymd_opt(1985, 10, 26).unwrap(),
NaiveTime::from_hms_opt(01, 20, 0).unwrap(),
NaiveTime::from_hms_opt(1, 20, 0).unwrap(),
),
tc_x,
400,
2 changes: 1 addition & 1 deletion examples/display-dsi-video-teartest-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ fn main() -> ! {
let mut buf = WriteTo::new(&mut buf);
write!(&mut buf, "f: {frame}").unwrap();
frame += 1;
colored_label(buf.as_str().unwrap(), 50, 20, Rgb888::RED, draw)
colored_label(buf.into_str().unwrap(), 50, 20, Rgb888::RED, draw)
.unwrap();

display_test(draw).unwrap();
6 changes: 3 additions & 3 deletions examples/ethernet-nucleo-h743zi2.rs
Original file line number Diff line number Diff line change
@@ -39,9 +39,9 @@ fn systick_init(syst: &mut stm32::SYST, clocks: CoreClocks) {
syst.enable_counter();
}

/// ======================================================================
/// Entry point
/// ======================================================================
// ======================================================================
// Entry point
// ======================================================================

/// TIME is an atomic u32 that counts milliseconds. Although not used
/// here, it is very useful to have for network protocols
2 changes: 1 addition & 1 deletion examples/utilities_display/display_primitives.rs
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ where
dt.time().minute()
)
.unwrap();
Text::new(buf.as_str().unwrap(), Point::new(x, y), fg_text_style)
Text::new(buf.into_str().unwrap(), Point::new(x, y), fg_text_style)
.draw(target)?;
date_labels(y - 75, target)?;
colored_label(
6 changes: 3 additions & 3 deletions examples/utilities_display/write.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ pub mod write_to {
}

#[allow(dead_code)]
pub fn as_str(self) -> Option<&'a str> {
pub fn into_str(self) -> Option<&'a str> {
if self.used <= self.buffer.len() {
// only successful concats of str - must be a valid str.
use core::str::from_utf8_unchecked;
@@ -27,7 +27,7 @@ pub mod write_to {
}
}

impl<'a> fmt::Write for WriteTo<'a> {
impl fmt::Write for WriteTo<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
if self.used > self.buffer.len() {
return Err(fmt::Error);
@@ -52,6 +52,6 @@ pub mod write_to {
) -> Result<&'a str, fmt::Error> {
let mut w = WriteTo::new(buffer);
fmt::write(&mut w, args)?;
w.as_str().ok_or(fmt::Error)
w.into_str().ok_or(fmt::Error)
}
}
4 changes: 3 additions & 1 deletion src/dsi.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,9 @@ pub struct DsiPllConfig {
}

impl DsiPllConfig {
/// # Safety: TODO
/// # Safety
///
/// TODO
pub unsafe fn manual(ndiv: u8, idf: u8, odf: u8, eckdiv: u8) -> Self {
DsiPllConfig {
ndiv,
44 changes: 21 additions & 23 deletions src/xspi/octospi.rs
Original file line number Diff line number Diff line change
@@ -183,31 +183,31 @@ impl<OSPI> fmt::Display for Hyperbus<OSPI> {
}
}

#[allow(unused)]
pub trait PinClk<OSPI> {}
#[allow(unused)]
pub trait PinNclk<OSPI> {}
#[allow(unused)]
pub trait PinDQS<OSPI> {}
#[allow(unused)]
pub trait PinNCS<OSPI> {}
#[allow(unused)]
pub trait PinIo0<OSPI> {}
#[allow(unused)]
pub trait PinIo1<OSPI> {}
#[allow(unused)]
pub trait PinIo2<OSPI> {}
#[allow(unused)]
pub trait PinIo3<OSPI> {}
#[allow(unused)]
pub trait PinIo4<OSPI> {}
#[allow(unused)]
pub trait PinIo5<OSPI> {}
#[allow(unused)]
pub trait PinIo6<OSPI> {}
#[allow(unused)]
pub trait PinIo7<OSPI> {}

// impl<OSPI, CLK, NCS, IO0, IO1, IO2, IO3> PinsQuad<OSPI>
// for (CLK, NCS, IO0, IO1, IO2, IO3)
// where
// CLK: PinClk<OSPI>,
// NCS: PinNCS<OSPI>,
// IO0: PinIo0<OSPI>,
// IO1: PinIo1<OSPI>,
// IO2: PinIo2<OSPI>,
// IO3: PinIo3<OSPI>,
// {
// }

macro_rules! pins {
(
$($BANK:ident:
@@ -470,11 +470,10 @@ macro_rules! octospi_impl {

// Prescaler
let spi_frequency = config.frequency.raw();
let divisor =
match (spi_kernel_ck + spi_frequency - 1) / spi_frequency {
divisor @ 1..=256 => divisor - 1,
_ => panic!("Invalid OCTOSPI frequency requested"),
};
let divisor = match spi_kernel_ck.div_ceil(spi_frequency) {
divisor @ 1..=256 => divisor - 1,
_ => panic!("Invalid OCTOSPI frequency requested"),
};
regs.dcr2
.write(|w| unsafe { w.prescaler().bits(divisor as u8) });

@@ -521,11 +520,10 @@ macro_rules! octospi_impl {
// Configure clock
let hyperbus: HyperbusConfig = hyperbus.into();
let spi_frequency = hyperbus.frequency.raw();
let divisor =
match (spi_kernel_ck + spi_frequency - 1) / spi_frequency {
divisor @ 1..=256 => divisor as u8,
_ => panic!("Invalid OCTOSPI frequency requested"),
};
let divisor = match spi_kernel_ck.div_ceil(spi_frequency) {
divisor @ 1..=256 => divisor as u8,
_ => panic!("Invalid OCTOSPI frequency requested"),
};
let frequency = Hertz::from_raw(spi_kernel_ck / divisor as u32);

// Calculate the achieved clock period in ns
@@ -578,7 +576,7 @@ macro_rules! octospi_impl {
let refresh_cycles = {
let interval_ns =
(1000 * hyperbus.refresh_interval.ticks() as u32);
(interval_ns + period_ns - 1) / period_ns
interval_ns.div_ceil(period_ns)
};
regs.dcr4
.write(|w| unsafe { w.refresh().bits(refresh_cycles) });
2 changes: 2 additions & 0 deletions src/xspi/qspi.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ use crate::{
use super::{common::BankSelect, Bank, Config, Qspi, QspiError, SamplingEdge};

/// Used to indicate that an IO pin is not used by the QSPI interface.
#[allow(unused)]
pub struct NoIo {}

/// Indicates a set of pins can be used for the QSPI interface on bank 1.
@@ -22,6 +23,7 @@ pub trait PinIo3Bank1 {}

/// Indicates a set of pins can be used for the QSPI interface on bank 2.
pub trait PinsBank2 {}
#[allow(unused)]
pub trait PinSckBank2 {}
pub trait PinIo0Bank2 {}
pub trait PinIo1Bank2 {}

0 comments on commit b92a4ad

Please sign in to comment.