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

Make embedded-hal 1.0.0 non-optional #753

Merged
merged 16 commits into from
Jan 13, 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
11 changes: 4 additions & 7 deletions rp2040-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ targets = ["thumbv6m-none-eabi"]

[dependencies]
cortex-m = "0.7.2"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-rc.3", optional = true }
eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "=1.0.0-rc.3", optional = true }
embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] }
embedded-hal = "1.0.0"
embedded-hal-nb = "1.0.0"
embedded-dma = "0.2.0"
embedded-io = "0.6.1"
fugit = "0.3.6"
Expand Down Expand Up @@ -79,9 +79,6 @@ rp2040-e5 = []
# critical section that is safe for multicore use
critical-section-impl = ["critical-section/restore-state-u8"]

# Support alpha release of embedded-hal
eh1_0_alpha = ["dep:eh1_0_alpha", "dep:eh_nb_1_0_alpha"]

# Add conversion functions between chrono types and the rp2040-hal specific DateTime type
chrono = ["dep:chrono"]

Expand Down Expand Up @@ -192,7 +189,7 @@ required-features = ["critical-section-impl"]

[[example]]
name = "pwm_blink_embedded_hal_1"
required-features = ["critical-section-impl", "eh1_0_alpha"]
required-features = ["critical-section-impl"]

