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

swap embedded-hals #720

Merged
merged 2 commits into from
Jan 10, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- shorten gpio ptr access
- bump embedded-hal to `1.0` (no more RC!)
- make `embedded-hal` `1.0` main implementation

## [v0.19.0] - 2023-12-11

Expand Down
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ sdio-host = { version = "0.6.0", optional = true }
embedded-dma = "0.2.0"
bare-metal = { version = "1" }
void = { default-features = false, version = "1.0.2" }
embedded-hal = { features = ["unproven"], version = "0.2.7" }
embedded-hal-nb = "1.0"
display-interface = { version = "0.4.1", optional = true }
fugit = "0.3.7"
fugit-timer = "0.1.3"
Expand All @@ -54,9 +52,16 @@ vcell = "0.1.3"
version = "0.3.14"
default-features = false

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

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

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

[dependencies.stm32_i2s_v12x]
version = "0.5.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/analog-stopwatch-with-spi-ssd1306.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn main() -> ! {
let mut delay = Timer::syst(cp.SYST, &clocks).delay();

ss.set_high();
delay.delay_ms(100_u32);
delay.delay_ms(100);
ss.set_low();

// Set up the display
Expand Down Expand Up @@ -201,7 +201,7 @@ fn main() -> ! {

disp.flush().unwrap();

delay.delay_ms(100u32);
delay.delay_ms(100);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/delay-syst-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> ! {
loop {
// On for 1s, off for 1s.
led.toggle();
delay.delay_ms(1000_u32);
delay.delay_ms(1000);
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/delay-timer-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fn main() -> ! {
loop {
// On for 1s, off for 3s.
led.set_high();
// Use `embedded_hal::DelayMs` trait
delay.delay_ms(1000_u32);
// Use `embedded_hal_02::DelayMs` trait
delay.delay_ms(1000);
led.set_low();
// or use `fugit::ExtU32` trait
delay.delay(3.secs());
Expand Down
6 changes: 3 additions & 3 deletions examples/dwt-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ fn main() -> ! {
// On for 1s, off for 1s.
led1.set_high();
led2.set_low();
delay.delay_ms(1000_u32);
delay.delay_ms(1000);
sw.lap();
led1.set_low();
led2.set_high();
delay.delay_ms(900_u32);
delay.delay_ms(900);
// Also you can measure with almost clock precision
let cd: ClockDuration = dwt.measure(|| delay.delay_ms(100_u32));
let cd: ClockDuration = dwt.measure(|| delay.delay_ms(100));
let _t: u32 = cd.as_ticks(); // Should return 48MHz * 0.1s as u32
let _t: f32 = cd.as_secs_f32(); // Should return ~0.1s as a f32
let _t: f64 = cd.as_secs_f64(); // Should return ~0.1s as a f64
Expand Down
2 changes: 1 addition & 1 deletion examples/ist7920-bidi-normal-spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> ! {

let mut select_figure = 0;
loop {
delay.delay_ms(500_u16);
delay.delay_ms(500);
let (begin, end) = match select_figure {
0 => {
select_figure = 1;
Expand Down
4 changes: 2 additions & 2 deletions examples/qei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use panic_halt as _;

use cortex_m_rt::entry;
use embedded_hal::Direction as RotaryDirection;
use embedded_hal_02::Direction as RotaryDirection;
use stm32f4xx_hal::{pac, prelude::*, qei::Qei};

#[entry]
Expand Down Expand Up @@ -58,6 +58,6 @@ fn main() -> ! {
current_count = new_count;
}

delay.delay_ms(10_u32);
delay.delay_ms(10);
}
}
2 changes: 1 addition & 1 deletion examples/rng-display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() -> ! {
}
disp.flush().unwrap();
//delay a little while between refreshes so the display is readable
delay_source.delay_ms(100u8);
delay_source.delay_ms(100);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/rtic-spi-slave-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#[rtic::app(device = stm32f4xx_hal::pac, peripherals = true, dispatchers = [TIM2])]
mod app {

use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal_02::spi::{Mode, Phase, Polarity};
use hal::{
dma::{
config::DmaConfig, DmaFlag, MemoryToPeripheral, PeripheralToMemory, Stream0, Stream5,
Expand Down
2 changes: 1 addition & 1 deletion examples/sd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> ! {
Err(_err) => (),
}

delay.delay_ms(1000u32);
delay.delay_ms(1000);
}

let nblocks = sdio.card().map(|c| c.block_count()).unwrap_or(0);
Expand Down
2 changes: 1 addition & 1 deletion examples/serial-9bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() -> ! {
led_bit8.set_low();
}

delay.delay_ms(10u32);
delay.delay_ms(10);
}
}
}
2 changes: 1 addition & 1 deletion examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use stm32f4xx_hal::dma::DmaFlag;
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use cortex_m_rt::entry;
use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal_02::spi::{Mode, Phase, Polarity};
use stm32f4xx_hal::pac::interrupt;
use stm32f4xx_hal::{
dma::{config, MemoryToPeripheral, Stream4, StreamsTuple, Transfer},
Expand Down
2 changes: 1 addition & 1 deletion examples/st7789-lcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn main() -> ! {
let mut drawer = ColoredCircleDrawer::new(&center_points, &test_colors);
loop {
drawer.draw(&mut lcd).unwrap();
delay.delay_ms(100u16);
delay.delay_ms(100);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn main() -> ! {

disp.flush().unwrap();

delay.delay_ms(100u32);
delay.delay_ms(100);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/stopwatch-with-ssd1306-and-interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn main() -> ! {

disp.flush().unwrap();

delay.delay_ms(100u32);
delay.delay_ms(100);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ macro_rules! adc {
/// to sample for at a given ADC clock frequency
pub fn configure_channel<CHANNEL>(&mut self, _channel: &CHANNEL, sequence: config::Sequence, sample_time: config::SampleTime)
where
CHANNEL: embedded_hal::adc::Channel<pac::$adc_type, ID=u8>
CHANNEL: embedded_hal_02::adc::Channel<pac::$adc_type, ID=u8>
{
//Check the sequence is long enough
self.adc_reg.sqr1.modify(|r, w| {
Expand Down Expand Up @@ -953,7 +953,7 @@ macro_rules! adc {
/// Note that it reconfigures the adc sequence and doesn't restore it
pub fn convert<PIN>(&mut self, pin: &PIN, sample_time: config::SampleTime) -> u16
where
PIN: embedded_hal::adc::Channel<pac::$adc_type, ID=u8>
PIN: embedded_hal_02::adc::Channel<pac::$adc_type, ID=u8>
{
self.adc_reg.cr2.modify(|_, w| w
.dma().clear_bit() //Disable dma
Expand Down Expand Up @@ -986,7 +986,7 @@ macro_rules! adc {

impl Adc<pac::$adc_type> {
fn read<PIN>(&mut self, pin: &mut PIN) -> nb::Result<u16, ()>
where PIN: embedded_hal::adc::Channel<pac::$adc_type, ID=u8>,
where PIN: embedded_hal_02::adc::Channel<pac::$adc_type, ID=u8>,
{
let enabled = self.is_enabled();
if !enabled {
Expand All @@ -1003,9 +1003,9 @@ macro_rules! adc {
}
}

impl<PIN> embedded_hal::adc::OneShot<pac::$adc_type, u16, PIN> for Adc<pac::$adc_type>
impl<PIN> embedded_hal_02::adc::OneShot<pac::$adc_type, u16, PIN> for Adc<pac::$adc_type>
where
PIN: embedded_hal::adc::Channel<pac::$adc_type, ID=u8>,
PIN: embedded_hal_02::adc::Channel<pac::$adc_type, ID=u8>,
{
type Error = ();

Expand Down
2 changes: 1 addition & 1 deletion src/adc/f4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
macro_rules! adc_pins {
($($pin:ty => ($adc:ident, $chan:expr)),+ $(,)*) => {
$(
impl embedded_hal::adc::Channel<pac::$adc> for $pin {
impl embedded_hal_02::adc::Channel<pac::$adc> for $pin {
type ID = u8;
fn channel() -> u8 { $chan }
}
Expand Down
6 changes: 3 additions & 3 deletions src/dwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ impl Delay {
}

// Implement DelayUs/DelayMs for various integer types
impl<T: Into<u64>> embedded_hal::blocking::delay::DelayUs<T> for Delay {
impl<T: Into<u64>> embedded_hal_02::blocking::delay::DelayUs<T> for Delay {
fn delay_us(&mut self, us: T) {
// Convert us to ticks
let start = DWT::cycle_count();
let ticks = (us.into() * self.clock.raw() as u64) / 1_000_000;
Delay::delay_ticks(start, ticks);
}
}
impl<T: Into<u64>> embedded_hal::blocking::delay::DelayMs<T> for Delay {
impl<T: Into<u64>> embedded_hal_02::blocking::delay::DelayMs<T> for Delay {
fn delay_ms(&mut self, ms: T) {
// Convert ms to ticks
let start = DWT::cycle_count();
Expand All @@ -114,7 +114,7 @@ impl<T: Into<u64>> embedded_hal::blocking::delay::DelayMs<T> for Delay {
}
}

impl embedded_hal_one::delay::DelayNs for Delay {
impl embedded_hal::delay::DelayNs for Delay {
fn delay_ns(&mut self, ns: u32) {
// Convert us to ticks
let start = DWT::cycle_count();
Expand Down
2 changes: 1 addition & 1 deletion src/fmpi2c/hal_02.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod blocking {
use super::super::{fmpi2c1, Error, FMPI2c, Instance};
use core::ops::Deref;
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
use embedded_hal_02::blocking::i2c::{Read, Write, WriteRead};

impl<I2C: Instance> WriteRead for FMPI2c<I2C>
where
Expand Down
6 changes: 3 additions & 3 deletions src/fmpi2c/hal_1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use embedded_hal_one::i2c::ErrorType;
use embedded_hal::i2c::ErrorType;

use super::Instance;

Expand All @@ -9,9 +9,9 @@ impl<I2C: Instance> ErrorType for super::FMPI2c<I2C> {
mod blocking {
use super::super::{fmpi2c1, FMPI2c, Instance};
use core::ops::Deref;
use embedded_hal_one::i2c::Operation;
use embedded_hal::i2c::Operation;

impl<I2C: Instance> embedded_hal_one::i2c::I2c for FMPI2c<I2C>
impl<I2C: Instance> embedded_hal::i2c::I2c for FMPI2c<I2C>
where
I2C: Deref<Target = fmpi2c1::RegisterBlock>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod hal_02;
mod hal_1;
pub mod outport;

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

use core::fmt;

Expand Down
4 changes: 2 additions & 2 deletions src/gpio/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use embedded_hal_one::digital::ErrorKind;
use embedded_hal::digital::ErrorKind;

/// Pin type with dynamic mode
///
Expand Down Expand Up @@ -31,7 +31,7 @@ pub enum PinModeError {
IncorrectMode,
}

impl embedded_hal_one::digital::Error for PinModeError {
impl embedded_hal::digital::Error for PinModeError {
fn kind(&self) -> ErrorKind {
ErrorKind::Other
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpio/hal_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
PartiallyErasedPin, Pin, PinMode, PinState,
};

use embedded_hal::digital::v2::{
use embedded_hal_02::digital::v2::{
InputPin, IoPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
};

Expand Down
Loading
Loading