diff --git a/Cargo.toml b/Cargo.toml
index eb55bbfa..d4b3465d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ repository = "https://github.com/stm32-rs/stm32g4xx-hal"
version = "0.0.2"
[dependencies]
-nb = "0.1.1"
+nb = "1"
stm32g4 = "0.15.1"
paste = "1.0"
bitflags = "1.2"
@@ -21,6 +21,7 @@ static_assertions = "1.1"
fugit = "0.3.7"
stm32-usbd = { version = "0.7.0", optional = true }
fixed = { version = "1.28.0", optional = true }
+embedded-io = "0.6"
[dependencies.cortex-m]
version = "0.7.7"
@@ -38,9 +39,13 @@ default-features = false
features = ["const-fn"]
version = "0.2.5"
-[dependencies.embedded-hal]
+[dependencies.embedded-hal-old]
+package = "embedded-hal"
features = ["unproven"]
-version = "0.2.4"
+version = "0.2.7"
+
+[dependencies.embedded-hal]
+version = "1.0.0"
[dependencies.embedded-dma]
version = "0.1.2"
@@ -93,7 +98,7 @@ stm32g4a1 = ["stm32g4/stm32g4a1"]
log-itm = ["cortex-m-log/itm"]
log-rtt = []
log-semihost = ["cortex-m-log/semihosting"]
-defmt = ["dep:defmt", "fugit/defmt"]
+defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3", "embedded-hal/defmt-03", "embedded-io/defmt-03"]
cordic = ["dep:fixed"]
[profile.dev]
diff --git a/examples/adc-continious-dma.rs b/examples/adc-continious-dma.rs
index e7ceb824..9788af0e 100644
--- a/examples/adc-continious-dma.rs
+++ b/examples/adc-continious-dma.rs
@@ -2,6 +2,7 @@
#![no_main]
mod utils;
+use utils::logger::info;
use crate::hal::{
adc::{
@@ -20,7 +21,6 @@ use crate::hal::{
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use utils::logger::info;
#[entry]
fn main() -> ! {
@@ -48,6 +48,7 @@ fn main() -> ! {
info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);
+
let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
diff --git a/examples/adc-one-shot-dma.rs b/examples/adc-one-shot-dma.rs
index 898e7f02..7226f6a2 100644
--- a/examples/adc-one-shot-dma.rs
+++ b/examples/adc-one-shot-dma.rs
@@ -17,10 +17,9 @@ use crate::hal::{
};
use stm32g4xx_hal as hal;
-use log::info;
-
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
@@ -49,6 +48,7 @@ fn main() -> ! {
info!("Setup Adc1");
let mut delay = cp.SYST.delay(&rcc.clocks);
+
let mut adc = dp
.ADC1
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
diff --git a/examples/adc-one-shot.rs b/examples/adc-one-shot.rs
index 7e727430..43f36ecb 100644
--- a/examples/adc-one-shot.rs
+++ b/examples/adc-one-shot.rs
@@ -3,7 +3,6 @@
use crate::hal::{
adc::{config::SampleTime, AdcClaim},
- delay::SYSTDelayExt,
pwr::PwrExt,
rcc::Config,
stm32::Peripherals,
@@ -13,10 +12,9 @@ use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
-
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs
index 7e815c4c..8b55119f 100644
--- a/examples/blinky_delay.rs
+++ b/examples/blinky_delay.rs
@@ -3,7 +3,6 @@
#![no_main]
#![no_std]
-use hal::delay::DelayFromCountDownTimer;
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::rcc::Config;
@@ -37,7 +36,7 @@ fn main() -> ! {
info!("Init Timer2 delay");
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
- let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
+ let mut delay_tim2 = timer2.start_count_down(100.millis()).delay();
loop {
info!("Toggle");
@@ -47,6 +46,6 @@ fn main() -> ! {
info!("Toggle");
led.toggle().unwrap();
info!("TIM2 delay");
- delay_tim2.delay_ms(1000_u16);
+ delay_tim2.delay_ms(1000);
}
}
diff --git a/examples/button.rs b/examples/button.rs
index f119b6a8..ef7990ec 100644
--- a/examples/button.rs
+++ b/examples/button.rs
@@ -14,7 +14,7 @@ use core::cell::RefCell;
use core::sync::atomic::{AtomicBool, Ordering};
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
-use embedded_hal::digital::v2::OutputPin;
+use embedded_hal::digital::OutputPin;
type ButtonPin = gpioc::PC13>;
diff --git a/examples/can-echo.rs b/examples/can-echo.rs
index a0d81fee..3126e0d4 100644
--- a/examples/can-echo.rs
+++ b/examples/can-echo.rs
@@ -22,10 +22,9 @@ use core::num::{NonZeroU16, NonZeroU8};
use cortex_m_rt::entry;
-use log::info;
-
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
@@ -116,7 +115,7 @@ fn main() -> ! {
bit_rate_switching: false,
marker: None,
};
- info!("Initial Header: {:#X?}", &header);
+ info!("Initial Header: {:#?}", &header);
info!("Transmit initial message");
block!(can.transmit(header, &buffer)).unwrap();
diff --git a/examples/comp_w_dac.rs b/examples/comp_w_dac.rs
index 20600068..a2a3d703 100644
--- a/examples/comp_w_dac.rs
+++ b/examples/comp_w_dac.rs
@@ -10,7 +10,6 @@ use rt::entry;
#[entry]
fn main() -> ! {
- use embedded_hal::Direction;
use hal::comparator::{self, ComparatorExt, ComparatorSplit};
use hal::dac::{Dac1IntSig1, DacExt, DacOut};
use hal::delay::SYSTDelayExt;
@@ -49,6 +48,11 @@ fn main() -> ! {
comp.output_pin(led2);
let _comp1 = comp.enable().lock();
+ enum Direction {
+ Upcounting,
+ Downcounting,
+ }
+
let mut dir = Direction::Upcounting;
let mut val = 0;
diff --git a/examples/dac.rs b/examples/dac.rs
index 7348f703..45552572 100644
--- a/examples/dac.rs
+++ b/examples/dac.rs
@@ -8,7 +8,6 @@
#![no_main]
#![no_std]
-use embedded_hal::Direction;
use hal::dac::{DacExt, DacOut, GeneratorConfig};
use hal::delay::SYSTDelayExt;
use hal::gpio::GpioExt;
@@ -37,6 +36,11 @@ fn main() -> ! {
// dac_generator will have its value set automatically from its internal noise generator
let mut dac_generator = dac1ch2.enable_generator(GeneratorConfig::noise(11));
+ enum Direction {
+ Upcounting,
+ Downcounting,
+ }
+
let mut dir = Direction::Upcounting;
let mut val = 0;
diff --git a/examples/i2c-bme680.rs b/examples/i2c-bme680.rs
index 2fa8a9c0..f3f18033 100644
--- a/examples/i2c-bme680.rs
+++ b/examples/i2c-bme680.rs
@@ -5,7 +5,7 @@
use bme680::*;
use core::time::Duration;
-use embedded_hal::blocking::delay::DelayMs;
+use embedded_hal::delay::DelayNs;
use hal::delay::DelayFromCountDownTimer;
use hal::i2c::Config;
use hal::prelude::*;
@@ -15,10 +15,10 @@ use hal::timer::Timer;
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
diff --git a/examples/i2c-mpu6050.rs b/examples/i2c-mpu6050.rs
index a0be9c10..a9bf69ad 100644
--- a/examples/i2c-mpu6050.rs
+++ b/examples/i2c-mpu6050.rs
@@ -10,11 +10,11 @@ use hal::time::{ExtU32, RateExtU32};
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
use mpu6050::*;
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
diff --git a/examples/i2c.rs b/examples/i2c.rs
index 78104767..beea9ae2 100644
--- a/examples/i2c.rs
+++ b/examples/i2c.rs
@@ -10,10 +10,10 @@ use hal::time::RateExtU32;
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
@@ -35,7 +35,7 @@ fn main() -> ! {
let buf: [u8; 1] = [0];
loop {
- match i2c.write(0x3c, &buf) {
+ match i2c.write(0x3Cu8, &buf) {
Ok(_) => info!("ok"),
Err(err) => info!("error: {:?}", err),
}
diff --git a/examples/pwm.rs b/examples/pwm.rs
index 9d2ca8e8..cee8f7d7 100644
--- a/examples/pwm.rs
+++ b/examples/pwm.rs
@@ -11,6 +11,7 @@ use hal::stm32;
use hal::time::RateExtU32;
use stm32g4xx_hal as hal;
extern crate cortex_m_rt as rt;
+use hal::prelude::SetDutyCycle;
#[macro_use]
mod utils;
@@ -26,7 +27,7 @@ fn main() -> ! {
let mut pwm = dp.TIM1.pwm(pin, 100.Hz(), &mut rcc);
- pwm.set_duty(pwm.get_max_duty() / 2);
+ let _ = pwm.set_duty_cycle_percent(50);
pwm.enable();
loop {
diff --git a/examples/spi-dma.rs b/examples/spi-dma.rs
index 04533e3f..dcfff763 100644
--- a/examples/spi-dma.rs
+++ b/examples/spi-dma.rs
@@ -28,6 +28,7 @@ use stm32g4xx_hal::dma::TransferExt;
#[macro_use]
mod utils;
+// use utils::logger::info;
const BUFFER_SIZE: usize = 254;
@@ -68,6 +69,6 @@ fn main() -> ! {
.into_memory_to_peripheral_transfer(spi.enable_tx_dma(), &mut dma_buf[..], config);
transfer_dma.start(|_spi| {});
loop {
- delay_tim2.delay_ms(1000_u16);
+ delay_tim2.delay_ms(1000);
}
}
diff --git a/examples/spi-example.rs b/examples/spi-example.rs
index 2543e3fc..a661e248 100644
--- a/examples/spi-example.rs
+++ b/examples/spi-example.rs
@@ -5,14 +5,14 @@
#![no_main]
#![no_std]
-use crate::hal::{
- block,
+use hal::{
delay::DelayFromCountDownTimer,
gpio::gpioa::PA5,
gpio::gpioa::PA6,
gpio::gpioa::PA7,
gpio::Alternate,
gpio::AF5,
+ hal_02::spi::FullDuplex,
prelude::*,
pwr::PwrExt,
rcc::Config,
@@ -59,11 +59,11 @@ fn main() -> ! {
for byte in message.iter() {
cs.set_low().unwrap();
spi.send(*byte as u8).unwrap();
- received_byte = block!(spi.read()).unwrap();
+ received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap();
cs.set_high().unwrap();
info!("{}", received_byte as char);
}
- delay_tim2.delay_ms(1000_u16);
+ delay_tim2.delay_ms(1000);
}
}
diff --git a/examples/uart-dma-tx.rs b/examples/uart-dma-tx.rs
index 78abeb4f..bc92922a 100644
--- a/examples/uart-dma-tx.rs
+++ b/examples/uart-dma-tx.rs
@@ -16,10 +16,10 @@ use hal::{rcc, stm32};
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
diff --git a/examples/uart-fifo.rs b/examples/uart-fifo.rs
index eb6ddb88..801ae471 100644
--- a/examples/uart-fifo.rs
+++ b/examples/uart-fifo.rs
@@ -7,6 +7,7 @@ extern crate cortex_m_rt as rt;
use core::fmt::Write;
+use embedded_io::{Read, ReadReady};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::*;
@@ -14,10 +15,10 @@ use hal::{rcc, stm32};
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use log::info;
#[macro_use]
mod utils;
+use utils::logger::info;
#[entry]
fn main() -> ! {
@@ -50,23 +51,24 @@ fn main() -> ! {
let (mut tx1, mut rx1) = usart.split();
+ let mut buffer = [0; 4];
let mut cnt = 0;
loop {
if rx1.fifo_threshold_reached() {
loop {
- match rx1.read() {
- Err(nb::Error::WouldBlock) => {
- // no more data available in fifo
- break;
- }
- Err(nb::Error::Other(_err)) => {
+ match rx1.read_ready() {
+ Ok(true) => (),
+ Ok(false) => break, // no more data available in fifo
+ Err(e) => {
// Handle other error Overrun, Framing, Noise or Parity
- }
- Ok(byte) => {
- writeln!(tx1, "{}: {}\r", cnt, byte).unwrap();
- cnt += 1;
+ utils::logger::error!("Error: {:?}", e);
}
}
+
+ let count = rx1.read(&mut buffer).unwrap();
+ let bytes = &buffer[count];
+ writeln!(tx1, "{}: {}\r", cnt, bytes).unwrap();
+ cnt += count;
}
}
}
diff --git a/examples/uart.rs b/examples/uart.rs
index 883ef3b7..e4ec6519 100644
--- a/examples/uart.rs
+++ b/examples/uart.rs
@@ -3,8 +3,7 @@
#![no_main]
#![no_std]
-use core::fmt::Write;
-
+use embedded_io::{Read, Write};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::FullConfig;
@@ -12,7 +11,6 @@ use hal::{rcc, stm32};
use stm32g4xx_hal as hal;
use cortex_m_rt::entry;
-use nb::block;
use utils::logger::info;
#[macro_use]
@@ -54,11 +52,15 @@ fn main() -> ! {
.unwrap();
writeln!(usart, "Hello USART3, yay!!\r\n").unwrap();
+ let mut read_buf = [0u8; 8];
+ usart.read_exact(&mut read_buf).unwrap();
+ usart.write_all(&read_buf).unwrap();
+ let mut single_byte_buffer = [0; 1];
let mut cnt = 0;
loop {
- match block!(usart.read()) {
- Ok(byte) => writeln!(usart, "{}: {}\r", cnt, byte).unwrap(),
+ match usart.read_exact(&mut single_byte_buffer) {
+ Ok(()) => writeln!(usart, "{}: {}\r", cnt, single_byte_buffer[0]).unwrap(),
Err(e) => writeln!(usart, "E: {:?}\r", e).unwrap(),
};
cnt += 1;
diff --git a/src/adc.rs b/src/adc.rs
index b40df49a..e2ed773d 100644
--- a/src/adc.rs
+++ b/src/adc.rs
@@ -1,5 +1,5 @@
//! Analog to digital converter configuration.
-//! https://github.com/stm32-rs/stm32l4xx-hal/blob/master/src/adc.rs
+//!
#![deny(missing_docs)]
@@ -20,10 +20,8 @@ use crate::{
};
use core::fmt;
use core::marker::PhantomData;
-use embedded_hal::{
- adc::{Channel, OneShot},
- blocking::delay::DelayUs,
-};
+use embedded_hal::delay::DelayNs;
+use embedded_hal_old::adc::{Channel, OneShot};
use self::config::ExternalTrigger12;
@@ -172,7 +170,7 @@ macro_rules! adc_opamp {
/// Contains types related to ADC configuration
pub mod config {
- use embedded_hal::adc::Channel;
+ use embedded_hal_old::adc::Channel;
/// The place in the sequence a given channel should be captured
#[derive(Debug, PartialEq, PartialOrd, Copy, Clone)]
@@ -316,7 +314,8 @@ pub mod config {
pub enum ClockMode {
/// (Asynchronous clock mode), adc_ker_ck. generated at product level (refer to Section 6: Reset and clock control (RCC)
Asynchronous,
- /// (Synchronous clock mode). adc_hclk/1 This configuration must be enabled only if the AHB clock prescaler is set to 1 (HPRE[3:0] = 0xxx in RCC_CFGR register) and if the system clock has a 50% duty cycle.
+ /// (Synchronous clock mode). adc_hclk/1
+ /// This configuration must be enabled only if the AHB clock prescaler is set to 1 (HPRE\[3:0\] = 0xxx in RCC_CFGR register) and if the system clock has a 50% duty cycle.
Synchronous_Div_1,
/// Synchronous clock mode. adc_hclk/2
Synchronous_Div_2,
@@ -1172,9 +1171,9 @@ impl Conversion {
!self.is_active()
}
- /// Converts from Conversion to Option.
+ /// Converts from `Conversion` to `Option`.
///
- /// Converts self into an Option, consuming self, and discarding the adc, if it is stopped.
+ /// Converts self into an `Option`, consuming self, and discarding the adc, if it is stopped.
#[inline(always)]
pub fn active(self) -> Option> {
match self {
@@ -1183,9 +1182,9 @@ impl Conversion {
}
}
- /// Converts from Conversion to Option.
+ /// Converts from `Conversion` to `Option`.
///
- /// Converts self into an Option, consuming self, and discarding the adc, if it is still active.
+ /// Converts self into an `Option`, consuming self, and discarding the adc, if it is still active.
#[inline(always)]
pub fn stopped(self) -> Option> {
match self {
@@ -1385,7 +1384,7 @@ pub trait AdcClaim {
self,
cs: ClockSource,
rcc: &Rcc,
- delay: &mut impl DelayUs,
+ delay: &mut impl DelayNs,
reset: bool,
) -> Adc;
@@ -1395,7 +1394,7 @@ pub trait AdcClaim {
cs: ClockSource,
rcc: &Rcc,
config: config::AdcConfig,
- delay: &mut impl DelayUs,
+ delay: &mut impl DelayNs,
reset: bool,
) -> Adc;
}
@@ -1587,7 +1586,7 @@ macro_rules! adc {
/// Powers-up an powered-down Adc
#[inline(always)]
- pub fn power_up(&mut self, delay: &mut impl DelayUs) {
+ pub fn power_up(&mut self, delay: &mut impl DelayNs) {
if self.is_deeppwd_enabled() {
self.disable_deeppwd_down();
}
@@ -1620,7 +1619,7 @@ macro_rules! adc {
/// Enables the Voltage Regulator
#[inline(always)]
- pub fn enable_vreg(&mut self, delay: &mut impl DelayUs) {
+ pub fn enable_vreg(&mut self, delay: &mut impl DelayNs) {
self.adc_reg.cr.modify(|_, w| w.advregen().set_bit());
while !self.adc_reg.cr.read().advregen().bit_is_set() {}
@@ -2129,7 +2128,7 @@ macro_rules! adc {
///
/// TODO: fix needing SYST
#[inline(always)]
- fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayUs, reset: bool) -> Adc {
+ fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayNs, reset: bool) -> Adc {
unsafe {
let rcc_ptr = &(*stm32::RCC::ptr());
stm32::$adc_type::enable(rcc_ptr);
@@ -2153,7 +2152,7 @@ macro_rules! adc {
/// claims and configures the Adc
#[inline(always)]
- fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig<$trigger_type>, delay: &mut impl DelayUs, reset :bool) -> Adc {
+ fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig<$trigger_type>, delay: &mut impl DelayNs, reset :bool) -> Adc {
let mut adc = self.claim(cs, rcc, delay, reset);
adc.adc.config = config;
@@ -2177,7 +2176,7 @@ macro_rules! adc {
impl Adc {
/// Powers-up an powered-down Adc
#[inline(always)]
- pub fn power_up(mut self, delay: &mut impl DelayUs) -> Adc {
+ pub fn power_up(mut self, delay: &mut impl DelayNs) -> Adc {
self.adc.power_up(delay);
Adc {
diff --git a/src/dac.rs b/src/dac.rs
index 109374c0..5289da29 100644
--- a/src/dac.rs
+++ b/src/dac.rs
@@ -12,7 +12,7 @@ use crate::gpio::gpioa::{PA4, PA5, PA6};
use crate::gpio::DefaultMode;
use crate::rcc::{self, *};
use crate::stm32::{DAC1, DAC2, DAC3, DAC4, RCC};
-use hal::blocking::delay::DelayUs;
+use embedded_hal::delay::DelayNs;
pub trait DacOut {
fn set_value(&mut self, val: V);
@@ -230,9 +230,9 @@ macro_rules! dac_helper {
///
/// After the calibration operation, the DAC channel is
/// disabled.
- pub fn calibrate_buffer(self, delay: &mut T) -> $CX
+ pub fn calibrate_buffer(self, delay: &mut D) -> $CX
where
- T: DelayUs,
+ D: DelayNs
{
let dac = unsafe { &(*<$DAC>::ptr()) };
dac.dac_cr.modify(|_, w| w.$en().clear_bit());
diff --git a/src/delay.rs b/src/delay.rs
index f40ffeae..1b869adf 100644
--- a/src/delay.rs
+++ b/src/delay.rs
@@ -1,9 +1,9 @@
//! Delay providers
//!
//! There are currently two delay providers. In general you should prefer to use
-//! [Delay](Delay), however if you do not have access to `SYST` you can use
-//! [DelayFromCountDownTimer](DelayFromCountDownTimer) with any timer that
-//! implements the [CountDown](embedded_hal::timer::CountDown) trait. This can be
+//! [Delay], however if you do not have access to `SYST` you can use
+//! [DelayFromCountDownTimer] with any timer that
+//! implements the [CountDown](embedded_hal_old::timer::CountDown) trait. This can be
//! useful if you're using [RTIC](https://rtic.rs)'s schedule API, which occupies
//! the `SYST` peripheral.
//!
@@ -38,24 +38,83 @@
use crate::rcc::Clocks;
use crate::time::MicroSecond;
-pub use cortex_m::delay::*;
+pub use cortex_m::delay::Delay;
use cortex_m::peripheral::SYST;
+use fugit::ExtU32Ceil;
use crate::nb::block;
use crate::time::ExtU32;
-use embedded_hal::blocking::delay::{DelayMs, DelayUs};
+use embedded_hal::delay::DelayNs;
+use embedded_hal_old::blocking::delay::{DelayMs, DelayUs};
-pub trait CountDown: embedded_hal::timer::CountDown {
+pub trait CountDown: embedded_hal_old::timer::CountDown {
fn max_period(&self) -> MicroSecond;
}
pub trait SYSTDelayExt {
- fn delay(self, clocks: &Clocks) -> Delay;
+ fn delay(self, clocks: &Clocks) -> SystDelay;
}
impl SYSTDelayExt for SYST {
- fn delay(self, clocks: &Clocks) -> Delay {
- Delay::new(self, clocks.ahb_clk.raw())
+ fn delay(self, clocks: &Clocks) -> SystDelay {
+ SystDelay(Delay::new(self, clocks.ahb_clk.raw()))
+ }
+}
+
+/// Delay provider
+pub struct SystDelay(Delay);
+
+impl DelayNs for SystDelay {
+ // TODO: the current fallback to 1us resolution is a stopgap until the module is reworked
+ fn delay_ns(&mut self, ns: u32) {
+ self.0.delay_us(ns.div_ceil(1000))
+ }
+ fn delay_us(&mut self, us: u32) {
+ self.0.delay_us(us);
+ }
+ fn delay_ms(&mut self, mut ms: u32) {
+ const MAX_MILLIS: u32 = u32::MAX / 1000;
+ while ms > MAX_MILLIS {
+ ms -= MAX_MILLIS;
+ DelayNs::delay_us(self, MAX_MILLIS * 1000);
+ }
+ DelayNs::delay_us(self, ms * 1000);
+ }
+}
+
+impl DelayUs for SystDelay {
+ fn delay_us(&mut self, us: u32) {
+ DelayNs::delay_us(self, us);
+ }
+}
+
+impl DelayUs for SystDelay {
+ fn delay_us(&mut self, us: u16) {
+ DelayNs::delay_us(self, us as u32);
+ }
+}
+
+impl DelayUs for SystDelay {
+ fn delay_us(&mut self, us: u8) {
+ DelayNs::delay_us(self, us as u32);
+ }
+}
+
+impl DelayMs for SystDelay {
+ fn delay_ms(&mut self, ms: u32) {
+ DelayNs::delay_ms(self, ms);
+ }
+}
+
+impl DelayMs for SystDelay {
+ fn delay_ms(&mut self, ms: u16) {
+ DelayNs::delay_ms(self, ms as u32);
+ }
+}
+
+impl DelayMs for SystDelay {
+ fn delay_ms(&mut self, ms: u8) {
+ DelayNs::delay_ms(self, ms as u32);
}
}
@@ -65,12 +124,12 @@ pub trait DelayExt {
T: Into;
}
-impl DelayExt for Delay {
+impl DelayExt for SystDelay {
fn delay(&mut self, delay: T)
where
T: Into,
{
- self.delay_us(delay.into().ticks())
+ self.0.delay_us(delay.into().ticks())
}
}
@@ -132,7 +191,7 @@ macro_rules! impl_delay_from_count_down_timer {
T: CountDown