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

Moving embedded-hal 0.2 traits to separate package #504

Open
wants to merge 2 commits 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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ 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.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "1" }
embedded-dma = "0.2.0"
cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] }
defmt = { version = ">=0.2.0,<0.4", optional = true }
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::hal_02::Direction;
#[macro_use]
mod utilities;
use stm32h7xx_hal::{pac, prelude::*};
Expand Down
13 changes: 6 additions & 7 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
//! - [Using ADC1 and ADC2 in parallel](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/adc12_parallel.rs)
//! - [Using ADC1 through DMA](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/adc_dma.rs)

use crate::hal::adc::{Channel, OneShot};
use crate::hal::blocking::delay::DelayUs;
use embedded_hal_02::blocking::delay::DelayUs;

use core::convert::Infallible;
use core::marker::PhantomData;
Expand Down Expand Up @@ -189,7 +188,7 @@ impl AdcCalLinear {
macro_rules! adc_pins {
($ADC:ident, $($input:ty => $chan:expr),+ $(,)*) => {
$(
impl Channel<$ADC> for $input {
impl embedded_hal_02::adc::Channel<$ADC> for $input {
type ID = u8;

fn channel() -> u8 {
Expand Down Expand Up @@ -823,7 +822,7 @@ macro_rules! adc_hal {
/// The value can be then read through the `read_sample` method.
// Refer to RM0433 Rev 7 - Chapter 25.4.16
pub fn start_conversion<PIN>(&mut self, _pin: &mut PIN)
where PIN: Channel<$ADC, ID = u8>,
where PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>,
{
let chan = PIN::channel();
assert!(chan <= 19);
Expand All @@ -841,7 +840,7 @@ macro_rules! adc_hal {
/// This method starts a conversion sequence with DMA
/// enabled. The DMA mode selected depends on the [`AdcDmaMode`] specified.
pub fn start_conversion_dma<PIN>(&mut self, _pin: &mut PIN, mode: AdcDmaMode)
where PIN: Channel<$ADC, ID = u8>,
where PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>,
{
let chan = PIN::channel();
assert!(chan <= 19);
Expand Down Expand Up @@ -1112,10 +1111,10 @@ macro_rules! adc_hal {
}
}

impl<WORD, PIN> OneShot<$ADC, WORD, PIN> for Adc<$ADC, Enabled>
impl<WORD, PIN> embedded_hal_02::adc::OneShot<$ADC, WORD, PIN> for Adc<$ADC, Enabled>
where
WORD: From<u32>,
PIN: Channel<$ADC, ID = u8>,
PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>,
{
type Error = ();

Expand Down
2 changes: 1 addition & 1 deletion src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::marker::PhantomData;
use core::mem::MaybeUninit;

use crate::gpio::{self, Analog};
use crate::hal::blocking::delay::DelayUs;
use crate::hal_02::blocking::delay::DelayUs;
use crate::rcc::{rec, ResetEnable};
#[cfg(not(feature = "rm0455"))]
use crate::stm32::DAC as DAC1;
Expand Down
31 changes: 14 additions & 17 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
use cast::u32;
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m::peripheral::SYST;
use embedded_hal::{
blocking::delay::{DelayMs, DelayUs},
timer::CountDown,
};
use void::Void;

use crate::nb::block;
Expand Down Expand Up @@ -110,7 +106,7 @@ impl<'a> Countdown<'a> {
}
}

impl<'a> CountDown for Countdown<'a> {
impl<'a> embedded_hal_02::timer::CountDown for Countdown<'a> {
type Time = fugit::MicrosDurationU32;

fn start<T>(&mut self, count: T)
Expand Down Expand Up @@ -163,25 +159,26 @@ impl Delay {
}
}

impl DelayMs<u32> for Delay {
impl embedded_hal_02::blocking::delay::DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
use embedded_hal_02::blocking::delay::DelayUs;
self.delay_us(ms * 1_000);
}
}

impl DelayMs<u16> for Delay {
impl embedded_hal_02::blocking::delay::DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
self.delay_ms(u32(ms));
}
}

impl DelayMs<u8> for Delay {
impl embedded_hal_02::blocking::delay::DelayMs<u8> for Delay {
fn delay_ms(&mut self, ms: u8) {
self.delay_ms(u32(ms));
}
}

impl DelayUs<u32> for Delay {
impl embedded_hal_02::blocking::delay::DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
// The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
const MAX_RVR: u32 = 0x00FF_FFFF;
Expand Down Expand Up @@ -220,13 +217,13 @@ impl DelayUs<u32> for Delay {
}
}

impl DelayUs<u16> for Delay {
impl embedded_hal_02::blocking::delay::DelayUs<u16> for Delay {
fn delay_us(&mut self, us: u16) {
self.delay_us(u32(us))
}
}

impl DelayUs<u8> for Delay {
impl embedded_hal_02::blocking::delay::DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
self.delay_us(u32(us))
}
Expand All @@ -251,9 +248,9 @@ macro_rules! impl_delay_from_count_down_timer {
($(($Delay:ident, $delay:ident, $num:expr)),+) => {
$(

impl<T> $Delay<u32> for DelayFromCountDownTimer<T>
impl<T> embedded_hal_02::blocking::delay::$Delay<u32> for DelayFromCountDownTimer<T>
where
T: CountDown<Time = Hertz>,
T: embedded_hal_02::timer::CountDown<Time = Hertz>,
{
fn $delay(&mut self, t: u32) {
let mut time_left = t;
Expand All @@ -280,18 +277,18 @@ macro_rules! impl_delay_from_count_down_timer {
}
}

impl<T> $Delay<u16> for DelayFromCountDownTimer<T>
impl<T> embedded_hal_02::blocking::delay::$Delay<u16> for DelayFromCountDownTimer<T>
where
T: CountDown<Time = Hertz>,
T: embedded_hal_02::timer::CountDown<Time = Hertz>,
{
fn $delay(&mut self, t: u16) {
self.$delay(t as u32);
}
}

impl<T> $Delay<u8> for DelayFromCountDownTimer<T>
impl<T> embedded_hal_02::blocking::delay::$Delay<u8> for DelayFromCountDownTimer<T>
where
T: CountDown<Time = Hertz>,
T: embedded_hal_02::timer::CountDown<Time = Hertz>,
{
fn $delay(&mut self, t: u8) {
self.$delay(t as u32);
Expand Down
16 changes: 8 additions & 8 deletions src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,9 @@ where
/// MDMA block. The length is referred to the source size
///
/// * `s_len`: The number of input words of s_size available. `None` if the
/// source is a peripheral
/// source is a peripheral
/// * `d_len`: The number of input words of d_size available. `None` if the
/// destination is a peripheral
/// destination is a peripheral
///
/// `s_len` and `d_len` cannot both be peripherals (None)
fn m_number_of_bytes(
Expand Down Expand Up @@ -1052,24 +1052,24 @@ where
/// # Panics
///
/// * When a memory-memory transfer is specified but the `second_buf`
/// argument is `None`.
/// argument is `None`.
///
/// * When the length is greater than 65536 bytes.
///
/// * When `config` specifies a `source_increment` that is smaller than the
/// source size.
/// source size.
///
/// * When `config` specifies a `destination_increment` that is smaller than
/// the destination size.
/// the destination size.
///
/// * When `config` specifies a `transfer_length` that is not a multiple of
/// both the source and destination sizes.
/// both the source and destination sizes.
///
/// * When `config` specifies a `packing_alignment` that extends the source,
/// but the source size is larger than the destination size.
/// but the source size is larger than the destination size.
///
/// * When `config` specifies a `packing_alignment` that truncates the
/// source, but the source size is smaller than the destination size.
/// source, but the source size is smaller than the destination size.
pub fn init_master(
mut stream: STREAM,
peripheral: PERIPHERAL,
Expand Down
8 changes: 4 additions & 4 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
//! - **Dynamic**: Pin mode is selected at runtime. See changing configurations for more details
//! - Input
//! - **PullUp**: Input connected to high with a weak pull up resistor. Will be high when nothing
//! is connected
//! is connected
//! - **PullDown**: Input connected to high with a weak pull up resistor. Will be low when nothing
//! is connected
//! is connected
//! - **Floating**: Input not pulled to high or low. Will be undefined when nothing is connected
//! - Output
//! - **PushPull**: Output which either drives the pin high or low
//! - **OpenDrain**: Output which leaves the gate floating, or pulls it do ground in drain
//! mode. Can be used as an input in the `open` configuration
//! mode. Can be used as an input in the `open` configuration
//!
//! ## Changing modes
//! The simplest way to change the pin mode is to use the `into_<mode>` functions. These return a
Expand Down Expand Up @@ -77,7 +77,7 @@ mod dynamic;
pub use dynamic::{Dynamic, DynamicPin};
mod hal_02;

pub use embedded_hal::digital::v2::PinState;
pub use embedded_hal_02::digital::v2::PinState;

use core::fmt;

Expand Down
Loading