Skip to content

Add embedded_hal 1.0, keep support for latest 0.2.x #240

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ targets = ["thumbv6m-none-eabi"]
[dependencies]
as-slice = "0.2.1"
cast = { version = "0.3.0", default-features = false }
cortex-m = "0.7.0"
cortex-m-rt = "0.7.0"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
cortex-m = "0.7.7"
cortex-m-rt = "0.7.5"
embedded-time = "0.12.0"
nb = "1.0.0"
rtcc = { version = "0.3.0", optional = true }
stm32l0 = "0.15.1"
stm32-usbd = { version = "0.6.0", optional = true }
void = { version = "1.0.2", default-features = false }

[dependencies.embedded-hal-02]
package = "embedded-hal"
version = "0.2.7"
features = ["unproven"]

[dependencies.embedded-hal]
version = "1.0"


[dev-dependencies]
aligned = "0.4.1"
cortex-m-rtic = "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use as_slice::AsMutSlice;

use crate::{
gpio::*,
hal::adc::{Channel, OneShot},
hal_02::adc::{Channel, OneShot},
pac::ADC,
rcc::{Enable, Rcc},
};
Expand Down
2 changes: 1 addition & 1 deletion src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Delays

use crate::hal::blocking::delay::{DelayMs, DelayUs};
use crate::hal_02::blocking::delay::{DelayMs, DelayUs};
use crate::rcc::Clocks;
use cast::u32;
use core::convert::TryInto;
Expand Down
4 changes: 2 additions & 2 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Output<MODE> {
/// Push pull output (type state)
pub struct PushPull;

use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
use crate::hal_02::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};

