Skip to content

Commit

Permalink
Move compatibility with ESP IDF from esp-idf-hal to this crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Oct 5, 2023
1 parent 5f69359 commit 4a71ea8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/dist
/target
Cargo.lock
/.vscode
/.espressif
/.embuild
**/*.rs.bk
17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ repository = "https://github.com/ivmarkov/edge-executor"
license = "MIT OR Apache-2.0"
readme = "README.md"

[patch.crates-io]
#esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal", branch = "all-executors" }
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }
esp-idf-hal = { path = "../esp-idf-hal" }

[features]
default = ["std", "crossbeam-queue"]
std = ["alloc"]
#std = ["alloc", "embedded-svc?/std"]
alloc = []
#alloc = ["embedded-svc?/alloc"]
alloc = ["esp-idf-hal?/alloc"]
wasm = ["std", "wasm-bindgen", "js-sys"]

[dependencies]
Expand All @@ -25,12 +28,16 @@ crossbeam-queue = { version = "0.3", optional = true }
async-task = { version = "4", default-features = false }
waker-fn = { version = "1.1", default-features = false }
log = { version = "0.4", default-features = false }
#embedded-svc = { version = "0.23", default-features = false, optional = true, default-features = false, features = ["experimental"] }
#embedded-svc = { version = "0.23", git = "https://github.com/esp-rs/embedded-svc", optional = true, default-features = false, features = ["experimental"] }

# ESP-IDF dependencies
esp-idf-hal = { version = "0.41", default-features = false, optional = true, features = ["native"] }

# WASM dependencies
wasm-bindgen = { version = "0.2.82", optional = true }
js-sys = { version = "0.3", optional = true }

[dev-dependencies]
simple_logger = "2.2"

[build-dependencies]
embuild = "0.31.2"
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub use crate::std::*;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr", target_has_atomic = "8"))]
pub use crate::eventloop::*;

#[cfg(all(feature = "alloc", feature = "esp-idf-hal", target_has_atomic = "ptr"))]
pub use crate::espidf::*;

#[cfg(feature = "wasm")]
pub use crate::wasm::*;

Expand Down Expand Up @@ -759,3 +762,40 @@ mod eventloop {
}
}
}

#[cfg(all(feature = "alloc", feature = "esp-idf-hal", target_has_atomic = "ptr"))]
mod espidf {
use core::num::NonZeroU32;

use esp_idf_hal::task::notification;

pub use super::*;

pub type EspExecutor<'a, const C: usize, S> = Executor<'a, C, FreeRtosMonitor, S>;
pub type EspBlocker = Blocker<FreeRtosMonitor>;

pub type FreeRtosMonitor = notification::Monitor;
pub type FreeRtosNotify = notification::Notifier;

impl Monitor for notification::Monitor {
type Notify = notification::Notifier;

fn notifier(&self) -> Self::Notify {
notification::Monitor::notifier(self)
}
}

impl Wait for notification::Monitor {
fn wait(&self) {
notification::Monitor::wait_any(self)
}
}

impl Notify for notification::Notifier {
fn notify(&self) {
unsafe {
notification::Notifier::notify_and_yield(self, NonZeroU32::new(1).unwrap());
}
}
}
}

0 comments on commit 4a71ea8

Please sign in to comment.