Skip to content

Commit

Permalink
split gpio on modules
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jul 10, 2021
1 parent ead0ccc commit 95ebb02
Show file tree
Hide file tree
Showing 19 changed files with 501 additions and 273 deletions.
5 changes: 2 additions & 3 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use panic_halt as _;
use nb::block;

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

#[entry]
Expand Down Expand Up @@ -45,8 +44,8 @@ fn main() -> ! {
// Wait for the timer to trigger an update and change the state of the LED
loop {
block!(timer.wait()).unwrap();
led.set_high().unwrap();
led.set_high();
block!(timer.wait()).unwrap();
led.set_low().unwrap();
led.set_low();
}
}
9 changes: 4 additions & 5 deletions examples/blinky_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use panic_halt as _;
use nb::block;

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

#[entry]
Expand All @@ -31,19 +30,19 @@ 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(),
gpioc.pc13.into_push_pull_output(&mut gpioc.crh).erase(),
gpioa.pa1.into_push_pull_output(&mut gpioa.crl).erase(),
];

// Wait for the timer to trigger an update and change the state of the LED
loop {
block!(timer.wait()).unwrap();
for led in leds.iter_mut() {
led.set_high().unwrap();
led.set_high();
}
block!(timer.wait()).unwrap();
for led in leds.iter_mut() {
led.set_low().unwrap();
led.set_low();
}
}
}
5 changes: 2 additions & 3 deletions examples/blinky_rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use panic_halt as _;
use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc};

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

