diff --git a/README.md b/README.md index 62aea006..fe273fdc 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 96f3e88b..38b8f286 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 c9bd2bc1..f64e2a95 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 e0fd1d96..1aa665fb 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 dd059eda..bfacdeef 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 4d0d2191..39875687 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 c4ef155e..00000000 --- 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 94e11dbc..00000000 --- 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 a41d0106..9c5c367a 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 ec97406b..00000000 --- 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 611c35ee..ccb5574d 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 9d8ef388..2be0e005 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 13c2191f..ff32941e 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 fa728692..eb1872d4 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 44673104..677e4089 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 de221463..d24f3f5c 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 d3618879..8b6bc010 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 070d17d4..67b212d5 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 f9bbd875..0b724fd8 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 69226750..5e33d79c 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 d61eb86c..f78066b7 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 16adcdb9..463dd83d 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 8e03861d..932cfcb8 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 2c27e276..f5d1a1d4 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 aad7cf6d..86252d55 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 ca76a129..654d5f47 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 c60b1d8b..37db9e05 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 10b7127d..dae673a5 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 5552b80d..85a2d845 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 7ba244ac..e1c7689e 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 f68fb4fa..f2e97699 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 63bfb9d2..1741508c 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"