From a61b2967f91f6bb2e34570953137f864bbd8acf7 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:31:36 +1100 Subject: [PATCH] Make clippy warnings errors (#53) * Make clippy warnings errors * Fix examples and clippy warnings --- .github/workflows/clippy.yml | 17 ++++++++--------- examples/blinky.rs | 2 +- examples/i2c_ssd1306.rs | 8 +++++++- examples/led_timer_interrupt.rs | 2 +- examples/serial.rs | 2 +- examples/watchdog_example.rs | 6 +++--- src/watchdog.rs | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index d910eb3..11fbc92 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -3,16 +3,15 @@ on: [push, pull_request] name: Clippy check jobs: clippy_check: - runs-on: ubuntu-latest + name: Run Clippy + runs-on: ubuntu-20.04 + env: + RUSTFLAGS: "-D warnings" steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: stable target: riscv32imac-unknown-none-elf - override: true components: clippy - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + - run: cargo clippy --workspace --examples -- -Dwarnings + - run: cargo clippy --workspace --examples --all-features -- -Dwarnings diff --git a/examples/blinky.rs b/examples/blinky.rs index 686ff47..0b8ee48 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -2,7 +2,7 @@ #![no_main] use bl602_hal as hal; -use embedded_hal::delay::DelayUs; +use embedded_hal::delay::DelayNs; use embedded_hal::digital::OutputPin; use hal::{ clock::{Strict, SysclkFreq, UART_PLL_FREQ}, diff --git a/examples/i2c_ssd1306.rs b/examples/i2c_ssd1306.rs index ea9a4d3..e4a73f1 100644 --- a/examples/i2c_ssd1306.rs +++ b/examples/i2c_ssd1306.rs @@ -9,6 +9,8 @@ use embedded_graphics::{ text::{Baseline, Text}, Drawable, }; +use embedded_hal::delay::DelayNs; + use hal::{ clock::{Strict, SysclkFreq, UART_PLL_FREQ}, pac, @@ -57,5 +59,9 @@ fn main() -> ! { display.flush().unwrap(); - loop {} + // Create a blocking delay function based on the current cpu frequency + let mut d = bl602_hal::delay::McycleDelay::new(clocks.sysclk().0); + loop { + d.delay_ms(1000); + } } diff --git a/examples/led_timer_interrupt.rs b/examples/led_timer_interrupt.rs index a996c77..a271fa7 100644 --- a/examples/led_timer_interrupt.rs +++ b/examples/led_timer_interrupt.rs @@ -17,7 +17,7 @@ use bl602_hal as hal; use core::cell::RefCell; use core::ops::DerefMut; use critical_section::{self, Mutex}; -use embedded_hal::digital::{OutputPin, ToggleableOutputPin}; +use embedded_hal::digital::{OutputPin, StatefulOutputPin}; use embedded_hal_zero::timer::CountDown; use embedded_time::{duration::*, rate::*}; use hal::{ diff --git a/examples/serial.rs b/examples/serial.rs index c211879..18e548b 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -3,7 +3,7 @@ use bl602_hal as hal; use core::fmt::Write; -use embedded_hal::delay::DelayUs; +use embedded_hal::delay::DelayNs; use hal::{ clock::{Strict, SysclkFreq, UART_PLL_FREQ}, pac, diff --git a/examples/watchdog_example.rs b/examples/watchdog_example.rs index d03fd25..8d03665 100644 --- a/examples/watchdog_example.rs +++ b/examples/watchdog_example.rs @@ -25,8 +25,8 @@ use core::cell::RefCell; use core::fmt::Write; use core::ops::DerefMut; use critical_section::{self, Mutex}; -use embedded_hal::delay::DelayUs; -use embedded_hal::digital::{OutputPin, ToggleableOutputPin}; +use embedded_hal::delay::DelayNs; +use embedded_hal::digital::{OutputPin, StatefulOutputPin}; use embedded_hal_zero::watchdog::{Watchdog, WatchdogEnable}; use embedded_time::{duration::*, rate::*}; use hal::{ @@ -152,7 +152,7 @@ fn Watchdog(_: &mut TrapFrame) { // Toggle the red led whenever the interrupt is triggered: critical_section::with(|cs| { if let Some(led_pin) = G_INTERRUPT_LED_PIN_R.borrow(cs).borrow_mut().deref_mut() { - led_pin.toggle(); + led_pin.toggle().unwrap(); } }); diff --git a/src/watchdog.rs b/src/watchdog.rs index 0c50ed1..a0c9f67 100644 --- a/src/watchdog.rs +++ b/src/watchdog.rs @@ -232,7 +232,7 @@ impl ConfiguredWatchdog0 { impl embedded_hal_zero::watchdog::Watchdog for ConfiguredWatchdog0 { /// This feeds the watchdog by resetting its counter value to 0. /// WCR register is write-only, no need to preserve register contents - fn feed(&mut self) -> () { + fn feed(&mut self) { let timer = unsafe { &*pac::TIMER::ptr() }; send_access_codes(); timer.wcr.write(|w| w.wcr().set_bit());