From 1e649bbc0b4c92494804bd374259251ac7c80c52 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Mon, 4 Nov 2019 00:49:43 +0100 Subject: [PATCH] Fix a number of clippy warnings Signed-off-by: Daniel Egger --- examples/adc_values.rs | 3 +-- examples/blinky.rs | 7 +++---- examples/blinky_adc.rs | 5 ++--- examples/blinky_delay.rs | 5 ++--- examples/blinky_multiple.rs | 7 +++---- examples/blinky_timer.rs | 5 ++--- examples/dac.rs | 9 ++++----- examples/flash_systick.rs | 7 +++---- examples/flash_systick_fancier.rs | 7 +++---- examples/i2c_find_address.rs | 18 +++++------------- examples/led_hal_button_irq.rs | 19 +++++++++---------- examples/serial_echo.rs | 3 +-- examples/serial_spi_bridge.rs | 3 +-- examples/spi_hal_apa102c.rs | 3 +-- examples/watchdog.rs | 3 +-- src/serial.rs | 2 +- 16 files changed, 42 insertions(+), 64 deletions(-) diff --git a/examples/adc_values.rs b/examples/adc_values.rs index 21d6195..a481970 100644 --- a/examples/adc_values.rs +++ b/examples/adc_values.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; diff --git a/examples/blinky.rs b/examples/blinky.rs index cef7638..e38f873 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -25,11 +24,11 @@ fn main() -> ! { loop { // Turn PA1 on a million times in a row for _ in 0..1_000_000 { - led.set_high(); + led.set_high().ok(); } // Then turn PA1 off a million times in a row for _ in 0..1_000_000 { - led.set_low(); + led.set_low().ok(); } } } diff --git a/examples/blinky_adc.rs b/examples/blinky_adc.rs index 1d7a9fa..f65bfc6 100644 --- a/examples/blinky_adc.rs +++ b/examples/blinky_adc.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused_imports)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -32,7 +31,7 @@ fn main() -> ! { let mut adc = Adc::new(p.ADC, &mut rcc); loop { - led.toggle(); + led.toggle().ok(); let val: u16 = adc.read(&mut an_in).unwrap(); diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs index a7a5b52..8284d76 100644 --- a/examples/blinky_delay.rs +++ b/examples/blinky_delay.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -26,7 +25,7 @@ fn main() -> ! { let mut delay = Delay::new(cp.SYST, &rcc); loop { - led.toggle(); + led.toggle().ok(); delay.delay_ms(1_000_u16); } }); diff --git a/examples/blinky_multiple.rs b/examples/blinky_multiple.rs index 141042d..3d01006 100644 --- a/examples/blinky_multiple.rs +++ b/examples/blinky_multiple.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -33,12 +32,12 @@ fn main() -> ! { let mut leds = [led1.downgrade(), led2.downgrade()]; loop { for l in &mut leds { - l.set_high(); + l.set_high().ok(); } delay.delay_ms(1_000_u16); for l in &mut leds { - l.set_low(); + l.set_low().ok(); } delay.delay_ms(1_000_u16); } diff --git a/examples/blinky_timer.rs b/examples/blinky_timer.rs index cf7db6f..b1b71fe 100644 --- a/examples/blinky_timer.rs +++ b/examples/blinky_timer.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -25,7 +24,7 @@ fn main() -> ! { let mut timer = Timer::tim1(p.TIM1, Hertz(1), &mut rcc); loop { - led.toggle(); + led.toggle().ok(); // Wait for the timer to expire nb::block!(timer.wait()).ok(); diff --git a/examples/dac.rs b/examples/dac.rs index 0784169..9a431fd 100644 --- a/examples/dac.rs +++ b/examples/dac.rs @@ -4,14 +4,13 @@ use cortex_m; use cortex_m_rt as rt; -#[allow(unused_imports)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; -use crate::hal::stm32; -use crate::hal::prelude::*; use crate::hal::dac::*; +use crate::hal::prelude::*; +use crate::hal::stm32; use rt::entry; @@ -59,4 +58,4 @@ fn main() -> ! { loop { continue; } -} \ No newline at end of file +} diff --git a/examples/flash_systick.rs b/examples/flash_systick.rs index 338d47a..104a581 100644 --- a/examples/flash_systick.rs +++ b/examples/flash_systick.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -69,13 +68,13 @@ fn SysTick() -> ! { // Check state variable, keep LED off most of the time and turn it on every 10th tick if *STATE < 10 { // Turn off the LED - led.set_low(); + led.set_low().ok(); // And now increment state variable *STATE += 1; } else { // Turn on the LED - led.set_high(); + led.set_high().ok(); // And set new state variable back to 0 *STATE = 0; diff --git a/examples/flash_systick_fancier.rs b/examples/flash_systick_fancier.rs index 1008044..0fd3771 100644 --- a/examples/flash_systick_fancier.rs +++ b/examples/flash_systick_fancier.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -73,13 +72,13 @@ fn SysTick() -> ! { // Check state variable, keep LED off most of the time and turn it on every 10th tick if *STATE < 10 { // Turn off the LED - led.set_low(); + led.set_low().ok(); // And now increment state variable *STATE += 1; } else { // Turn on the LED - led.set_high(); + led.set_high().ok(); // And set new state variable back to 0 *STATE = 0; diff --git a/examples/i2c_find_address.rs b/examples/i2c_find_address.rs index 9499e3d..bc63d51 100644 --- a/examples/i2c_find_address.rs +++ b/examples/i2c_find_address.rs @@ -1,16 +1,11 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; -use crate::hal::{ - prelude::*, - i2c::I2c, - stm32, -}; +use crate::hal::{i2c::I2c, prelude::*, stm32}; use cortex_m_rt::entry; @@ -38,16 +33,13 @@ fn main() -> ! { // The write method sends the specified address and checks for acknowledgement; // if no ack is given by the slave device the result is Err(), otherwise Ok() // Since we only care for an acknowledgement the data sent can be empty - match i2c.write(add, &[]) { - Ok(_) => { - _devices += 1; - }, - Err(_) => (), + if i2c.write(add, &[]).is_ok() { + _devices += 1; } } // Here the variable "_devices" counts how many i2c addresses were a hit - }); + }); } loop { diff --git a/examples/led_hal_button_irq.rs b/examples/led_hal_button_irq.rs index 1af4676..8397f0f 100644 --- a/examples/led_hal_button_irq.rs +++ b/examples/led_hal_button_irq.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; @@ -50,15 +49,13 @@ fn main() -> ! { let mut led = gpioa.pa1.into_push_pull_output(cs); // Turn off LED - led.set_low(); + led.set_low().ok(); // Initialise delay provider let delay = Delay::new(cp.SYST, &rcc); // Enable external interrupt for PB1 - syscfg - .exticr1 - .modify(|_, w| unsafe { w.exti1().bits(1) }); + syscfg.exticr1.modify(|_, w| unsafe { w.exti1().bits(1) }); // Set interrupt request mask for line 1 exti.imr.modify(|_, w| w.mr1().set_bit()); @@ -73,8 +70,10 @@ fn main() -> ! { // Enable EXTI IRQ, set prio 1 and clear any pending IRQs let mut nvic = cp.NVIC; - nvic.enable(Interrupt::EXTI0_1); - unsafe { nvic.set_priority(Interrupt::EXTI0_1, 1) }; + unsafe { + nvic.set_priority(Interrupt::EXTI0_1, 1); + cortex_m::peripheral::NVIC::unmask(Interrupt::EXTI0_1); + } cortex_m::peripheral::NVIC::unpend(Interrupt::EXTI0_1); }); } @@ -97,13 +96,13 @@ fn EXTI0_1() { INT.borrow(cs).borrow_mut().deref_mut(), ) { // Turn on LED - led.set_high(); + led.set_high().ok(); // Wait a second delay.delay_ms(1_000_u16); // Turn off LED - led.set_low(); + led.set_low().ok(); // Clear event triggering the interrupt exti.pr.write(|w| w.pif1().set_bit()); diff --git a/examples/serial_echo.rs b/examples/serial_echo.rs index d06f7aa..4467795 100644 --- a/examples/serial_echo.rs +++ b/examples/serial_echo.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; diff --git a/examples/serial_spi_bridge.rs b/examples/serial_spi_bridge.rs index fbf8e82..5b35249 100644 --- a/examples/serial_spi_bridge.rs +++ b/examples/serial_spi_bridge.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; diff --git a/examples/spi_hal_apa102c.rs b/examples/spi_hal_apa102c.rs index 51ebd85..03e0be1 100644 --- a/examples/spi_hal_apa102c.rs +++ b/examples/spi_hal_apa102c.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; diff --git a/examples/watchdog.rs b/examples/watchdog.rs index df0e44a..4170f55 100644 --- a/examples/watchdog.rs +++ b/examples/watchdog.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -#[allow(unused)] -use panic_halt; +use panic_halt as _; use stm32f0xx_hal as hal; diff --git a/src/serial.rs b/src/serial.rs index 3beca39..f95d066 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -600,5 +600,5 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result { }) }; - return Err(err); + Err(err) }