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

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

@ -1,51 +0,0 @@
use core::future::Future;
use core::pin::Pin;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
Failed,
AddressMisaligned,
BufferMisaligned,
}
pub trait Flash {
type ReadFuture<'a>: Future<Output = Result<(), Error>>;
type WriteFuture<'a>: Future<Output = Result<(), Error>>;
type ErasePageFuture<'a>: Future<Output = Result<(), Error>>;
/// Reads data from the flash device.
///
/// address must be a multiple of self.read_size().
/// buf.len() must be a multiple of self.read_size().
fn read<'a>(self: Pin<&'a mut Self>, address: usize, buf: &'a mut [u8])
-> Self::ReadFuture<'a>;
/// Writes data to the flash device.
///
/// address must be a multiple of self.write_size().
/// buf.len() must be a multiple of self.write_size().
fn write<'a>(self: Pin<&'a mut Self>, address: usize, buf: &'a [u8]) -> Self::WriteFuture<'a>;
/// Erases a single page from the flash device.
///
/// address must be a multiple of self.erase_size().
fn erase<'a>(self: Pin<&'a mut Self>, address: usize) -> Self::ErasePageFuture<'a>;
/// Returns the total size, in bytes.
/// This is not guaranteed to be a power of 2.
fn size(&self) -> usize;
/// Returns the read size in bytes.
/// This is guaranteed to be a power of 2.
fn read_size(&self) -> usize;
/// Returns the write size in bytes.
/// This is guaranteed to be a power of 2.
fn write_size(&self) -> usize;
/// Returns the erase size in bytes.
/// This is guaranteed to be a power of 2.
fn erase_size(&self) -> usize;
}

View File

@ -1,48 +0,0 @@
use core::future::Future;
use core::pin::Pin;
/// Wait for a pin to become high.
pub trait WaitForHigh {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a pin to become high.
///
/// If the pin is already high, the future completes immediately.
/// Otherwise, it completes when it becomes high.
fn wait_for_high<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a pin to become low.
pub trait WaitForLow {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a pin to become low.
///
/// If the pin is already low, the future completes immediately.
/// Otherwise, it completes when it becomes low.
fn wait_for_low<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a rising edge (transition from low to high)
pub trait WaitForRisingEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a rising edge (transition from low to high)
fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for a falling edge (transition from high to low)
pub trait WaitForFallingEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for a falling edge (transition from high to low)
fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}
/// Wait for any edge (any transition, high to low or low to high)
pub trait WaitForAnyEdge {
type Future<'a>: Future<Output = ()> + 'a;
/// Wait for any edge (any transition, high to low or low to high)
fn wait_for_any_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a>;
}

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;

View File

@ -1,15 +0,0 @@
use core::future::Future;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
Other,
}
pub trait Uart {
type ReceiveFuture<'a>: Future<Output = Result<(), Error>>;
type SendFuture<'a>: Future<Output = Result<(), Error>>;
fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReceiveFuture<'a>;
fn send<'a>(&'a mut self, buf: &'a [u8]) -> Self::SendFuture<'a>;
}