#[entry]
Expand Down Expand Up @@ -43,10 +42,10 @@ fn main() -> ! {
rtc.set_alarm(5);
block!(rtc.wait_alarm()).unwrap();
if led_on {
led.set_low().unwrap();
led.set_low();
led_on = false;
} else {
led.set_high().unwrap();
led.set_high();
led_on = true;
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/blinky_rtcalarm_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::hal::{
use core::cell::RefCell;
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;

// A type definition for the GPIO pin to be used for our LED
type LEDPIN = gpioc::PC13<Output<PushPull>>;
Expand Down
1 change: 0 additions & 1 deletion examples/blinky_timer_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::hal::{
use core::cell::RefCell;
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;

// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
// verbosity at runtime, at the cost of throwing off the timing of the blink
Expand Down
3 changes: 1 addition & 2 deletions examples/can-loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use bxcan::{
use panic_halt as _;

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

Expand Down Expand Up @@ -111,7 +110,7 @@ fn main() -> ! {

let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
let mut led = gpiob.pb9.into_push_pull_output(&mut gpiob.crh);
led.set_high().unwrap();
led.set_high();

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

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

#[entry]
Expand All @@ -34,9 +33,9 @@ fn main() -> ! {
let mut delay = Delay::new(cp.SYST, clocks);

loop {
led.set_high().unwrap();
led.set_high();
delay.delay_ms(1_000_u16);
led.set_low().unwrap();
led.set_low();
delay.delay_ms(1_000_u16);
}
}
2 changes: 1 addition & 1 deletion examples/exti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn EXTI9_5() {
let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr() };

if int_pin.check_interrupt() {
led.toggle().unwrap();
led.toggle();

// if we don't clear this bit, the ISR would trigger indefinitely
int_pin.clear_interrupt_pending_bit();
Expand Down
19 changes: 3 additions & 16 deletions examples/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use panic_halt as _;

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

#[entry]
Expand All @@ -27,25 +26,13 @@ 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();

#[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();

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

loop {}
}
4 changes: 2 additions & 2 deletions examples/mfrc522.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use panic_itm as _;
use cortex_m::iprintln;

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

Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() -> ! {
let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap();

let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
led.set_high().unwrap();
led.set_high();

loop {
if let Ok(atqa) = mfrc522.reqa() {
Expand Down
13 changes: 6 additions & 7 deletions examples/multi_mode_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use nb::block;

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use stm32f1xx_hal::{gpio::State, pac, prelude::*, timer::Timer};
use stm32f1xx_hal::{gpio::PinState, pac, prelude::*, timer::Timer};

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -37,16 +36,16 @@ 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()).unwrap();
hprintln!("{}", pin.is_high()).unwrap();
pin.as_push_pull_output(&mut gpioc.crh, |out| {
out.set_high().unwrap();
out.set_high();
block!(timer.wait()).unwrap();
out.set_low().unwrap();
out.set_low();
block!(timer.wait()).unwrap();
});
pin.as_push_pull_output_with_state(&mut gpioc.crh, State::High, |out| {
pin.as_push_pull_output_with_state(&mut gpioc.crh, PinState::High, |out| {
block!(timer.wait()).unwrap();
out.set_low().unwrap();
out.set_low();
block!(timer.wait()).unwrap();
});
}
Expand Down
6 changes: 3 additions & 3 deletions examples/nojtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ fn main() -> ! {
let mut pb4 = pb4.into_push_pull_output(&mut gpiob.crl);

loop {
pa15.toggle().unwrap();
pb3.toggle().unwrap();
pb4.toggle().unwrap();
pa15.toggle();
pb3.toggle();
pb4.toggle();
cortex_m::asm::delay(8_000_000);
}
}
9 changes: 4 additions & 5 deletions examples/timer-interrupt-rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use panic_halt as _;

use rtic::app;

use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{
gpio::{gpioc::PC13, Output, PushPull, State},
gpio::{gpioc::PC13, Output, PinState, PushPull},
pac,
prelude::*,
timer::{CountDownTimer, Event, Timer},
Expand Down Expand Up @@ -49,7 +48,7 @@ const APP: () = {
// function in order to configure the port. For pins 0-7, crl should be passed instead
let led = gpioc
.pc13
.into_push_pull_output_with_state(&mut gpioc.crh, State::High);
.into_push_pull_output_with_state(&mut gpioc.crh, PinState::High);
// Configure the syst timer to trigger an update every second and enables interrupt
let mut timer =
Timer::tim1(cx.device.TIM1, &clocks, &mut rcc.apb2).start_count_down(1.hz());
Expand Down Expand Up @@ -85,10 +84,10 @@ const APP: () = {

if *cx.resources.led_state {
// Uses resources managed by rtic to turn led off (on bluepill)
cx.resources.led.set_high().unwrap();
cx.resources.led.set_high();
*cx.resources.led_state = false;
} else {
cx.resources.led.set_low().unwrap();
cx.resources.led.set_low();
*cx.resources.led_state = true;
}
*COUNT += 1;
Expand Down
1 change: 0 additions & 1 deletion examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extern crate panic_semihosting;

use cortex_m::asm::delay;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::usb::{Peripheral, UsbBus};
use stm32f1xx_hal::{prelude::*, stm32};
use usb_device::prelude::*;
Expand Down
1 change: 0 additions & 1 deletion examples/usb_serial_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate panic_semihosting;

use cortex_m::asm::{delay, wfi};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::pac::{interrupt, Interrupt};
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
use stm32f1xx_hal::{prelude::*, stm32};
Expand Down
3 changes: 1 addition & 2 deletions examples/usb_serial_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
extern crate panic_semihosting;

use cortex_m::asm::delay;
use embedded_hal::digital::v2::OutputPin;
use rtic::app;
use stm32f1xx_hal::prelude::*;
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
Expand Down Expand Up @@ -45,7 +44,7 @@ const APP: () = {
// This forced reset is needed only for development, without it host
// will not reset your device when you upload new firmware.
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
usb_dp.set_low().unwrap();
usb_dp.set_low();
delay(clocks.sysclk().0 / 100);

let usb_dm = gpioa.pa11;
Expand Down
Loading

0 comments on commit 95ebb02

Please sign in to comment.