embassy, embassy-nrf: add nightly
Cargo feature to gate nightly-only features.
This commit is contained in:
@ -10,8 +10,12 @@ default = []
|
||||
std = ["futures/std", "time", "time-tick-1mhz", "embassy-macros/std"]
|
||||
wasm = ["wasm-bindgen", "js-sys", "embassy-macros/wasm", "wasm-timer", "time", "time-tick-1mhz"]
|
||||
|
||||
# Enable nightly-only features
|
||||
nightly = ["embedded-hal-async"]
|
||||
|
||||
# Implement embedded-hal 1.0 alpha and embedded-hal-async traits.
|
||||
unstable-traits = ["embedded-hal-1", "embedded-hal-async"]
|
||||
# Implement embedded-hal-async traits if `nightly` is set as well.
|
||||
unstable-traits = ["embedded-hal-1"]
|
||||
|
||||
# Enable `embassy::time` module.
|
||||
# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation.
|
||||
|
@ -32,13 +32,15 @@ enum State<T> {
|
||||
unsafe impl<T: Send> Send for Signal<T> {}
|
||||
unsafe impl<T: Send> Sync for Signal<T> {}
|
||||
|
||||
impl<T: Send> Signal<T> {
|
||||
impl<T> Signal<T> {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
state: UnsafeCell::new(State::None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send> Signal<T> {
|
||||
/// Mark this Signal as completed.
|
||||
pub fn signal(&self, val: T) {
|
||||
critical_section::with(|_| unsafe {
|
||||
|
@ -57,6 +57,7 @@ pub struct TaskHeader {
|
||||
}
|
||||
|
||||
impl TaskHeader {
|
||||
#[cfg(feature = "nightly")]
|
||||
pub(crate) const fn new() -> Self {
|
||||
Self {
|
||||
state: AtomicU32::new(0),
|
||||
@ -71,6 +72,21 @@ impl TaskHeader {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
state: AtomicU32::new(0),
|
||||
run_queue_item: RunQueueItem::new(),
|
||||
executor: Cell::new(ptr::null()),
|
||||
poll_fn: UninitCell::uninit(),
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
expires_at: Cell::new(Instant::from_ticks(0)),
|
||||
#[cfg(feature = "time")]
|
||||
timer_queue_item: timer_queue::TimerQueueItem::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn enqueue(&self) {
|
||||
critical_section::with(|cs| {
|
||||
let state = self.state.load(Ordering::Relaxed);
|
||||
@ -113,7 +129,8 @@ pub struct TaskStorage<F: Future + 'static> {
|
||||
}
|
||||
|
||||
impl<F: Future + 'static> TaskStorage<F> {
|
||||
/// Create a new Task, in not-spawned state.
|
||||
/// Create a new TaskStorage, in not-spawned state.
|
||||
#[cfg(feature = "nightly")]
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
raw: TaskHeader::new(),
|
||||
@ -121,6 +138,15 @@ impl<F: Future + 'static> TaskStorage<F> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new TaskStorage, in not-spawned state.
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
raw: TaskHeader::new(),
|
||||
future: UninitCell::uninit(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to spawn a task in a pool.
|
||||
///
|
||||
/// See [`Self::spawn()`] for details.
|
||||
|
@ -1,8 +1,13 @@
|
||||
#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)]
|
||||
#![feature(generic_associated_types)]
|
||||
#![feature(const_fn_trait_bound)]
|
||||
#![feature(const_fn_fn_ptr_basics)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![cfg_attr(
|
||||
feature = "nightly",
|
||||
feature(
|
||||
const_fn_trait_bound,
|
||||
const_fn_fn_ptr_basics,
|
||||
generic_associated_types,
|
||||
type_alias_impl_trait
|
||||
)
|
||||
)]
|
||||
#![allow(clippy::new_without_default)]
|
||||
|
||||
// This mod MUST go first, so that the others see its macros.
|
||||
@ -20,7 +25,8 @@ pub mod io;
|
||||
pub mod time;
|
||||
pub mod util;
|
||||
|
||||
pub use embassy_macros::*;
|
||||
#[cfg(feature = "nightly")]
|
||||
pub use embassy_macros::{main, task};
|
||||
|
||||
#[doc(hidden)]
|
||||
/// Implementation details for embassy macros. DO NOT USE.
|
||||
|
@ -16,11 +16,7 @@ pub struct Delay;
|
||||
|
||||
#[cfg(feature = "unstable-traits")]
|
||||
mod eh1 {
|
||||
use core::future::Future;
|
||||
use futures::FutureExt;
|
||||
|
||||
use super::*;
|
||||
use crate::time::Timer;
|
||||
|
||||
impl embedded_hal_1::delay::blocking::DelayUs for Delay {
|
||||
type Error = core::convert::Infallible;
|
||||
@ -33,6 +29,14 @@ mod eh1 {
|
||||
Ok(block_for(Duration::from_millis(ms as u64)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable-traits", feature = "nightly"))]
|
||||
mod eh1a {
|
||||
use super::*;
|
||||
use crate::time::Timer;
|
||||
use core::future::Future;
|
||||
use futures::FutureExt;
|
||||
|
||||
impl embedded_hal_async::delay::DelayUs for Delay {
|
||||
type Error = core::convert::Infallible;
|
||||
|
Reference in New Issue
Block a user