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

Upgrade to embedded-hal v1.0.0 #476

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
## [Unreleased]

* MSRV increased to Rust 1.66.1 [#473]
* Upgraded to embedded-hal v1.0.0-rc.3

* delay: `delay_ms` and 'delay_us` methods now require importing: `use embedded_hal::delay::DelayNs;`

* pwm: Renamed `get_max_duty` -> `max_duty_cycle`; `set_duty` -> `set_duty_cycle`
* pwm: `enable` method now returns type `Result<(), PwmError>`
* pwm: LPTIMs can return a `NotEnabled` error from `set_duty_cycle`

* serial: Implement embedded-io `Read` and `Write` traits
* serial: Rename methods `read` -> `read_byte`; `write` -> `write_byte`

* rng: Use the `fill` method instead of the old `read` method

## [v0.15.1] 2023-11-03

Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
fugit = "0.3.5"
embedded-hal = { version = "0.2.6", features = ["unproven"] }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-dma = "0.2.0"
embedded-io = "0.6.1"
cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] }
defmt = { version = ">=0.2.0,<0.4", optional = true }
stm32h7 = { version = "^0.15.1", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions examples/blinky-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use cortex_m_rt::entry;
use stm32h7xx_hal::{pac, prelude::*};

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0

use log::info;

#[macro_use]
Expand Down Expand Up @@ -53,13 +55,13 @@ fn main() -> ! {
led2.set_low();
led3.set_high();
led4.set_low();
delay.delay_ms(500_u16);
delay.delay_ms(500);

led1.set_low();
led2.set_high();
led3.set_low();
led4.set_high();
delay.delay_ms(500_u16);
delay.delay_ms(500);
}
}
}
11 changes: 6 additions & 5 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#![no_std]

use cortex_m_rt::entry;
#[macro_use]
mod utilities;

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

use log::info;

#[macro_use]
mod utilities;

#[entry]
fn main() -> ! {
utilities::logger::init();
Expand Down Expand Up @@ -42,9 +43,9 @@ fn main() -> ! {

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

led.set_low();
delay.delay_ms(500_u16);
delay.delay_ms(500);
}
}
1 change: 1 addition & 0 deletions examples/blinky_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![no_std]

use cortex_m_rt::entry;
use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

#[macro_use]
Expand Down
10 changes: 5 additions & 5 deletions examples/blinky_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mod utilities;
extern crate nb;

use cortex_m_rt::entry;
use stm32h7xx_hal::{pac, prelude::*, time::MilliSeconds};
use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

use log::info;

