Move traits to separate crate.

This commit is contained in:
xoviat 2021-03-02 00:32:23 +01:00 committed by Dario Nieuwenhuis
parent 084b64053a
commit 9626aee7db
20 changed files with 53 additions and 22 deletions

2
.cargo/config Normal file
View File

@ -0,0 +1,2 @@
[unstable]
namespaced-features = true

View File

@ -2,6 +2,7 @@
[workspace]
members = [
"embassy",
"embassy-traits",
"embassy-nrf",
"embassy-stm32f4",
"embassy-nrf-examples",

View File

@ -7,7 +7,7 @@ Embassy is a project to make async/await a first-class option for embedded devel
`embassy` provides a set of traits and types specifically designed for `async` usage.
- `embassy::io`: `AsyncBufRead`, `AsyncWrite`. Traits for byte-stream IO, essentially `no_std` compatible versions of `futures::io`.
- `embassy::flash`: Flash device trait.
- `embassy::traits::flash`: Flash device trait.
- `embassy::time`: `Clock` and `Alarm` traits. Std-like `Duration` and `Instant`.
- More traits for SPI, I2C, UART async HAL coming soon.

View File

@ -12,7 +12,7 @@ use defmt::panic;
use nrf52840_hal::gpio;
use embassy::executor::{task, Executor};
use embassy::gpio::{WaitForHigh, WaitForLow};
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
use embassy::util::Forever;
use embassy_nrf::gpiote::{Gpiote, GpiotePin};
use embassy_nrf::interrupt;

View File

@ -12,7 +12,7 @@ use futures::pin_mut;
use nrf52840_hal::gpio;
use embassy::executor::{task, Executor};
use embassy::flash::Flash;
use embassy::traits::flash::Flash;
use embassy::util::Forever;
use embassy_nrf::{interrupt, qspi};

View File

@ -10,7 +10,7 @@ use cortex_m_rt::entry;
use defmt::panic;
use embassy::executor::{task, Executor};
use embassy::time::{Duration, Timer};
use embassy::uart::Uart;
use embassy::traits::uart::Uart;
use embassy::util::Forever;
use embassy_nrf::{interrupt, pac, rtc, uarte};
use futures::future::{select, Either};

View File

@ -4,7 +4,7 @@ use core::ops::Deref;
use core::pin::Pin;
use core::ptr;
use core::task::{Context, Poll};
use embassy::gpio::{WaitForHigh, WaitForLow};
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
use embassy::interrupt::InterruptExt;
use embassy::util::Signal;

View File

@ -23,7 +23,7 @@ use crate::util::peripheral::{PeripheralMutex, PeripheralState};
// - activate/deactivate
// - set gpio in high drive
use embassy::flash::{Error, Flash};
use embassy::traits::flash::{Error, Flash};
use embassy::util::{DropBomb, WakerRegistration};
use futures::future::poll_fn;

View File

@ -207,7 +207,7 @@ where
}
}
impl<T: Instance> embassy::uart::Uart for Uarte<T> {
impl<T: Instance> embassy::traits::uart::Uart for Uarte<T> {
type ReceiveFuture<'a> = ReceiveFuture<'a, T>;
type SendFuture<'a> = SendFuture<'a, T>;
@ -287,7 +287,7 @@ impl<'a, T> Future for SendFuture<'a, T>
where
T: Instance,
{
type Output = Result<(), embassy::uart::Error>;
type Output = Result<(), embassy::traits::uart::Error>;
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let Self { uarte, buf } = unsafe { self.get_unchecked_mut() };
@ -355,7 +355,7 @@ impl<'a, T> Future for ReceiveFuture<'a, T>
where
T: Instance,
{
type Output = Result<(), embassy::uart::Error>;
type Output = Result<(), embassy::traits::uart::Error>;
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let Self { uarte, buf } = unsafe { self.get_unchecked_mut() };

View File

@ -9,7 +9,7 @@ use example_common::{panic, *};
use cortex_m_rt::entry;
use embassy::executor::{task, Executor};
use embassy::gpio::*;
use embassy::traits::gpio::*;
use embassy::util::Forever;
use embassy_stm32f4::exti;
use embassy_stm32f4::interrupt;

View File

@ -10,7 +10,7 @@ use example_common::{panic, *};
use cortex_m::singleton;
use cortex_m_rt::entry;
use embassy::executor::{task, Executor};
use embassy::uart::Uart;
use embassy::traits::uart::Uart;
use embassy::util::Forever;
use embassy_stm32f4::interrupt;
use embassy_stm32f4::serial;

View File

@ -2,8 +2,8 @@ use core::future::Future;
use core::mem;
use core::pin::Pin;
use embassy::gpio::{WaitForFallingEdge, WaitForRisingEdge};
use embassy::interrupt::Interrupt;
use embassy::traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
use embassy::util::InterruptFuture;
use crate::hal::gpio;

View File

@ -9,7 +9,7 @@ use core::ptr;
use core::sync::atomic::{self, Ordering};
use embassy::interrupt::InterruptExt;
use embassy::uart::{Error, Uart};
use embassy::traits::uart::{Error, Uart};
use embassy::util::Signal;
use crate::hal::dma::config::DmaConfig;

17
embassy-traits/Cargo.toml Normal file
View File

@ -0,0 +1,17 @@
[package]
name = "embassy-traits"
version = "0.1.0"
authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
edition = "2018"
[dependencies]
defmt = { version = "0.2.0", optional = true }
[features]
std = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []

10
embassy-traits/src/lib.rs Normal file
View File

@ -0,0 +1,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(generic_associated_types)]
#![feature(const_fn)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_option)]
#![allow(incomplete_features)]
pub mod flash;
pub mod gpio;
pub mod uart;

View File

@ -5,12 +5,13 @@ authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
edition = "2018"
[features]
std = ["futures/std"]
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
std = ["futures/std", "embassy-traits/std"]
defmt = ["embassy-traits/defmt", "dep:defmt"]
defmt-trace = ["embassy-traits/defmt-trace"]
defmt-debug = ["embassy-traits/defmt-debug"]
defmt-info = ["embassy-traits/defmt-info"]
defmt-warn = ["embassy-traits/defmt-warn"]
defmt-error = ["embassy-traits/defmt-error"]
[dependencies]
defmt = { version = "0.2.0", optional = true }
@ -20,4 +21,5 @@ cortex-m = "0.7.1"
futures = { version = "0.3.5", default-features = false }
pin-project = { version = "1.0.2", default-features = false }
embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
embassy-traits = { version = "0.1.0", path = "../embassy-traits"}

View File

@ -9,10 +9,9 @@
pub(crate) mod fmt;
pub mod executor;
pub mod flash;
pub mod gpio;
pub mod interrupt;
pub mod io;
pub mod time;
pub mod uart;
pub mod util;
pub use embassy_traits as traits;