Skip to content

Commit

Permalink
Merge pull request #204 from torkeldanielsson/rustfmt
Browse files Browse the repository at this point in the history
rustfmt
  • Loading branch information
therealprof authored Apr 26, 2020
2 parents c89f804 + 89600ec commit 1357e5a
Show file tree
Hide file tree
Showing 46 changed files with 364 additions and 454 deletions.
9 changes: 2 additions & 7 deletions examples/adc-dma-circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ use panic_halt as _;

use cortex_m::{asm, singleton};

use stm32f1xx_hal::{
prelude::*,
pac,
adc,
dma::Half,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{adc, dma::Half, pac, prelude::*};

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -58,4 +53,4 @@ fn main() -> ! {
asm::bkpt();

loop {}
}
}
8 changes: 2 additions & 6 deletions examples/adc-dma-rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ use panic_halt as _;

use cortex_m::{asm, singleton};

use stm32f1xx_hal::{
prelude::*,
pac,
adc,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{adc, pac, prelude::*};

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -48,7 +44,7 @@ fn main() -> ! {
// one can call the is_done method of RxDma and only call wait after that method returns true.
let (_buf, adc_dma) = adc_dma.read(buf).wait();
asm::bkpt();

// Consumes the AdcDma struct, restores adc configuration to previous state and returns the
// Adc struct in normal mode.
let (_adc1, _adc_ch0, _dma_ch1) = adc_dma.split();
Expand Down
6 changes: 1 addition & 5 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

use panic_semihosting as _;

use stm32f1xx_hal::{
prelude::*,
pac,
adc,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{adc, pac, prelude::*};

use cortex_m_semihosting::hprintln;

Expand Down
14 changes: 8 additions & 6 deletions examples/adc_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

use panic_semihosting as _;

use stm32f1xx_hal::{
prelude::*,
pac,
adc,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{adc, pac, prelude::*};

use cortex_m_semihosting::hprintln;

Expand All @@ -20,7 +16,13 @@ fn main() -> ! {
let mut flash = p.FLASH.constrain();
let mut rcc = p.RCC.constrain();

let clocks = rcc.cfgr.use_hse(8.mhz()).sysclk(56.mhz()).pclk1(28.mhz()).adcclk(14.mhz()).freeze(&mut flash.acr);
let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(56.mhz())
.pclk1(28.mhz())
.adcclk(14.mhz())
.freeze(&mut flash.acr);
hprintln!("sysclk freq: {}", clocks.sysclk().0).unwrap();
hprintln!("adc freq: {}", clocks.adcclk().0).unwrap();

Expand Down
6 changes: 1 addition & 5 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ use panic_halt as _;

use nb::block;

use stm32f1xx_hal::{
prelude::*,
pac,
timer::Timer,
};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
fn main() -> ! {
Expand Down
8 changes: 2 additions & 6 deletions examples/blinky_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ use panic_halt as _;

use nb::block;

use stm32f1xx_hal::{
prelude::*,
pac,
timer::Timer,
};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
fn main() -> ! {
Expand All @@ -36,7 +32,7 @@ fn main() -> ! {
// Create an array of LEDS to blink
let mut leds = [
gpioc.pc13.into_push_pull_output(&mut gpioc.crh).downgrade(),
gpioa.pa1.into_push_pull_output(&mut gpioa.crl).downgrade()
gpioa.pa1.into_push_pull_output(&mut gpioa.crl).downgrade(),
];

// Wait for the timer to trigger an update and change the state of the LED
Expand Down
11 changes: 3 additions & 8 deletions examples/blinky_rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

use panic_halt as _;

use stm32f1xx_hal::{
prelude::*,
pac,
rtc::Rtc,
};
use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc};

use nb::block;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use nb::block;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -49,8 +45,7 @@ fn main() -> ! {
if led_on {
led.set_low().unwrap();
led_on = false;
}
else {
} else {
led.set_high().unwrap();
led_on = true;
}
Expand Down
7 changes: 2 additions & 5 deletions examples/blinky_timer_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ use stm32f1xx_hal as hal;

use crate::hal::{
gpio::*,
prelude::*,
pac::{interrupt, Interrupt, Peripherals, TIM2},
prelude::*,
timer::*,
};

use core::cell::RefCell;
use cortex_m::{
asm::wfi,
interrupt::Mutex,
peripheral::Peripherals as c_m_Peripherals};
use cortex_m::{asm::wfi, interrupt::Mutex, peripheral::Peripherals as c_m_Peripherals};
use cortex_m_rt::entry;

// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
Expand Down
6 changes: 1 addition & 5 deletions examples/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

use panic_halt as _;

use stm32f1xx_hal::{
prelude::*,
pac,
delay::Delay,
};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};

#[entry]
fn main() -> ! {
Expand Down
25 changes: 13 additions & 12 deletions examples/exti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@

use panic_halt as _;

use stm32f1xx_hal::{
prelude::*,
pac
};
use core::mem::MaybeUninit;
use cortex_m_rt::entry;
use pac::interrupt;
use core::mem::MaybeUninit;
use stm32f1xx_hal::gpio::*;
use stm32f1xx_hal::{pac, prelude::*};

// These two are owned by the ISR. main() may only access them during the initialization phase,
// where the interrupt is not yet enabled (i.e. no concurrent accesses can occur).
// After enabling the interrupt, main() may not have any references to these objects any more.
// For the sake of minimalism, we do not use RTFM here, which would be the better way.
static mut LED : MaybeUninit<stm32f1xx_hal::gpio::gpioc::PC13<Output<PushPull>>> = MaybeUninit::uninit();
static mut INT_PIN : MaybeUninit<stm32f1xx_hal::gpio::gpioa::PA7<Input<Floating>>> = MaybeUninit::uninit();
static mut LED: MaybeUninit<stm32f1xx_hal::gpio::gpioc::PC13<Output<PushPull>>> =
MaybeUninit::uninit();
static mut INT_PIN: MaybeUninit<stm32f1xx_hal::gpio::gpioa::PA7<Input<Floating>>> =
MaybeUninit::uninit();

#[interrupt]
fn EXTI9_5() {
let led = unsafe { &mut *LED.as_mut_ptr()};
let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr()};
let led = unsafe { &mut *LED.as_mut_ptr() };
let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr() };

if int_pin.check_interrupt() {
led.toggle().unwrap();
Expand All @@ -50,17 +49,19 @@ fn main() -> ! {
let mut gpioc = p.GPIOC.split(&mut rcc.apb2);
let mut afio = p.AFIO.constrain(&mut rcc.apb2);

let led = unsafe { &mut *LED.as_mut_ptr()};
let led = unsafe { &mut *LED.as_mut_ptr() };
*led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);

let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr()};
let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr() };
*int_pin = gpioa.pa7.into_floating_input(&mut gpioa.crl);
int_pin.make_interrupt_source(&mut afio);
int_pin.trigger_on_edge(&p.EXTI, Edge::RISING_FALLING);
int_pin.enable_interrupt(&p.EXTI);
} // initialization ends here

unsafe { pac::NVIC::unmask(pac::Interrupt::EXTI9_5); }
unsafe {
pac::NVIC::unmask(pac::Interrupt::EXTI9_5);
}

loop {}
}
2 changes: 1 addition & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use panic_semihosting as _;

use stm32f1xx_hal as _;
use cortex_m_semihosting::hprintln;
use stm32f1xx_hal as _;

use cortex_m_rt::entry;

Expand Down
2 changes: 1 addition & 1 deletion examples/itm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#![no_main]
#![no_std]

use panic_itm as _;
use cortex_m::iprintln;
use panic_itm as _;
use stm32f1xx_hal as _;

use cortex_m_rt::entry;
Expand Down
23 changes: 16 additions & 7 deletions examples/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

use panic_halt as _;

use stm32f1xx_hal::{
prelude::*,
pac,
};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{pac, prelude::*};

#[entry]
fn main() -> ! {
Expand All @@ -30,13 +27,25 @@ fn main() -> ! {
let mut gpioc = p.GPIOC.split(&mut rcc.apb2);

#[cfg(feature = "stm32f100")]
gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high().unwrap();
gpioc
.pc9
.into_push_pull_output(&mut gpioc.crh)
.set_high()
.unwrap();

#[cfg(feature = "stm32f101")]
gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high().unwrap();
gpioc
.pc9
.into_push_pull_output(&mut gpioc.crh)
.set_high()
.unwrap();

#[cfg(feature = "stm32f103")]
gpioc.pc13.into_push_pull_output(&mut gpioc.crh).set_low().unwrap();
gpioc
.pc13
.into_push_pull_output(&mut gpioc.crh)
.set_low()
.unwrap();

loop {}
}
8 changes: 2 additions & 6 deletions examples/mfrc522.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ use panic_itm as _;

use cortex_m::iprintln;

use stm32f1xx_hal::{
prelude::*,
pac,
spi::Spi,
};
use mfrc522::Mfrc522;
use cortex_m_rt::entry;
use embedded_hal::digital::{v1_compat::OldOutputPin, v2::OutputPin};
use mfrc522::Mfrc522;
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};

#[entry]
fn main() -> ! {
Expand Down
5 changes: 1 addition & 4 deletions examples/nojtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

use panic_halt as _;

use stm32f1xx_hal::{
prelude::*,
pac,
};
use cortex_m_rt::entry;
use stm32f1xx_hal::{pac, prelude::*};

#[entry]
fn main() -> ! {
Expand Down
2 changes: 1 addition & 1 deletion examples/panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use panic_semihosting as _;
//use panic_itm as _;
use stm32f1xx_hal as _;
use cortex_m_semihosting::hprintln;
use stm32f1xx_hal as _;

use cortex_m_rt::{entry, exception, ExceptionFrame};

Expand Down
16 changes: 9 additions & 7 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use panic_halt as _;

use cortex_m::asm;
use cortex_m_rt::entry;
use stm32f1xx_hal::{
prelude::*,
pac,
timer::{Tim2NoRemap, Timer},
prelude::*,
pwm::Channel,
time::U32Ext,
pwm::Channel
timer::{Tim2NoRemap, Timer},
};
use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -50,8 +50,11 @@ fn main() -> ! {
// let c3 = gpiob.pb8.into_alternate_push_pull(&mut gpiob.crh);
// let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh);

let mut pwm = Timer::tim2(p.TIM2, &clocks, &mut rcc.apb1)
.pwm::<Tim2NoRemap, _, _, _>(pins, &mut afio.mapr, 1.khz());
let mut pwm = Timer::tim2(p.TIM2, &clocks, &mut rcc.apb1).pwm::<Tim2NoRemap, _, _, _>(
pins,
&mut afio.mapr,
1.khz(),
);

//// Operations affecting all defined channels on the Timer

Expand Down Expand Up @@ -85,7 +88,6 @@ fn main() -> ! {

asm::bkpt();


// Extract the PwmChannel for C3
let mut pwm_channel = pwm.split().2;

Expand Down
Loading

0 comments on commit 1357e5a

Please sign in to comment.