Expand Down Expand Up @@ -50,13 +51,12 @@ fn main() -> ! {
for _ in 0..5 {
// 20ms wait with timer
led.toggle();
timer.start(MilliSeconds::from_ticks(20).into_rate());
timer.start(50.Hz()).unwrap();
block!(timer.wait()).ok();

// Delay for 500ms. Timer must operate correctly on next
// use.
// Delay for 500ms. Timer must operate correctly on next use.
led.toggle();
delay.delay_ms(500_u16);
delay.delay_ms(500);
}
}
}
3 changes: 2 additions & 1 deletion examples/can-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::hal::{
rcc,
rcc::rec,
};
use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use fdcan::{
config::NominalBitTiming,
filter::{StandardFilter, StandardFilterSlot},
Expand Down Expand Up @@ -135,7 +136,7 @@ fn main() -> ! {
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
delay.delay_ms(1);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
Expand Down
3 changes: 2 additions & 1 deletion examples/can-fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::hal::{
rcc,
rcc::rec,
};
use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use fdcan::{
config::{DataBitTiming, FrameTransmissionConfig, NominalBitTiming},
filter::{StandardFilter, StandardFilterSlot},
Expand Down Expand Up @@ -167,7 +168,7 @@ fn main() -> ! {
info!("Received Header: {:#X?}", rxheader);
info!("received data: {:X?}", &buffer);

delay.delay_ms(1_u16);
delay.delay_ms(1);
block!(can.transmit(rxheader.unwrap().to_tx_header(None), &buffer))
.unwrap();
info!("Transmit: {:X?}", buffer);
Expand Down
2 changes: 1 addition & 1 deletion examples/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use cortex_m::asm;
use cortex_m_rt::entry;
use stm32h7xx_hal::hal::Direction;
use stm32h7xx_hal::qei::Direction;
#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*};
Expand Down
2 changes: 2 additions & 0 deletions examples/display-dsi-command-teartest-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use log::info;
use otm8009a::Otm8009AConfig;
use stm32h7xx_hal::dsi::{ColorCoding, DsiChannel, DsiConfig, DsiPllConfig};

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0

extern crate cortex_m;
extern crate cortex_m_rt as rt;
use cortex_m_rt::{entry, exception};
Expand Down
2 changes: 2 additions & 0 deletions examples/display-dsi-video-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use log::info;
use otm8009a::Otm8009AConfig;
use stm32h7xx_hal::dsi::{ColorCoding, DsiChannel, DsiConfig, DsiPllConfig};

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0

extern crate cortex_m;
extern crate cortex_m_rt as rt;
use cortex_m_rt::{entry, exception};
Expand Down
2 changes: 2 additions & 0 deletions examples/display-dsi-video-teartest-stm32h747i-disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern crate cortex_m;
extern crate cortex_m_rt as rt;
use cortex_m_rt::{entry, exception};

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0

use crate::utilities_display::display_target::BufferedDisplay;
use stm32h7xx_hal::gpio::Speed;
use stm32h7xx_hal::ltdc;
Expand Down
3 changes: 2 additions & 1 deletion examples/embedded-graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern crate cortex_m_rt as rt;
use core::sync::atomic::{AtomicU32, Ordering};
use cortex_m_rt::{entry, exception};

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use stm32h7xx_hal::gpio::Speed;
use stm32h7xx_hal::rcc::CoreClocks;
use stm32h7xx_hal::{ltdc, xspi};
Expand Down Expand Up @@ -205,7 +206,7 @@ fn main() -> ! {
let mut lcd_disp_ctrl = gpiod.pd10.into_push_pull_output();
let mut lcd_bl_ctrl = gpiog.pg15.into_push_pull_output();

delay.delay_ms(40u8);
delay.delay_ms(40);

let mut ltdc = ltdc::Ltdc::new(dp.LTDC, ccdr.peripheral.LTDC, &ccdr.clocks);

Expand Down
6 changes: 3 additions & 3 deletions examples/gpio_with_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![no_std]

use cortex_m_rt::entry;

use embedded_hal_1::delay::DelayNs; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

use log::info;
Expand Down Expand Up @@ -45,10 +45,10 @@ fn main() -> ! {

loop {
led.set_high();
delay.delay_ms(100_u16);
delay.delay_ms(100);

led.set_low();
delay.delay_ms(100_u16);
delay.delay_ms(100);

let is_high = led.with_input(|x| x.is_high());
info!("LED pin high? {}", is_high);
Expand Down
5 changes: 3 additions & 2 deletions examples/i2c.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![no_main]
#![no_std]

use cortex_m_rt::entry;
#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*};

use cortex_m_rt::entry;
use embedded_hal_1::i2c::*; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

use log::info;

Expand Down
5 changes: 2 additions & 3 deletions examples/i2c4_bdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

use core::mem::MaybeUninit;

use cortex_m_rt::entry;
#[macro_use]
mod utilities;

use embedded_hal_1::i2c::*; // this example uses embedded-hal v1.0
use stm32h7xx_hal::dma::{
bdma::{BdmaConfig, StreamsTuple},
PeripheralToMemory, Transfer,
};

use stm32h7xx_hal::prelude::*;
use stm32h7xx_hal::{i2c, pac, pac::interrupt, rcc::LowPowerMode};

use cortex_m_rt::entry;

use log::info;

// The BDMA can only interact with SRAM4.
Expand Down
23 changes: 13 additions & 10 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use cortex_m::asm;
use cortex_m_rt::entry;

use embedded_hal_1::pwm::*; // this example uses embedded-hal v1.0
use stm32h7xx_hal::{pac, prelude::*};

#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*};

use log::info;

Expand Down Expand Up @@ -47,23 +50,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.max_duty_cycle();
pwm.set_duty_cycle(max / 2).unwrap();

info!("50%");
pwm.enable();
pwm.enable().unwrap();
asm::bkpt();

info!("25%");
pwm.set_duty(max / 4);
pwm.set_duty_cycle(max / 4).unwrap();
asm::bkpt();

info!("12.5%");
pwm.set_duty(max / 8);
pwm.set_duty_cycle(max / 8).unwrap();
asm::bkpt();

info!("100%");
pwm.set_duty(max);
pwm.set_duty_cycle(max).unwrap();
asm::bkpt();

let mut pwm = dp.TIM12.pwm(
Expand All @@ -74,9 +77,9 @@ fn main() -> ! {
);

// Output PWM on PB14
let max = pwm.get_max_duty();
pwm.set_duty(max / 2);
pwm.enable();
let max = pwm.max_duty_cycle();
pwm.set_duty_cycle(max / 2).unwrap();
pwm.enable().unwrap();

loop {
cortex_m::asm::nop()
Expand Down
Loading
Loading