Skip to content

Commit

Permalink
Make embedded-hal 0.2.7 support optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Jan 24, 2024
1 parent b72dc44 commit 1bc93b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ embedded-dma = "0.2.0"
embedded-hal = "1.0.0"
embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = [
"unproven",
] }
], optional = true }
embedded-io = "0.6.1"
gd32f1 = { version = "0.8.0", features = ["critical-section"] }
nb = "1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::pac::{
};
use crate::rcu::{Clocks, Enable, Reset, APB2};
use core::{
convert::Infallible,
marker::PhantomData,
sync::atomic::{self, Ordering},
};
Expand Down Expand Up @@ -494,12 +493,13 @@ impl Adc {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<WORD, PIN> embedded_hal_02::adc::OneShot<ADC, WORD, PIN> for Adc
where
WORD: From<u16>,
PIN: Channel<ADC, ID = u8>,
{
type Error = Infallible;
type Error = core::convert::Infallible;

fn read(&mut self, pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
let res = self.read_channel(pin);
Expand Down
19 changes: 12 additions & 7 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::rcu::Clocks;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;
use embedded_hal::delay::DelayNs;
use embedded_hal_02::blocking::delay::{DelayMs, DelayUs};

/// System timer (SysTick) as a delay provider
pub struct Delay {
Expand Down Expand Up @@ -60,37 +59,43 @@ impl DelayNs for Delay {
}
}

impl DelayMs<u32> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
DelayNs::delay_ms(self, ms);
}
}

impl DelayMs<u16> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
DelayNs::delay_ms(self, ms.into());
}
}

impl DelayMs<u8> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayMs<u8> for Delay {
fn delay_ms(&mut self, ms: u8) {
DelayNs::delay_ms(self, ms.into());
}
}

impl DelayUs<u32> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
DelayNs::delay_us(self, us)
}
}

impl DelayUs<u16> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayUs<u16> for Delay {
fn delay_us(&mut self, us: u16) {
DelayNs::delay_us(self, us.into())
}
}

impl DelayUs<u8> for Delay {
#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::delay::DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
DelayNs::delay_us(self, us.into())
}
Expand Down
3 changes: 3 additions & 0 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl<TIMER, PIN> SetDutyCycle for PwmChannel<TIMER, PIN> {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<TIMER, PIN> embedded_hal_02::PwmPin for PwmChannel<TIMER, PIN> {
type Duty = u16;

Expand Down Expand Up @@ -263,6 +264,7 @@ impl<TIMER, PIN> PwmChannelComplementary<TIMER, PIN> {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<TIMER, PIN> embedded_hal_02::PwmPin for PwmChannelComplementary<TIMER, PIN> {
type Duty = u16;

Expand Down Expand Up @@ -643,6 +645,7 @@ macro_rules! hal {
)?
}

#[cfg(feature = "embedded-hal-02")]
impl<PINS> embedded_hal_02::Pwm for Pwm<$TIMERX, PINS>
where
PINS: Pins<$TIMERX>,
Expand Down

0 comments on commit 1bc93b2

Please sign in to comment.