From c4f23f21d7409becf66ac0b5be46859b3bb26ff4 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Fri, 26 Aug 2022 14:58:43 +0300 Subject: [PATCH] fix examples --- examples/adc.rs | 6 +++--- examples/adc_temperature.rs | 6 +++--- examples/crc.rs | 2 +- examples/dynamic_gpio.rs | 2 +- examples/hello.rs | 2 +- examples/mfrc522.rs | 9 +++++++-- examples/multi_mode_gpio.rs | 2 +- examples/panics.rs | 2 +- examples/qei.rs | 2 +- examples/rtc.rs | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/adc.rs b/examples/adc.rs index 1f349a0c..40e21ccb 100644 --- a/examples/adc.rs +++ b/examples/adc.rs @@ -22,7 +22,7 @@ fn main() -> ! { // practical needs. User specified value is be approximated using supported // prescaler values 2/4/6/8. let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr); - hprintln!("adc freq: {}", clocks.adcclk()).unwrap(); + hprintln!("adc freq: {}", clocks.adcclk()); // Setup ADC let mut adc1 = adc::Adc::adc1(p.ADC1, clocks); @@ -41,12 +41,12 @@ fn main() -> ! { loop { let data: u16 = adc1.read(&mut ch0).unwrap(); - hprintln!("adc1: {}", data).unwrap(); + hprintln!("adc1: {}", data); #[cfg(any(feature = "stm32f103", feature = "connectivity"))] { let data1: u16 = adc2.read(&mut ch1).unwrap(); - hprintln!("adc2: {}", data1).unwrap(); + hprintln!("adc2: {}", data1); } } } diff --git a/examples/adc_temperature.rs b/examples/adc_temperature.rs index 7655d680..4e58a7ea 100644 --- a/examples/adc_temperature.rs +++ b/examples/adc_temperature.rs @@ -34,8 +34,8 @@ fn main() -> ! { usbpre: rcc::UsbPre::DIV1_5, adcpre: rcc::AdcPre::DIV2, }, &mut flash.acr);*/ - hprintln!("sysclk freq: {}", clocks.sysclk()).unwrap(); - hprintln!("adc freq: {}", clocks.adcclk()).unwrap(); + hprintln!("sysclk freq: {}", clocks.sysclk()); + hprintln!("adc freq: {}", clocks.adcclk()); // Setup ADC let mut adc = adc::Adc::adc1(p.ADC1, clocks); @@ -44,6 +44,6 @@ fn main() -> ! { loop { let temp = adc.read_temp(); - hprintln!("temp: {}", temp).unwrap(); + hprintln!("temp: {}", temp); } } diff --git a/examples/crc.rs b/examples/crc.rs index 88ca61ff..bf5829a9 100644 --- a/examples/crc.rs +++ b/examples/crc.rs @@ -21,7 +21,7 @@ fn main() -> ! { crc.write(0x12345678); let val = crc.read(); - hprintln!("found={:08x}, expected={:08x}", val, 0xdf8a8a2b_u32).ok(); + hprintln!("found={:08x}, expected={:08x}", val, 0xdf8a8a2b_u32); loop {} } diff --git a/examples/dynamic_gpio.rs b/examples/dynamic_gpio.rs index b49f2b07..b96a84ca 100644 --- a/examples/dynamic_gpio.rs +++ b/examples/dynamic_gpio.rs @@ -39,7 +39,7 @@ fn main() -> ! { loop { pin.make_floating_input(&mut gpioc.crh); block!(timer.wait()).unwrap(); - hprintln!("{}", pin.is_high().unwrap()).unwrap(); + hprintln!("{}", pin.is_high().unwrap()); pin.make_push_pull_output(&mut gpioc.crh); pin.set_high().unwrap(); diff --git a/examples/hello.rs b/examples/hello.rs index 724a728e..e9ea4e76 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -14,6 +14,6 @@ use cortex_m_rt::entry; #[entry] fn main() -> ! { - hprintln!("Hello, world!").unwrap(); + hprintln!("Hello, world!"); loop {} } diff --git a/examples/mfrc522.rs b/examples/mfrc522.rs index 26fc4b8a..000fdc72 100644 --- a/examples/mfrc522.rs +++ b/examples/mfrc522.rs @@ -8,8 +8,13 @@ use cortex_m::iprintln; use cortex_m_rt::entry; use embedded_hal::digital::v1_compat::OldOutputPin; +use embedded_hal::spi::{Mode, Phase, Polarity}; use mfrc522::Mfrc522; use stm32f1xx_hal::{pac, prelude::*, spi::Spi}; +pub const MODE: Mode = Mode { + polarity: Polarity::IdleLow, + phase: Phase::CaptureOnFirstTransition, +}; #[entry] fn main() -> ! { @@ -32,7 +37,7 @@ fn main() -> ! { dp.SPI1, (sck, miso, mosi), &mut afio.mapr, - mfrc522::MODE, + MODE, 1.MHz(), clocks, ); @@ -46,7 +51,7 @@ fn main() -> ! { loop { if let Ok(atqa) = mfrc522.reqa() { if let Ok(uid) = mfrc522.select(&atqa) { - iprintln!(_stim, "* {:?}", uid); + iprintln!(_stim, "* {:?}", uid.as_bytes()); } } } diff --git a/examples/multi_mode_gpio.rs b/examples/multi_mode_gpio.rs index 500a0c80..c38ad244 100644 --- a/examples/multi_mode_gpio.rs +++ b/examples/multi_mode_gpio.rs @@ -37,7 +37,7 @@ fn main() -> ! { // Wait for the timer to trigger an update and change the state of the LED loop { block!(timer.wait()).unwrap(); - hprintln!("{}", pin.is_high()).unwrap(); + hprintln!("{}", pin.is_high()); pin.as_push_pull_output(&mut gpioc.crh, |out| { out.set_high(); block!(timer.wait()).unwrap(); diff --git a/examples/panics.rs b/examples/panics.rs index 8d202169..e736a12f 100644 --- a/examples/panics.rs +++ b/examples/panics.rs @@ -13,7 +13,7 @@ use cortex_m_rt::{entry, exception, ExceptionFrame}; #[entry] fn main() -> ! { - hprintln!("Hello, world!").unwrap(); + hprintln!("Hello, world!"); loop {} } diff --git a/examples/qei.rs b/examples/qei.rs index b19b8b17..766e6f74 100644 --- a/examples/qei.rs +++ b/examples/qei.rs @@ -48,6 +48,6 @@ fn main() -> ! { let elapsed = after.wrapping_sub(before) as i16; - hprintln!("{}", elapsed).unwrap(); + hprintln!("{}", elapsed); } } diff --git a/examples/rtc.rs b/examples/rtc.rs index e3910415..6cc28211 100644 --- a/examples/rtc.rs +++ b/examples/rtc.rs @@ -22,6 +22,6 @@ fn main() -> ! { let rtc = Rtc::new(p.RTC, &mut backup_domain); loop { - hprintln!("time: {}", rtc.current_time()).unwrap(); + hprintln!("time: {}", rtc.current_time()); } }