Skip to content
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

Increase cargo clippy coverage in CI #517

Merged
merged 3 commits into from
Dec 30, 2024
Merged
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
7 changes: 5 additions & 2 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ name: Clippy
jobs:
clippy_check:
runs-on: ubuntu-latest
env:
FLAGS: rt,defmt,log
PERIPHERAL: xspi,sdmmc,sdmmc-fatfs,fmc,usb_hs,rtc,ethernet,ltdc,crc,rand,can,dsi
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.80.0
toolchain: 1.83.0
target: thumbv7em-none-eabihf
components: clippy
- uses: clechasseur/rs-clippy-check@v3
with:
args: --examples --target thumbv7em-none-eabihf --features=rt,stm32h743v -- -D warnings
args: --examples --target thumbv7em-none-eabihf --features=stm32h743v,${{ env.FLAGS }},${{ env.PERIPHERAL }} -- -D warnings
24 changes: 11 additions & 13 deletions examples/blinky-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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 rxheader = block!(can.receive0(&mut buffer)).unwrap();
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
Expand Up @@ -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 rxheader = block!(can.receive0(&mut buffer)).unwrap();
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
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions examples/display-dsi-video-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/display-dsi-video-teartest-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions examples/ethernet-nucleo-h743zi2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/utilities_display/display_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions examples/utilities_display/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Up @@ -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,
Expand Down
44 changes: 21 additions & 23 deletions src/xspi/octospi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) });

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) });
Expand Down
2 changes: 2 additions & 0 deletions src/xspi/qspi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {}
Expand Down
Loading