Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to embedded-hal 1.0.0-alpha.1 #251

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@ default-target = "x86_64-unknown-linux-gnu"

[dependencies]
cortex-m = "0.6.0"
nb = "0.1.2"
nb = "1"
cortex-m-rt = "0.6.8"
stm32f1 = "0.11.0"
as-slice = "0.1"

[dependencies.void]
default-features = false
version = "1.0.2"
embedded-hal = "=1.0.0-alpha.1"

[dependencies.cast]
default-features = false
version = "0.2.2"

[dependencies.embedded-hal]
version = "0.2.3"
features = ["unproven"]

[dependencies.stm32-usbd]
version = "0.5.0"
features = ["ram_access_1x16"]
Expand Down
4 changes: 2 additions & 2 deletions examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ fn main() -> ! {
let mut ch1 = gpiob.pb1.into_analog(&mut gpiob.crl);

loop {
let data: u16 = adc1.read(&mut ch0).unwrap();
let data: u16 = adc1.try_read(&mut ch0).unwrap();
hprintln!("adc1: {}", data).unwrap();

#[cfg(feature = "stm32f103")]
{
let data1: u16 = adc2.read(&mut ch1).unwrap();
let data1: u16 = adc2.try_read(&mut ch1).unwrap();
hprintln!("adc2: {}", data1).unwrap();
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use panic_halt as _;
use nb::block;

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

#[entry]
Expand Down Expand Up @@ -44,9 +44,9 @@ 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();
block!(timer.wait()).unwrap();
led.set_low().unwrap();
block!(timer.try_wait()).unwrap();
led.try_set_high().unwrap();
block!(timer.try_wait()).unwrap();
led.try_set_low().unwrap();
}
}
10 changes: 5 additions & 5 deletions examples/blinky_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use panic_halt as _;
use nb::block;

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

#[entry]
Expand Down Expand Up @@ -37,13 +37,13 @@ fn main() -> ! {

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

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

#[entry]
Expand Down Expand Up @@ -43,10 +43,10 @@ fn main() -> ! {
rtc.set_alarm(5);
block!(rtc.wait_alarm()).unwrap();
if led_on {
led.set_low().unwrap();
led.try_set_low().unwrap();
led_on = false;
} else {
led.set_high().unwrap();
led.try_set_high().unwrap();
led_on = true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/blinky_timer_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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;
use embedded_hal::digital::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 Expand Up @@ -62,8 +62,8 @@ fn TIM2() {
})
});

let _ = led.toggle();
let _ = tim.wait();
let _ = led.try_toggle();
let _ = tim.try_wait();
}

#[entry]
Expand All @@ -81,7 +81,7 @@ fn main() -> ! {
// Configure PC13 pin to blink LED
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
let _ = led.set_high(); // Turn off
let _ = led.try_set_high(); // Turn off

// Move the pin into our global storage
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
Expand Down
10 changes: 5 additions & 5 deletions examples/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use panic_halt as _;

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

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

loop {
led.set_high().unwrap();
delay.delay_ms(1_000_u16);
led.set_low().unwrap();
delay.delay_ms(1_000_u16);
led.try_set_high().unwrap();
delay.try_delay_ms(1_000_u16).unwrap();
led.try_set_low().unwrap();
delay.try_delay_ms(1_000_u16).unwrap();
}
}
14 changes: 7 additions & 7 deletions examples/dynamic_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nb::block;

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

#[entry]
Expand Down Expand Up @@ -37,13 +37,13 @@ fn main() -> ! {
// Wait for the timer to trigger an update and change the state of the LED
loop {
pin.make_floating_input(&mut gpioc.crh);
block!(timer.wait()).unwrap();
hprintln!("{}", pin.is_high().unwrap()).unwrap();
block!(timer.try_wait()).unwrap();
hprintln!("{}", pin.try_is_high().unwrap()).unwrap();

pin.make_push_pull_output(&mut gpioc.crh);
pin.set_high().unwrap();
block!(timer.wait()).unwrap();
pin.set_low().unwrap();
block!(timer.wait()).unwrap();
pin.try_set_high().unwrap();
block!(timer.try_wait()).unwrap();
pin.try_set_low().unwrap();
block!(timer.try_wait()).unwrap();
}
}
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.try_toggle().unwrap();

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

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

#[entry]
Expand All @@ -30,21 +30,21 @@ fn main() -> ! {
gpioc
.pc9
.into_push_pull_output(&mut gpioc.crh)
.set_high()
.try_set_high()
.unwrap();

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

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

loop {}
Expand Down
6 changes: 3 additions & 3 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::OutputPin;
use mfrc522::Mfrc522;
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};

Expand Down Expand Up @@ -39,10 +39,10 @@ fn main() -> ! {
);

let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap();
let mut mfrc522 = Mfrc522::new(spi, nss).unwrap();

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

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

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

#[entry]
Expand Down Expand Up @@ -36,18 +36,18 @@ 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();
block!(timer.try_wait()).unwrap();
hprintln!("{}", pin.try_is_high().unwrap()).unwrap();
pin.as_push_pull_output(&mut gpioc.crh, |out| {
out.set_high().unwrap();
block!(timer.wait()).unwrap();
out.set_low().unwrap();
block!(timer.wait()).unwrap();
out.try_set_high().unwrap();
block!(timer.try_wait()).unwrap();
out.try_set_low().unwrap();
block!(timer.try_wait()).unwrap();
});
pin.as_push_pull_output_with_state(&mut gpioc.crh, State::High, |out| {
block!(timer.wait()).unwrap();
out.set_low().unwrap();
block!(timer.wait()).unwrap();
block!(timer.try_wait()).unwrap();
out.try_set_low().unwrap();
block!(timer.try_wait()).unwrap();
});
}
}
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.try_toggle().unwrap();
pb3.try_toggle().unwrap();
pb4.try_toggle().unwrap();
cortex_m::asm::delay(8_000_000);
}
}
18 changes: 9 additions & 9 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,50 @@ fn main() -> ! {
//// Operations affecting all defined channels on the Timer

// Adjust period to 0.5 seconds
pwm.set_period(500.ms());
pwm.try_set_period(500.ms()).unwrap();

asm::bkpt();

// Return to the original frequency
pwm.set_period(1.khz());
pwm.try_set_period(1.khz()).unwrap();

asm::bkpt();

let max = pwm.get_max_duty();
let max = pwm.try_get_max_duty().unwrap();

//// Operations affecting single channels can be accessed through
//// the Pwm object or via dereferencing to the pin.

// Use the Pwm object to set C3 to full strength
pwm.set_duty(Channel::C3, max);
pwm.try_set_duty(Channel::C3, max).unwrap();

asm::bkpt();

// Use the Pwm object to set C3 to be dim
pwm.set_duty(Channel::C3, max / 4);
pwm.try_set_duty(Channel::C3, max / 4).unwrap();

asm::bkpt();

// Use the Pwm object to set C3 to be zero
pwm.set_duty(Channel::C3, 0);
pwm.try_set_duty(Channel::C3, 0).unwrap();

asm::bkpt();

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

// Use the PwmChannel object to set C3 to be full strength
pwm_channel.set_duty(max);
pwm_channel.try_set_duty(max).unwrap();

asm::bkpt();

// Use the PwmChannel object to set C3 to be dim
pwm_channel.set_duty(max / 4);
pwm_channel.try_set_duty(max / 4).unwrap();

asm::bkpt();

// Use the PwmChannel object to set C3 to be zero
pwm_channel.set_duty(0);
pwm_channel.try_set_duty(0).unwrap();

asm::bkpt();

Expand Down
Loading