From 0719b05d63a1d80d3b8ea39a411545a6e8e22ec2 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 27 Jan 2022 00:08:02 +0100 Subject: [PATCH] traits: migrate Delay to embedded-hal 1.0+async, remove Rng and Flash. --- README.md | 9 -- docs/modules/ROOT/pages/traits.adoc | 1 - embassy-nrf/Cargo.toml | 2 +- embassy-stm32/Cargo.toml | 2 +- embassy-stm32/src/rng.rs | 90 ++++++------ embassy-traits/Cargo.toml | 1 - embassy-traits/src/delay.rs | 13 -- embassy-traits/src/flash.rs | 57 -------- embassy-traits/src/lib.rs | 3 - embassy-traits/src/rng.rs | 75 ---------- embassy/Cargo.toml | 11 +- embassy/src/lib.rs | 1 - embassy/src/time/delay.rs | 129 +++++++++++------- examples/nrf/Cargo.toml | 1 - examples/stm32f1/Cargo.toml | 1 - examples/stm32f1/src/bin/adc.rs | 5 +- examples/stm32f3/Cargo.toml | 1 - examples/stm32f4/Cargo.toml | 3 +- examples/stm32f7/Cargo.toml | 1 - examples/stm32g0/Cargo.toml | 1 - examples/stm32g4/Cargo.toml | 1 - examples/stm32h7/Cargo.toml | 1 - examples/stm32h7/src/bin/rng.rs | 19 +-- examples/stm32l0/Cargo.toml | 1 - examples/stm32l1/Cargo.toml | 1 - examples/stm32l4/Cargo.toml | 2 +- examples/stm32l4/src/bin/rng.rs | 11 +- .../stm32l4/src/bin/usart_blocking_async.rs | 2 +- examples/stm32u5/Cargo.toml | 1 - examples/stm32wb55/Cargo.toml | 1 - examples/stm32wl55/Cargo.toml | 1 - tests/stm32/Cargo.toml | 1 - 32 files changed, 145 insertions(+), 304 deletions(-) delete mode 100644 embassy-traits/src/delay.rs delete mode 100644 embassy-traits/src/flash.rs delete mode 100644 embassy-traits/src/rng.rs diff --git a/README.md b/README.md index 62aea0064..fe273fdc1 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,6 @@ Embassy is a project to make async/await a first-class option for embedded development. For more information and instructions to get started, go to [https://embassy.dev](https://embassy.dev). -## Traits and types - -`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::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. - ## Executor The `embassy::executor` module provides an async/await executor designed for embedded usage. diff --git a/docs/modules/ROOT/pages/traits.adoc b/docs/modules/ROOT/pages/traits.adoc index 96f3e88bb..38b8f2862 100644 --- a/docs/modules/ROOT/pages/traits.adoc +++ b/docs/modules/ROOT/pages/traits.adoc @@ -3,7 +3,6 @@ Embassy provides a set of traits and types specifically designed for `async` usage. Many of these futures will be upstreamed to the `embedded-hal` crate at some point in the future, probably when the required GAT (Generic Associated Types) feature is stabilized in Rust. * `embassy::io`: `AsyncBufRead`, `AsyncWrite`. Traits for byte-stream IO, essentially `no_std` compatible versions of `futures::io`. The primary reason for re-defining these traits is that the `futures::io` variant requires `std::io::Error`, which does not work in the `no_std` environment. -* `embassy::traits`: Async traits for Flash, SPI, I2C, UART, RNG, GPIO and more. * `embassy::time`: Time `Driver` trait that is implemented for different platforms. Time in Embassy is represented using the `Duration` and `Instant` types. These traits are implemented by the platform-specific crates, such as `embassy-nrf` or `embassy-stm32`. diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index c9bd2bc14..f64e2a950 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -50,7 +50,7 @@ embassy = { version = "0.1.0", path = "../embassy" } embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } -embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index e0fd1d963..1aa665fb6 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -11,7 +11,7 @@ embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["s embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-net = { version = "0.1.0", path = "../embassy-net", default-features = false, optional = true } -embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index dd059eda7..bfacdeefa 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,8 +1,6 @@ #![macro_use] -use core::future::Future; use core::task::Poll; -use embassy::traits; use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; @@ -48,6 +46,46 @@ impl Rng { // Reference manual says to discard the first. let _ = self.next_u32(); } + + pub async fn async_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { + unsafe { + T::regs().cr().modify(|reg| { + reg.set_rngen(true); + }) + } + + for chunk in dest.chunks_mut(4) { + poll_fn(|cx| { + RNG_WAKER.register(cx.waker()); + unsafe { + T::regs().cr().modify(|reg| { + reg.set_ie(true); + }); + } + + let bits = unsafe { T::regs().sr().read() }; + + if bits.drdy() { + Poll::Ready(Ok(())) + } else if bits.seis() { + self.reset(); + Poll::Ready(Err(Error::SeedError)) + } else if bits.ceis() { + self.reset(); + Poll::Ready(Err(Error::ClockError)) + } else { + Poll::Pending + } + }) + .await?; + let random_bytes = unsafe { T::regs().dr().read() }.to_be_bytes(); + for (dest, src) in chunk.iter_mut().zip(random_bytes.iter()) { + *dest = *src + } + } + + Ok(()) + } } impl RngCore for Rng { @@ -83,54 +121,6 @@ impl RngCore for Rng { impl CryptoRng for Rng {} -impl traits::rng::Rng for Rng { - type Error = Error; - type RngFuture<'a> - where - Self: 'a, - = impl Future> + 'a; - - fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a> { - unsafe { - T::regs().cr().modify(|reg| { - reg.set_rngen(true); - }); - } - async move { - for chunk in dest.chunks_mut(4) { - poll_fn(|cx| { - RNG_WAKER.register(cx.waker()); - unsafe { - T::regs().cr().modify(|reg| { - reg.set_ie(true); - }); - } - - let bits = unsafe { T::regs().sr().read() }; - - if bits.drdy() { - Poll::Ready(Ok(())) - } else if bits.seis() { - self.reset(); - Poll::Ready(Err(Error::SeedError)) - } else if bits.ceis() { - self.reset(); - Poll::Ready(Err(Error::ClockError)) - } else { - Poll::Pending - } - }) - .await?; - let random_bytes = unsafe { T::regs().dr().read() }.to_be_bytes(); - for (dest, src) in chunk.iter_mut().zip(random_bytes.iter()) { - *dest = *src - } - } - Ok(()) - } - } -} - pub(crate) mod sealed { use super::*; diff --git a/embassy-traits/Cargo.toml b/embassy-traits/Cargo.toml index 4d0d21916..39875687f 100644 --- a/embassy-traits/Cargo.toml +++ b/embassy-traits/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" std = [] [dependencies] -defmt = { version = "0.3", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy" } embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy"} diff --git a/embassy-traits/src/delay.rs b/embassy-traits/src/delay.rs deleted file mode 100644 index c4ef155ee..000000000 --- a/embassy-traits/src/delay.rs +++ /dev/null @@ -1,13 +0,0 @@ -use core::future::Future; - -pub trait Delay { - type DelayFuture<'a>: Future + 'a - where - Self: 'a; - - /// Future that completes after now + millis - fn delay_ms(&mut self, millis: u64) -> Self::DelayFuture<'_>; - - /// Future that completes after now + micros - fn delay_us(&mut self, micros: u64) -> Self::DelayFuture<'_>; -} diff --git a/embassy-traits/src/flash.rs b/embassy-traits/src/flash.rs deleted file mode 100644 index 94e11dbc5..000000000 --- a/embassy-traits/src/flash.rs +++ /dev/null @@ -1,57 +0,0 @@ -use core::future::Future; - -#[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> - where - Self: 'a; - - type WriteFuture<'a>: Future> - where - Self: 'a; - - type ErasePageFuture<'a>: Future> - where - Self: 'a; - - /// 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>(&'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>(&'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(&mut self, address: usize) -> Self::ErasePageFuture<'_>; - - /// 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; -} diff --git a/embassy-traits/src/lib.rs b/embassy-traits/src/lib.rs index a41d0106f..9c5c367a8 100644 --- a/embassy-traits/src/lib.rs +++ b/embassy-traits/src/lib.rs @@ -3,6 +3,3 @@ #![feature(type_alias_impl_trait)] pub mod adapter; -pub mod delay; -pub mod flash; -pub mod rng; diff --git a/embassy-traits/src/rng.rs b/embassy-traits/src/rng.rs deleted file mode 100644 index ec97406b0..000000000 --- a/embassy-traits/src/rng.rs +++ /dev/null @@ -1,75 +0,0 @@ -use core::future::Future; - -/// Random-number Generator -pub trait Rng { - type Error; - - type RngFuture<'a>: Future> + 'a - where - Self: 'a; - - /// Completely fill the provided buffer with random bytes. - /// - /// May result in delays if entropy is exhausted prior to completely - /// filling the buffer. Upon completion, the buffer will be completely - /// filled or an error will have been reported. - fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a>; -} - -pub struct Random { - rng: T, -} - -impl Random { - pub fn new(rng: T) -> Self { - Self { rng } - } - - pub async fn next_u8(&mut self, range: u8) -> Result { - // Lemire's method - let t = (-(range as i8) % (range as i8)) as u8; - loop { - let mut buf = [0; 1]; - self.rng.fill_bytes(&mut buf).await?; - let x = u8::from_le_bytes(buf); - let m = x as u16 * range as u16; - let l = m as u8; - if l < t { - continue; - } - return Ok((m >> 8) as u8); - } - } - - pub async fn next_u16(&mut self, range: u16) -> Result { - // Lemire's method - let t = (-(range as i16) % (range as i16)) as u16; - loop { - let mut buf = [0; 2]; - self.rng.fill_bytes(&mut buf).await?; - let x = u16::from_le_bytes(buf); - let m = x as u32 * range as u32; - let l = m as u16; - if l < t { - continue; - } - return Ok((m >> 16) as u16); - } - } - - pub async fn next_u32(&mut self, range: u32) -> Result { - // Lemire's method - let t = (-(range as i32) % (range as i32)) as u32; - loop { - let mut buf = [0; 4]; - self.rng.fill_bytes(&mut buf).await?; - let x = u32::from_le_bytes(buf); - let m = x as u64 * range as u64; - let l = m as u32; - if l < t { - continue; - } - return Ok((m >> 32) as u32); - } - } -} diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml index 611c35eed..ccb5574d7 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml @@ -7,9 +7,12 @@ resolver = "2" [features] default = [] -std = ["futures/std", "embassy-traits/std", "time", "time-tick-1mhz", "embassy-macros/std"] +std = ["futures/std", "time", "time-tick-1mhz", "embassy-macros/std"] wasm = ["wasm-bindgen", "js-sys", "embassy-macros/wasm", "wasm-timer", "time", "time-tick-1mhz"] +# Implement embedded-hal 1.0 alpha and embedded-hal-async traits. +unstable-traits = ["embedded-hal-1", "embedded-hal-async"] + # Enable `embassy::time` module. # NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. # Enabling it directly without supplying a time driver will fail to link. @@ -29,13 +32,15 @@ executor-agnostic = [] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} +embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} + futures = { version = "0.3.17", default-features = false, features = [ "cfg-target-has-atomic", "unstable" ] } pin-project = { version = "1.0.8", default-features = false } embassy-macros = { version = "0.1.0", path = "../embassy-macros"} -embassy-traits = { version = "0.1.0", path = "../embassy-traits"} atomic-polyfill = "0.1.5" critical-section = "0.2.5" -embedded-hal = "0.2.6" heapless = "0.7.5" cfg-if = "1.0.0" diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 9d8ef3888..2be0e0052 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -21,7 +21,6 @@ pub mod time; pub mod util; pub use embassy_macros::*; -pub use embassy_traits as traits; #[doc(hidden)] /// Implementation details for embassy macros. DO NOT USE. diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs index 13c2191f6..ff32941ee 100644 --- a/embassy/src/time/delay.rs +++ b/embassy/src/time/delay.rs @@ -1,6 +1,10 @@ -use core::future::Future; +use super::{Duration, Instant}; -use super::{Duration, Instant, Timer}; +/// Blocks for at least `duration`. +pub fn block_for(duration: Duration) { + let expires_at = Instant::now() + duration; + while Instant::now() < expires_at {} +} /// Type implementing async delays and blocking `embedded-hal` delays. /// @@ -10,55 +14,86 @@ use super::{Duration, Instant, Timer}; /// active driver. pub struct Delay; -impl crate::traits::delay::Delay for Delay { - type DelayFuture<'a> = impl Future + 'a; +#[cfg(feature = "unstable-traits")] +mod eh1 { + use core::future::Future; + use futures::FutureExt; - fn delay_ms(&mut self, millis: u64) -> Self::DelayFuture<'_> { - Timer::after(Duration::from_millis(millis)) + use super::*; + use crate::time::Timer; + + impl embedded_hal_1::delay::blocking::DelayUs for Delay { + type Error = core::convert::Infallible; + + fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { + Ok(block_for(Duration::from_micros(us as u64))) + } + + fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { + Ok(block_for(Duration::from_millis(ms as u64))) + } } - fn delay_us(&mut self, micros: u64) -> Self::DelayFuture<'_> { - Timer::after(Duration::from_micros(micros)) + + impl embedded_hal_async::delay::DelayUs for Delay { + type Error = core::convert::Infallible; + + type DelayUsFuture<'a> + where + Self: 'a, + = impl Future> + 'a; + + fn delay_us(&mut self, micros: u32) -> Self::DelayUsFuture<'_> { + Timer::after(Duration::from_micros(micros as _)).map(Ok) + } + + type DelayMsFuture<'a> + where + Self: 'a, + = impl Future> + 'a; + + fn delay_ms(&mut self, millis: u32) -> Self::DelayMsFuture<'_> { + Timer::after(Duration::from_millis(millis as _)).map(Ok) + } } } -impl embedded_hal::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u8) { - block_for(Duration::from_millis(ms as u64)) +mod eh02 { + use super::*; + use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; + + impl DelayMs for Delay { + fn delay_ms(&mut self, ms: u8) { + block_for(Duration::from_millis(ms as u64)) + } + } + + impl DelayMs for Delay { + fn delay_ms(&mut self, ms: u16) { + block_for(Duration::from_millis(ms as u64)) + } + } + + impl DelayMs for Delay { + fn delay_ms(&mut self, ms: u32) { + block_for(Duration::from_millis(ms as u64)) + } + } + + impl DelayUs for Delay { + fn delay_us(&mut self, us: u8) { + block_for(Duration::from_micros(us as u64)) + } + } + + impl DelayUs for Delay { + fn delay_us(&mut self, us: u16) { + block_for(Duration::from_micros(us as u64)) + } + } + + impl DelayUs for Delay { + fn delay_us(&mut self, us: u32) { + block_for(Duration::from_micros(us as u64)) + } } } - -impl embedded_hal::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u16) { - block_for(Duration::from_millis(ms as u64)) - } -} - -impl embedded_hal::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u32) { - block_for(Duration::from_millis(ms as u64)) - } -} - -impl embedded_hal::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u8) { - block_for(Duration::from_micros(us as u64)) - } -} - -impl embedded_hal::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u16) { - block_for(Duration::from_micros(us as u64)) - } -} - -impl embedded_hal::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u32) { - block_for(Duration::from_micros(us as u64)) - } -} - -/// Blocks for at least `duration`. -pub fn block_for(duration: Duration) { - let expires_at = Instant::now() + duration; - while Instant::now() < expires_at {} -} diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index fa7286923..eb1872d45 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -7,7 +7,6 @@ version = "0.1.0" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } defmt = "0.3" diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 44673104e..677e40892 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } defmt = "0.3" diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index de2214630..d24f3f5cb 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs @@ -6,10 +6,9 @@ mod example_common; use embassy::executor::Spawner; -use embassy::time::Delay; +use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::adc::Adc; use embassy_stm32::Peripherals; -use embassy_traits::delay::Delay as _; use example_common::*; #[embassy::main] @@ -24,6 +23,6 @@ async fn main(_spawner: Spawner, p: Peripherals) { loop { let v = adc.read(&mut pin); info!("--> {} - {} mV", v, adc.to_millivolts(v)); - Delay.delay_ms(100).await; + Timer::after(Duration::from_millis(100)).await; } } diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index d36188798..8b6bc010c 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f303vc", "unstable-pac", "memory-x", "time-driver-any", "exti"] } defmt = "0.3" diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 070d17d48..67b212d5c 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -7,8 +7,7 @@ resolver = "2" [dependencies] -embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } +embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "unstable-traits"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } defmt = "0.3" diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index f9bbd8757..0b724fd85 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 692267501..5e33d79ca 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } defmt = "0.3" diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index d61eb86cd..f78066b7d 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 16adcdb91..463dd83d5 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -9,7 +9,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h743zi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] } embassy-hal-common = { path = "../../embassy-hal-common", default-features = false, features = ["defmt"] } diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index 8e03861d5..932cfcb8b 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs @@ -5,9 +5,6 @@ #[path = "../example_common.rs"] mod example_common; use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy::traits::rng::Random; -use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::rng::Rng; use embassy_stm32::Peripherals; use example_common::*; @@ -16,17 +13,9 @@ use example_common::*; async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); - let mut led = Output::new(p.PB14, Level::High, Speed::Low); + let mut rng = Rng::new(p.RNG); - let mut rng = Random::new(Rng::new(p.RNG)); - - loop { - info!("high {}", unwrap!(rng.next_u8(16).await)); - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - info!("low {}", unwrap!(rng.next_u8(16).await)); - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } + let mut buf = [0u8; 16]; + unwrap!(rng.async_fill_bytes(&mut buf).await); + info!("random bytes: {:02x}", buf); } diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 2c27e276c..f5d1a1d41 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] } diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index aad7cf6d2..86252d558 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } defmt = "0.3" diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index ca76a1299..654d5f473 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -9,7 +9,7 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt" ] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } +embassy-traits = { version = "0.1.0", path = "../../embassy-traits" } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } defmt = "0.3" diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index c60b1d8bc..37db9e05a 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -5,8 +5,6 @@ #[path = "../example_common.rs"] mod example_common; use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy::traits::rng::Random; use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, Peripherals}; @@ -28,10 +26,9 @@ fn config() -> Config { async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); - let mut rng = Random::new(Rng::new(p.RNG)); + let mut rng = Rng::new(p.RNG); - loop { - info!("random {}", unwrap!(rng.next_u8(16).await)); - Timer::after(Duration::from_secs(1)).await; - } + let mut buf = [0u8; 16]; + unwrap!(rng.async_fill_bytes(&mut buf).await); + info!("random bytes: {:02x}", buf); } diff --git a/examples/stm32l4/src/bin/usart_blocking_async.rs b/examples/stm32l4/src/bin/usart_blocking_async.rs index 10b7127da..dae673a5d 100644 --- a/examples/stm32l4/src/bin/usart_blocking_async.rs +++ b/examples/stm32l4/src/bin/usart_blocking_async.rs @@ -6,10 +6,10 @@ mod example_common; use embassy::executor::Spawner; -use embassy::traits::adapter::BlockingAsync; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; +use embassy_traits::adapter::BlockingAsync; use embedded_hal_async::serial::{Read, Write}; use example_common::*; diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 5552b80d9..85a2d8455 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32u585ai", "memory-x" ] } defmt = "0.3" diff --git a/examples/stm32wb55/Cargo.toml b/examples/stm32wb55/Cargo.toml index 7ba244ac6..e1c7689ef 100644 --- a/examples/stm32wb55/Cargo.toml +++ b/examples/stm32wb55/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wb55cc", "time-driver-any", "exti"] } defmt = "0.3" diff --git a/examples/stm32wl55/Cargo.toml b/examples/stm32wl55/Cargo.toml index f68fb4fa2..f2e97699b 100644 --- a/examples/stm32wl55/Cargo.toml +++ b/examples/stm32wl55/Cargo.toml @@ -7,7 +7,6 @@ resolver = "2" [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time"] } diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 63bfb9d22..1741508cb 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -14,7 +14,6 @@ stm32wb55rg = ["embassy-stm32/stm32wb55rg"] [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } -embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } defmt = "0.3.0"