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 #112

Closed
wants to merge 2 commits 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: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@ features = ["stm32h743", "rt"]
targets = ["thumbv7em-none-eabihf"]

[dependencies]
embedded-hal = "0.2.4"
embedded-hal = "=1.0.0-alpha.1"
cortex-m = "^0.6.2"
cortex-m-rt = "^0.6.12"
stm32h7 = "0.11.0"
void = { version = "1.0.2", default-features = false }
cast = { version = "0.2.3", default-features = false }
nb = "0.1.2"
nb = "1"
paste = "0.1.18"

[dependencies.bare-metal]
version = "0.2.5"
features = ["const-fn"]
version = "1"

[dev-dependencies]
panic-itm = "~0.4.1"
cortex-m-rtic = "0.5.3"
cortex-m-log = { version = "~0.6", features = ["itm"] }

[features]
default = ["unproven"]
unproven = ["embedded-hal/unproven"]
device-selected = []
revision_v = []
singlecore = []
Expand Down Expand Up @@ -89,3 +85,4 @@ required-features = ["revision_v"]
[[example]]
name = "qspi"
required-features = ["quadspi"]

2 changes: 1 addition & 1 deletion examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() -> ! {
let mut channel = gpioc.pc0.into_analog(); // ANALOG IN 10

loop {
let data: u32 = adc1.read(&mut channel).unwrap();
let data: u32 = adc1.try_read(&mut channel).unwrap();
// voltage = reading * (vref/resolution)
println!(
log,
Expand Down
4 changes: 2 additions & 2 deletions examples/adc12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fn main() -> ! {
let mut channel_pc3 = gpioc.pc3.into_analog(); // AIN 13

loop {
let data_pc2: u32 = adc1.read(&mut channel_pc2).unwrap();
let data_pc3: u32 = adc2.read(&mut channel_pc3).unwrap();
let data_pc2: u32 = adc1.try_read(&mut channel_pc2).unwrap();
let data_pc3: u32 = adc2.try_read(&mut channel_pc3).unwrap();
// voltage = reading * (vref/resolution)
println!(log, "ADC readings: {} {}", data_pc2, data_pc3);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern crate panic_itm;

use cortex_m_rt::entry;
use stm32h7xx_hal::hal::digital::v2::OutputPin;
use stm32h7xx_hal::hal::digital::OutputPin;
use stm32h7xx_hal::{pac, prelude::*};

use cortex_m_log::println;
Expand Down Expand Up @@ -44,11 +44,11 @@ fn main() -> ! {

loop {
loop {
led.set_high().unwrap();
delay.delay_ms(500_u16);
led.try_set_high().unwrap();
delay.try_delay_ms(500_u16).unwrap();

led.set_low().unwrap();
delay.delay_ms(500_u16);
led.try_set_low().unwrap();
delay.try_delay_ms(500_u16).unwrap();
}
}
}
6 changes: 3 additions & 3 deletions examples/blinky_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern crate panic_itm;

use cortex_m_rt::entry;
use stm32h7xx_hal::hal::digital::v2::ToggleableOutputPin;
use stm32h7xx_hal::hal::digital::ToggleableOutputPin;
use stm32h7xx_hal::{pac, prelude::*};

use cortex_m_log::println;
Expand Down Expand Up @@ -61,8 +61,8 @@ fn main() -> ! {
// acceptable for your application.
let period = random % 200_u32;

led.toggle().unwrap();
delay.delay_ms(period);
led.try_toggle().unwrap();
delay.try_delay_ms(period).unwrap();
}
Err(err) => println!(log, "RNG error: {:?}", err),
}
Expand Down
14 changes: 7 additions & 7 deletions examples/blinky_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate panic_itm;
extern crate nb;

use cortex_m_rt::entry;
use stm32h7xx_hal::hal::digital::v2::{OutputPin, ToggleableOutputPin};
use stm32h7xx_hal::hal::digital::{OutputPin, ToggleableOutputPin};
use stm32h7xx_hal::{pac, prelude::*};

use cortex_m_log::println;
Expand Down Expand Up @@ -41,7 +41,7 @@ fn main() -> ! {

// Configure PE1 as output.
let mut led = gpioe.pe1.into_push_pull_output();
led.set_low().unwrap();
led.try_set_low().unwrap();

// Get the delay provider.
let mut delay = cp.SYST.delay(ccdr.clocks);
Expand All @@ -52,14 +52,14 @@ fn main() -> ! {
loop {
for _ in 0..5 {
// 20ms wait with timer
led.toggle().unwrap();
timer.start(20.ms());
block!(timer.wait()).ok();
led.try_toggle().unwrap();
timer.try_start(20.ms()).unwrap();
block!(timer.try_wait()).ok();

// Delay for 500ms. Timer must operate correctly on next
// use.
led.toggle().unwrap();
delay.delay_ms(500_u16);
led.try_toggle().unwrap();
delay.try_delay_ms(500_u16).unwrap();
}
}
}
2 changes: 1 addition & 1 deletion examples/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate panic_itm;

use cortex_m::asm;
use cortex_m_rt::entry;
use stm32h7xx_hal::hal::Direction;
use stm32h7xx_hal::hal::qei::Direction;
use stm32h7xx_hal::{pac, prelude::*};

use stm32h7xx_hal::traits::DacOut;
Expand Down
2 changes: 1 addition & 1 deletion examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ fn main() -> ! {
let mut buf = [0x60];
loop {
buf[0] = 0x11;
i2c.write_read(0x76, &buf.clone(), &mut buf).unwrap();
i2c.try_write_read(0x76, &buf.clone(), &mut buf).unwrap();
}
}
12 changes: 6 additions & 6 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ fn main() -> ! {
.pwm(pins, 10.khz(), ccdr.peripheral.TIM1, &ccdr.clocks);

// Output PWM on PA8
let max = pwm.get_max_duty();
pwm.set_duty(max / 2);
let max = pwm.try_get_max_duty().unwrap();
pwm.try_set_duty(max / 2).unwrap();

println!(log, "50%");
pwm.enable();
pwm.try_enable().unwrap();
asm::bkpt();

println!(log, "25%");
pwm.set_duty(max / 4);
pwm.try_set_duty(max / 4).unwrap();
asm::bkpt();

println!(log, "12.5%");
pwm.set_duty(max / 8);
pwm.try_set_duty(max / 8).unwrap();
asm::bkpt();

println!(log, "100%");
pwm.set_duty(max);
pwm.try_set_duty(max).unwrap();
asm::bkpt();

loop {}
Expand Down
4 changes: 2 additions & 2 deletions examples/rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern crate panic_itm;
extern crate rtic;

use stm32h7xx_hal::hal::digital::v2::ToggleableOutputPin;
use stm32h7xx_hal::hal::digital::ToggleableOutputPin;

use rtic::app;
use stm32h7xx_hal::gpio::{gpioc::PC13, gpioi::PI13};
Expand Down Expand Up @@ -52,6 +52,6 @@ const APP: () = {
#[task(binds = EXTI15_10, resources = [button, led])]
fn button_click(ctx: button_click::Context) {
ctx.resources.button.clear_interrupt_pending_bit();
ctx.resources.led.toggle().unwrap();
ctx.resources.led.try_toggle().unwrap();
}
};
10 changes: 5 additions & 5 deletions examples/rtic_timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern crate panic_itm;
extern crate rtic;

use stm32h7xx_hal::hal::digital::v2::ToggleableOutputPin;
use stm32h7xx_hal::hal::digital::ToggleableOutputPin;

use rtic::app;
use stm32h7xx_hal::gpio::gpioi::{PI12, PI13, PI14, PI15};
Expand Down Expand Up @@ -86,24 +86,24 @@ const APP: () = {
#[task(binds = TIM1_UP, resources = [led1, timer1])]
fn timer1_tick(ctx: timer1_tick::Context) {
ctx.resources.timer1.clear_irq();
ctx.resources.led1.toggle().unwrap();
ctx.resources.led1.try_toggle().unwrap();
}

#[task(binds = TIM2, resources = [led2, timer2])]
fn timer2_tick(ctx: timer2_tick::Context) {
ctx.resources.timer2.clear_irq();
ctx.resources.led2.toggle().unwrap();
ctx.resources.led2.try_toggle().unwrap();
}

#[task(binds = TIM8_BRK_TIM12, resources = [led3, timer3])]
fn timer3_tick(ctx: timer3_tick::Context) {
ctx.resources.timer3.clear_irq();
ctx.resources.led3.toggle().unwrap();
ctx.resources.led3.try_toggle().unwrap();
}

#[task(binds = TIM17, resources = [led4, timer4])]
fn timer4_tick(ctx: timer4_tick::Context) {
ctx.resources.timer4.clear_irq();
ctx.resources.led4.toggle().unwrap();
ctx.resources.led4.try_toggle().unwrap();
}
};
4 changes: 2 additions & 2 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() -> ! {

loop {
// Echo what is received on the serial link.
let received = block!(rx.read()).unwrap();
block!(tx.write(received)).ok();
let received = block!(rx.try_read()).unwrap();
block!(tx.try_write(received)).ok();
}
}
6 changes: 3 additions & 3 deletions examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ fn main() -> ! {
);

// Write fixed data
spi.write(&[0x11u8, 0x22, 0x33]).unwrap();
spi.try_write(&[0x11u8, 0x22, 0x33]).unwrap();

// Echo what is received on the SPI
let mut received = 0;
loop {
block!(spi.send(received)).ok();
received = block!(spi.read()).unwrap();
block!(spi.try_send(received)).ok();
received = block!(spi.try_read()).unwrap();
}
}
7 changes: 4 additions & 3 deletions examples/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ fn main() -> ! {
// Setup Temperature Sensor on the disabled ADC
let mut channel = adc::Temperature::new();
channel.enable(&adc3);
delay.delay_us(25_u16);
delay.try_delay_us(25_u16).unwrap();
let mut adc3 = adc3.enable();

let vdda = 2.500; // Volts

loop {
let word: u32 =
adc3.read(&mut channel).expect("Temperature read failed.");
let word: u32 = adc3
.try_read(&mut channel)
.expect("Temperature read failed.");

// Average slope
let cal = (110.0 - 30.0)
Expand Down
2 changes: 1 addition & 1 deletion examples/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() -> ! {

// Enable the watchdog with a limit of 100 ms and wait forever
// -> restart the chip
watchdog.start(100.ms());
watchdog.try_start(100.ms()).unwrap();

loop {}
}
14 changes: 6 additions & 8 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::hal::adc::{Channel, OneShot};
use crate::hal::blocking::delay::DelayUs;

use core::convert::Infallible;
use core::marker::PhantomData;

use crate::stm32::{ADC1, ADC2, ADC3, ADC3_COMMON};
Expand Down Expand Up @@ -159,10 +160,7 @@ macro_rules! adc_pins {
$(
impl Channel<$ADC> for $input {
type ID = u8;

fn channel() -> u8 {
$chan
}
const CHANNEL: Self::ID = $chan;
}
)+
};
Expand Down Expand Up @@ -438,7 +436,7 @@ macro_rules! adc_hal {
w.deeppwd().clear_bit()
.advregen().set_bit()
);
delay.delay_us(10_u8);
delay.try_delay_us(10_u8).unwrap(); // infallible
}

/// Enables Deeppowerdown-mode and disables voltage regulator
Expand Down Expand Up @@ -768,10 +766,10 @@ macro_rules! adc_hal {
WORD: From<u32>,
PIN: Channel<$ADC, ID = u8>,
{
type Error = ();
type Error = Infallible;

fn read(&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
let res = self.convert(PIN::channel());
fn try_read(&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
let res = self.convert(PIN::CHANNEL);
Ok(res.into())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ macro_rules! dac {
let mut trim = 0;
while true {
dac.ccr.modify(|_, w| unsafe { w.$trim().bits(trim) });
delay.delay_us(64_u32);
delay.try_delay_us(64_u32).ok(); // infallible
if dac.sr.read().$cal_flag().bit() {
break;
}
Expand Down
Loading