/// Fully erased pin
pub struct Pin<MODE> {
Expand Down Expand Up @@ -245,7 +245,7 @@ macro_rules! gpio {
pub mod $gpiox {
use core::marker::PhantomData;

use crate::hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
use crate::hal_02::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
use crate::pac::$GPIOX;
use crate::rcc::{Enable, Rcc};
use super::{
Expand Down
2 changes: 1 addition & 1 deletion src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cast::u8;
use embedded_time::rate::Hertz;

// I²C traits
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
use crate::hal_02::blocking::i2c::{Read, Write, WriteRead};

// I/O Imports
use crate::gpio::{AltMode, OpenDrain, Output};
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ compile_error!(
"This crate requires one of the following features enabled: stm32l0x1, stm32l0x2, stm32l0x3"
);

use embedded_hal as hal;
pub use embedded_hal as hal;
pub use embedded_hal_02 as hal_02;

#[cfg(feature = "stm32l0x1")]
pub use stm32l0::stm32l0x1 as pac;
Expand Down
8 changes: 4 additions & 4 deletions src/lptim.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Low-Power Timer (LPTIM) support.

use crate::gpio::{self, gpiob};
use crate::hal;
use crate::hal_02;
use crate::pac::LPTIM;
use crate::pwr::PWR;
use crate::rcc::{Enable, Rcc, Reset};
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<M: CountMode> LpTimer<M> {
}
}

impl hal::timer::CountDown for LpTimer<Periodic> {
impl hal_02::timer::CountDown for LpTimer<Periodic> {
type Time = Hertz;

fn start<T>(&mut self, freq: T)
Expand All @@ -362,9 +362,9 @@ impl hal::timer::CountDown for LpTimer<Periodic> {
}
}

impl hal::timer::Periodic for LpTimer<Periodic> {}
impl hal_02::timer::Periodic for LpTimer<Periodic> {}

impl hal::timer::CountDown for LpTimer<OneShot> {
impl hal_02::timer::CountDown for LpTimer<OneShot> {
type Time = Microseconds;

fn start<T>(&mut self, period: T)
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use embedded_hal::{
pub use crate::hal_02::{
adc::OneShot as _,
digital::v2::*,
prelude::*,
Expand Down
4 changes: 2 additions & 2 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::gpio::{
gpiob::PB3,
};
use crate::gpio::{AltMode, PinMode};
use crate::hal;
use crate::hal_02;
use crate::pac::{tim2, TIM2, TIM3};
use crate::rcc::{Enable, Rcc, Reset};
use cast::{u16, u32};
Expand Down Expand Up @@ -212,7 +212,7 @@ impl<I, C> Pwm<I, C, Unassigned> {
}
}

impl<I, C, P> hal::PwmPin for Pwm<I, C, Assigned<P>>
impl<I, C, P> hal_02::PwmPin for Pwm<I, C, Assigned<P>>
where
I: Instance,
C: Channel,
Expand Down
2 changes: 1 addition & 1 deletion src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use embedded_time::rate::Extensions;
use void::Void;

use crate::{
hal::timer::{self, Cancel as _},
hal_02::timer::{self, Cancel as _},
pac,
pwr::PWR,
rcc::Rcc,
Expand Down
16 changes: 8 additions & 8 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use core::ptr;
use nb::block;

use crate::gpio::{AltMode, PinMode};
use crate::hal;
use crate::hal::prelude::*;
use crate::hal_02;
use crate::hal_02::prelude::*;
pub use crate::pac::{LPUART1, USART1, USART2, USART4, USART5};
use crate::rcc::{Enable, Rcc, LSE};
use embedded_time::rate::{Baud, Extensions};
Expand Down Expand Up @@ -476,15 +476,15 @@ macro_rules! usart {
}
}

impl hal::serial::Read<u8> for Serial<$USARTX> {
impl hal_02::serial::Read<u8> for Serial<$USARTX> {
type Error = Error;

fn read(&mut self) -> nb::Result<u8, Error> {
self.rx.read()
}
}

impl hal::serial::Write<u8> for Serial<$USARTX> {
impl hal_02::serial::Write<u8> for Serial<$USARTX> {
type Error = Error;

fn flush(&mut self) -> nb::Result<(), Self::Error> {
Expand Down Expand Up @@ -614,7 +614,7 @@ macro_rules! usart {
}
}

impl hal::serial::Read<u8> for Rx<$USARTX> {
impl hal_02::serial::Read<u8> for Rx<$USARTX> {
type Error = Error;

fn read(&mut self) -> nb::Result<u8, Error> {
Expand All @@ -636,7 +636,7 @@ macro_rules! usart {
}
}

impl hal::serial::Write<u8> for Tx<$USARTX> {
impl hal_02::serial::Write<u8> for Tx<$USARTX> {
type Error = Error;

fn flush(&mut self) -> nb::Result<(), Self::Error> {
Expand Down Expand Up @@ -798,7 +798,7 @@ impl Serial<LPUART1> {

impl<USART> fmt::Write for Serial<USART>
where
Serial<USART>: hal::serial::Write<u8>,
Serial<USART>: hal_02::serial::Write<u8>,
{
fn write_str(&mut self, s: &str) -> fmt::Result {
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
Expand All @@ -811,7 +811,7 @@ where

impl<USART> fmt::Write for Tx<USART>
where
Tx<USART>: hal::serial::Write<u8>,
Tx<USART>: hal_02::serial::Write<u8>,
{
fn write_str(&mut self, s: &str) -> fmt::Result {
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
Expand Down
10 changes: 5 additions & 5 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::gpio::gpioa::*;
use crate::gpio::gpiob::*;

use crate::gpio::{AltMode, Analog, OpenDrain, Output, PushPull};
use crate::hal;
use crate::hal_02;
use crate::pac::SPI1;
#[cfg(any(
feature = "io-STM32L051",
Expand All @@ -26,7 +26,7 @@ use crate::pac::SPI1;
use crate::pac::SPI2;
use crate::rcc::{Enable, Rcc};

pub use hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
pub use hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};

/// SPI error
#[derive(Debug)]
Expand Down Expand Up @@ -416,7 +416,7 @@ macro_rules! spi {
}
}

impl<PINS> hal::spi::FullDuplex<u8> for Spi<$SPIX, PINS> {
impl<PINS> hal_02::spi::FullDuplex<u8> for Spi<$SPIX, PINS> {
type Error = Error;

fn read(&mut self) -> nb::Result<u8, Error> {
Expand Down Expand Up @@ -459,9 +459,9 @@ macro_rules! spi {

}

impl<PINS> crate::hal::blocking::spi::transfer::Default<u8> for Spi<$SPIX, PINS> {}
impl<PINS> hal_02::blocking::spi::transfer::Default<u8> for Spi<$SPIX, PINS> {}

impl<PINS> crate::hal::blocking::spi::write::Default<u8> for Spi<$SPIX, PINS> {}
impl<PINS> hal_02::blocking::spi::write::Default<u8> for Spi<$SPIX, PINS> {}
)+
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Timers
use crate::hal::timer::{CountDown, Periodic};
use crate::hal_02::timer::{CountDown, Periodic};
use crate::pac::{tim2, tim21, tim22, tim6, TIM2, TIM21, TIM22, TIM3, TIM6};
use crate::rcc::{Clocks, Enable, Rcc, Reset};
use cast::{u16, u32};
Expand Down
2 changes: 1 addition & 1 deletion src/watchdog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hal::watchdog;
use crate::hal_02::watchdog;
use crate::pac::{IWDG, WWDG};
use crate::rcc::{Enable, Rcc};
use embedded_time::rate::Hertz;
Expand Down