[[example]]
name = "rom_funcs"
Expand Down
15 changes: 4 additions & 11 deletions rp2040-hal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,11 @@ volatile until a 1.0.0 release.
See the [open issues](https://github.com/rp-rs/rp-hal/issues) for a list of
proposed features (and known issues).

### Support for embedded-hal 1.0
### Implemented traits

We plan to support embedded-hal 1.0 soon after it is released.

For now, there is preliminary support for alpha/rc versions of embedded-hal, which can
be enabled with the feature `eh1_0_alpha`. Please note that this support does not
provide any semver compatibility guarantees: With that feature activated, there
will be breaking changes even in minor versions of rp2040-hal.

Support for embedded-hal 1.0(-alpha/rc) exists in parallel to support for
embedded-hal 0.2: Traits of both versions are implemented and can be used
at the same time.
This crate aims to implement all traits from embedded-hal, both version
0.2 and 1.0. They can be used at the same time, so you can upgrade drivers
incrementally.

<!-- CONTRIBUTING -->
## Contributing
Expand Down
3 changes: 2 additions & 1 deletion rp2040-hal/examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use rp2040_hal as hal;

// Some traits we need
use core::fmt::Write;
use embedded_hal::adc::OneShot;
// Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2
use embedded_hal_0_2::adc::OneShot;
use hal::fugit::RateExtU32;
use rp2040_hal::Clock;

Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::delay::DelayNs;
use embedded_hal::digital::OutputPin;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/dht11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use hal::Clock;

/// The linker will place this boot block at the start of our program image. We
Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/examples/gpio_dyn_pin_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::delay::DelayNs;
use embedded_hal::digital::OutputPin;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand Down
6 changes: 3 additions & 3 deletions rp2040-hal/examples/gpio_in_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::InputPin;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::InputPin;
use embedded_hal::digital::OutputPin;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand Down Expand Up @@ -78,7 +78,7 @@ fn main() -> ! {
let mut out_pin = pins.gpio25.into_push_pull_output();

// Configure GPIO 23 as an input
let in_pin = pins.gpio23.into_pull_down_input();
let mut in_pin = pins.gpio23.into_pull_down_input();

// Output is the opposite of the input
loop {
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/gpio_irq_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;

// Our interrupt macro
use hal::pac::interrupt;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use panic_halt as _;
use rp2040_hal as hal;

// Some traits we need
use embedded_hal::blocking::i2c::Write;
use embedded_hal_0_2::blocking::i2c::Write;
use hal::fugit::RateExtU32;

// A shorter alias for the Peripheral Access Crate, which provides low-level
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/mem_to_mem_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use cortex_m::singleton;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use hal::dma::{single_buffer, DMAExt};
use hal::pac;
use panic_halt as _;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/multicore_fifo_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/multicore_polyblink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand Down
6 changes: 3 additions & 3 deletions rp2040-hal/examples/pwm_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use panic_halt as _;
use rp2040_hal as hal;

// Some traits we need
use embedded_hal::PwmPin;
use embedded_hal::pwm::SetDutyCycle;
use rp2040_hal::clocks::Clock;

// A shorter alias for the Peripheral Access Crate, which provides low-level
Expand Down Expand Up @@ -105,13 +105,13 @@ fn main() -> ! {
// Ramp brightness up
for i in LOW..=HIGH {
delay.delay_us(8);
channel.set_duty(i);
let _ = channel.set_duty_cycle(i);
}

// Ramp brightness down
for i in (LOW..=HIGH).rev() {
delay.delay_us(8);
channel.set_duty(i);
let _ = channel.set_duty_cycle(i);
}

delay.delay_ms(500);
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/pwm_blink_embedded_hal_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use panic_halt as _;
use rp2040_hal as hal;

// Some traits we need
use eh1_0_alpha::pwm::SetDutyCycle;
use embedded_hal::pwm::SetDutyCycle;
use rp2040_hal::clocks::Clock;

// A shorter alias for the Peripheral Access Crate, which provides low-level
Expand Down
5 changes: 2 additions & 3 deletions rp2040-hal/examples/pwm_irq_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use panic_halt as _;
use rp2040_hal as hal;

// Some traits we need
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::PwmPin;
use embedded_hal::digital::OutputPin;

// Our interrupt macro
use hal::pac::interrupt;
Expand Down Expand Up @@ -135,7 +134,7 @@ fn main() -> ! {
// Connect to GPI O1 as the input to channel B on PWM0
let input_pin = pins.gpio1.reconfigure();
let channel = &mut pwm.channel_b;
channel.enable();
channel.set_enabled(true);

// Enable an interrupt whenever GPI O1 goes from high to low (the end of a pulse)
input_pin.set_interrupt_enabled(gpio::Interrupt::EdgeLow, true);
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/rosc_as_system_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rp2040_hal as hal;
// register access
use hal::pac;

use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use fugit::{HertzU32, RateExtU32};
use hal::clocks::{Clock, ClockSource, ClocksManager, StoppableClock};
use hal::pac::rosc::ctrl::FREQ_RANGE_A;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/rtc_irq_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rp2040_hal as hal;
use hal::{gpio, pac, rtc};

// Some traits we need
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;

// Our interrupt macro
use hal::pac::interrupt;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/rtc_sleep_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rp2040_hal as hal;
use hal::{clocks::ClockGate, gpio, pac, rtc};

// Some traits we need
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;

// Our interrupt macro
use hal::pac::interrupt;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/spi_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use cortex_m::singleton;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::digital::OutputPin;
use hal::dma::{bidirectional, DMAExt};
use hal::fugit::RateExtU32;
use hal::pac;
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/vector_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use hal::pac;
// Some traits we need
use core::cell::RefCell;
use critical_section::Mutex;
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_hal::digital::StatefulOutputPin;
use hal::fugit::MicrosDurationU32;
use pac::interrupt;
use rp2040_hal::clocks::Clock;
Expand Down
3 changes: 1 addition & 2 deletions rp2040-hal/examples/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use rp2040_hal as hal;
use hal::pac;

// Some traits we need
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::watchdog::{Watchdog, WatchdogEnable};
use embedded_hal::digital::OutputPin;
use hal::fugit::ExtU32;
use rp2040_hal::clocks::Clock;

Expand Down
15 changes: 10 additions & 5 deletions rp2040-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
//!
//! ## Usage
//!
//! Capture ADC reading from a pin
//! Capture ADC reading from a pin:

//! ```no_run
//! use embedded_hal::adc::OneShot;
//! // Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2
//! use embedded_hal_0_2::adc::OneShot;
//! use rp2040_hal::{adc::Adc, adc::AdcPin, gpio::Pins, pac, Sio};
//! let mut peripherals = pac::Peripherals::take().unwrap();
//! let sio = Sio::new(peripherals.SIO);
Expand All @@ -20,8 +22,10 @@
//! ```
//!
//! Capture ADC reading from temperature sensor. Note that this needs conversion to be a real-world temperature.
//!
//! ```no_run
//! use embedded_hal::adc::OneShot;
//! // Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2
//! use embedded_hal_0_2::adc::OneShot;
//! use rp2040_hal::{adc::Adc, gpio::Pins, pac, Sio};
//! let mut peripherals = pac::Peripherals::take().unwrap();
//! let sio = Sio::new(peripherals.SIO);
Expand Down Expand Up @@ -118,7 +122,8 @@

use core::convert::Infallible;
use core::marker::PhantomData;
use embedded_hal::adc::{Channel, OneShot};
// Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2
use embedded_hal_0_2::adc::{Channel, OneShot};

use crate::{
dma,
Expand Down Expand Up @@ -223,7 +228,7 @@ impl Channel<Adc> for TempSense {
/// by calling [`Adc::take_temp_sensor()`]. Either way, the resulting objects can be
/// passed to the [`OneShot::read()`][a] trait method to actually do the read.
///
/// [a]: embedded_hal::adc::OneShot::read
/// [a]: embedded_hal_0_2::adc::OneShot::read
pub struct Adc {
device: ADC,
}
Expand Down
Loading
Loading