Skip to content

Commit

Permalink
Merge pull request #759 from jannic/v0.9.x
Browse files Browse the repository at this point in the history
Prepare release 0.9.2 with e-h 1.0.0 support
  • Loading branch information
jannic authored Jan 25, 2024
2 parents 7b04000 + 0a28a1b commit 655d5ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
11 changes: 10 additions & 1 deletion rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.2]

### Changed

- Update embedded-hal 1 to version 1.0.0.
(This is the version of embedded-hal activated by feature
"eh1_0_alpha". Embedded-hal 0.9 is still supported by default.) - @jannic

## [0.9.1]

### Added
Expand Down Expand Up @@ -339,7 +347,8 @@ The Minimum-Supported Rust Version (MSRV) for this release is 1.54.

- Initial release

[Unreleased]: https://github.com/rp-rs/rp-hal/compare/v0.9.1...HEAD
[Unreleased]: https://github.com/rp-rs/rp-hal/compare/v0.9.2...HEAD
[0.9.2]: https://github.com/rp-rs/rp-hal/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/rp-rs/rp-hal/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/rp-rs/rp-hal/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/rp-rs/rp-hal/compare/v0.8.0...v0.8.1
Expand Down
6 changes: 3 additions & 3 deletions rp2040-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rp2040-hal"
version = "0.9.1"
version = "0.9.2"
authors = ["The rp-rs Developers"]
edition = "2021"
homepage = "https://github.com/rp-rs/rp-hal"
Expand All @@ -18,8 +18,8 @@ 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.1", optional = true }
eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "=1.0.0-rc.1", optional = true }
eh1_0_alpha = { package = "embedded-hal", version = "1.0.0", optional = true }
eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "1.0.0", optional = true }
embedded-dma = "0.2.0"
fugit = "0.3.6"
itertools = { version = "0.10.1", default-features = false }
Expand Down
14 changes: 6 additions & 8 deletions rp2040-hal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ https://github.com/rp-rs/rp-hal-boards/ for more details.
To include this crate in your project, amend your `Cargo.toml` file to include

```toml
rp2040-hal = "0.9.1"
rp2040-hal = "0.9.2"
```

To obtain a copy of the source code (e.g. if you want to propose a bug-fix or
Expand All @@ -94,16 +94,14 @@ proposed features (and known issues).

### Support for embedded-hal 1.0

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
This crate now supports embedded-hal 1.0, albeit still optional and
hidden behind the `eh1_0_alpha` feature flag. 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.
Support for embedded-hal 1.0 exists in parallel to support for
embedded-hal 0.2: Traits of both versions are implemented and can be
used at the same time.

<!-- CONTRIBUTING -->
## Contributing
Expand Down
27 changes: 7 additions & 20 deletions rp2040-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,9 +1398,7 @@ impl<T: AnyPin> embedded_hal::digital::v2::OutputPin for InOutPin<T> {

#[cfg(feature = "eh1_0_alpha")]
mod eh1 {
use eh1_0_alpha::digital::{
ErrorType, InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
};
use eh1_0_alpha::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};

use super::{Error, FunctionSio, Pin, PinId, PullType, SioConfig, SioInput, SioOutput};

Expand Down Expand Up @@ -1434,36 +1432,25 @@ mod eh1 {
I: PinId,
P: PullType,
{
fn is_set_high(&self) -> Result<bool, Self::Error> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(self._is_set_high())
}

fn is_set_low(&self) -> Result<bool, Self::Error> {
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(self._is_set_low())
}
}

impl<I, P> ToggleableOutputPin for Pin<I, FunctionSio<SioOutput>, P>
where
I: PinId,
P: PullType,
{
fn toggle(&mut self) -> Result<(), Self::Error> {
self._toggle();
Ok(())
}
}

impl<I, P> InputPin for Pin<I, FunctionSio<SioInput>, P>
where
I: PinId,
P: PullType,
{
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(self._is_high())
}

fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(self._is_low())
}
}
Expand All @@ -1480,11 +1467,11 @@ mod eh1 {
impl<'a, I: PinId, F: super::func::Function, P: PullType> InputPin
for super::AsInputPin<'a, I, F, P>
{
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(self.0._is_high())
}

fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(self.0._is_low())
}
}
Expand Down
5 changes: 5 additions & 0 deletions rp2040-hal/src/rom_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ macro_rules! declare_rom_function {
}

$(#[$outer])*
/// # Safety
///
/// This is a low-level C function. It may be difficult to call safely from
/// Rust. If in doubt, check the RP2040 datasheet for details and do your own
/// safety evaluation.
pub unsafe extern "C" fn $name( $($argname: $ty),* ) -> $ret {
$name::ptr()($($argname),*)
}
Expand Down
18 changes: 17 additions & 1 deletion rp2040-hal/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,26 @@ macro_rules! impl_delay_traits {
impl_delay_traits!(u8, u16, u32, i32);

#[cfg(feature = "eh1_0_alpha")]
impl eh1_0_alpha::delay::DelayUs for Timer {
impl eh1_0_alpha::delay::DelayNs for Timer {
fn delay_ns(&mut self, ns: u32) {
// For now, just use microsecond delay, internally. Of course, this
// might cause a much longer delay than necessary. So a more advanced
// implementation would be desirable for sub-microsecond delays.
let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 };
// With rustc 1.73, this can be replaced by:
// let us = ns.div_ceil(1000);
self.delay_us_internal(us)
}

fn delay_us(&mut self, us: u32) {
self.delay_us_internal(us)
}

fn delay_ms(&mut self, ms: u32) {
for _ in 0..ms {
self.delay_us_internal(1000);
}
}
}

/// Implementation of the embedded_hal::Timer traits using rp2040_hal::timer counter
Expand Down

0 comments on commit 655d5ba

Please sign in to comment.