diff options
164 files changed, 923 insertions, 434 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d76e5ced4..d2e8e316b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml | |||
| @@ -69,4 +69,4 @@ jobs: | |||
| 69 | steps: | 69 | steps: |
| 70 | - uses: actions/checkout@v2 | 70 | - uses: actions/checkout@v2 |
| 71 | - name: Test | 71 | - name: Test |
| 72 | run: cd embassy-util && cargo test | 72 | run: cd embassy-sync && cargo test |
diff --git a/.vscode/settings.json b/.vscode/settings.json index d6ce75c99..5e9e51799 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | "rust-analyzer.linkedProjects": [ | 18 | "rust-analyzer.linkedProjects": [ |
| 19 | // Declare for the target you wish to develop | 19 | // Declare for the target you wish to develop |
| 20 | //"embassy-executor/Cargo.toml", | 20 | //"embassy-executor/Cargo.toml", |
| 21 | //"embassy-util/Cargo.toml", | 21 | //"embassy-sync/Cargo.toml", |
| 22 | "examples/nrf/Cargo.toml", | 22 | "examples/nrf/Cargo.toml", |
| 23 | // "examples/rp/Cargo.toml", | 23 | // "examples/rp/Cargo.toml", |
| 24 | // "examples/std/Cargo.toml", | 24 | // "examples/std/Cargo.toml", |
diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index 9c2e72be5..a42f88688 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml | |||
| @@ -14,7 +14,7 @@ target = "thumbv7em-none-eabi" | |||
| 14 | [dependencies] | 14 | [dependencies] |
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
| 16 | log = { version = "0.4", optional = true } | 16 | log = { version = "0.4", optional = true } |
| 17 | embassy-util = { version = "0.1.0", path = "../../embassy-util" } | 17 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync" } |
| 18 | embedded-storage = "0.3.0" | 18 | embedded-storage = "0.3.0" |
| 19 | embedded-storage-async = "0.3.0" | 19 | embedded-storage-async = "0.3.0" |
| 20 | 20 | ||
diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml index b06e8102c..234393e7c 100644 --- a/embassy-boot/nrf/Cargo.toml +++ b/embassy-boot/nrf/Cargo.toml | |||
| @@ -15,7 +15,7 @@ target = "thumbv7em-none-eabi" | |||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "0.3", optional = true } |
| 17 | 17 | ||
| 18 | embassy-util = { path = "../../embassy-util" } | 18 | embassy-sync = { path = "../../embassy-sync" } |
| 19 | embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } | 19 | embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } |
| 20 | embassy-boot = { path = "../boot", default-features = false } | 20 | embassy-boot = { path = "../boot", default-features = false } |
| 21 | cortex-m = { version = "0.7.6" } | 21 | cortex-m = { version = "0.7.6" } |
diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index d8f492531..ad4657e0d 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml | |||
| @@ -17,7 +17,7 @@ defmt = { version = "0.3", optional = true } | |||
| 17 | defmt-rtt = { version = "0.3", optional = true } | 17 | defmt-rtt = { version = "0.3", optional = true } |
| 18 | log = { version = "0.4", optional = true } | 18 | log = { version = "0.4", optional = true } |
| 19 | 19 | ||
| 20 | embassy-util = { path = "../../embassy-util" } | 20 | embassy-sync = { path = "../../embassy-sync" } |
| 21 | embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] } | 21 | embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] } |
| 22 | embassy-boot = { path = "../boot", default-features = false } | 22 | embassy-boot = { path = "../boot", default-features = false } |
| 23 | cortex-m = { version = "0.7.6" } | 23 | cortex-m = { version = "0.7.6" } |
diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml index 1f16da31b..7efced669 100644 --- a/embassy-cortex-m/Cargo.toml +++ b/embassy-cortex-m/Cargo.toml | |||
| @@ -35,7 +35,7 @@ prio-bits-8 = [] | |||
| 35 | defmt = { version = "0.3", optional = true } | 35 | defmt = { version = "0.3", optional = true } |
| 36 | log = { version = "0.4.14", optional = true } | 36 | log = { version = "0.4.14", optional = true } |
| 37 | 37 | ||
| 38 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 38 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 39 | embassy-executor = { version = "0.1.0", path = "../embassy-executor"} | 39 | embassy-executor = { version = "0.1.0", path = "../embassy-executor"} |
| 40 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} | 40 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} |
| 41 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} | 41 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} |
diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs index 80c452f84..0d1745d8a 100644 --- a/embassy-cortex-m/src/executor.rs +++ b/embassy-cortex-m/src/executor.rs | |||
| @@ -71,7 +71,7 @@ impl<I: Interrupt> InterruptExecutor<I> { | |||
| 71 | /// Executor instance in a place where it'll live forever and grants you mutable | 71 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 72 | /// access. There's a few ways to do this: | 72 | /// access. There's a few ways to do this: |
| 73 | /// | 73 | /// |
| 74 | /// - a [Forever](embassy_util::Forever) (safe) | 74 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 75 | /// - a `static mut` (unsafe) | 75 | /// - a `static mut` (unsafe) |
| 76 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 76 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 77 | pub fn start(&'static mut self) -> SendSpawner { | 77 | pub fn start(&'static mut self) -> SendSpawner { |
diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 866666871..462680720 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml | |||
| @@ -16,7 +16,7 @@ std = [] | |||
| 16 | nightly = ["embedded-hal-async", "embedded-storage-async"] | 16 | nightly = ["embedded-hal-async", "embedded-storage-async"] |
| 17 | 17 | ||
| 18 | [dependencies] | 18 | [dependencies] |
| 19 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 19 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 20 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 20 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 21 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } | 21 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } |
| 22 | embedded-hal-async = { version = "0.1.0-alpha.1", optional = true } | 22 | embedded-hal-async = { version = "0.1.0-alpha.1", optional = true } |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs index bd023fb6a..0bc6afd98 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | |||
| @@ -4,15 +4,15 @@ | |||
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::i2c::I2cDevice; | 6 | //! use embassy_embedded_hal::shared_bus::i2c::I2cDevice; |
| 7 | //! use embassy_util::mutex::Mutex; | 7 | //! use embassy_sync::mutex::Mutex; |
| 8 | //! use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 8 | //! use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 9 | //! | 9 | //! |
| 10 | //! static I2C_BUS: Forever<Mutex::<ThreadModeRawMutex, Twim<TWISPI0>>> = Forever::new(); | 10 | //! static I2C_BUS: StaticCell<Mutex::<ThreadModeRawMutex, Twim<TWISPI0>>> = StaticCell::new(); |
| 11 | //! let config = twim::Config::default(); | 11 | //! let config = twim::Config::default(); |
| 12 | //! let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | 12 | //! let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); |
| 13 | //! let i2c = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); | 13 | //! let i2c = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); |
| 14 | //! let i2c_bus = Mutex::<ThreadModeRawMutex, _>::new(i2c); | 14 | //! let i2c_bus = Mutex::<ThreadModeRawMutex, _>::new(i2c); |
| 15 | //! let i2c_bus = I2C_BUS.put(i2c_bus); | 15 | //! let i2c_bus = I2C_BUS.init(i2c_bus); |
| 16 | //! | 16 | //! |
| 17 | //! // Device 1, using embedded-hal-async compatible driver for QMC5883L compass | 17 | //! // Device 1, using embedded-hal-async compatible driver for QMC5883L compass |
| 18 | //! let i2c_dev1 = I2cDevice::new(i2c_bus); | 18 | //! let i2c_dev1 = I2cDevice::new(i2c_bus); |
| @@ -24,8 +24,8 @@ | |||
| 24 | //! ``` | 24 | //! ``` |
| 25 | use core::future::Future; | 25 | use core::future::Future; |
| 26 | 26 | ||
| 27 | use embassy_util::blocking_mutex::raw::RawMutex; | 27 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 28 | use embassy_util::mutex::Mutex; | 28 | use embassy_sync::mutex::Mutex; |
| 29 | use embedded_hal_async::i2c; | 29 | use embedded_hal_async::i2c; |
| 30 | 30 | ||
| 31 | use crate::shared_bus::I2cDeviceError; | 31 | use crate::shared_bus::I2cDeviceError; |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index caa37f6f3..c95b59ef0 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -4,16 +4,16 @@ | |||
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::spi::SpiDevice; | 6 | //! use embassy_embedded_hal::shared_bus::spi::SpiDevice; |
| 7 | //! use embassy_util::mutex::Mutex; | 7 | //! use embassy_sync::mutex::Mutex; |
| 8 | //! use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 8 | //! use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 9 | //! | 9 | //! |
| 10 | //! static SPI_BUS: Forever<Mutex<ThreadModeRawMutex, spim::Spim<SPI3>>> = Forever::new(); | 10 | //! static SPI_BUS: StaticCell<Mutex<ThreadModeRawMutex, spim::Spim<SPI3>>> = StaticCell::new(); |
| 11 | //! let mut config = spim::Config::default(); | 11 | //! let mut config = spim::Config::default(); |
| 12 | //! config.frequency = spim::Frequency::M32; | 12 | //! config.frequency = spim::Frequency::M32; |
| 13 | //! let irq = interrupt::take!(SPIM3); | 13 | //! let irq = interrupt::take!(SPIM3); |
| 14 | //! let spi = spim::Spim::new_txonly(p.SPI3, irq, p.P0_15, p.P0_18, config); | 14 | //! let spi = spim::Spim::new_txonly(p.SPI3, irq, p.P0_15, p.P0_18, config); |
| 15 | //! let spi_bus = Mutex::<ThreadModeRawMutex, _>::new(spi); | 15 | //! let spi_bus = Mutex::<ThreadModeRawMutex, _>::new(spi); |
| 16 | //! let spi_bus = SPI_BUS.put(spi_bus); | 16 | //! let spi_bus = SPI_BUS.init(spi_bus); |
| 17 | //! | 17 | //! |
| 18 | //! // Device 1, using embedded-hal-async compatible driver for ST7735 LCD display | 18 | //! // Device 1, using embedded-hal-async compatible driver for ST7735 LCD display |
| 19 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); | 19 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); |
| @@ -27,8 +27,8 @@ | |||
| 27 | //! ``` | 27 | //! ``` |
| 28 | use core::future::Future; | 28 | use core::future::Future; |
| 29 | 29 | ||
| 30 | use embassy_util::blocking_mutex::raw::RawMutex; | 30 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 31 | use embassy_util::mutex::Mutex; | 31 | use embassy_sync::mutex::Mutex; |
| 32 | use embedded_hal_1::digital::blocking::OutputPin; | 32 | use embedded_hal_1::digital::blocking::OutputPin; |
| 33 | use embedded_hal_1::spi::ErrorType; | 33 | use embedded_hal_1::spi::ErrorType; |
| 34 | use embedded_hal_async::spi; | 34 | use embedded_hal_async::spi; |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 1fc343d15..a611e2d27 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; | 6 | //! use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; |
| 7 | //! use embassy_util::blocking_mutex::{NoopMutex, raw::NoopRawMutex}; | 7 | //! use embassy_sync::blocking_mutex::{NoopMutex, raw::NoopRawMutex}; |
| 8 | //! | 8 | //! |
| 9 | //! static I2C_BUS: Forever<NoopMutex<RefCell<Twim<TWISPI0>>>> = Forever::new(); | 9 | //! static I2C_BUS: StaticCell<NoopMutex<RefCell<Twim<TWISPI0>>>> = StaticCell::new(); |
| 10 | //! let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); | 10 | //! let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); |
| 11 | //! let i2c = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, Config::default()); | 11 | //! let i2c = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, Config::default()); |
| 12 | //! let i2c_bus = NoopMutex::new(RefCell::new(i2c)); | 12 | //! let i2c_bus = NoopMutex::new(RefCell::new(i2c)); |
| 13 | //! let i2c_bus = I2C_BUS.put(i2c_bus); | 13 | //! let i2c_bus = I2C_BUS.init(i2c_bus); |
| 14 | //! | 14 | //! |
| 15 | //! let i2c_dev1 = I2cDevice::new(i2c_bus); | 15 | //! let i2c_dev1 = I2cDevice::new(i2c_bus); |
| 16 | //! let mpu = Mpu6050::new(i2c_dev1); | 16 | //! let mpu = Mpu6050::new(i2c_dev1); |
| @@ -18,8 +18,8 @@ | |||
| 18 | 18 | ||
| 19 | use core::cell::RefCell; | 19 | use core::cell::RefCell; |
| 20 | 20 | ||
| 21 | use embassy_util::blocking_mutex::raw::RawMutex; | 21 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 22 | use embassy_util::blocking_mutex::Mutex; | 22 | use embassy_sync::blocking_mutex::Mutex; |
| 23 | use embedded_hal_1::i2c::blocking::{I2c, Operation}; | 23 | use embedded_hal_1::i2c::blocking::{I2c, Operation}; |
| 24 | use embedded_hal_1::i2c::ErrorType; | 24 | use embedded_hal_1::i2c::ErrorType; |
| 25 | 25 | ||
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index a61326594..23845d887 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -4,13 +4,13 @@ | |||
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice; | 6 | //! use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice; |
| 7 | //! use embassy_util::blocking_mutex::{NoopMutex, raw::NoopRawMutex}; | 7 | //! use embassy_sync::blocking_mutex::{NoopMutex, raw::NoopRawMutex}; |
| 8 | //! | 8 | //! |
| 9 | //! static SPI_BUS: Forever<NoopMutex<RefCell<Spim<SPI3>>>> = Forever::new(); | 9 | //! static SPI_BUS: StaticCell<NoopMutex<RefCell<Spim<SPI3>>>> = StaticCell::new(); |
| 10 | //! let irq = interrupt::take!(SPIM3); | 10 | //! let irq = interrupt::take!(SPIM3); |
| 11 | //! let spi = Spim::new_txonly(p.SPI3, irq, p.P0_15, p.P0_18, Config::default()); | 11 | //! let spi = Spim::new_txonly(p.SPI3, irq, p.P0_15, p.P0_18, Config::default()); |
| 12 | //! let spi_bus = NoopMutex::new(RefCell::new(spi)); | 12 | //! let spi_bus = NoopMutex::new(RefCell::new(spi)); |
| 13 | //! let spi_bus = SPI_BUS.put(spi_bus); | 13 | //! let spi_bus = SPI_BUS.init(spi_bus); |
| 14 | //! | 14 | //! |
| 15 | //! // Device 1, using embedded-hal compatible driver for ST7735 LCD display | 15 | //! // Device 1, using embedded-hal compatible driver for ST7735 LCD display |
| 16 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); | 16 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); |
| @@ -20,8 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | use core::cell::RefCell; | 21 | use core::cell::RefCell; |
| 22 | 22 | ||
| 23 | use embassy_util::blocking_mutex::raw::RawMutex; | 23 | use embassy_sync::blocking_mutex::raw::RawMutex; |
| 24 | use embassy_util::blocking_mutex::Mutex; | 24 | use embassy_sync::blocking_mutex::Mutex; |
| 25 | use embedded_hal_1::digital::blocking::OutputPin; | 25 | use embedded_hal_1::digital::blocking::OutputPin; |
| 26 | use embedded_hal_1::spi; | 26 | use embedded_hal_1::spi; |
| 27 | use embedded_hal_1::spi::blocking::SpiBusFlush; | 27 | use embedded_hal_1::spi::blocking::SpiBusFlush; |
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 25c3f0abd..1a611720c 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -30,9 +30,13 @@ nightly = [] | |||
| 30 | 30 | ||
| 31 | integrated-timers = ["dep:embassy-time"] | 31 | integrated-timers = ["dep:embassy-time"] |
| 32 | 32 | ||
| 33 | # Trace interrupt invocations with rtos-trace. | ||
| 34 | rtos-trace-interrupt = ["rtos-trace"] | ||
| 35 | |||
| 33 | [dependencies] | 36 | [dependencies] |
| 34 | defmt = { version = "0.3", optional = true } | 37 | defmt = { version = "0.3", optional = true } |
| 35 | log = { version = "0.4.14", optional = true } | 38 | log = { version = "0.4.14", optional = true } |
| 39 | rtos-trace = { version = "0.1.2", optional = true } | ||
| 36 | 40 | ||
| 37 | futures-util = { version = "0.3.17", default-features = false } | 41 | futures-util = { version = "0.3.17", default-features = false } |
| 38 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} | 42 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} |
| @@ -40,7 +44,8 @@ embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true} | |||
| 40 | atomic-polyfill = "1.0.1" | 44 | atomic-polyfill = "1.0.1" |
| 41 | critical-section = "1.1" | 45 | critical-section = "1.1" |
| 42 | cfg-if = "1.0.0" | 46 | cfg-if = "1.0.0" |
| 47 | static_cell = "1.0" | ||
| 43 | 48 | ||
| 44 | # WASM dependencies | 49 | # WASM dependencies |
| 45 | wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } | 50 | wasm-bindgen = { version = "0.2.82", optional = true } |
| 46 | js-sys = { version = "0.3", optional = true } \ No newline at end of file | 51 | js-sys = { version = "0.3", optional = true } |
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs index d6e758dfb..4b27a264e 100644 --- a/embassy-executor/src/arch/cortex_m.rs +++ b/embassy-executor/src/arch/cortex_m.rs | |||
| @@ -41,7 +41,7 @@ impl Executor { | |||
| 41 | /// Executor instance in a place where it'll live forever and grants you mutable | 41 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 42 | /// access. There's a few ways to do this: | 42 | /// access. There's a few ways to do this: |
| 43 | /// | 43 | /// |
| 44 | /// - a [Forever](crate::util::Forever) (safe) | 44 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 45 | /// - a `static mut` (unsafe) | 45 | /// - a `static mut` (unsafe) |
| 46 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 46 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 47 | /// | 47 | /// |
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs index 7a7d5698c..2a4b006da 100644 --- a/embassy-executor/src/arch/riscv32.rs +++ b/embassy-executor/src/arch/riscv32.rs | |||
| @@ -43,7 +43,7 @@ impl Executor { | |||
| 43 | /// Executor instance in a place where it'll live forever and grants you mutable | 43 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 44 | /// access. There's a few ways to do this: | 44 | /// access. There's a few ways to do this: |
| 45 | /// | 45 | /// |
| 46 | /// - a [Forever](crate::util::Forever) (safe) | 46 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 47 | /// - a `static mut` (unsafe) | 47 | /// - a `static mut` (unsafe) |
| 48 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 48 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 49 | /// | 49 | /// |
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs index b93ab8a79..701f0eb18 100644 --- a/embassy-executor/src/arch/std.rs +++ b/embassy-executor/src/arch/std.rs | |||
| @@ -40,7 +40,7 @@ impl Executor { | |||
| 40 | /// Executor instance in a place where it'll live forever and grants you mutable | 40 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 41 | /// access. There's a few ways to do this: | 41 | /// access. There's a few ways to do this: |
| 42 | /// | 42 | /// |
| 43 | /// - a [Forever](crate::util::Forever) (safe) | 43 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 44 | /// - a `static mut` (unsafe) | 44 | /// - a `static mut` (unsafe) |
| 45 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 45 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 46 | /// | 46 | /// |
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs index 9d5aa31ed..98091cfbb 100644 --- a/embassy-executor/src/arch/wasm.rs +++ b/embassy-executor/src/arch/wasm.rs | |||
| @@ -59,7 +59,7 @@ impl Executor { | |||
| 59 | /// Executor instance in a place where it'll live forever and grants you mutable | 59 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 60 | /// access. There's a few ways to do this: | 60 | /// access. There's a few ways to do this: |
| 61 | /// | 61 | /// |
| 62 | /// - a [Forever](crate::util::Forever) (safe) | 62 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 63 | /// - a `static mut` (unsafe) | 63 | /// - a `static mut` (unsafe) |
| 64 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 64 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 65 | pub fn start(&'static mut self, init: impl FnOnce(Spawner)) { | 65 | pub fn start(&'static mut self, init: impl FnOnce(Spawner)) { |
diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs index 20bd7b8a5..f908aaa70 100644 --- a/embassy-executor/src/arch/xtensa.rs +++ b/embassy-executor/src/arch/xtensa.rs | |||
| @@ -43,7 +43,7 @@ impl Executor { | |||
| 43 | /// Executor instance in a place where it'll live forever and grants you mutable | 43 | /// Executor instance in a place where it'll live forever and grants you mutable |
| 44 | /// access. There's a few ways to do this: | 44 | /// access. There's a few ways to do this: |
| 45 | /// | 45 | /// |
| 46 | /// - a [Forever](crate::util::Forever) (safe) | 46 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) |
| 47 | /// - a `static mut` (unsafe) | 47 | /// - a `static mut` (unsafe) |
| 48 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | 48 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) |
| 49 | /// | 49 | /// |
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 9328a7378..e4cbd04b9 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -38,7 +38,38 @@ cfg_if::cfg_if! { | |||
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[doc(hidden)] | ||
| 42 | /// Implementation details for embassy macros. DO NOT USE. | ||
| 43 | pub mod export { | ||
| 44 | #[cfg(feature = "rtos-trace")] | ||
| 45 | pub use rtos_trace::trace; | ||
| 46 | |||
| 47 | /// Expands the given block of code when `embassy-executor` is compiled with | ||
| 48 | /// the `rtos-trace-interrupt` feature. | ||
| 49 | #[doc(hidden)] | ||
| 50 | #[macro_export] | ||
| 51 | #[cfg(feature = "rtos-trace-interrupt")] | ||
| 52 | macro_rules! rtos_trace_interrupt { | ||
| 53 | ($($tt:tt)*) => { $($tt)* }; | ||
| 54 | } | ||
| 55 | |||
| 56 | /// Does not expand the given block of code when `embassy-executor` is | ||
| 57 | /// compiled without the `rtos-trace-interrupt` feature. | ||
| 58 | #[doc(hidden)] | ||
| 59 | #[macro_export] | ||
| 60 | #[cfg(not(feature = "rtos-trace-interrupt"))] | ||
| 61 | macro_rules! rtos_trace_interrupt { | ||
| 62 | ($($tt:tt)*) => {}; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 41 | pub mod raw; | 66 | pub mod raw; |
| 42 | 67 | ||
| 43 | mod spawner; | 68 | mod spawner; |
| 44 | pub use spawner::*; | 69 | pub use spawner::*; |
| 70 | |||
| 71 | /// Do not use. Used for macros and HALs only. Not covered by semver guarantees. | ||
| 72 | #[doc(hidden)] | ||
| 73 | pub mod _export { | ||
| 74 | pub use static_cell::StaticCell; | ||
| 75 | } | ||
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index afe67decb..e1258ebb5 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | //! ## WARNING: here be dragons! | 5 | //! ## WARNING: here be dragons! |
| 6 | //! | 6 | //! |
| 7 | //! Using this module requires respecting subtle safety contracts. If you can, prefer using the safe | 7 | //! Using this module requires respecting subtle safety contracts. If you can, prefer using the safe |
| 8 | //! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. | 8 | //! [executor wrappers](crate::Executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. |
| 9 | 9 | ||
| 10 | mod run_queue; | 10 | mod run_queue; |
| 11 | #[cfg(feature = "integrated-timers")] | 11 | #[cfg(feature = "integrated-timers")] |
| @@ -26,6 +26,8 @@ use critical_section::CriticalSection; | |||
| 26 | use embassy_time::driver::{self, AlarmHandle}; | 26 | use embassy_time::driver::{self, AlarmHandle}; |
| 27 | #[cfg(feature = "integrated-timers")] | 27 | #[cfg(feature = "integrated-timers")] |
| 28 | use embassy_time::Instant; | 28 | use embassy_time::Instant; |
| 29 | #[cfg(feature = "rtos-trace")] | ||
| 30 | use rtos_trace::trace; | ||
| 29 | 31 | ||
| 30 | use self::run_queue::{RunQueue, RunQueueItem}; | 32 | use self::run_queue::{RunQueue, RunQueueItem}; |
| 31 | use self::util::UninitCell; | 33 | use self::util::UninitCell; |
| @@ -247,7 +249,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | |||
| 247 | /// | 249 | /// |
| 248 | /// This is the core of the Embassy executor. It is low-level, requiring manual | 250 | /// This is the core of the Embassy executor. It is low-level, requiring manual |
| 249 | /// handling of wakeups and task polling. If you can, prefer using one of the | 251 | /// handling of wakeups and task polling. If you can, prefer using one of the |
| 250 | /// higher level executors in [`crate::executor`]. | 252 | /// [higher level executors](crate::Executor). |
| 251 | /// | 253 | /// |
| 252 | /// The raw executor leaves it up to you to handle wakeups and scheduling: | 254 | /// The raw executor leaves it up to you to handle wakeups and scheduling: |
| 253 | /// | 255 | /// |
| @@ -306,6 +308,9 @@ impl Executor { | |||
| 306 | /// - `task` must NOT be already enqueued (in this executor or another one). | 308 | /// - `task` must NOT be already enqueued (in this executor or another one). |
| 307 | #[inline(always)] | 309 | #[inline(always)] |
| 308 | unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull<TaskHeader>) { | 310 | unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull<TaskHeader>) { |
| 311 | #[cfg(feature = "rtos-trace")] | ||
| 312 | trace::task_ready_begin(task.as_ptr() as u32); | ||
| 313 | |||
| 309 | if self.run_queue.enqueue(cs, task) { | 314 | if self.run_queue.enqueue(cs, task) { |
| 310 | (self.signal_fn)(self.signal_ctx) | 315 | (self.signal_fn)(self.signal_ctx) |
| 311 | } | 316 | } |
| @@ -323,6 +328,9 @@ impl Executor { | |||
| 323 | pub(super) unsafe fn spawn(&'static self, task: NonNull<TaskHeader>) { | 328 | pub(super) unsafe fn spawn(&'static self, task: NonNull<TaskHeader>) { |
| 324 | task.as_ref().executor.set(self); | 329 | task.as_ref().executor.set(self); |
| 325 | 330 | ||
| 331 | #[cfg(feature = "rtos-trace")] | ||
| 332 | trace::task_new(task.as_ptr() as u32); | ||
| 333 | |||
| 326 | critical_section::with(|cs| { | 334 | critical_section::with(|cs| { |
| 327 | self.enqueue(cs, task); | 335 | self.enqueue(cs, task); |
| 328 | }) | 336 | }) |
| @@ -365,9 +373,15 @@ impl Executor { | |||
| 365 | return; | 373 | return; |
| 366 | } | 374 | } |
| 367 | 375 | ||
| 376 | #[cfg(feature = "rtos-trace")] | ||
| 377 | trace::task_exec_begin(p.as_ptr() as u32); | ||
| 378 | |||
| 368 | // Run the task | 379 | // Run the task |
| 369 | task.poll_fn.read()(p as _); | 380 | task.poll_fn.read()(p as _); |
| 370 | 381 | ||
| 382 | #[cfg(feature = "rtos-trace")] | ||
| 383 | trace::task_exec_end(); | ||
| 384 | |||
| 371 | // Enqueue or update into timer_queue | 385 | // Enqueue or update into timer_queue |
| 372 | #[cfg(feature = "integrated-timers")] | 386 | #[cfg(feature = "integrated-timers")] |
| 373 | self.timer_queue.update(p); | 387 | self.timer_queue.update(p); |
| @@ -381,6 +395,9 @@ impl Executor { | |||
| 381 | let next_expiration = self.timer_queue.next_expiration(); | 395 | let next_expiration = self.timer_queue.next_expiration(); |
| 382 | driver::set_alarm(self.alarm, next_expiration.as_ticks()); | 396 | driver::set_alarm(self.alarm, next_expiration.as_ticks()); |
| 383 | } | 397 | } |
| 398 | |||
| 399 | #[cfg(feature = "rtos-trace")] | ||
| 400 | trace::system_idle(); | ||
| 384 | } | 401 | } |
| 385 | 402 | ||
| 386 | /// Get a spawner that spawns tasks in this executor. | 403 | /// Get a spawner that spawns tasks in this executor. |
| @@ -426,3 +443,21 @@ unsafe fn _embassy_time_schedule_wake(at: Instant, waker: &core::task::Waker) { | |||
| 426 | let expires_at = task.expires_at.get(); | 443 | let expires_at = task.expires_at.get(); |
| 427 | task.expires_at.set(expires_at.min(at)); | 444 | task.expires_at.set(expires_at.min(at)); |
| 428 | } | 445 | } |
| 446 | |||
| 447 | #[cfg(feature = "rtos-trace")] | ||
| 448 | impl rtos_trace::RtosTraceOSCallbacks for Executor { | ||
| 449 | fn task_list() { | ||
| 450 | // We don't know what tasks exist, so we can't send them. | ||
| 451 | } | ||
| 452 | #[cfg(feature = "integrated-timers")] | ||
| 453 | fn time() -> u64 { | ||
| 454 | Instant::now().as_micros() | ||
| 455 | } | ||
| 456 | #[cfg(not(feature = "integrated-timers"))] | ||
| 457 | fn time() -> u64 { | ||
| 458 | 0 | ||
| 459 | } | ||
| 460 | } | ||
| 461 | |||
| 462 | #[cfg(feature = "rtos-trace")] | ||
| 463 | rtos_trace::global_os_callbacks! {Executor} | ||
diff --git a/embassy-futures/Cargo.toml b/embassy-futures/Cargo.toml new file mode 100644 index 000000000..e564f5a96 --- /dev/null +++ b/embassy-futures/Cargo.toml | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-futures" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [package.metadata.embassy_docs] | ||
| 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-futures-v$VERSION/embassy-futures/src/" | ||
| 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-futures/src/" | ||
| 9 | features = ["nightly"] | ||
| 10 | target = "thumbv7em-none-eabi" | ||
| 11 | |||
| 12 | [dependencies] | ||
| 13 | defmt = { version = "0.3", optional = true } | ||
| 14 | log = { version = "0.4.14", optional = true } | ||
diff --git a/embassy-futures/README.md b/embassy-futures/README.md new file mode 100644 index 000000000..971f4c835 --- /dev/null +++ b/embassy-futures/README.md | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # embassy-futures | ||
| 2 | |||
| 3 | Utilities for working with futures: | ||
| 4 | |||
| 5 | - [`select`](select::select) - waiting for one out of two futures to complete. | ||
| 6 | - [`select3`](select::select3) - waiting for one out of three futures to complete. | ||
| 7 | - [`select4`](select::select4) - waiting for one out of four futures to complete. | ||
| 8 | - [`select_all`](select::select_all) - waiting for one future in a list of futures to complete. | ||
| 9 | - [`yield_now`](yield_now::yield_now) - yielding the current task. | ||
diff --git a/embassy-util/src/fmt.rs b/embassy-futures/src/fmt.rs index f8bb0a035..f8bb0a035 100644 --- a/embassy-util/src/fmt.rs +++ b/embassy-futures/src/fmt.rs | |||
diff --git a/embassy-futures/src/lib.rs b/embassy-futures/src/lib.rs new file mode 100644 index 000000000..45bea2529 --- /dev/null +++ b/embassy-futures/src/lib.rs | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![doc = include_str!("../README.md")] | ||
| 3 | #![warn(missing_docs)] | ||
| 4 | |||
| 5 | // This mod MUST go first, so that the others see its macros. | ||
| 6 | pub(crate) mod fmt; | ||
| 7 | |||
| 8 | mod select; | ||
| 9 | mod yield_now; | ||
| 10 | |||
| 11 | pub use select::*; | ||
| 12 | pub use yield_now::*; | ||
diff --git a/embassy-util/src/select.rs b/embassy-futures/src/select.rs index 8cecb7fa0..8cecb7fa0 100644 --- a/embassy-util/src/select.rs +++ b/embassy-futures/src/select.rs | |||
diff --git a/embassy-util/src/yield_now.rs b/embassy-futures/src/yield_now.rs index 1ebecb916..1ebecb916 100644 --- a/embassy-util/src/yield_now.rs +++ b/embassy-futures/src/yield_now.rs | |||
diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml index c7435ab3e..9d5e7aed2 100644 --- a/embassy-lora/Cargo.toml +++ b/embassy-lora/Cargo.toml | |||
| @@ -25,7 +25,7 @@ defmt = { version = "0.3", optional = true } | |||
| 25 | log = { version = "0.4.14", optional = true } | 25 | log = { version = "0.4.14", optional = true } |
| 26 | 26 | ||
| 27 | embassy-time = { version = "0.1.0", path = "../embassy-time" } | 27 | embassy-time = { version = "0.1.0", path = "../embassy-time" } |
| 28 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 28 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 29 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } | 29 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } |
| 30 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } | 30 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } |
| 31 | embedded-hal-async = { version = "0.1.0-alpha.1" } | 31 | embedded-hal-async = { version = "0.1.0-alpha.1" } |
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 4a4c5cfb7..7822d0153 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs | |||
| @@ -12,7 +12,7 @@ use embassy_stm32::subghz::{ | |||
| 12 | Status, SubGhz, TcxoMode, TcxoTrim, Timeout, TxParams, | 12 | Status, SubGhz, TcxoMode, TcxoTrim, Timeout, TxParams, |
| 13 | }; | 13 | }; |
| 14 | use embassy_stm32::Peripheral; | 14 | use embassy_stm32::Peripheral; |
| 15 | use embassy_util::channel::signal::Signal; | 15 | use embassy_sync::signal::Signal; |
| 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; | 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; |
| 17 | use lorawan_device::async_device::Timings; | 17 | use lorawan_device::async_device::Timings; |
| 18 | 18 | ||
diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 9e40a56f1..f6e41bcb4 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs | |||
| @@ -19,7 +19,13 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> { | |||
| 19 | let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed); | 19 | let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed); |
| 20 | let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed); | 20 | let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed); |
| 21 | let func: fn(*mut ()) = ::core::mem::transmute(func); | 21 | let func: fn(*mut ()) = ::core::mem::transmute(func); |
| 22 | func(ctx) | 22 | ::embassy_executor::rtos_trace_interrupt! { |
| 23 | ::embassy_executor::export::trace::isr_enter(); | ||
| 24 | } | ||
| 25 | func(ctx); | ||
| 26 | ::embassy_executor::rtos_trace_interrupt! { | ||
| 27 | ::embassy_executor::export::trace::isr_exit(); | ||
| 28 | } | ||
| 23 | } | 29 | } |
| 24 | 30 | ||
| 25 | static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false); | 31 | static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false); |
diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index 52987d7d2..afe9bd3e2 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs | |||
| @@ -34,8 +34,8 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 34 | let main = quote! { | 34 | let main = quote! { |
| 35 | #[wasm_bindgen::prelude::wasm_bindgen(start)] | 35 | #[wasm_bindgen::prelude::wasm_bindgen(start)] |
| 36 | pub fn main() -> Result<(), wasm_bindgen::JsValue> { | 36 | pub fn main() -> Result<(), wasm_bindgen::JsValue> { |
| 37 | static EXECUTOR: ::embassy_util::Forever<::embassy_executor::Executor> = ::embassy_util::Forever::new(); | 37 | static EXECUTOR: ::embassy_executor::_export::StaticCell<::embassy_executor::Executor> = ::embassy_executor::_export::StaticCell::new(); |
| 38 | let executor = EXECUTOR.put(::embassy_executor::Executor::new()); | 38 | let executor = EXECUTOR.init(::embassy_executor::Executor::new()); |
| 39 | 39 | ||
| 40 | executor.start(|spawner| { | 40 | executor.start(|spawner| { |
| 41 | spawner.spawn(__embassy_main(spawner)).unwrap(); | 41 | spawner.spawn(__embassy_main(spawner)).unwrap(); |
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 9f9bb2261..2143f36d3 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml | |||
| @@ -38,7 +38,7 @@ defmt = { version = "0.3", optional = true } | |||
| 38 | log = { version = "0.4.14", optional = true } | 38 | log = { version = "0.4.14", optional = true } |
| 39 | 39 | ||
| 40 | embassy-time = { version = "0.1.0", path = "../embassy-time" } | 40 | embassy-time = { version = "0.1.0", path = "../embassy-time" } |
| 41 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 41 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 42 | embedded-io = { version = "0.3.0", features = [ "async" ] } | 42 | embedded-io = { version = "0.3.0", features = [ "async" ] } |
| 43 | 43 | ||
| 44 | managed = { version = "0.8.0", default-features = false, features = [ "map" ] } | 44 | managed = { version = "0.8.0", default-features = false, features = [ "map" ] } |
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 4b6a7ae2a..8d2dd4bca 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -2,8 +2,8 @@ use core::cell::UnsafeCell; | |||
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll}; |
| 4 | 4 | ||
| 5 | use embassy_sync::waitqueue::WakerRegistration; | ||
| 5 | use embassy_time::{Instant, Timer}; | 6 | use embassy_time::{Instant, Timer}; |
| 6 | use embassy_util::waitqueue::WakerRegistration; | ||
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | use futures::pin_mut; | 8 | use futures::pin_mut; |
| 9 | use heapless::Vec; | 9 | use heapless::Vec; |
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 0ef7f5bbd..186c73a58 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -18,7 +18,7 @@ flavors = [ | |||
| 18 | 18 | ||
| 19 | time = ["dep:embassy-time"] | 19 | time = ["dep:embassy-time"] |
| 20 | 20 | ||
| 21 | defmt = ["dep:defmt", "embassy-executor/defmt", "embassy-util/defmt", "embassy-usb?/defmt", "embedded-io?/defmt", "embassy-embedded-hal/defmt"] | 21 | defmt = ["dep:defmt", "embassy-executor/defmt", "embassy-sync/defmt", "embassy-usb?/defmt", "embedded-io?/defmt", "embassy-embedded-hal/defmt"] |
| 22 | 22 | ||
| 23 | # Enable nightly-only features | 23 | # Enable nightly-only features |
| 24 | nightly = ["embedded-hal-1", "embedded-hal-async", "embassy-usb", "embedded-storage-async", "dep:embedded-io", "embassy-embedded-hal/nightly"] | 24 | nightly = ["embedded-hal-1", "embedded-hal-async", "embassy-usb", "embedded-storage-async", "dep:embedded-io", "embassy-embedded-hal/nightly"] |
| @@ -66,7 +66,7 @@ _gpio-p1 = [] | |||
| 66 | [dependencies] | 66 | [dependencies] |
| 67 | embassy-executor = { version = "0.1.0", path = "../embassy-executor", optional = true } | 67 | embassy-executor = { version = "0.1.0", path = "../embassy-executor", optional = true } |
| 68 | embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } | 68 | embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } |
| 69 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 69 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 70 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} | 70 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} |
| 71 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 71 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 72 | embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } | 72 | embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 21ff1d73b..62af544ae 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -21,7 +21,7 @@ use core::task::Poll; | |||
| 21 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 21 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 22 | use embassy_hal_common::ring_buffer::RingBuffer; | 22 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 23 | use embassy_hal_common::{into_ref, PeripheralRef}; | 23 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 24 | use embassy_util::waitqueue::WakerRegistration; | 24 | use embassy_sync::waitqueue::WakerRegistration; |
| 25 | use futures::future::poll_fn; | 25 | use futures::future::poll_fn; |
| 26 | // Re-export SVD variants to allow user to directly set values | 26 | // Re-export SVD variants to allow user to directly set values |
| 27 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | 27 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; |
| @@ -45,8 +45,10 @@ enum TxState { | |||
| 45 | Transmitting(usize), | 45 | Transmitting(usize), |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | /// A type for storing the state of the UARTE peripheral that can be stored in a static. | ||
| 48 | pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>); | 49 | pub struct State<'d, U: UarteInstance, T: TimerInstance>(StateStorage<StateInner<'d, U, T>>); |
| 49 | impl<'d, U: UarteInstance, T: TimerInstance> State<'d, U, T> { | 50 | impl<'d, U: UarteInstance, T: TimerInstance> State<'d, U, T> { |
| 51 | /// Create an instance for storing UARTE peripheral state. | ||
| 50 | pub fn new() -> Self { | 52 | pub fn new() -> Self { |
| 51 | Self(StateStorage::new()) | 53 | Self(StateStorage::new()) |
| 52 | } | 54 | } |
| @@ -75,6 +77,12 @@ pub struct BufferedUarte<'d, U: UarteInstance, T: TimerInstance> { | |||
| 75 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} | 77 | impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {} |
| 76 | 78 | ||
| 77 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | 79 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { |
| 80 | /// Create a new instance of a BufferedUarte. | ||
| 81 | /// | ||
| 82 | /// See the [module documentation](crate::buffered_uarte) for more details about the intended use. | ||
| 83 | /// | ||
| 84 | /// The BufferedUarte uses the provided state to store the buffers and peripheral state. The timer and ppi channels are used to 'emulate' idle line detection so that read operations | ||
| 85 | /// can return early if there is no data to receive. | ||
| 78 | pub fn new( | 86 | pub fn new( |
| 79 | state: &'d mut State<'d, U, T>, | 87 | state: &'d mut State<'d, U, T>, |
| 80 | peri: impl Peripheral<P = U> + 'd, | 88 | peri: impl Peripheral<P = U> + 'd, |
| @@ -178,6 +186,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 178 | } | 186 | } |
| 179 | } | 187 | } |
| 180 | 188 | ||
| 189 | /// Adjust the baud rate to the provided value. | ||
| 181 | pub fn set_baudrate(&mut self, baudrate: Baudrate) { | 190 | pub fn set_baudrate(&mut self, baudrate: Baudrate) { |
| 182 | self.inner.with(|state| { | 191 | self.inner.with(|state| { |
| 183 | let r = U::regs(); | 192 | let r = U::regs(); |
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index a61ff6aa5..924629908 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | //! General purpose input/output for nRF. | ||
| 1 | #![macro_use] | 2 | #![macro_use] |
| 2 | 3 | ||
| 3 | use core::convert::Infallible; | 4 | use core::convert::Infallible; |
| @@ -26,8 +27,11 @@ pub enum Port { | |||
| 26 | #[derive(Debug, Eq, PartialEq)] | 27 | #[derive(Debug, Eq, PartialEq)] |
| 27 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 28 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 28 | pub enum Pull { | 29 | pub enum Pull { |
| 30 | /// No pull. | ||
| 29 | None, | 31 | None, |
| 32 | /// Internal pull-up resistor. | ||
| 30 | Up, | 33 | Up, |
| 34 | /// Internal pull-down resistor. | ||
| 31 | Down, | 35 | Down, |
| 32 | } | 36 | } |
| 33 | 37 | ||
| @@ -37,6 +41,7 @@ pub struct Input<'d, T: Pin> { | |||
| 37 | } | 41 | } |
| 38 | 42 | ||
| 39 | impl<'d, T: Pin> Input<'d, T> { | 43 | impl<'d, T: Pin> Input<'d, T> { |
| 44 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | ||
| 40 | #[inline] | 45 | #[inline] |
| 41 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { | 46 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { |
| 42 | let mut pin = Flex::new(pin); | 47 | let mut pin = Flex::new(pin); |
| @@ -45,11 +50,13 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 45 | Self { pin } | 50 | Self { pin } |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 53 | /// Test if current pin level is high. | ||
| 48 | #[inline] | 54 | #[inline] |
| 49 | pub fn is_high(&self) -> bool { | 55 | pub fn is_high(&self) -> bool { |
| 50 | self.pin.is_high() | 56 | self.pin.is_high() |
| 51 | } | 57 | } |
| 52 | 58 | ||
| 59 | /// Test if current pin level is low. | ||
| 53 | #[inline] | 60 | #[inline] |
| 54 | pub fn is_low(&self) -> bool { | 61 | pub fn is_low(&self) -> bool { |
| 55 | self.pin.is_low() | 62 | self.pin.is_low() |
| @@ -66,7 +73,9 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 66 | #[derive(Debug, Eq, PartialEq)] | 73 | #[derive(Debug, Eq, PartialEq)] |
| 67 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 74 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 68 | pub enum Level { | 75 | pub enum Level { |
| 76 | /// Logical low. | ||
| 69 | Low, | 77 | Low, |
| 78 | /// Logical high. | ||
| 70 | High, | 79 | High, |
| 71 | } | 80 | } |
| 72 | 81 | ||
| @@ -88,6 +97,7 @@ impl Into<bool> for Level { | |||
| 88 | } | 97 | } |
| 89 | } | 98 | } |
| 90 | 99 | ||
| 100 | /// Drive strength settings for an output pin. | ||
| 91 | // These numbers match DRIVE_A exactly so hopefully the compiler will unify them. | 101 | // These numbers match DRIVE_A exactly so hopefully the compiler will unify them. |
| 92 | #[derive(Clone, Copy, Debug, PartialEq)] | 102 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 93 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 103 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -117,6 +127,7 @@ pub struct Output<'d, T: Pin> { | |||
| 117 | } | 127 | } |
| 118 | 128 | ||
| 119 | impl<'d, T: Pin> Output<'d, T> { | 129 | impl<'d, T: Pin> Output<'d, T> { |
| 130 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [OutputDriver] configuration. | ||
| 120 | #[inline] | 131 | #[inline] |
| 121 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { | 132 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { |
| 122 | let mut pin = Flex::new(pin); | 133 | let mut pin = Flex::new(pin); |
| @@ -264,11 +275,13 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 264 | self.pin.conf().reset(); | 275 | self.pin.conf().reset(); |
| 265 | } | 276 | } |
| 266 | 277 | ||
| 278 | /// Test if current pin level is high. | ||
| 267 | #[inline] | 279 | #[inline] |
| 268 | pub fn is_high(&self) -> bool { | 280 | pub fn is_high(&self) -> bool { |
| 269 | !self.is_low() | 281 | !self.is_low() |
| 270 | } | 282 | } |
| 271 | 283 | ||
| 284 | /// Test if current pin level is low. | ||
| 272 | #[inline] | 285 | #[inline] |
| 273 | pub fn is_low(&self) -> bool { | 286 | pub fn is_low(&self) -> bool { |
| 274 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 | 287 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 |
| @@ -374,6 +387,7 @@ pub(crate) mod sealed { | |||
| 374 | } | 387 | } |
| 375 | } | 388 | } |
| 376 | 389 | ||
| 390 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | ||
| 377 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { | 391 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { |
| 378 | /// Number of the pin within the port (0..31) | 392 | /// Number of the pin within the port (0..31) |
| 379 | #[inline] | 393 | #[inline] |
| @@ -392,6 +406,7 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'stat | |||
| 392 | } | 406 | } |
| 393 | } | 407 | } |
| 394 | 408 | ||
| 409 | /// Peripheral port register value | ||
| 395 | #[inline] | 410 | #[inline] |
| 396 | fn psel_bits(&self) -> u32 { | 411 | fn psel_bits(&self) -> u32 { |
| 397 | self.pin_port() as u32 | 412 | self.pin_port() as u32 |
| @@ -406,12 +421,16 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'stat | |||
| 406 | } | 421 | } |
| 407 | } | 422 | } |
| 408 | 423 | ||
| 409 | // Type-erased GPIO pin | 424 | /// Type-erased GPIO pin |
| 410 | pub struct AnyPin { | 425 | pub struct AnyPin { |
| 411 | pin_port: u8, | 426 | pin_port: u8, |
| 412 | } | 427 | } |
| 413 | 428 | ||
| 414 | impl AnyPin { | 429 | impl AnyPin { |
| 430 | /// Create an [AnyPin] for a specific pin. | ||
| 431 | /// | ||
| 432 | /// # Safety | ||
| 433 | /// - `pin_port` should not in use by another driver. | ||
| 415 | #[inline] | 434 | #[inline] |
| 416 | pub unsafe fn steal(pin_port: u8) -> Self { | 435 | pub unsafe fn steal(pin_port: u8) -> Self { |
| 417 | Self { pin_port } | 436 | Self { pin_port } |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index cf49b0db0..b52035705 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -3,7 +3,7 @@ use core::future::Future; | |||
| 3 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll}; |
| 4 | 4 | ||
| 5 | use embassy_hal_common::{impl_peripheral, Peripheral, PeripheralRef}; | 5 | use embassy_hal_common::{impl_peripheral, Peripheral, PeripheralRef}; |
| 6 | use embassy_util::waitqueue::AtomicWaker; | 6 | use embassy_sync::waitqueue::AtomicWaker; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::sealed::Pin as _; |
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index cd6100339..6f66f7a78 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | //! Nvmcerature sensor interface. | 1 | //! Non-Volatile Memory Controller (NVMC) module. |
| 2 | 2 | ||
| 3 | use core::{ptr, slice}; | 3 | use core::{ptr, slice}; |
| 4 | 4 | ||
| @@ -10,13 +10,19 @@ use embedded_storage::nor_flash::{ | |||
| 10 | use crate::peripherals::NVMC; | 10 | use crate::peripherals::NVMC; |
| 11 | use crate::{pac, Peripheral}; | 11 | use crate::{pac, Peripheral}; |
| 12 | 12 | ||
| 13 | /// Erase size of NVMC flash in bytes. | ||
| 13 | pub const PAGE_SIZE: usize = 4096; | 14 | pub const PAGE_SIZE: usize = 4096; |
| 15 | |||
| 16 | /// Size of NVMC flash in bytes. | ||
| 14 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; | 17 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; |
| 15 | 18 | ||
| 19 | /// Error type for NVMC operations. | ||
| 16 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 20 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 17 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 21 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 18 | pub enum Error { | 22 | pub enum Error { |
| 23 | /// Opration using a location not in flash. | ||
| 19 | OutOfBounds, | 24 | OutOfBounds, |
| 25 | /// Unaligned operation or using unaligned buffers. | ||
| 20 | Unaligned, | 26 | Unaligned, |
| 21 | } | 27 | } |
| 22 | 28 | ||
| @@ -29,11 +35,13 @@ impl NorFlashError for Error { | |||
| 29 | } | 35 | } |
| 30 | } | 36 | } |
| 31 | 37 | ||
| 38 | /// Non-Volatile Memory Controller (NVMC) that implements the `embedded-storage` traits. | ||
| 32 | pub struct Nvmc<'d> { | 39 | pub struct Nvmc<'d> { |
| 33 | _p: PeripheralRef<'d, NVMC>, | 40 | _p: PeripheralRef<'d, NVMC>, |
| 34 | } | 41 | } |
| 35 | 42 | ||
| 36 | impl<'d> Nvmc<'d> { | 43 | impl<'d> Nvmc<'d> { |
| 44 | /// Create Nvmc driver. | ||
| 37 | pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self { | 45 | pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self { |
| 38 | into_ref!(_p); | 46 | into_ref!(_p); |
| 39 | Self { _p } | 47 | Self { _p } |
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 23ab011bc..8f5ed14cd 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -26,6 +26,7 @@ mod dppi; | |||
| 26 | #[cfg(feature = "_ppi")] | 26 | #[cfg(feature = "_ppi")] |
| 27 | mod ppi; | 27 | mod ppi; |
| 28 | 28 | ||
| 29 | /// An instance of the Programmable peripheral interconnect on nRF devices. | ||
| 29 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { | 30 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { |
| 30 | ch: PeripheralRef<'d, C>, | 31 | ch: PeripheralRef<'d, C>, |
| 31 | #[cfg(feature = "_dppi")] | 32 | #[cfg(feature = "_dppi")] |
| @@ -34,20 +35,32 @@ pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize | |||
| 34 | tasks: [Task; TASK_COUNT], | 35 | tasks: [Task; TASK_COUNT], |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 38 | #[cfg(feature = "_dppi")] | ||
| 37 | const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::<u32>(); | 39 | const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::<u32>(); |
| 38 | 40 | ||
| 39 | /// Represents a task that a peripheral can do. | 41 | /// Represents a task that a peripheral can do. |
| 40 | /// When a task is subscribed to a PPI channel it will run when the channel is triggered by | ||
| 41 | /// a published event. | ||
| 42 | /// | 42 | /// |
| 43 | /// The pointer is to a task register | 43 | /// When a task is subscribed to a PPI channel, it will run when the channel is triggered by |
| 44 | /// a published event. | ||
| 44 | #[derive(PartialEq, Eq, Clone, Copy)] | 45 | #[derive(PartialEq, Eq, Clone, Copy)] |
| 45 | pub struct Task(pub NonNull<u32>); | 46 | pub struct Task(NonNull<u32>); |
| 47 | |||
| 46 | impl Task { | 48 | impl Task { |
| 49 | /// Create a new `Task` from a task register pointer | ||
| 50 | /// | ||
| 51 | /// # Safety | ||
| 52 | /// | ||
| 53 | /// `ptr` must be a pointer to a valid `TASKS_*` register from an nRF peripheral. | ||
| 54 | pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self { | ||
| 55 | Self(ptr) | ||
| 56 | } | ||
| 57 | |||
| 47 | pub(crate) fn from_reg<T>(reg: &T) -> Self { | 58 | pub(crate) fn from_reg<T>(reg: &T) -> Self { |
| 48 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) | 59 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) |
| 49 | } | 60 | } |
| 50 | 61 | ||
| 62 | /// Address of subscription register for this task. | ||
| 63 | #[cfg(feature = "_dppi")] | ||
| 51 | pub fn subscribe_reg(&self) -> *mut u32 { | 64 | pub fn subscribe_reg(&self) -> *mut u32 { |
| 52 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } | 65 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } |
| 53 | } | 66 | } |
| @@ -59,16 +72,27 @@ impl Task { | |||
| 59 | unsafe impl Send for Task {} | 72 | unsafe impl Send for Task {} |
| 60 | 73 | ||
| 61 | /// Represents an event that a peripheral can publish. | 74 | /// Represents an event that a peripheral can publish. |
| 62 | /// An event can be set to publish on a PPI channel when the event happens. | ||
| 63 | /// | 75 | /// |
| 64 | /// The pointer is to an event register | 76 | /// An event can be set to publish on a PPI channel when the event happens. |
| 65 | #[derive(PartialEq, Eq, Clone, Copy)] | 77 | #[derive(PartialEq, Eq, Clone, Copy)] |
| 66 | pub struct Event(pub NonNull<u32>); | 78 | pub struct Event(NonNull<u32>); |
| 79 | |||
| 67 | impl Event { | 80 | impl Event { |
| 81 | /// Create a new `Event` from an event register pointer | ||
| 82 | /// | ||
| 83 | /// # Safety | ||
| 84 | /// | ||
| 85 | /// `ptr` must be a pointer to a valid `EVENTS_*` register from an nRF peripheral. | ||
| 86 | pub unsafe fn new_unchecked(ptr: NonNull<u32>) -> Self { | ||
| 87 | Self(ptr) | ||
| 88 | } | ||
| 89 | |||
| 68 | pub(crate) fn from_reg<T>(reg: &T) -> Self { | 90 | pub(crate) fn from_reg<T>(reg: &T) -> Self { |
| 69 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) | 91 | Self(unsafe { NonNull::new_unchecked(reg as *const _ as *mut _) }) |
| 70 | } | 92 | } |
| 71 | 93 | ||
| 94 | /// Address of publish register for this event. | ||
| 95 | #[cfg(feature = "_dppi")] | ||
| 72 | pub fn publish_reg(&self) -> *mut u32 { | 96 | pub fn publish_reg(&self) -> *mut u32 { |
| 73 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } | 97 | unsafe { self.0.as_ptr().add(REGISTER_DPPI_CONFIG_OFFSET) } |
| 74 | } | 98 | } |
| @@ -87,21 +111,29 @@ pub(crate) mod sealed { | |||
| 87 | pub trait Group {} | 111 | pub trait Group {} |
| 88 | } | 112 | } |
| 89 | 113 | ||
| 114 | /// Interface for PPI channels. | ||
| 90 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized { | 115 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized { |
| 91 | /// Returns the number of the channel | 116 | /// Returns the number of the channel |
| 92 | fn number(&self) -> usize; | 117 | fn number(&self) -> usize; |
| 93 | } | 118 | } |
| 94 | 119 | ||
| 120 | /// Interface for PPI channels that can be configured. | ||
| 95 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { | 121 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { |
| 122 | /// Convert into a type erased configurable channel. | ||
| 96 | fn degrade(self) -> AnyConfigurableChannel; | 123 | fn degrade(self) -> AnyConfigurableChannel; |
| 97 | } | 124 | } |
| 98 | 125 | ||
| 126 | /// Interface for PPI channels that cannot be configured. | ||
| 99 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { | 127 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { |
| 128 | /// Convert into a type erased static channel. | ||
| 100 | fn degrade(self) -> AnyStaticChannel; | 129 | fn degrade(self) -> AnyStaticChannel; |
| 101 | } | 130 | } |
| 102 | 131 | ||
| 132 | /// Interface for a group of PPI channels. | ||
| 103 | pub trait Group: sealed::Group + Sized { | 133 | pub trait Group: sealed::Group + Sized { |
| 134 | /// Returns the number of the group. | ||
| 104 | fn number(&self) -> usize; | 135 | fn number(&self) -> usize; |
| 136 | /// Convert into a type erased group. | ||
| 105 | fn degrade(self) -> AnyGroup { | 137 | fn degrade(self) -> AnyGroup { |
| 106 | AnyGroup { | 138 | AnyGroup { |
| 107 | number: self.number() as u8, | 139 | number: self.number() as u8, |
| @@ -196,6 +228,7 @@ macro_rules! impl_ppi_channel { | |||
| 196 | // ====================== | 228 | // ====================== |
| 197 | // groups | 229 | // groups |
| 198 | 230 | ||
| 231 | /// A type erased PPI group. | ||
| 199 | pub struct AnyGroup { | 232 | pub struct AnyGroup { |
| 200 | number: u8, | 233 | number: u8, |
| 201 | } | 234 | } |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index 450a290a2..19abc4e18 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -20,6 +20,7 @@ fn regs() -> &'static pac::ppi::RegisterBlock { | |||
| 20 | 20 | ||
| 21 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task | 21 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task |
| 22 | impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { | 22 | impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { |
| 23 | /// Configure PPI channel to trigger `task`. | ||
| 23 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { | 24 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { |
| 24 | into_ref!(ch); | 25 | into_ref!(ch); |
| 25 | 26 | ||
| @@ -32,6 +33,7 @@ impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { | |||
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 35 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 36 | /// Configure PPI channel to trigger `task` on `event`. | ||
| 35 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self { | 37 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self { |
| 36 | into_ref!(ch); | 38 | into_ref!(ch); |
| 37 | 39 | ||
| @@ -46,6 +48,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 46 | 48 | ||
| 47 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task | 49 | #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task |
| 48 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 50 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 51 | /// Configure PPI channel to trigger `task1` and `task2` on `event`. | ||
| 49 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { | 52 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { |
| 50 | into_ref!(ch); | 53 | into_ref!(ch); |
| 51 | 54 | ||
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index 83f2916b9..762e09715 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_hal_common::{into_ref, PeripheralRef}; | 5 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 6 | use embassy_util::waitqueue::AtomicWaker; | 6 | use embassy_sync::waitqueue::AtomicWaker; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::sealed::Pin as _; |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 6d7ebb4b1..c97cb1656 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -526,7 +526,7 @@ cfg_if::cfg_if! { | |||
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | pub(crate) mod sealed { | 528 | pub(crate) mod sealed { |
| 529 | use embassy_util::waitqueue::AtomicWaker; | 529 | use embassy_sync::waitqueue::AtomicWaker; |
| 530 | 530 | ||
| 531 | use super::*; | 531 | use super::*; |
| 532 | 532 | ||
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 7aad561b6..42da51d0f 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs | |||
| @@ -4,7 +4,7 @@ use core::task::Poll; | |||
| 4 | 4 | ||
| 5 | use embassy_hal_common::drop::OnDrop; | 5 | use embassy_hal_common::drop::OnDrop; |
| 6 | use embassy_hal_common::{into_ref, PeripheralRef}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | use embassy_util::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::interrupt::InterruptExt; | 10 | use crate::interrupt::InterruptExt; |
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index f2ef46d8d..7dc66349e 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -4,7 +4,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; | 6 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; |
| 7 | use embassy_util::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | use pac::{saadc, SAADC}; | 9 | use pac::{saadc, SAADC}; |
| 10 | use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; | 10 | use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; |
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 57c0c14c7..be2fc02fc 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -363,7 +363,7 @@ impl<'d, T: Instance> Drop for Spim<'d, T> { | |||
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | pub(crate) mod sealed { | 365 | pub(crate) mod sealed { |
| 366 | use embassy_util::waitqueue::AtomicWaker; | 366 | use embassy_sync::waitqueue::AtomicWaker; |
| 367 | 367 | ||
| 368 | use super::*; | 368 | use super::*; |
| 369 | 369 | ||
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index 1491e4268..d520fd686 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs | |||
| @@ -4,7 +4,7 @@ use core::task::Poll; | |||
| 4 | 4 | ||
| 5 | use embassy_hal_common::drop::OnDrop; | 5 | use embassy_hal_common::drop::OnDrop; |
| 6 | use embassy_hal_common::{into_ref, PeripheralRef}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | use embassy_util::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | use fixed::types::I30F2; | 8 | use fixed::types::I30F2; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index b961d65a0..c32a44637 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs | |||
| @@ -3,9 +3,9 @@ use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; | |||
| 3 | use core::{mem, ptr}; | 3 | use core::{mem, ptr}; |
| 4 | 4 | ||
| 5 | use critical_section::CriticalSection; | 5 | use critical_section::CriticalSection; |
| 6 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 7 | use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; | ||
| 6 | use embassy_time::driver::{AlarmHandle, Driver}; | 8 | use embassy_time::driver::{AlarmHandle, Driver}; |
| 7 | use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 8 | use embassy_util::blocking_mutex::CriticalSectionMutex as Mutex; | ||
| 9 | 9 | ||
| 10 | use crate::interrupt::{Interrupt, InterruptExt}; | 10 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 11 | use crate::{interrupt, pac}; | 11 | use crate::{interrupt, pac}; |
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index b3b613db2..3de5a8962 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -5,7 +5,7 @@ use core::task::Poll; | |||
| 5 | 5 | ||
| 6 | use embassy_hal_common::drop::OnDrop; | 6 | use embassy_hal_common::drop::OnDrop; |
| 7 | use embassy_hal_common::{into_ref, PeripheralRef}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use embassy_util::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
| 11 | use crate::interrupt::{Interrupt, InterruptExt}; | 11 | use crate::interrupt::{Interrupt, InterruptExt}; |
| @@ -40,8 +40,8 @@ macro_rules! impl_timer { | |||
| 40 | fn regs() -> &'static pac::timer0::RegisterBlock { | 40 | fn regs() -> &'static pac::timer0::RegisterBlock { |
| 41 | unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) } | 41 | unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) } |
| 42 | } | 42 | } |
| 43 | fn waker(n: usize) -> &'static ::embassy_util::waitqueue::AtomicWaker { | 43 | fn waker(n: usize) -> &'static ::embassy_sync::waitqueue::AtomicWaker { |
| 44 | use ::embassy_util::waitqueue::AtomicWaker; | 44 | use ::embassy_sync::waitqueue::AtomicWaker; |
| 45 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 45 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 46 | static WAKERS: [AtomicWaker; $ccs] = [NEW_AW; $ccs]; | 46 | static WAKERS: [AtomicWaker; $ccs] = [NEW_AW; $ccs]; |
| 47 | &WAKERS[n] | 47 | &WAKERS[n] |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 9587d1f40..850f6d0fa 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -13,9 +13,9 @@ use core::task::Poll; | |||
| 13 | 13 | ||
| 14 | use embassy_embedded_hal::SetConfig; | 14 | use embassy_embedded_hal::SetConfig; |
| 15 | use embassy_hal_common::{into_ref, PeripheralRef}; | 15 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 16 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 16 | #[cfg(feature = "time")] | 17 | #[cfg(feature = "time")] |
| 17 | use embassy_time::{Duration, Instant}; | 18 | use embassy_time::{Duration, Instant}; |
| 18 | use embassy_util::waitqueue::AtomicWaker; | ||
| 19 | use futures::future::poll_fn; | 19 | use futures::future::poll_fn; |
| 20 | 20 | ||
| 21 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 21 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 0d24cf65f..4347ea558 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -932,7 +932,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteRxWithIdle<'d, U, T> { | |||
| 932 | pub(crate) mod sealed { | 932 | pub(crate) mod sealed { |
| 933 | use core::sync::atomic::AtomicU8; | 933 | use core::sync::atomic::AtomicU8; |
| 934 | 934 | ||
| 935 | use embassy_util::waitqueue::AtomicWaker; | 935 | use embassy_sync::waitqueue::AtomicWaker; |
| 936 | 936 | ||
| 937 | use super::*; | 937 | use super::*; |
| 938 | 938 | ||
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 509ee313e..688326e9c 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -7,10 +7,10 @@ use core::task::Poll; | |||
| 7 | 7 | ||
| 8 | use cortex_m::peripheral::NVIC; | 8 | use cortex_m::peripheral::NVIC; |
| 9 | use embassy_hal_common::{into_ref, PeripheralRef}; | 9 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 10 | pub use embassy_usb; | 11 | pub use embassy_usb; |
| 11 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; |
| 12 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 13 | use embassy_util::waitqueue::AtomicWaker; | ||
| 14 | use futures::future::poll_fn; | 14 | use futures::future::poll_fn; |
| 15 | use futures::Future; | 15 | use futures::Future; |
| 16 | use pac::usbd::RegisterBlock; | 16 | use pac::usbd::RegisterBlock; |
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index af7c8ee6e..cfd95b7b4 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml | |||
| @@ -27,10 +27,10 @@ nightly = ["embassy-executor/nightly", "embedded-hal-1", "embedded-hal-async", " | |||
| 27 | unstable-traits = ["embedded-hal-1"] | 27 | unstable-traits = ["embedded-hal-1"] |
| 28 | 28 | ||
| 29 | [dependencies] | 29 | [dependencies] |
| 30 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 30 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 31 | embassy-executor = { version = "0.1.0", path = "../embassy-executor" } | 31 | embassy-executor = { version = "0.1.0", path = "../embassy-executor" } |
| 32 | embassy-time = { version = "0.1.0", path = "../embassy-time", features = [ "tick-1mhz" ] } | 32 | embassy-time = { version = "0.1.0", path = "../embassy-time", features = [ "tick-1mhz" ] } |
| 33 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} | 33 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-2"]} |
| 34 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 34 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 35 | embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } | 35 | embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } |
| 36 | atomic-polyfill = "1.0.1" | 36 | atomic-polyfill = "1.0.1" |
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index f9fa8378b..428855c7f 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -5,7 +5,7 @@ use core::task::{Context, Poll}; | |||
| 5 | 5 | ||
| 6 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; | 6 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; |
| 7 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; | 7 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; |
| 8 | use embassy_util::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::pac::common::{Reg, RW}; | 10 | use crate::pac::common::{Reg, RW}; |
| 11 | use crate::pac::SIO; | 11 | use crate::pac::SIO; |
| @@ -189,7 +189,7 @@ impl<'d, T: Pin> InputFuture<'d, T> { | |||
| 189 | unsafe { | 189 | unsafe { |
| 190 | let irq = interrupt::IO_IRQ_BANK0::steal(); | 190 | let irq = interrupt::IO_IRQ_BANK0::steal(); |
| 191 | irq.disable(); | 191 | irq.disable(); |
| 192 | irq.set_priority(interrupt::Priority::P6); | 192 | irq.set_priority(interrupt::Priority::P3); |
| 193 | 193 | ||
| 194 | // Each INTR register is divided into 8 groups, one group for each | 194 | // Each INTR register is divided into 8 groups, one group for each |
| 195 | // pin, and each group consists of LEVEL_LOW, LEVEL_HIGH, EDGE_LOW, | 195 | // pin, and each group consists of LEVEL_LOW, LEVEL_HIGH, EDGE_LOW, |
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index 5bc1f66c8..5215c0c0f 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs | |||
| @@ -2,9 +2,9 @@ use core::cell::Cell; | |||
| 2 | 2 | ||
| 3 | use atomic_polyfill::{AtomicU8, Ordering}; | 3 | use atomic_polyfill::{AtomicU8, Ordering}; |
| 4 | use critical_section::CriticalSection; | 4 | use critical_section::CriticalSection; |
| 5 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 6 | use embassy_sync::blocking_mutex::Mutex; | ||
| 5 | use embassy_time::driver::{AlarmHandle, Driver}; | 7 | use embassy_time::driver::{AlarmHandle, Driver}; |
| 6 | use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 7 | use embassy_util::blocking_mutex::Mutex; | ||
| 8 | 8 | ||
| 9 | use crate::interrupt::{Interrupt, InterruptExt}; | 9 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 10 | use crate::{interrupt, pac}; | 10 | use crate::{interrupt, pac}; |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index c47ea0bca..7a8e5c59b 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -31,7 +31,7 @@ flavors = [ | |||
| 31 | ] | 31 | ] |
| 32 | 32 | ||
| 33 | [dependencies] | 33 | [dependencies] |
| 34 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 34 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 35 | embassy-executor = { version = "0.1.0", path = "../embassy-executor" } | 35 | embassy-executor = { version = "0.1.0", path = "../embassy-executor" } |
| 36 | embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } | 36 | embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } |
| 37 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} | 37 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} |
| @@ -72,7 +72,7 @@ quote = "1.0.15" | |||
| 72 | stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features = false, features = ["metadata"]} | 72 | stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features = false, features = ["metadata"]} |
| 73 | 73 | ||
| 74 | [features] | 74 | [features] |
| 75 | defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-util/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embedded-io?/defmt", "embassy-usb?/defmt"] | 75 | defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embedded-io?/defmt", "embassy-usb?/defmt"] |
| 76 | sdmmc-rs = ["embedded-sdmmc"] | 76 | sdmmc-rs = ["embedded-sdmmc"] |
| 77 | net = ["embassy-net" ] | 77 | net = ["embassy-net" ] |
| 78 | memory-x = ["stm32-metapac/memory-x"] | 78 | memory-x = ["stm32-metapac/memory-x"] |
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index bbb9a12cb..fb9dc9d08 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::task::Poll; | 1 | use core::task::Poll; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::{into_ref, PeripheralRef}; | 3 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 4 | use embassy_util::waitqueue::AtomicWaker; | 4 | use embassy_sync::waitqueue::AtomicWaker; |
| 5 | use futures::future::poll_fn; | 5 | use futures::future::poll_fn; |
| 6 | 6 | ||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index bd2cd5b57..674255ddc 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use core::sync::atomic::{fence, Ordering}; | 3 | use core::sync::atomic::{fence, Ordering}; |
| 4 | use core::task::Waker; | 4 | use core::task::Waker; |
| 5 | 5 | ||
| 6 | use embassy_util::waitqueue::AtomicWaker; | 6 | use embassy_sync::waitqueue::AtomicWaker; |
| 7 | 7 | ||
| 8 | use super::{TransferOptions, Word, WordSize}; | 8 | use super::{TransferOptions, Word, WordSize}; |
| 9 | use crate::_generated::BDMA_CHANNEL_COUNT; | 9 | use crate::_generated::BDMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 0c66005c7..a45b8780b 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use embassy_util::waitqueue::AtomicWaker; | 4 | use embassy_sync::waitqueue::AtomicWaker; |
| 5 | 5 | ||
| 6 | use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; | 6 | use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; |
| 7 | use crate::_generated::DMA_CHANNEL_COUNT; | 7 | use crate::_generated::DMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index 1aea6c65d..bde8c3ef3 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use embassy_util::waitqueue::AtomicWaker; | 4 | use embassy_sync::waitqueue::AtomicWaker; |
| 5 | 5 | ||
| 6 | use super::{Request, TransferOptions, Word, WordSize}; | 6 | use super::{Request, TransferOptions, Word, WordSize}; |
| 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; | 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 37593914f..1ab0438ad 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -7,7 +7,7 @@ use core::task::Waker; | |||
| 7 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 7 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 8 | use embassy_hal_common::{into_ref, PeripheralRef}; | 8 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 9 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 9 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 10 | use embassy_util::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | 11 | ||
| 12 | use crate::gpio::sealed::{AFType, Pin as __GpioPin}; | 12 | use crate::gpio::sealed::{AFType, Pin as __GpioPin}; |
| 13 | use crate::gpio::{AnyPin, Speed}; | 13 | use crate::gpio::{AnyPin, Speed}; |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 1bc1fb72e..d67c3c5e4 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -5,7 +5,7 @@ use core::task::Waker; | |||
| 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 6 | use embassy_hal_common::{into_ref, PeripheralRef}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 7 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 8 | use embassy_util::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::{AFType, Pin as _}; | 10 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 11 | use crate::gpio::{AnyPin, Speed}; | 11 | use crate::gpio::{AnyPin, Speed}; |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index ecb180bbe..935149b13 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -4,7 +4,7 @@ use core::pin::Pin; | |||
| 4 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | 5 | ||
| 6 | use embassy_hal_common::impl_peripheral; | 6 | use embassy_hal_common::impl_peripheral; |
| 7 | use embassy_util::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | 8 | ||
| 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; | 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; |
| 10 | use crate::pac::exti::regs::Lines; | 10 | use crate::pac::exti::regs::Lines; |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index b4303d3d4..07a3105da 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -5,7 +5,7 @@ use atomic_polyfill::{AtomicUsize, Ordering}; | |||
| 5 | use embassy_embedded_hal::SetConfig; | 5 | use embassy_embedded_hal::SetConfig; |
| 6 | use embassy_hal_common::drop::OnDrop; | 6 | use embassy_hal_common::drop::OnDrop; |
| 7 | use embassy_hal_common::{into_ref, PeripheralRef}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use embassy_util::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
| 11 | use crate::dma::NoDma; | 11 | use crate::dma::NoDma; |
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 81e28f355..520f2ab9a 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_hal_common::{into_ref, PeripheralRef}; | 5 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 6 | use embassy_util::waitqueue::AtomicWaker; | 6 | use embassy_sync::waitqueue::AtomicWaker; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | use rand_core::{CryptoRng, RngCore}; | 8 | use rand_core::{CryptoRng, RngCore}; |
| 9 | 9 | ||
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 3ad31ec87..67758c492 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -5,7 +5,7 @@ use core::task::Poll; | |||
| 5 | 5 | ||
| 6 | use embassy_hal_common::drop::OnDrop; | 6 | use embassy_hal_common::drop::OnDrop; |
| 7 | use embassy_hal_common::{into_ref, PeripheralRef}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use embassy_util::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; | 10 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; |
| 11 | 11 | ||
| @@ -1514,8 +1514,8 @@ foreach_peripheral!( | |||
| 1514 | INNER | 1514 | INNER |
| 1515 | } | 1515 | } |
| 1516 | 1516 | ||
| 1517 | fn state() -> &'static ::embassy_util::waitqueue::AtomicWaker { | 1517 | fn state() -> &'static ::embassy_sync::waitqueue::AtomicWaker { |
| 1518 | static WAKER: ::embassy_util::waitqueue::AtomicWaker = ::embassy_util::waitqueue::AtomicWaker::new(); | 1518 | static WAKER: ::embassy_sync::waitqueue::AtomicWaker = ::embassy_sync::waitqueue::AtomicWaker::new(); |
| 1519 | &WAKER | 1519 | &WAKER |
| 1520 | } | 1520 | } |
| 1521 | } | 1521 | } |
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 7f4723162..6989a43d3 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -4,10 +4,10 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 4 | use core::{mem, ptr}; | 4 | use core::{mem, ptr}; |
| 5 | 5 | ||
| 6 | use atomic_polyfill::{AtomicU32, AtomicU8}; | 6 | use atomic_polyfill::{AtomicU32, AtomicU8}; |
| 7 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 8 | use embassy_sync::blocking_mutex::Mutex; | ||
| 7 | use embassy_time::driver::{AlarmHandle, Driver}; | 9 | use embassy_time::driver::{AlarmHandle, Driver}; |
| 8 | use embassy_time::TICKS_PER_SECOND; | 10 | use embassy_time::TICKS_PER_SECOND; |
| 9 | use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 10 | use embassy_util::blocking_mutex::Mutex; | ||
| 11 | use stm32_metapac::timer::regs; | 11 | use stm32_metapac::timer::regs; |
| 12 | 12 | ||
| 13 | use crate::interrupt::{CriticalSection, InterruptExt}; | 13 | use crate::interrupt::{CriticalSection, InterruptExt}; |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index ec2231e43..a7fa43894 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -4,7 +4,7 @@ use core::task::Poll; | |||
| 4 | use atomic_polyfill::{compiler_fence, Ordering}; | 4 | use atomic_polyfill::{compiler_fence, Ordering}; |
| 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 6 | use embassy_hal_common::ring_buffer::RingBuffer; | 6 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 7 | use embassy_util::waitqueue::WakerRegistration; | 7 | use embassy_sync::waitqueue::WakerRegistration; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use super::*; | 10 | use super::*; |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 3861e42d0..db965824a 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -6,10 +6,10 @@ use core::task::Poll; | |||
| 6 | 6 | ||
| 7 | use atomic_polyfill::{AtomicBool, AtomicU8}; | 7 | use atomic_polyfill::{AtomicBool, AtomicU8}; |
| 8 | use embassy_hal_common::into_ref; | 8 | use embassy_hal_common::into_ref; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 9 | use embassy_time::{block_for, Duration}; | 10 | use embassy_time::{block_for, Duration}; |
| 10 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; | 11 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; |
| 11 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 12 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 12 | use embassy_util::waitqueue::AtomicWaker; | ||
| 13 | use futures::future::poll_fn; | 13 | use futures::future::poll_fn; |
| 14 | use futures::Future; | 14 | use futures::Future; |
| 15 | use pac::common::{Reg, RW}; | 15 | use pac::common::{Reg, RW}; |
diff --git a/embassy-util/Cargo.toml b/embassy-sync/Cargo.toml index d4708d735..0d14bba55 100644 --- a/embassy-util/Cargo.toml +++ b/embassy-sync/Cargo.toml | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "embassy-util" | 2 | name = "embassy-sync" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | 5 | ||
| 6 | [package.metadata.embassy_docs] | 6 | [package.metadata.embassy_docs] |
| 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-util-v$VERSION/embassy-util/src/" | 7 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-sync-v$VERSION/embassy-sync/src/" |
| 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-util/src/" | 8 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-sync/src/" |
| 9 | features = ["nightly"] | 9 | features = ["nightly"] |
| 10 | target = "thumbv7em-none-eabi" | 10 | target = "thumbv7em-none-eabi" |
| 11 | 11 | ||
| @@ -31,3 +31,4 @@ futures-util = { version = "0.3.17", features = [ "channel" ] } | |||
| 31 | 31 | ||
| 32 | # Enable critical-section implementation for std, for tests | 32 | # Enable critical-section implementation for std, for tests |
| 33 | critical-section = { version = "1.1", features = ["std"] } | 33 | critical-section = { version = "1.1", features = ["std"] } |
| 34 | static_cell = "1.0" | ||
diff --git a/embassy-sync/README.md b/embassy-sync/README.md new file mode 100644 index 000000000..106295c0d --- /dev/null +++ b/embassy-sync/README.md | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # embassy-sync | ||
| 2 | |||
| 3 | Synchronization primitives and data structures with an async API: | ||
| 4 | |||
| 5 | - [`Channel`](channel::Channel) - A Multiple Producer Multiple Consumer (MPMC) channel. Each message is only received by a single consumer. | ||
| 6 | - [`PubSubChannel`](pubsub::PubSubChannel) - A broadcast channel (publish-subscribe) channel. Each message is received by all consumers. | ||
| 7 | - [`Signal`](signal::Signal) - Signalling latest value to a single consumer. | ||
| 8 | - [`Mutex`](mutex::Mutex) - A Mutex for synchronizing state between asynchronous tasks. | ||
| 9 | - [`Pipe`](pipe::Pipe) - Byte stream implementing `embedded_io` traits. | ||
| 10 | - [`WakerRegistration`](waitqueue::WakerRegistration) - Utility to register and wake a `Waker`. | ||
| 11 | - [`AtomicWaker`](waitqueue::AtomicWaker) - A variant of `WakerRegistration` accessible using a non-mut API. | ||
| 12 | - [`MultiWakerRegistration`](waitqueue::MultiWakerRegistration) - Utility registering and waking multiple `Waker`'s. | ||
diff --git a/embassy-util/build.rs b/embassy-sync/build.rs index 6fe82b44f..6fe82b44f 100644 --- a/embassy-util/build.rs +++ b/embassy-sync/build.rs | |||
diff --git a/embassy-util/src/blocking_mutex/mod.rs b/embassy-sync/src/blocking_mutex/mod.rs index 8a4a4c642..8a4a4c642 100644 --- a/embassy-util/src/blocking_mutex/mod.rs +++ b/embassy-sync/src/blocking_mutex/mod.rs | |||
diff --git a/embassy-util/src/blocking_mutex/raw.rs b/embassy-sync/src/blocking_mutex/raw.rs index 15796f1b2..15796f1b2 100644 --- a/embassy-util/src/blocking_mutex/raw.rs +++ b/embassy-sync/src/blocking_mutex/raw.rs | |||
diff --git a/embassy-util/src/channel/mpmc.rs b/embassy-sync/src/channel.rs index 535f77e6f..76f42d0e7 100644 --- a/embassy-util/src/channel/mpmc.rs +++ b/embassy-sync/src/channel.rs | |||
| @@ -373,8 +373,8 @@ where | |||
| 373 | /// Establish a new bounded channel. For example, to create one with a NoopMutex: | 373 | /// Establish a new bounded channel. For example, to create one with a NoopMutex: |
| 374 | /// | 374 | /// |
| 375 | /// ``` | 375 | /// ``` |
| 376 | /// use embassy_util::channel::mpmc::Channel; | 376 | /// use embassy_sync::channel::Channel; |
| 377 | /// use embassy_util::blocking_mutex::raw::NoopRawMutex; | 377 | /// use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 378 | /// | 378 | /// |
| 379 | /// // Declare a bounded channel of 3 u32s. | 379 | /// // Declare a bounded channel of 3 u32s. |
| 380 | /// let mut channel = Channel::<NoopRawMutex, u32, 3>::new(); | 380 | /// let mut channel = Channel::<NoopRawMutex, u32, 3>::new(); |
| @@ -471,10 +471,10 @@ mod tests { | |||
| 471 | use futures_executor::ThreadPool; | 471 | use futures_executor::ThreadPool; |
| 472 | use futures_timer::Delay; | 472 | use futures_timer::Delay; |
| 473 | use futures_util::task::SpawnExt; | 473 | use futures_util::task::SpawnExt; |
| 474 | use static_cell::StaticCell; | ||
| 474 | 475 | ||
| 475 | use super::*; | 476 | use super::*; |
| 476 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; | 477 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; |
| 477 | use crate::Forever; | ||
| 478 | 478 | ||
| 479 | fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize { | 479 | fn capacity<T, const N: usize>(c: &ChannelState<T, N>) -> usize { |
| 480 | c.queue.capacity() - c.queue.len() | 480 | c.queue.capacity() - c.queue.len() |
| @@ -549,8 +549,8 @@ mod tests { | |||
| 549 | async fn receiver_receives_given_try_send_async() { | 549 | async fn receiver_receives_given_try_send_async() { |
| 550 | let executor = ThreadPool::new().unwrap(); | 550 | let executor = ThreadPool::new().unwrap(); |
| 551 | 551 | ||
| 552 | static CHANNEL: Forever<Channel<CriticalSectionRawMutex, u32, 3>> = Forever::new(); | 552 | static CHANNEL: StaticCell<Channel<CriticalSectionRawMutex, u32, 3>> = StaticCell::new(); |
| 553 | let c = &*CHANNEL.put(Channel::new()); | 553 | let c = &*CHANNEL.init(Channel::new()); |
| 554 | let c2 = c; | 554 | let c2 = c; |
| 555 | assert!(executor | 555 | assert!(executor |
| 556 | .spawn(async move { | 556 | .spawn(async move { |
| @@ -571,8 +571,8 @@ mod tests { | |||
| 571 | async fn senders_sends_wait_until_capacity() { | 571 | async fn senders_sends_wait_until_capacity() { |
| 572 | let executor = ThreadPool::new().unwrap(); | 572 | let executor = ThreadPool::new().unwrap(); |
| 573 | 573 | ||
| 574 | static CHANNEL: Forever<Channel<CriticalSectionRawMutex, u32, 1>> = Forever::new(); | 574 | static CHANNEL: StaticCell<Channel<CriticalSectionRawMutex, u32, 1>> = StaticCell::new(); |
| 575 | let c = &*CHANNEL.put(Channel::new()); | 575 | let c = &*CHANNEL.init(Channel::new()); |
| 576 | assert!(c.try_send(1).is_ok()); | 576 | assert!(c.try_send(1).is_ok()); |
| 577 | 577 | ||
| 578 | let c2 = c; | 578 | let c2 = c; |
diff --git a/embassy-sync/src/fmt.rs b/embassy-sync/src/fmt.rs new file mode 100644 index 000000000..f8bb0a035 --- /dev/null +++ b/embassy-sync/src/fmt.rs | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | #![macro_use] | ||
| 2 | #![allow(unused_macros)] | ||
| 3 | |||
| 4 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 5 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 6 | |||
| 7 | macro_rules! assert { | ||
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | ::core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | ::defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | macro_rules! assert_eq { | ||
| 19 | ($($x:tt)*) => { | ||
| 20 | { | ||
| 21 | #[cfg(not(feature = "defmt"))] | ||
| 22 | ::core::assert_eq!($($x)*); | ||
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | ::defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 26 | }; | ||
| 27 | } | ||
| 28 | |||
| 29 | macro_rules! assert_ne { | ||
| 30 | ($($x:tt)*) => { | ||
| 31 | { | ||
| 32 | #[cfg(not(feature = "defmt"))] | ||
| 33 | ::core::assert_ne!($($x)*); | ||
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | ::defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | macro_rules! debug_assert { | ||
| 41 | ($($x:tt)*) => { | ||
| 42 | { | ||
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | ::core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | ::defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 50 | |||
| 51 | macro_rules! debug_assert_eq { | ||
| 52 | ($($x:tt)*) => { | ||
| 53 | { | ||
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | ::core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | ::defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | macro_rules! debug_assert_ne { | ||
| 63 | ($($x:tt)*) => { | ||
| 64 | { | ||
| 65 | #[cfg(not(feature = "defmt"))] | ||
| 66 | ::core::debug_assert_ne!($($x)*); | ||
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | ::defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 72 | |||
| 73 | macro_rules! todo { | ||
| 74 | ($($x:tt)*) => { | ||
| 75 | { | ||
| 76 | #[cfg(not(feature = "defmt"))] | ||
| 77 | ::core::todo!($($x)*); | ||
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | ::defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 83 | |||
| 84 | macro_rules! unreachable { | ||
| 85 | ($($x:tt)*) => { | ||
| 86 | { | ||
| 87 | #[cfg(not(feature = "defmt"))] | ||
| 88 | ::core::unreachable!($($x)*); | ||
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | ::defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 94 | |||
| 95 | macro_rules! panic { | ||
| 96 | ($($x:tt)*) => { | ||
| 97 | { | ||
| 98 | #[cfg(not(feature = "defmt"))] | ||
| 99 | ::core::panic!($($x)*); | ||
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | ::defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 105 | |||
| 106 | macro_rules! trace { | ||
| 107 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 108 | { | ||
| 109 | #[cfg(feature = "log")] | ||
| 110 | ::log::trace!($s $(, $x)*); | ||
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | ::defmt::trace!($s $(, $x)*); | ||
| 113 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 114 | let _ = ($( & $x ),*); | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | } | ||
| 118 | |||
| 119 | macro_rules! debug { | ||
| 120 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 121 | { | ||
| 122 | #[cfg(feature = "log")] | ||
| 123 | ::log::debug!($s $(, $x)*); | ||
| 124 | #[cfg(feature = "defmt")] | ||
| 125 | ::defmt::debug!($s $(, $x)*); | ||
| 126 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 127 | let _ = ($( & $x ),*); | ||
| 128 | } | ||
| 129 | }; | ||
| 130 | } | ||
| 131 | |||
| 132 | macro_rules! info { | ||
| 133 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 134 | { | ||
| 135 | #[cfg(feature = "log")] | ||
| 136 | ::log::info!($s $(, $x)*); | ||
| 137 | #[cfg(feature = "defmt")] | ||
| 138 | ::defmt::info!($s $(, $x)*); | ||
| 139 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 140 | let _ = ($( & $x ),*); | ||
| 141 | } | ||
| 142 | }; | ||
| 143 | } | ||
| 144 | |||
| 145 | macro_rules! warn { | ||
| 146 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 147 | { | ||
| 148 | #[cfg(feature = "log")] | ||
| 149 | ::log::warn!($s $(, $x)*); | ||
| 150 | #[cfg(feature = "defmt")] | ||
| 151 | ::defmt::warn!($s $(, $x)*); | ||
| 152 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 153 | let _ = ($( & $x ),*); | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | } | ||
| 157 | |||
| 158 | macro_rules! error { | ||
| 159 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 160 | { | ||
| 161 | #[cfg(feature = "log")] | ||
| 162 | ::log::error!($s $(, $x)*); | ||
| 163 | #[cfg(feature = "defmt")] | ||
| 164 | ::defmt::error!($s $(, $x)*); | ||
| 165 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 166 | let _ = ($( & $x ),*); | ||
| 167 | } | ||
| 168 | }; | ||
| 169 | } | ||
| 170 | |||
| 171 | #[cfg(feature = "defmt")] | ||
| 172 | macro_rules! unwrap { | ||
| 173 | ($($x:tt)*) => { | ||
| 174 | ::defmt::unwrap!($($x)*) | ||
| 175 | }; | ||
| 176 | } | ||
| 177 | |||
| 178 | #[cfg(not(feature = "defmt"))] | ||
| 179 | macro_rules! unwrap { | ||
| 180 | ($arg:expr) => { | ||
| 181 | match $crate::fmt::Try::into_result($arg) { | ||
| 182 | ::core::result::Result::Ok(t) => t, | ||
| 183 | ::core::result::Result::Err(e) => { | ||
| 184 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | }; | ||
| 188 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 189 | match $crate::fmt::Try::into_result($arg) { | ||
| 190 | ::core::result::Result::Ok(t) => t, | ||
| 191 | ::core::result::Result::Err(e) => { | ||
| 192 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | #[cfg(feature = "defmt-timestamp-uptime")] | ||
| 199 | defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() } | ||
| 200 | |||
| 201 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 202 | pub struct NoneError; | ||
| 203 | |||
| 204 | pub trait Try { | ||
| 205 | type Ok; | ||
| 206 | type Error; | ||
| 207 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 208 | } | ||
| 209 | |||
| 210 | impl<T> Try for Option<T> { | ||
| 211 | type Ok = T; | ||
| 212 | type Error = NoneError; | ||
| 213 | |||
| 214 | #[inline] | ||
| 215 | fn into_result(self) -> Result<T, NoneError> { | ||
| 216 | self.ok_or(NoneError) | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | impl<T, E> Try for Result<T, E> { | ||
| 221 | type Ok = T; | ||
| 222 | type Error = E; | ||
| 223 | |||
| 224 | #[inline] | ||
| 225 | fn into_result(self) -> Self { | ||
| 226 | self | ||
| 227 | } | ||
| 228 | } | ||
diff --git a/embassy-util/src/lib.rs b/embassy-sync/src/lib.rs index 110c72811..25150e8aa 100644 --- a/embassy-util/src/lib.rs +++ b/embassy-sync/src/lib.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] |
| 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] | 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] |
| 3 | #![allow(clippy::new_without_default)] | 3 | #![allow(clippy::new_without_default)] |
| 4 | #![doc = include_str!("../../README.md")] | 4 | #![doc = include_str!("../README.md")] |
| 5 | #![warn(missing_docs)] | 5 | #![warn(missing_docs)] |
| 6 | 6 | ||
| 7 | // This mod MUST go first, so that the others see its macros. | 7 | // This mod MUST go first, so that the others see its macros. |
| @@ -14,12 +14,6 @@ pub mod blocking_mutex; | |||
| 14 | pub mod channel; | 14 | pub mod channel; |
| 15 | pub mod mutex; | 15 | pub mod mutex; |
| 16 | pub mod pipe; | 16 | pub mod pipe; |
| 17 | pub mod pubsub; | ||
| 18 | pub mod signal; | ||
| 17 | pub mod waitqueue; | 19 | pub mod waitqueue; |
| 18 | |||
| 19 | mod forever; | ||
| 20 | mod select; | ||
| 21 | mod yield_now; | ||
| 22 | |||
| 23 | pub use forever::*; | ||
| 24 | pub use select::*; | ||
| 25 | pub use yield_now::*; | ||
diff --git a/embassy-util/src/mutex.rs b/embassy-sync/src/mutex.rs index 75a6e8dd3..75a6e8dd3 100644 --- a/embassy-util/src/mutex.rs +++ b/embassy-sync/src/mutex.rs | |||
diff --git a/embassy-util/src/pipe.rs b/embassy-sync/src/pipe.rs index 9c20aeeff..7d64b648e 100644 --- a/embassy-util/src/pipe.rs +++ b/embassy-sync/src/pipe.rs | |||
| @@ -241,8 +241,8 @@ where | |||
| 241 | /// Establish a new bounded pipe. For example, to create one with a NoopMutex: | 241 | /// Establish a new bounded pipe. For example, to create one with a NoopMutex: |
| 242 | /// | 242 | /// |
| 243 | /// ``` | 243 | /// ``` |
| 244 | /// use embassy_util::pipe::Pipe; | 244 | /// use embassy_sync::pipe::Pipe; |
| 245 | /// use embassy_util::blocking_mutex::raw::NoopRawMutex; | 245 | /// use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 246 | /// | 246 | /// |
| 247 | /// // Declare a bounded pipe, with a buffer of 256 bytes. | 247 | /// // Declare a bounded pipe, with a buffer of 256 bytes. |
| 248 | /// let mut pipe = Pipe::<NoopRawMutex, 256>::new(); | 248 | /// let mut pipe = Pipe::<NoopRawMutex, 256>::new(); |
| @@ -461,10 +461,10 @@ mod io_impls { | |||
| 461 | mod tests { | 461 | mod tests { |
| 462 | use futures_executor::ThreadPool; | 462 | use futures_executor::ThreadPool; |
| 463 | use futures_util::task::SpawnExt; | 463 | use futures_util::task::SpawnExt; |
| 464 | use static_cell::StaticCell; | ||
| 464 | 465 | ||
| 465 | use super::*; | 466 | use super::*; |
| 466 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; | 467 | use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; |
| 467 | use crate::Forever; | ||
| 468 | 468 | ||
| 469 | fn capacity<const N: usize>(c: &PipeState<N>) -> usize { | 469 | fn capacity<const N: usize>(c: &PipeState<N>) -> usize { |
| 470 | N - c.buffer.len() | 470 | N - c.buffer.len() |
| @@ -528,8 +528,8 @@ mod tests { | |||
| 528 | async fn receiver_receives_given_try_write_async() { | 528 | async fn receiver_receives_given_try_write_async() { |
| 529 | let executor = ThreadPool::new().unwrap(); | 529 | let executor = ThreadPool::new().unwrap(); |
| 530 | 530 | ||
| 531 | static CHANNEL: Forever<Pipe<CriticalSectionRawMutex, 3>> = Forever::new(); | 531 | static CHANNEL: StaticCell<Pipe<CriticalSectionRawMutex, 3>> = StaticCell::new(); |
| 532 | let c = &*CHANNEL.put(Pipe::new()); | 532 | let c = &*CHANNEL.init(Pipe::new()); |
| 533 | let c2 = c; | 533 | let c2 = c; |
| 534 | let f = async move { | 534 | let f = async move { |
| 535 | assert_eq!(c2.try_write(&[42]), Ok(1)); | 535 | assert_eq!(c2.try_write(&[42]), Ok(1)); |
diff --git a/embassy-util/src/channel/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs index ecc8fbd8f..62a9e4763 100644 --- a/embassy-util/src/channel/pubsub/mod.rs +++ b/embassy-sync/src/pubsub/mod.rs | |||
| @@ -33,9 +33,9 @@ pub use subscriber::{DynSubscriber, Subscriber}; | |||
| 33 | /// ## Example | 33 | /// ## Example |
| 34 | /// | 34 | /// |
| 35 | /// ``` | 35 | /// ``` |
| 36 | /// # use embassy_util::blocking_mutex::raw::NoopRawMutex; | 36 | /// # use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 37 | /// # use embassy_util::channel::pubsub::WaitResult; | 37 | /// # use embassy_sync::pubsub::WaitResult; |
| 38 | /// # use embassy_util::channel::pubsub::PubSubChannel; | 38 | /// # use embassy_sync::pubsub::PubSubChannel; |
| 39 | /// # use futures_executor::block_on; | 39 | /// # use futures_executor::block_on; |
| 40 | /// # let test = async { | 40 | /// # let test = async { |
| 41 | /// // Create the channel. This can be static as well | 41 | /// // Create the channel. This can be static as well |
diff --git a/embassy-util/src/channel/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs index 705797f60..705797f60 100644 --- a/embassy-util/src/channel/pubsub/publisher.rs +++ b/embassy-sync/src/pubsub/publisher.rs | |||
diff --git a/embassy-util/src/channel/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs index b9a2cbe18..b9a2cbe18 100644 --- a/embassy-util/src/channel/pubsub/subscriber.rs +++ b/embassy-sync/src/pubsub/subscriber.rs | |||
diff --git a/embassy-util/src/ring_buffer.rs b/embassy-sync/src/ring_buffer.rs index 521084024..521084024 100644 --- a/embassy-util/src/ring_buffer.rs +++ b/embassy-sync/src/ring_buffer.rs | |||
diff --git a/embassy-util/src/channel/signal.rs b/embassy-sync/src/signal.rs index 05889f5a4..f6ebeb9b9 100644 --- a/embassy-util/src/channel/signal.rs +++ b/embassy-sync/src/signal.rs | |||
| @@ -6,7 +6,7 @@ use core::task::{Context, Poll, Waker}; | |||
| 6 | 6 | ||
| 7 | /// Single-slot signaling primitive. | 7 | /// Single-slot signaling primitive. |
| 8 | /// | 8 | /// |
| 9 | /// This is similar to a [`Channel`](crate::channel::mpmc::Channel) with a buffer size of 1, except | 9 | /// This is similar to a [`Channel`](crate::channel::Channel) with a buffer size of 1, except |
| 10 | /// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead | 10 | /// "sending" to it (calling [`Signal::signal`]) when full will overwrite the previous value instead |
| 11 | /// of waiting for the receiver to pop the previous value. | 11 | /// of waiting for the receiver to pop the previous value. |
| 12 | /// | 12 | /// |
| @@ -14,12 +14,12 @@ use core::task::{Context, Poll, Waker}; | |||
| 14 | /// the latest data, and therefore it's fine to "lose" messages. This is often the case for "state" | 14 | /// the latest data, and therefore it's fine to "lose" messages. This is often the case for "state" |
| 15 | /// updates. | 15 | /// updates. |
| 16 | /// | 16 | /// |
| 17 | /// For more advanced use cases, you might want to use [`Channel`](crate::channel::mpmc::Channel) instead. | 17 | /// For more advanced use cases, you might want to use [`Channel`](crate::channel::Channel) instead. |
| 18 | /// | 18 | /// |
| 19 | /// Signals are generally declared as `static`s and then borrowed as required. | 19 | /// Signals are generally declared as `static`s and then borrowed as required. |
| 20 | /// | 20 | /// |
| 21 | /// ``` | 21 | /// ``` |
| 22 | /// use embassy_util::channel::signal::Signal; | 22 | /// use embassy_sync::signal::Signal; |
| 23 | /// | 23 | /// |
| 24 | /// enum SomeCommand { | 24 | /// enum SomeCommand { |
| 25 | /// On, | 25 | /// On, |
diff --git a/embassy-util/src/waitqueue/mod.rs b/embassy-sync/src/waitqueue/mod.rs index 6661a6b61..6661a6b61 100644 --- a/embassy-util/src/waitqueue/mod.rs +++ b/embassy-sync/src/waitqueue/mod.rs | |||
diff --git a/embassy-util/src/waitqueue/multi_waker.rs b/embassy-sync/src/waitqueue/multi_waker.rs index 325d2cb3a..325d2cb3a 100644 --- a/embassy-util/src/waitqueue/multi_waker.rs +++ b/embassy-sync/src/waitqueue/multi_waker.rs | |||
diff --git a/embassy-util/src/waitqueue/waker.rs b/embassy-sync/src/waitqueue/waker.rs index 64e300eb8..64e300eb8 100644 --- a/embassy-util/src/waitqueue/waker.rs +++ b/embassy-sync/src/waitqueue/waker.rs | |||
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 161c101fe..f0f622aba 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -49,6 +49,6 @@ critical-section = "1.1" | |||
| 49 | cfg-if = "1.0.0" | 49 | cfg-if = "1.0.0" |
| 50 | 50 | ||
| 51 | # WASM dependencies | 51 | # WASM dependencies |
| 52 | wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } | 52 | wasm-bindgen = { version = "0.2.81", optional = true } |
| 53 | js-sys = { version = "0.3", optional = true } | 53 | js-sys = { version = "0.3", optional = true } |
| 54 | wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file | 54 | wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file |
diff --git a/embassy-time/README.md b/embassy-time/README.md new file mode 100644 index 000000000..2be80ff9c --- /dev/null +++ b/embassy-time/README.md | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # embassy-time | ||
| 2 | |||
| 3 | Timekeeping, delays and timeouts. | ||
| 4 | |||
| 5 | Timekeeping is done with elapsed time since system boot. Time is represented in | ||
| 6 | ticks, where the tick rate is defined by the current driver, usually to match | ||
| 7 | the tick rate of the hardware. | ||
| 8 | |||
| 9 | Tick counts are 64 bits. At the highest supported tick rate of 1Mhz this supports | ||
| 10 | representing time spans of up to ~584558 years, which is big enough for all practical | ||
| 11 | purposes and allows not having to worry about overflows. | ||
| 12 | |||
| 13 | [`Instant`] represents a given instant of time (relative to system boot), and [`Duration`] | ||
| 14 | represents the duration of a span of time. They implement the math operations you'd expect, | ||
| 15 | like addition and substraction. | ||
| 16 | |||
| 17 | # Delays and timeouts | ||
| 18 | |||
| 19 | [`Timer`] allows performing async delays. [`Ticker`] allows periodic delays without drifting over time. | ||
| 20 | |||
| 21 | An implementation of the `embedded-hal` delay traits is provided by [`Delay`], for compatibility | ||
| 22 | with libraries from the ecosystem. | ||
| 23 | |||
| 24 | # Wall-clock time | ||
| 25 | |||
| 26 | The `time` module deals exclusively with a monotonically increasing tick count. | ||
| 27 | Therefore it has no direct support for wall-clock time ("real life" datetimes | ||
| 28 | like `2021-08-24 13:33:21`). | ||
| 29 | |||
| 30 | If persistence across reboots is not needed, support can be built on top of | ||
| 31 | `embassy_time` by storing the offset between "seconds elapsed since boot" | ||
| 32 | and "seconds since unix epoch". | ||
| 33 | |||
| 34 | # Time driver | ||
| 35 | |||
| 36 | The `time` module is backed by a global "time driver" specified at build time. | ||
| 37 | Only one driver can be active in a program. | ||
| 38 | |||
| 39 | All methods and structs transparently call into the active driver. This makes it | ||
| 40 | possible for libraries to use `embassy_time` in a driver-agnostic way without | ||
| 41 | requiring generic parameters. | ||
| 42 | |||
| 43 | For more details, check the [`driver`] module. | ||
diff --git a/embassy-time/src/driver.rs b/embassy-time/src/driver.rs index 216b27408..79ae14b91 100644 --- a/embassy-time/src/driver.rs +++ b/embassy-time/src/driver.rs | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | //! | 6 | //! |
| 7 | //! - Define a struct `MyDriver` | 7 | //! - Define a struct `MyDriver` |
| 8 | //! - Implement [`Driver`] for it | 8 | //! - Implement [`Driver`] for it |
| 9 | //! - Register it as the global driver with [`time_driver_impl`]. | 9 | //! - Register it as the global driver with [`time_driver_impl`](crate::time_driver_impl). |
| 10 | //! - Enable the Cargo features `embassy-executor/time` and one of `embassy-time/tick-*` corresponding to the | 10 | //! - Enable the Cargo features `embassy-executor/time` and one of `embassy-time/tick-*` corresponding to the |
| 11 | //! tick rate of your driver. | 11 | //! tick rate of your driver. |
| 12 | //! | 12 | //! |
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index a6454d55e..a6c5d78cc 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs | |||
| @@ -1,50 +1,9 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] |
| 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] | 2 | #![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] |
| 3 | #![doc = include_str!("../README.md")] | ||
| 3 | #![allow(clippy::new_without_default)] | 4 | #![allow(clippy::new_without_default)] |
| 4 | #![warn(missing_docs)] | 5 | #![warn(missing_docs)] |
| 5 | 6 | ||
| 6 | //! Timekeeping, delays and timeouts. | ||
| 7 | //! | ||
| 8 | //! Timekeeping is done with elapsed time since system boot. Time is represented in | ||
| 9 | //! ticks, where the tick rate is defined by the current driver, usually to match | ||
| 10 | //! the tick rate of the hardware. | ||
| 11 | //! | ||
| 12 | //! Tick counts are 64 bits. At the highest supported tick rate of 1Mhz this supports | ||
| 13 | //! representing time spans of up to ~584558 years, which is big enough for all practical | ||
| 14 | //! purposes and allows not having to worry about overflows. | ||
| 15 | //! | ||
| 16 | //! [`Instant`] represents a given instant of time (relative to system boot), and [`Duration`] | ||
| 17 | //! represents the duration of a span of time. They implement the math operations you'd expect, | ||
| 18 | //! like addition and substraction. | ||
| 19 | //! | ||
| 20 | //! # Delays and timeouts | ||
| 21 | //! | ||
| 22 | //! [`Timer`] allows performing async delays. [`Ticker`] allows periodic delays without drifting over time. | ||
| 23 | //! | ||
| 24 | //! An implementation of the `embedded-hal` delay traits is provided by [`Delay`], for compatibility | ||
| 25 | //! with libraries from the ecosystem. | ||
| 26 | //! | ||
| 27 | //! # Wall-clock time | ||
| 28 | //! | ||
| 29 | //! The `time` module deals exclusively with a monotonically increasing tick count. | ||
| 30 | //! Therefore it has no direct support for wall-clock time ("real life" datetimes | ||
| 31 | //! like `2021-08-24 13:33:21`). | ||
| 32 | //! | ||
| 33 | //! If persistence across reboots is not needed, support can be built on top of | ||
| 34 | //! `embassy_time` by storing the offset between "seconds elapsed since boot" | ||
| 35 | //! and "seconds since unix epoch". | ||
| 36 | //! | ||
| 37 | //! # Time driver | ||
| 38 | //! | ||
| 39 | //! The `time` module is backed by a global "time driver" specified at build time. | ||
| 40 | //! Only one driver can be active in a program. | ||
| 41 | //! | ||
| 42 | //! All methods and structs transparently call into the active driver. This makes it | ||
| 43 | //! possible for libraries to use `embassy_time` in a driver-agnostic way without | ||
| 44 | //! requiring generic parameters. | ||
| 45 | //! | ||
| 46 | //! For more details, check the [`driver`] module. | ||
| 47 | |||
| 48 | // This mod MUST go first, so that the others see its macros. | 7 | // This mod MUST go first, so that the others see its macros. |
| 49 | pub(crate) mod fmt; | 8 | pub(crate) mod fmt; |
| 50 | 9 | ||
diff --git a/embassy-usb-hid/Cargo.toml b/embassy-usb-hid/Cargo.toml index 5e9cfebf7..730351485 100644 --- a/embassy-usb-hid/Cargo.toml +++ b/embassy-usb-hid/Cargo.toml | |||
| @@ -14,7 +14,7 @@ default = ["usbd-hid"] | |||
| 14 | usbd-hid = ["dep:usbd-hid", "ssmarshal"] | 14 | usbd-hid = ["dep:usbd-hid", "ssmarshal"] |
| 15 | 15 | ||
| 16 | [dependencies] | 16 | [dependencies] |
| 17 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 17 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 18 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | 18 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } |
| 19 | 19 | ||
| 20 | defmt = { version = "0.3", optional = true } | 20 | defmt = { version = "0.3", optional = true } |
diff --git a/embassy-usb-ncm/Cargo.toml b/embassy-usb-ncm/Cargo.toml index 47c1f36bd..15d3db96f 100644 --- a/embassy-usb-ncm/Cargo.toml +++ b/embassy-usb-ncm/Cargo.toml | |||
| @@ -10,7 +10,7 @@ features = ["defmt"] | |||
| 10 | target = "thumbv7em-none-eabi" | 10 | target = "thumbv7em-none-eabi" |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| 13 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 13 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } |
| 15 | 15 | ||
| 16 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "0.3", optional = true } |
diff --git a/embassy-usb-serial/Cargo.toml b/embassy-usb-serial/Cargo.toml index 633610471..9788588e9 100644 --- a/embassy-usb-serial/Cargo.toml +++ b/embassy-usb-serial/Cargo.toml | |||
| @@ -10,7 +10,7 @@ features = ["defmt"] | |||
| 10 | target = "thumbv7em-none-eabi" | 10 | target = "thumbv7em-none-eabi" |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| 13 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 13 | embassy-sync = { version = "0.1.0", path = "../embassy-sync" } |
| 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } | 14 | embassy-usb = { version = "0.1.0", path = "../embassy-usb" } |
| 15 | 15 | ||
| 16 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "0.3", optional = true } |
diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb-serial/src/lib.rs index e561be9df..f3de2ec1b 100644 --- a/embassy-usb-serial/src/lib.rs +++ b/embassy-usb-serial/src/lib.rs | |||
| @@ -9,11 +9,11 @@ use core::cell::Cell; | |||
| 9 | use core::mem::{self, MaybeUninit}; | 9 | use core::mem::{self, MaybeUninit}; |
| 10 | use core::sync::atomic::{AtomicBool, Ordering}; | 10 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 11 | 11 | ||
| 12 | use embassy_sync::blocking_mutex::CriticalSectionMutex; | ||
| 12 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; | 13 | use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; |
| 13 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; | 14 | use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; |
| 14 | use embassy_usb::types::*; | 15 | use embassy_usb::types::*; |
| 15 | use embassy_usb::Builder; | 16 | use embassy_usb::Builder; |
| 16 | use embassy_util::blocking_mutex::CriticalSectionMutex; | ||
| 17 | 17 | ||
| 18 | /// This should be used as `device_class` when building the `UsbDevice`. | 18 | /// This should be used as `device_class` when building the `UsbDevice`. |
| 19 | pub const USB_CLASS_CDC: u8 = 0x02; | 19 | pub const USB_CLASS_CDC: u8 = 0x02; |
diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index 6adbd399b..8cad4d314 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml | |||
| @@ -10,7 +10,7 @@ features = ["defmt"] | |||
| 10 | target = "thumbv7em-none-eabi" | 10 | target = "thumbv7em-none-eabi" |
| 11 | 11 | ||
| 12 | [dependencies] | 12 | [dependencies] |
| 13 | embassy-util = { version = "0.1.0", path = "../embassy-util" } | 13 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
| 16 | log = { version = "0.4.14", optional = true } | 16 | log = { version = "0.4.14", optional = true } |
diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 1ca24cc08..6be88bc76 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs | |||
| @@ -10,6 +10,7 @@ use crate::{Interface, STRING_INDEX_CUSTOM_START}; | |||
| 10 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
| 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 11 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 12 | #[non_exhaustive] | 12 | #[non_exhaustive] |
| 13 | /// Configuration used when creating [UsbDevice]. | ||
| 13 | pub struct Config<'a> { | 14 | pub struct Config<'a> { |
| 14 | pub(crate) vendor_id: u16, | 15 | pub(crate) vendor_id: u16, |
| 15 | pub(crate) product_id: u16, | 16 | pub(crate) product_id: u16, |
| @@ -96,6 +97,7 @@ pub struct Config<'a> { | |||
| 96 | } | 97 | } |
| 97 | 98 | ||
| 98 | impl<'a> Config<'a> { | 99 | impl<'a> Config<'a> { |
| 100 | /// Create default configuration with the provided vid and pid values. | ||
| 99 | pub fn new(vid: u16, pid: u16) -> Self { | 101 | pub fn new(vid: u16, pid: u16) -> Self { |
| 100 | Self { | 102 | Self { |
| 101 | device_class: 0x00, | 103 | device_class: 0x00, |
diff --git a/embassy-usb/src/control.rs b/embassy-usb/src/control.rs index 12e5303c3..3e5749a01 100644 --- a/embassy-usb/src/control.rs +++ b/embassy-usb/src/control.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | //! USB control data types. | ||
| 1 | use core::mem; | 2 | use core::mem; |
| 2 | 3 | ||
| 3 | use super::types::*; | 4 | use super::types::*; |
| @@ -8,7 +9,7 @@ use super::types::*; | |||
| 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 9 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 9 | pub enum RequestType { | 10 | pub enum RequestType { |
| 10 | /// Request is a USB standard request. Usually handled by | 11 | /// Request is a USB standard request. Usually handled by |
| 11 | /// [`UsbDevice`](crate::device::UsbDevice). | 12 | /// [`UsbDevice`](crate::UsbDevice). |
| 12 | Standard = 0, | 13 | Standard = 0, |
| 13 | /// Request is intended for a USB class. | 14 | /// Request is intended for a USB class. |
| 14 | Class = 1, | 15 | Class = 1, |
diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 2a84ff9e7..7888f1639 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs | |||
| @@ -12,7 +12,7 @@ pub trait Driver<'a> { | |||
| 12 | 12 | ||
| 13 | /// Allocates an endpoint and specified endpoint parameters. This method is called by the device | 13 | /// Allocates an endpoint and specified endpoint parameters. This method is called by the device |
| 14 | /// and class implementations to allocate endpoints, and can only be called before | 14 | /// and class implementations to allocate endpoints, and can only be called before |
| 15 | /// [`start`](UsbBus::start) is called. | 15 | /// [`start`](Self::start) is called. |
| 16 | /// | 16 | /// |
| 17 | /// # Arguments | 17 | /// # Arguments |
| 18 | /// | 18 | /// |
| @@ -95,7 +95,7 @@ pub trait Bus { | |||
| 95 | /// | 95 | /// |
| 96 | /// # Errors | 96 | /// # Errors |
| 97 | /// | 97 | /// |
| 98 | /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support | 98 | /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support |
| 99 | /// simulating a disconnect or it has not been enabled at creation time. | 99 | /// simulating a disconnect or it has not been enabled at creation time. |
| 100 | fn force_reset(&mut self) -> Result<(), Unsupported> { | 100 | fn force_reset(&mut self) -> Result<(), Unsupported> { |
| 101 | Err(Unsupported) | 101 | Err(Unsupported) |
| @@ -105,7 +105,7 @@ pub trait Bus { | |||
| 105 | /// | 105 | /// |
| 106 | /// # Errors | 106 | /// # Errors |
| 107 | /// | 107 | /// |
| 108 | /// * [`Unsupported`](crate::UsbError::Unsupported) - This UsbBus implementation doesn't support | 108 | /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support |
| 109 | /// remote wakeup or it has not been enabled at creation time. | 109 | /// remote wakeup or it has not been enabled at creation time. |
| 110 | fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>; | 110 | fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>; |
| 111 | } | 111 | } |
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 3f6e13472..5a3f8ba88 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -12,7 +12,7 @@ mod descriptor_reader; | |||
| 12 | pub mod driver; | 12 | pub mod driver; |
| 13 | pub mod types; | 13 | pub mod types; |
| 14 | 14 | ||
| 15 | use embassy_util::{select, Either}; | 15 | use embassy_futures::{select, Either}; |
| 16 | use heapless::Vec; | 16 | use heapless::Vec; |
| 17 | 17 | ||
| 18 | pub use self::builder::{Builder, Config}; | 18 | pub use self::builder::{Builder, Config}; |
diff --git a/embassy-util/src/channel/mod.rs b/embassy-util/src/channel/mod.rs deleted file mode 100644 index 5df1f5c5c..000000000 --- a/embassy-util/src/channel/mod.rs +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | //! Async channels | ||
| 2 | |||
| 3 | pub mod mpmc; | ||
| 4 | pub mod pubsub; | ||
| 5 | pub mod signal; | ||
diff --git a/embassy-util/src/forever.rs b/embassy-util/src/forever.rs deleted file mode 100644 index 4f3698211..000000000 --- a/embassy-util/src/forever.rs +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | use core::cell::UnsafeCell; | ||
| 2 | use core::mem::MaybeUninit; | ||
| 3 | |||
| 4 | use atomic_polyfill::{AtomicBool, Ordering}; | ||
| 5 | |||
| 6 | /// Type with static lifetime that may be written to once at runtime. | ||
| 7 | /// | ||
| 8 | /// This may be used to initialize static objects at runtime, typically in the init routine. | ||
| 9 | /// This is useful for objects such as Embassy's RTC, which cannot be initialized in a const | ||
| 10 | /// context. | ||
| 11 | /// | ||
| 12 | /// Note: IF a global mutable variable is desired, use a CriticalSectionMutex or ThreadModeMutex instead. | ||
| 13 | /// | ||
| 14 | /// ``` | ||
| 15 | /// use embassy_util::Forever; | ||
| 16 | /// // Using an integer for the sake of keeping this example self-contained, | ||
| 17 | /// // see https://github.com/embassy-rs/embassy/wiki/Getting-Started for a more "proper" example. | ||
| 18 | /// static SOME_INT: Forever<u32> =Forever::new(); | ||
| 19 | /// | ||
| 20 | /// // put returns a mutable pointer to the object stored in the forever, which may then be passed | ||
| 21 | /// // around. | ||
| 22 | /// let mut x = SOME_INT.put(42); | ||
| 23 | /// assert_eq!(*x, 42); | ||
| 24 | /// ``` | ||
| 25 | pub struct Forever<T> { | ||
| 26 | used: AtomicBool, | ||
| 27 | t: UnsafeCell<MaybeUninit<T>>, | ||
| 28 | } | ||
| 29 | |||
| 30 | unsafe impl<T> Send for Forever<T> {} | ||
| 31 | unsafe impl<T> Sync for Forever<T> {} | ||
| 32 | |||
| 33 | impl<T> Forever<T> { | ||
| 34 | /// Create a new `Forever`. | ||
| 35 | #[inline(always)] | ||
| 36 | pub const fn new() -> Self { | ||
| 37 | Self { | ||
| 38 | used: AtomicBool::new(false), | ||
| 39 | t: UnsafeCell::new(MaybeUninit::uninit()), | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | /// Store a value in this `Forever`, returning a mutable reference to it. | ||
| 44 | /// | ||
| 45 | /// Using this method, the compiler usually constructs `val` in the stack and then moves | ||
| 46 | /// it into the `Forever`. If `T` is big, this is likely to cause stack overflows. | ||
| 47 | /// Considering using [`Signal::put_with`] instead, which will construct it in-place inside the `Forever`. | ||
| 48 | /// | ||
| 49 | /// # Panics | ||
| 50 | /// | ||
| 51 | /// Panics if this `Forever` already has a value stored in it. | ||
| 52 | #[inline(always)] | ||
| 53 | #[allow(clippy::mut_from_ref)] | ||
| 54 | pub fn put(&'static self, val: T) -> &'static mut T { | ||
| 55 | self.put_with(|| val) | ||
| 56 | } | ||
| 57 | |||
| 58 | /// Store the closure return value in this `Forever`, returning a mutable reference to it. | ||
| 59 | /// | ||
| 60 | /// The advantage over [`Forever::put`] is that this method allows the closure to construct | ||
| 61 | /// the `T` value in-place directly inside the `Forever`, saving stack space. | ||
| 62 | /// | ||
| 63 | /// # Panics | ||
| 64 | /// | ||
| 65 | /// Panics if this `Forever` already has a value stored in it. | ||
| 66 | #[inline(always)] | ||
| 67 | #[allow(clippy::mut_from_ref)] | ||
| 68 | pub fn put_with(&'static self, val: impl FnOnce() -> T) -> &'static mut T { | ||
| 69 | if self | ||
| 70 | .used | ||
| 71 | .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) | ||
| 72 | .is_err() | ||
| 73 | { | ||
| 74 | panic!("Forever.put() called multiple times"); | ||
| 75 | } | ||
| 76 | |||
| 77 | let p: &'static mut MaybeUninit<T> = unsafe { &mut *self.t.get() }; | ||
| 78 | p.write(val()) | ||
| 79 | } | ||
| 80 | |||
| 81 | /// Unsafely get a mutable reference to the contents of this Forever. | ||
| 82 | /// | ||
| 83 | /// # Safety | ||
| 84 | /// | ||
| 85 | /// This is undefined behavior if: | ||
| 86 | /// | ||
| 87 | /// - The `Forever` has not been initialized yet (with `put' or `put_with`), or | ||
| 88 | /// - A reference to the contents (mutable or not) already exists. | ||
| 89 | #[inline(always)] | ||
| 90 | #[allow(clippy::mut_from_ref)] | ||
| 91 | pub unsafe fn steal(&self) -> &mut T { | ||
| 92 | let p: &mut MaybeUninit<T> = &mut *self.t.get(); | ||
| 93 | p.assume_init_mut() | ||
| 94 | } | ||
| 95 | } | ||
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index ef9346639..b9ff92578 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-nrf-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util" } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync" } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] } |
| 10 | embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } | 10 | embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } |
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index 27eafa653..f143d1e8d 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32f3-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } |
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index 7de0b82d7..29c87eee1 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32f7-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } |
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index 65d34c70b..5669527fe 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32h7-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } |
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index 8f37869e3..48624d5ec 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32l0-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } |
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 6abf1986d..00b638ca5 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32l1-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } |
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index 6f2d12ff1..51ba730d5 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32l4-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } |
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index be97d4ebb..182acf694 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-boot-stm32wl-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } |
diff --git a/examples/nrf-rtos-trace/.cargo/config.toml b/examples/nrf-rtos-trace/.cargo/config.toml new file mode 100644 index 000000000..8ca28df39 --- /dev/null +++ b/examples/nrf-rtos-trace/.cargo/config.toml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip nRF52840_xxAA" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml new file mode 100644 index 000000000..87c9f33f5 --- /dev/null +++ b/examples/nrf-rtos-trace/Cargo.toml | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-nrf-rtos-trace-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | |||
| 6 | [features] | ||
| 7 | default = ["log", "nightly"] | ||
| 8 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits"] | ||
| 9 | log = [ | ||
| 10 | "dep:log", | ||
| 11 | "embassy-sync/log", | ||
| 12 | "embassy-executor/log", | ||
| 13 | "embassy-time/log", | ||
| 14 | "embassy-nrf/log", | ||
| 15 | ] | ||
| 16 | |||
| 17 | [dependencies] | ||
| 18 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync" } | ||
| 19 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt", "integrated-timers"] } | ||
| 20 | embassy-time = { version = "0.1.0", path = "../../embassy-time" } | ||
| 21 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | ||
| 22 | |||
| 23 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | ||
| 24 | cortex-m-rt = "0.7.0" | ||
| 25 | panic-probe = { version = "0.3" } | ||
| 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 27 | rand = { version = "0.8.4", default-features = false } | ||
| 28 | serde = { version = "1.0.136", default-features = false } | ||
| 29 | rtos-trace = "0.1.3" | ||
| 30 | systemview-target = { version = "0.1.2", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } | ||
| 31 | log = { version = "0.4.17", optional = true } | ||
| 32 | |||
| 33 | [[bin]] | ||
| 34 | name = "rtos_trace" | ||
| 35 | required-features = ["nightly"] | ||
diff --git a/examples/nrf-rtos-trace/build.rs b/examples/nrf-rtos-trace/build.rs new file mode 100644 index 000000000..36cdb65a8 --- /dev/null +++ b/examples/nrf-rtos-trace/build.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
diff --git a/examples/nrf-rtos-trace/memory.x b/examples/nrf-rtos-trace/memory.x new file mode 100644 index 000000000..9b04edec0 --- /dev/null +++ b/examples/nrf-rtos-trace/memory.x | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 5 | FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 7 | } | ||
diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs new file mode 100644 index 000000000..7d1ad87c8 --- /dev/null +++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use core::task::Poll; | ||
| 6 | |||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_time::{Duration, Instant, Timer}; | ||
| 9 | #[cfg(feature = "log")] | ||
| 10 | use log::*; | ||
| 11 | use panic_probe as _; | ||
| 12 | // N.B. systemview_target cannot be used at the same time as defmt_rtt. | ||
| 13 | use rtos_trace; | ||
| 14 | use systemview_target::SystemView; | ||
| 15 | |||
| 16 | static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); | ||
| 17 | rtos_trace::global_trace! {SystemView} | ||
| 18 | |||
| 19 | struct TraceInfo(); | ||
| 20 | |||
| 21 | impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo { | ||
| 22 | fn system_description() {} | ||
| 23 | fn sysclock() -> u32 { | ||
| 24 | 64000000 | ||
| 25 | } | ||
| 26 | } | ||
| 27 | rtos_trace::global_application_callbacks! {TraceInfo} | ||
| 28 | |||
| 29 | #[embassy_executor::task] | ||
| 30 | async fn run1() { | ||
| 31 | loop { | ||
| 32 | #[cfg(feature = "log")] | ||
| 33 | info!("DING DONG"); | ||
| 34 | #[cfg(not(feature = "log"))] | ||
| 35 | rtos_trace::trace::marker(13); | ||
| 36 | Timer::after(Duration::from_ticks(16000)).await; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | #[embassy_executor::task] | ||
| 41 | async fn run2() { | ||
| 42 | loop { | ||
| 43 | Timer::at(Instant::from_ticks(0)).await; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | #[embassy_executor::task] | ||
| 48 | async fn run3() { | ||
| 49 | futures::future::poll_fn(|cx| { | ||
| 50 | cx.waker().wake_by_ref(); | ||
| 51 | Poll::<()>::Pending | ||
| 52 | }) | ||
| 53 | .await; | ||
| 54 | } | ||
| 55 | |||
| 56 | #[embassy_executor::main] | ||
| 57 | async fn main(spawner: Spawner) { | ||
| 58 | let _p = embassy_nrf::init(Default::default()); | ||
| 59 | LOGGER.init(); | ||
| 60 | #[cfg(feature = "log")] | ||
| 61 | { | ||
| 62 | ::log::set_logger(&LOGGER).ok(); | ||
| 63 | ::log::set_max_level(::log::LevelFilter::Trace); | ||
| 64 | } | ||
| 65 | |||
| 66 | spawner.spawn(run1()).unwrap(); | ||
| 67 | spawner.spawn(run2()).unwrap(); | ||
| 68 | spawner.spawn(run3()).unwrap(); | ||
| 69 | } | ||
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 876dcf734..8309dda08 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -8,7 +8,8 @@ default = ["nightly"] | |||
| 8 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] | 8 | nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] |
| 9 | 9 | ||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 11 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 12 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | ||
| 12 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 13 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 13 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 14 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 15 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| @@ -22,6 +23,7 @@ embedded-io = "0.3.0" | |||
| 22 | defmt = "0.3" | 23 | defmt = "0.3" |
| 23 | defmt-rtt = "0.3" | 24 | defmt-rtt = "0.3" |
| 24 | 25 | ||
| 26 | static_cell = "1.0" | ||
| 25 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 27 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 26 | cortex-m-rt = "0.7.0" | 28 | cortex-m-rt = "0.7.0" |
| 27 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 29 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs index 195200988..d782a79e7 100644 --- a/examples/nrf/src/bin/channel.rs +++ b/examples/nrf/src/bin/channel.rs | |||
| @@ -5,9 +5,9 @@ | |||
| 5 | use defmt::unwrap; | 5 | use defmt::unwrap; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 8 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 9 | use embassy_sync::channel::Channel; | ||
| 8 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 9 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 10 | use embassy_util::channel::mpmc::Channel; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | enum LedState { | 13 | enum LedState { |
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs index c9c458aec..fcccdaed5 100644 --- a/examples/nrf/src/bin/channel_sender_receiver.rs +++ b/examples/nrf/src/bin/channel_sender_receiver.rs | |||
| @@ -5,10 +5,10 @@ | |||
| 5 | use defmt::unwrap; | 5 | use defmt::unwrap; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | 7 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; |
| 8 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 9 | use embassy_sync::channel::{Channel, Receiver, Sender}; | ||
| 8 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 9 | use embassy_util::blocking_mutex::raw::NoopRawMutex; | 11 | use static_cell::StaticCell; |
| 10 | use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; | ||
| 11 | use embassy_util::Forever; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | enum LedState { | 14 | enum LedState { |
| @@ -16,7 +16,7 @@ enum LedState { | |||
| 16 | Off, | 16 | Off, |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new(); | 19 | static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new(); |
| 20 | 20 | ||
| 21 | #[embassy_executor::task] | 21 | #[embassy_executor::task] |
| 22 | async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { | 22 | async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { |
| @@ -43,7 +43,7 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta | |||
| 43 | #[embassy_executor::main] | 43 | #[embassy_executor::main] |
| 44 | async fn main(spawner: Spawner) { | 44 | async fn main(spawner: Spawner) { |
| 45 | let p = embassy_nrf::init(Default::default()); | 45 | let p = embassy_nrf::init(Default::default()); |
| 46 | let channel = CHANNEL.put(Channel::new()); | 46 | let channel = CHANNEL.init(Channel::new()); |
| 47 | 47 | ||
| 48 | unwrap!(spawner.spawn(send_task(channel.sender()))); | 48 | unwrap!(spawner.spawn(send_task(channel.sender()))); |
| 49 | unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); | 49 | unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); |
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index b653689a7..25806ae48 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_nrf::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_nrf::interrupt; | 63 | use embassy_nrf::interrupt; |
| 64 | use embassy_nrf::interrupt::InterruptExt; | 64 | use embassy_nrf::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(SWI1_EGU1); | 122 | let irq = interrupt::take!(SWI1_EGU1); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(SWI0_EGU0); | 129 | let irq = interrupt::take!(SWI0_EGU0); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs index 876297883..c402c6ba1 100644 --- a/examples/nrf/src/bin/mutex.rs +++ b/examples/nrf/src/bin/mutex.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 8 | use embassy_sync::mutex::Mutex; | ||
| 7 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::{Duration, Timer}; |
| 8 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 9 | use embassy_util::mutex::Mutex; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); | 12 | static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); |
diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf/src/bin/pubsub.rs index 1d90217f2..688e6d075 100644 --- a/examples/nrf/src/bin/pubsub.rs +++ b/examples/nrf/src/bin/pubsub.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::unwrap; | 5 | use defmt::unwrap; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 8 | use embassy_sync::pubsub::{DynSubscriber, PubSubChannel, Subscriber}; | ||
| 7 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::{Duration, Timer}; |
| 8 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 9 | use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | /// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher | 12 | /// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher |
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 415579be7..1b067f5e4 100644 --- a/examples/nrf/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs | |||
| @@ -8,7 +8,7 @@ use defmt::{info, unwrap}; | |||
| 8 | use embassy_executor::raw::TaskStorage; | 8 | use embassy_executor::raw::TaskStorage; |
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use embassy_util::Forever; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | async fn run1() { | 14 | async fn run1() { |
| @@ -25,14 +25,14 @@ async fn run2() { | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static EXECUTOR: Forever<Executor> = Forever::new(); | 28 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 29 | 29 | ||
| 30 | #[entry] | 30 | #[entry] |
| 31 | fn main() -> ! { | 31 | fn main() -> ! { |
| 32 | info!("Hello World!"); | 32 | info!("Hello World!"); |
| 33 | 33 | ||
| 34 | let _p = embassy_nrf::init(Default::default()); | 34 | let _p = embassy_nrf::init(Default::default()); |
| 35 | let executor = EXECUTOR.put(Executor::new()); | 35 | let executor = EXECUTOR.init(Executor::new()); |
| 36 | 36 | ||
| 37 | let run1_task = TaskStorage::new(); | 37 | let run1_task = TaskStorage::new(); |
| 38 | let run2_task = TaskStorage::new(); | 38 | let run2_task = TaskStorage::new(); |
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs index dab8e475d..1adaf53fd 100644 --- a/examples/nrf/src/bin/uart_split.rs +++ b/examples/nrf/src/bin/uart_split.rs | |||
| @@ -7,8 +7,8 @@ use embassy_executor::Spawner; | |||
| 7 | use embassy_nrf::peripherals::UARTE0; | 7 | use embassy_nrf::peripherals::UARTE0; |
| 8 | use embassy_nrf::uarte::UarteRx; | 8 | use embassy_nrf::uarte::UarteRx; |
| 9 | use embassy_nrf::{interrupt, uarte}; | 9 | use embassy_nrf::{interrupt, uarte}; |
| 10 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 10 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy_util::channel::mpmc::Channel; | 11 | use embassy_sync::channel::Channel; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); | 14 | static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); |
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index f0a870317..ca6c7e0d1 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs | |||
| @@ -14,21 +14,21 @@ use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; | |||
| 14 | use embassy_nrf::rng::Rng; | 14 | use embassy_nrf::rng::Rng; |
| 15 | use embassy_nrf::usb::{Driver, PowerUsb}; | 15 | use embassy_nrf::usb::{Driver, PowerUsb}; |
| 16 | use embassy_nrf::{interrupt, pac, peripherals}; | 16 | use embassy_nrf::{interrupt, pac, peripherals}; |
| 17 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 18 | use embassy_sync::channel::Channel; | ||
| 17 | use embassy_usb::{Builder, Config, UsbDevice}; | 19 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 18 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 20 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 19 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 20 | use embassy_util::channel::mpmc::Channel; | ||
| 21 | use embassy_util::Forever; | ||
| 22 | use embedded_io::asynch::{Read, Write}; | 21 | use embedded_io::asynch::{Read, Write}; |
| 22 | use static_cell::StaticCell; | ||
| 23 | use {defmt_rtt as _, panic_probe as _}; | 23 | use {defmt_rtt as _, panic_probe as _}; |
| 24 | 24 | ||
| 25 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; | 25 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; |
| 26 | 26 | ||
| 27 | macro_rules! forever { | 27 | macro_rules! singleton { |
| 28 | ($val:expr) => {{ | 28 | ($val:expr) => {{ |
| 29 | type T = impl Sized; | 29 | type T = impl Sized; |
| 30 | static FOREVER: Forever<T> = Forever::new(); | 30 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 31 | FOREVER.put_with(move || $val) | 31 | STATIC_CELL.init_with(move || $val) |
| 32 | }}; | 32 | }}; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -116,7 +116,7 @@ async fn main(spawner: Spawner) { | |||
| 116 | control_buf: [u8; 128], | 116 | control_buf: [u8; 128], |
| 117 | serial_state: State<'static>, | 117 | serial_state: State<'static>, |
| 118 | } | 118 | } |
| 119 | let res: &mut Resources = forever!(Resources { | 119 | let res: &mut Resources = singleton!(Resources { |
| 120 | device_descriptor: [0; 256], | 120 | device_descriptor: [0; 256], |
| 121 | config_descriptor: [0; 256], | 121 | config_descriptor: [0; 256], |
| 122 | bos_descriptor: [0; 256], | 122 | bos_descriptor: [0; 256], |
| @@ -174,10 +174,10 @@ async fn main(spawner: Spawner) { | |||
| 174 | 174 | ||
| 175 | // Init network stack | 175 | // Init network stack |
| 176 | let device = Device { mac_addr: our_mac_addr }; | 176 | let device = Device { mac_addr: our_mac_addr }; |
| 177 | let stack = &*forever!(Stack::new( | 177 | let stack = &*singleton!(Stack::new( |
| 178 | device, | 178 | device, |
| 179 | config, | 179 | config, |
| 180 | forever!(StackResources::<1, 2, 8>::new()), | 180 | singleton!(StackResources::<1, 2, 8>::new()), |
| 181 | seed | 181 | seed |
| 182 | )); | 182 | )); |
| 183 | 183 | ||
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index cf0078eec..ba2159c72 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs | |||
| @@ -8,14 +8,14 @@ use core::sync::atomic::{AtomicBool, Ordering}; | |||
| 8 | 8 | ||
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_futures::{select, Either}; | ||
| 11 | use embassy_nrf::gpio::{Input, Pin, Pull}; | 12 | use embassy_nrf::gpio::{Input, Pin, Pull}; |
| 12 | use embassy_nrf::usb::{Driver, PowerUsb}; | 13 | use embassy_nrf::usb::{Driver, PowerUsb}; |
| 13 | use embassy_nrf::{interrupt, pac}; | 14 | use embassy_nrf::{interrupt, pac}; |
| 15 | use embassy_sync::signal::Signal; | ||
| 14 | use embassy_usb::control::OutResponse; | 16 | use embassy_usb::control::OutResponse; |
| 15 | use embassy_usb::{Builder, Config, DeviceStateHandler}; | 17 | use embassy_usb::{Builder, Config, DeviceStateHandler}; |
| 16 | use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; | 18 | use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; |
| 17 | use embassy_util::channel::signal::Signal; | ||
| 18 | use embassy_util::{select, Either}; | ||
| 19 | use futures::future::join; | 19 | use futures::future::join; |
| 20 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; | 20 | use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {defmt_rtt as _, panic_probe as _}; |
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 4c1a93087..d62d7e520 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs | |||
| @@ -12,7 +12,7 @@ use embassy_nrf::{interrupt, pac, peripherals}; | |||
| 12 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 13 | use embassy_usb::{Builder, Config, UsbDevice}; | 13 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 14 | use embassy_usb_serial::{CdcAcmClass, State}; | 14 | use embassy_usb_serial::{CdcAcmClass, State}; |
| 15 | use embassy_util::Forever; | 15 | use static_cell::StaticCell; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; | 18 | type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; |
| @@ -67,8 +67,8 @@ async fn main(spawner: Spawner) { | |||
| 67 | control_buf: [u8; 64], | 67 | control_buf: [u8; 64], |
| 68 | serial_state: State<'static>, | 68 | serial_state: State<'static>, |
| 69 | } | 69 | } |
| 70 | static RESOURCES: Forever<Resources> = Forever::new(); | 70 | static RESOURCES: StaticCell<Resources> = StaticCell::new(); |
| 71 | let res = RESOURCES.put(Resources { | 71 | let res = RESOURCES.init(Resources { |
| 72 | device_descriptor: [0; 256], | 72 | device_descriptor: [0; 256], |
| 73 | config_descriptor: [0; 256], | 73 | config_descriptor: [0; 256], |
| 74 | bos_descriptor: [0; 256], | 74 | bos_descriptor: [0; 256], |
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index c2dcf429a..d804a660b 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -5,7 +5,7 @@ version = "0.1.0" | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } | 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } |
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index b7009017c..c7cec6b19 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-std-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } |
| 10 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } | 10 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } |
| @@ -20,3 +20,4 @@ libc = "0.2.101" | |||
| 20 | clap = { version = "3.0.0-beta.5", features = ["derive"] } | 20 | clap = { version = "3.0.0-beta.5", features = ["derive"] } |
| 21 | rand_core = { version = "0.6.3", features = ["std"] } | 21 | rand_core = { version = "0.6.3", features = ["std"] } |
| 22 | heapless = { version = "0.7.5", default-features = false } | 22 | heapless = { version = "0.7.5", default-features = false } |
| 23 | static_cell = "1.0" | ||
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 528609260..9b1450b72 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -4,22 +4,22 @@ use clap::Parser; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::tcp::TcpSocket; | 5 | use embassy_net::tcp::TcpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use embedded_io::asynch::Write; | 7 | use embedded_io::asynch::Write; |
| 9 | use heapless::Vec; | 8 | use heapless::Vec; |
| 10 | use log::*; | 9 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 10 | use rand_core::{OsRng, RngCore}; |
| 11 | use static_cell::StaticCell; | ||
| 12 | 12 | ||
| 13 | #[path = "../tuntap.rs"] | 13 | #[path = "../tuntap.rs"] |
| 14 | mod tuntap; | 14 | mod tuntap; |
| 15 | 15 | ||
| 16 | use crate::tuntap::TunTapDevice; | 16 | use crate::tuntap::TunTapDevice; |
| 17 | 17 | ||
| 18 | macro_rules! forever { | 18 | macro_rules! singleton { |
| 19 | ($val:expr) => {{ | 19 | ($val:expr) => {{ |
| 20 | type T = impl Sized; | 20 | type T = impl Sized; |
| 21 | static FOREVER: Forever<T> = Forever::new(); | 21 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 22 | FOREVER.put_with(move || $val) | 22 | STATIC_CELL.init_with(move || $val) |
| 23 | }}; | 23 | }}; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -63,10 +63,10 @@ async fn main_task(spawner: Spawner) { | |||
| 63 | let seed = u64::from_le_bytes(seed); | 63 | let seed = u64::from_le_bytes(seed); |
| 64 | 64 | ||
| 65 | // Init network stack | 65 | // Init network stack |
| 66 | let stack = &*forever!(Stack::new( | 66 | let stack = &*singleton!(Stack::new( |
| 67 | device, | 67 | device, |
| 68 | config, | 68 | config, |
| 69 | forever!(StackResources::<1, 2, 8>::new()), | 69 | singleton!(StackResources::<1, 2, 8>::new()), |
| 70 | seed | 70 | seed |
| 71 | )); | 71 | )); |
| 72 | 72 | ||
| @@ -97,7 +97,7 @@ async fn main_task(spawner: Spawner) { | |||
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | static EXECUTOR: Forever<Executor> = Forever::new(); | 100 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 101 | 101 | ||
| 102 | fn main() { | 102 | fn main() { |
| 103 | env_logger::builder() | 103 | env_logger::builder() |
| @@ -106,7 +106,7 @@ fn main() { | |||
| 106 | .format_timestamp_nanos() | 106 | .format_timestamp_nanos() |
| 107 | .init(); | 107 | .init(); |
| 108 | 108 | ||
| 109 | let executor = EXECUTOR.put(Executor::new()); | 109 | let executor = EXECUTOR.init(Executor::new()); |
| 110 | executor.run(|spawner| { | 110 | executor.run(|spawner| { |
| 111 | spawner.spawn(main_task(spawner)).unwrap(); | 111 | spawner.spawn(main_task(spawner)).unwrap(); |
| 112 | }); | 112 | }); |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 07e11c385..392a97f0d 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -4,21 +4,21 @@ use clap::Parser; | |||
| 4 | use embassy_executor::{Executor, Spawner}; | 4 | use embassy_executor::{Executor, Spawner}; |
| 5 | use embassy_net::udp::UdpSocket; | 5 | use embassy_net::udp::UdpSocket; |
| 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; | 6 | use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; |
| 7 | use embassy_util::Forever; | ||
| 8 | use heapless::Vec; | 7 | use heapless::Vec; |
| 9 | use log::*; | 8 | use log::*; |
| 10 | use rand_core::{OsRng, RngCore}; | 9 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::StaticCell; | ||
| 11 | 11 | ||
| 12 | #[path = "../tuntap.rs"] | 12 | #[path = "../tuntap.rs"] |
| 13 | mod tuntap; | 13 | mod tuntap; |
| 14 | 14 | ||
| 15 | use crate::tuntap::TunTapDevice; | 15 | use crate::tuntap::TunTapDevice; |
| 16 | 16 | ||
| 17 | macro_rules! forever { | 17 | macro_rules! singleton { |
| 18 | ($val:expr) => {{ | 18 | ($val:expr) => {{ |
| 19 | type T = impl Sized; | 19 | type T = impl Sized; |
| 20 | static FOREVER: Forever<T> = Forever::new(); | 20 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 21 | FOREVER.put_with(move || $val) | 21 | STATIC_CELL.init_with(move || $val) |
| 22 | }}; | 22 | }}; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| @@ -62,10 +62,10 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 62 | let seed = u64::from_le_bytes(seed); |
| 63 | 63 | ||
| 64 | // Init network stack | 64 | // Init network stack |
| 65 | let stack = &*forever!(Stack::new( | 65 | let stack = &*singleton!(Stack::new( |
| 66 | device, | 66 | device, |
| 67 | config, | 67 | config, |
| 68 | forever!(StackResources::<1, 2, 8>::new()), | 68 | singleton!(StackResources::<1, 2, 8>::new()), |
| 69 | seed | 69 | seed |
| 70 | )); | 70 | )); |
| 71 | 71 | ||
| @@ -93,7 +93,7 @@ async fn main_task(spawner: Spawner) { | |||
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | static EXECUTOR: Forever<Executor> = Forever::new(); | 96 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 97 | 97 | ||
| 98 | fn main() { | 98 | fn main() { |
| 99 | env_logger::builder() | 99 | env_logger::builder() |
| @@ -102,7 +102,7 @@ fn main() { | |||
| 102 | .format_timestamp_nanos() | 102 | .format_timestamp_nanos() |
| 103 | .init(); | 103 | .init(); |
| 104 | 104 | ||
| 105 | let executor = EXECUTOR.put(Executor::new()); | 105 | let executor = EXECUTOR.init(Executor::new()); |
| 106 | executor.run(|spawner| { | 106 | executor.run(|spawner| { |
| 107 | spawner.spawn(main_task(spawner)).unwrap(); | 107 | spawner.spawn(main_task(spawner)).unwrap(); |
| 108 | }); | 108 | }); |
diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index 35cba4cee..85ee54f70 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs | |||
| @@ -5,10 +5,10 @@ mod serial_port; | |||
| 5 | 5 | ||
| 6 | use async_io::Async; | 6 | use async_io::Async; |
| 7 | use embassy_executor::Executor; | 7 | use embassy_executor::Executor; |
| 8 | use embassy_util::Forever; | ||
| 9 | use embedded_io::asynch::Read; | 8 | use embedded_io::asynch::Read; |
| 10 | use log::*; | 9 | use log::*; |
| 11 | use nix::sys::termios; | 10 | use nix::sys::termios; |
| 11 | use static_cell::StaticCell; | ||
| 12 | 12 | ||
| 13 | use self::serial_port::SerialPort; | 13 | use self::serial_port::SerialPort; |
| 14 | 14 | ||
| @@ -40,7 +40,7 @@ async fn run() { | |||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | static EXECUTOR: Forever<Executor> = Forever::new(); | 43 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 44 | 44 | ||
| 45 | fn main() { | 45 | fn main() { |
| 46 | env_logger::builder() | 46 | env_logger::builder() |
| @@ -49,7 +49,7 @@ fn main() { | |||
| 49 | .format_timestamp_nanos() | 49 | .format_timestamp_nanos() |
| 50 | .init(); | 50 | .init(); |
| 51 | 51 | ||
| 52 | let executor = EXECUTOR.put(Executor::new()); | 52 | let executor = EXECUTOR.init(Executor::new()); |
| 53 | executor.run(|spawner| { | 53 | executor.run(|spawner| { |
| 54 | spawner.spawn(run()).unwrap(); | 54 | spawner.spawn(run()).unwrap(); |
| 55 | }); | 55 | }); |
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 8476200d4..cd2995d2c 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -11,7 +11,7 @@ cortex-m-rt = "0.7.0" | |||
| 11 | defmt = "0.3" | 11 | defmt = "0.3" |
| 12 | defmt-rtt = "0.3" | 12 | defmt-rtt = "0.3" |
| 13 | panic-probe = "0.3" | 13 | panic-probe = "0.3" |
| 14 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 14 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 15 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 15 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 16 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 16 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 17 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] } | 17 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] } |
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index fbc96400c..8660e743d 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32f1-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } |
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index 27894df50..b4bff4d85 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32f2-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index b5ea28bb6..d152b145f 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32f3-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| @@ -23,3 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 23 | heapless = { version = "0.7.5", default-features = false } | 23 | heapless = { version = "0.7.5", default-features = false } |
| 24 | nb = "1.0.0" | 24 | nb = "1.0.0" |
| 25 | embedded-storage = "0.3.0" | 25 | embedded-storage = "0.3.0" |
| 26 | static_cell = "1.0" | ||
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 61fc6dcab..02c475f66 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs | |||
| @@ -15,9 +15,9 @@ use embassy_executor::Spawner; | |||
| 15 | use embassy_stm32::exti::ExtiInput; | 15 | use embassy_stm32::exti::ExtiInput; |
| 16 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; | 16 | use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; |
| 17 | use embassy_stm32::peripherals::PA0; | 17 | use embassy_stm32::peripherals::PA0; |
| 18 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 19 | use embassy_sync::channel::Channel; | ||
| 18 | use embassy_time::{with_timeout, Duration, Timer}; | 20 | use embassy_time::{with_timeout, Duration, Timer}; |
| 19 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 20 | use embassy_util::channel::mpmc::Channel; | ||
| 21 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 22 | ||
| 23 | struct Leds<'a> { | 23 | struct Leds<'a> { |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index e96c31249..9e8228a4b 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 64 | use embassy_stm32::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 122 | let irq = interrupt::take!(UART4); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 129 | let irq = interrupt::take!(UART5); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 04a217aff..9bfdda92d 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -5,7 +5,7 @@ version = "0.1.0" | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 8 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } |
| @@ -23,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false } | |||
| 23 | nb = "1.0.0" | 23 | nb = "1.0.0" |
| 24 | embedded-storage = "0.3.0" | 24 | embedded-storage = "0.3.0" |
| 25 | micromath = "2.0.0" | 25 | micromath = "2.0.0" |
| 26 | static_cell = "1.0" | ||
| 26 | 27 | ||
| 27 | usb-device = "0.2" | 28 | usb-device = "0.2" |
| 28 | usbd-serial = "0.1.1" | 29 | usbd-serial = "0.1.1" |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index e96c31249..9e8228a4b 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor}; | |||
| 63 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 64 | use embassy_stm32::interrupt::InterruptExt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use embassy_util::Forever; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| 69 | #[embassy_executor::task] | 69 | #[embassy_executor::task] |
| @@ -108,9 +108,9 @@ async fn run_low() { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); | 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); |
| 112 | static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); | 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); |
| 113 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); | 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 114 | ||
| 115 | #[entry] | 115 | #[entry] |
| 116 | fn main() -> ! { | 116 | fn main() -> ! { |
| @@ -121,19 +121,19 @@ fn main() -> ! { | |||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 121 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 122 | let irq = interrupt::take!(UART4); |
| 123 | irq.set_priority(interrupt::Priority::P6); | 123 | irq.set_priority(interrupt::Priority::P6); |
| 124 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); |
| 125 | let spawner = executor.start(); | 125 | let spawner = executor.start(); |
| 126 | unwrap!(spawner.spawn(run_high())); | 126 | unwrap!(spawner.spawn(run_high())); |
| 127 | 127 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 129 | let irq = interrupt::take!(UART5); |
| 130 | irq.set_priority(interrupt::Priority::P7); | 130 | irq.set_priority(interrupt::Priority::P7); |
| 131 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); |
| 132 | let spawner = executor.start(); | 132 | let spawner = executor.start(); |
| 133 | unwrap!(spawner.spawn(run_med())); | 133 | unwrap!(spawner.spawn(run_med())); |
| 134 | 134 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 135 | // Low priority executor: runs in thread mode, using WFE/SEV |
| 136 | let executor = EXECUTOR_LOW.put(Executor::new()); | 136 | let executor = EXECUTOR_LOW.init(Executor::new()); |
| 137 | executor.run(|spawner| { | 137 | executor.run(|spawner| { |
| 138 | unwrap!(spawner.spawn(run_low())); | 138 | unwrap!(spawner.spawn(run_low())); |
| 139 | }); | 139 | }); |
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 29d6da4d8..a446fe3fb 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32f7-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } |
| @@ -24,3 +24,4 @@ nb = "1.0.0" | |||
| 24 | rand_core = "0.6.3" | 24 | rand_core = "0.6.3" |
| 25 | critical-section = "1.1" | 25 | critical-section = "1.1" |
| 26 | embedded-storage = "0.3.0" | 26 | embedded-storage = "0.3.0" |
| 27 | static_cell = "1.0" | ||
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index bdffabcb3..5202edf62 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | macro_rules! forever { | 21 | macro_rules! singleton { |
| 22 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
| 23 | type T = impl Sized; | 23 | type T = impl Sized; |
| 24 | static FOREVER: Forever<T> = Forever::new(); | 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 25 | FOREVER.put_with(move || $val) | 25 | STATIC_CELL.init_with(move || $val) |
| 26 | }}; | 26 | }}; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -52,7 +52,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 52 | 52 | ||
| 53 | let device = unsafe { | 53 | let device = unsafe { |
| 54 | Ethernet::new( | 54 | Ethernet::new( |
| 55 | forever!(State::new()), | 55 | singleton!(State::new()), |
| 56 | p.ETH, | 56 | p.ETH, |
| 57 | eth_int, | 57 | eth_int, |
| 58 | p.PA1, | 58 | p.PA1, |
| @@ -78,10 +78,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 78 | //}); | 78 | //}); |
| 79 | 79 | ||
| 80 | // Init network stack | 80 | // Init network stack |
| 81 | let stack = &*forever!(Stack::new( | 81 | let stack = &*singleton!(Stack::new( |
| 82 | device, | 82 | device, |
| 83 | config, | 83 | config, |
| 84 | forever!(StackResources::<1, 2, 8>::new()), | 84 | singleton!(StackResources::<1, 2, 8>::new()), |
| 85 | seed | 85 | seed |
| 86 | )); | 86 | )); |
| 87 | 87 | ||
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 5c80d43eb..30f2b86f8 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32g0-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } |
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index 74c645cf5..f81df0b70 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32g4-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } |
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index a416796ea..0f76f3226 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32h7-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } |
| @@ -28,6 +28,7 @@ critical-section = "1.1" | |||
| 28 | micromath = "2.0.0" | 28 | micromath = "2.0.0" |
| 29 | stm32-fmc = "0.2.4" | 29 | stm32-fmc = "0.2.4" |
| 30 | embedded-storage = "0.3.0" | 30 | embedded-storage = "0.3.0" |
| 31 | static_cell = "1.0" | ||
| 31 | 32 | ||
| 32 | # cargo build/run | 33 | # cargo build/run |
| 33 | [profile.dev] | 34 | [profile.dev] |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 83210bcb5..4ccc0b5ef 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::StaticCell; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | macro_rules! forever { | 21 | macro_rules! singleton { |
| 22 | ($val:expr) => {{ | 22 | ($val:expr) => {{ |
| 23 | type T = impl Sized; | 23 | type T = impl Sized; |
| 24 | static FOREVER: Forever<T> = Forever::new(); | 24 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 25 | FOREVER.put_with(move || $val) | 25 | STATIC_CELL.init_with(move || $val) |
| 26 | }}; | 26 | }}; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -53,7 +53,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 53 | 53 | ||
| 54 | let device = unsafe { | 54 | let device = unsafe { |
| 55 | Ethernet::new( | 55 | Ethernet::new( |
| 56 | forever!(State::new()), | 56 | singleton!(State::new()), |
| 57 | p.ETH, | 57 | p.ETH, |
| 58 | eth_int, | 58 | eth_int, |
| 59 | p.PA1, | 59 | p.PA1, |
| @@ -79,10 +79,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 79 | //}); | 79 | //}); |
| 80 | 80 | ||
| 81 | // Init network stack | 81 | // Init network stack |
| 82 | let stack = &*forever!(Stack::new( | 82 | let stack = &*singleton!(Stack::new( |
| 83 | device, | 83 | device, |
| 84 | config, | 84 | config, |
| 85 | forever!(StackResources::<1, 2, 8>::new()), | 85 | singleton!(StackResources::<1, 2, 8>::new()), |
| 86 | seed | 86 | seed |
| 87 | )); | 87 | )); |
| 88 | 88 | ||
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 99946f504..64fd84141 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -13,17 +13,17 @@ use embassy_stm32::rng::Rng; | |||
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{interrupt, Config}; | 14 | use embassy_stm32::{interrupt, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 16 | use embassy_util::Forever; | ||
| 17 | use embedded_io::asynch::Write; | 16 | use embedded_io::asynch::Write; |
| 18 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 17 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; |
| 19 | use rand_core::RngCore; | 18 | use rand_core::RngCore; |
| 19 | use static_cell::StaticCell; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | macro_rules! forever { | 22 | macro_rules! singleton { |
| 23 | ($val:expr) => {{ | 23 | ($val:expr) => {{ |
| 24 | type T = impl Sized; | 24 | type T = impl Sized; |
| 25 | static FOREVER: Forever<T> = Forever::new(); | 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 26 | FOREVER.put_with(move || $val) | 26 | STATIC_CELL.init_with(move || $val) |
| 27 | }}; | 27 | }}; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 54 | 54 | ||
| 55 | let device = unsafe { | 55 | let device = unsafe { |
| 56 | Ethernet::new( | 56 | Ethernet::new( |
| 57 | forever!(State::new()), | 57 | singleton!(State::new()), |
| 58 | p.ETH, | 58 | p.ETH, |
| 59 | eth_int, | 59 | eth_int, |
| 60 | p.PA1, | 60 | p.PA1, |
| @@ -80,10 +80,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 80 | //}); | 80 | //}); |
| 81 | 81 | ||
| 82 | // Init network stack | 82 | // Init network stack |
| 83 | let stack = &*forever!(Stack::new( | 83 | let stack = &*singleton!(Stack::new( |
| 84 | device, | 84 | device, |
| 85 | config, | 85 | config, |
| 86 | forever!(StackResources::<1, 2, 8>::new()), | 86 | singleton!(StackResources::<1, 2, 8>::new()), |
| 87 | seed | 87 | seed |
| 88 | )); | 88 | )); |
| 89 | 89 | ||
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index be2ac268e..cc3e4e3ca 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::{info, unwrap}; | 5 | use defmt::{info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_sync::signal::Signal; | ||
| 7 | use embassy_time::{Duration, Timer}; | 8 | use embassy_time::{Duration, Timer}; |
| 8 | use embassy_util::channel::signal::Signal; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | static SIGNAL: Signal<u32> = Signal::new(); | 11 | static SIGNAL: Signal<u32> = Signal::new(); |
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index c28f937a8..1f407f002 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -12,8 +12,8 @@ use embassy_stm32::dma::NoDma; | |||
| 12 | use embassy_stm32::peripherals::SPI3; | 12 | use embassy_stm32::peripherals::SPI3; |
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{spi, Config}; | 14 | use embassy_stm32::{spi, Config}; |
| 15 | use embassy_util::Forever; | ||
| 16 | use heapless::String; | 15 | use heapless::String; |
| 16 | use static_cell::StaticCell; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | #[embassy_executor::task] | 19 | #[embassy_executor::task] |
| @@ -31,7 +31,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | static EXECUTOR: Forever<Executor> = Forever::new(); | 34 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 35 | 35 | ||
| 36 | #[entry] | 36 | #[entry] |
| 37 | fn main() -> ! { | 37 | fn main() -> ! { |
| @@ -54,7 +54,7 @@ fn main() -> ! { | |||
| 54 | spi::Config::default(), | 54 | spi::Config::default(), |
| 55 | ); | 55 | ); |
| 56 | 56 | ||
| 57 | let executor = EXECUTOR.put(Executor::new()); | 57 | let executor = EXECUTOR.init(Executor::new()); |
| 58 | 58 | ||
| 59 | executor.run(|spawner| { | 59 | executor.run(|spawner| { |
| 60 | unwrap!(spawner.spawn(main_task(spi))); | 60 | unwrap!(spawner.spawn(main_task(spi))); |
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 6c78c194f..53004fc9b 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -11,8 +11,8 @@ use embassy_executor::Executor; | |||
| 11 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; | 11 | use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; |
| 12 | use embassy_stm32::time::mhz; | 12 | use embassy_stm32::time::mhz; |
| 13 | use embassy_stm32::{spi, Config}; | 13 | use embassy_stm32::{spi, Config}; |
| 14 | use embassy_util::Forever; | ||
| 15 | use heapless::String; | 14 | use heapless::String; |
| 15 | use static_cell::StaticCell; | ||
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | #[embassy_executor::task] | 18 | #[embassy_executor::task] |
| @@ -27,7 +27,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) { | |||
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | static EXECUTOR: Forever<Executor> = Forever::new(); | 30 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 31 | 31 | ||
| 32 | #[entry] | 32 | #[entry] |
| 33 | fn main() -> ! { | 33 | fn main() -> ! { |
| @@ -50,7 +50,7 @@ fn main() -> ! { | |||
| 50 | spi::Config::default(), | 50 | spi::Config::default(), |
| 51 | ); | 51 | ); |
| 52 | 52 | ||
| 53 | let executor = EXECUTOR.put(Executor::new()); | 53 | let executor = EXECUTOR.init(Executor::new()); |
| 54 | 54 | ||
| 55 | executor.run(|spawner| { | 55 | executor.run(|spawner| { |
| 56 | unwrap!(spawner.spawn(main_task(spi))); | 56 | unwrap!(spawner.spawn(main_task(spi))); |
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index 1384d54c6..87c2b1253 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs | |||
| @@ -7,7 +7,7 @@ use defmt::*; | |||
| 7 | use embassy_executor::Executor; | 7 | use embassy_executor::Executor; |
| 8 | use embassy_stm32::dma::NoDma; | 8 | use embassy_stm32::dma::NoDma; |
| 9 | use embassy_stm32::usart::{Config, Uart}; | 9 | use embassy_stm32::usart::{Config, Uart}; |
| 10 | use embassy_util::Forever; | 10 | use static_cell::StaticCell; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | #[embassy_executor::task] | 13 | #[embassy_executor::task] |
| @@ -27,13 +27,13 @@ async fn main_task() { | |||
| 27 | } | 27 | } |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | static EXECUTOR: Forever<Executor> = Forever::new(); | 30 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 31 | 31 | ||
| 32 | #[entry] | 32 | #[entry] |
| 33 | fn main() -> ! { | 33 | fn main() -> ! { |
| 34 | info!("Hello World!"); | 34 | info!("Hello World!"); |
| 35 | 35 | ||
| 36 | let executor = EXECUTOR.put(Executor::new()); | 36 | let executor = EXECUTOR.init(Executor::new()); |
| 37 | 37 | ||
| 38 | executor.run(|spawner| { | 38 | executor.run(|spawner| { |
| 39 | unwrap!(spawner.spawn(main_task())); | 39 | unwrap!(spawner.spawn(main_task())); |
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index f8d58bb84..3adffcbeb 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -9,8 +9,8 @@ use defmt::*; | |||
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_stm32::dma::NoDma; | 10 | use embassy_stm32::dma::NoDma; |
| 11 | use embassy_stm32::usart::{Config, Uart}; | 11 | use embassy_stm32::usart::{Config, Uart}; |
| 12 | use embassy_util::Forever; | ||
| 13 | use heapless::String; | 12 | use heapless::String; |
| 13 | use static_cell::StaticCell; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | #[embassy_executor::task] | 16 | #[embassy_executor::task] |
| @@ -30,13 +30,13 @@ async fn main_task() { | |||
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | static EXECUTOR: Forever<Executor> = Forever::new(); | 33 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 34 | 34 | ||
| 35 | #[entry] | 35 | #[entry] |
| 36 | fn main() -> ! { | 36 | fn main() -> ! { |
| 37 | info!("Hello World!"); | 37 | info!("Hello World!"); |
| 38 | 38 | ||
| 39 | let executor = EXECUTOR.put(Executor::new()); | 39 | let executor = EXECUTOR.init(Executor::new()); |
| 40 | 40 | ||
| 41 | executor.run(|spawner| { | 41 | executor.run(|spawner| { |
| 42 | unwrap!(spawner.spawn(main_task())); | 42 | unwrap!(spawner.spawn(main_task())); |
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index 64080ec45..df2b600f8 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs | |||
| @@ -7,8 +7,8 @@ use embassy_executor::Spawner; | |||
| 7 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 8 | use embassy_stm32::peripherals::{DMA1_CH1, UART7}; | 8 | use embassy_stm32::peripherals::{DMA1_CH1, UART7}; |
| 9 | use embassy_stm32::usart::{Config, Uart, UartRx}; | 9 | use embassy_stm32::usart::{Config, Uart, UartRx}; |
| 10 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | 10 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 11 | use embassy_util::channel::mpmc::Channel; | 11 | use embassy_sync::channel::Channel; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | #[embassy_executor::task] | 14 | #[embassy_executor::task] |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index fdb716d15..11751a21d 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -8,7 +8,7 @@ default = ["nightly"] | |||
| 8 | nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"] | 8 | nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"] |
| 9 | 9 | ||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 11 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 12 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 12 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 13 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 13 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| @@ -29,3 +29,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } | |||
| 29 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 29 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 30 | heapless = { version = "0.7.5", default-features = false } | 30 | heapless = { version = "0.7.5", default-features = false } |
| 31 | embedded-hal = "0.2.6" | 31 | embedded-hal = "0.2.6" |
| 32 | static_cell = "1.0" | ||
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs index bd87e62a4..edc17304a 100644 --- a/examples/stm32l0/src/bin/raw_spawn.rs +++ b/examples/stm32l0/src/bin/raw_spawn.rs | |||
| @@ -8,7 +8,7 @@ use defmt::*; | |||
| 8 | use embassy_executor::raw::TaskStorage; | 8 | use embassy_executor::raw::TaskStorage; |
| 9 | use embassy_executor::Executor; | 9 | use embassy_executor::Executor; |
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | use embassy_util::Forever; | 11 | use static_cell::StaticCell; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | async fn run1() { | 14 | async fn run1() { |
| @@ -25,14 +25,14 @@ async fn run2() { | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static EXECUTOR: Forever<Executor> = Forever::new(); | 28 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); |
| 29 | 29 | ||
| 30 | #[entry] | 30 | #[entry] |
| 31 | fn main() -> ! { | 31 | fn main() -> ! { |
| 32 | info!("Hello World!"); | 32 | info!("Hello World!"); |
| 33 | 33 | ||
| 34 | let _p = embassy_stm32::init(Default::default()); | 34 | let _p = embassy_stm32::init(Default::default()); |
| 35 | let executor = EXECUTOR.put(Executor::new()); | 35 | let executor = EXECUTOR.init(Executor::new()); |
| 36 | 36 | ||
| 37 | let run1_task = TaskStorage::new(); | 37 | let run1_task = TaskStorage::new(); |
| 38 | let run2_task = TaskStorage::new(); | 38 | let run2_task = TaskStorage::new(); |
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index 43f844b67..18b35b305 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32l1-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } |
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index eaffa253e..cb7238e4c 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -6,7 +6,7 @@ version = "0.1.0" | |||
| 6 | [features] | 6 | [features] |
| 7 | 7 | ||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 9 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 10 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 10 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 12 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 12 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 4d96d31fc..624c73c26 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -6,7 +6,7 @@ version = "0.1.0" | |||
| 6 | [features] | 6 | [features] |
| 7 | 7 | ||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 9 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 10 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 10 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 11 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 12 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| @@ -28,3 +28,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 28 | heapless = { version = "0.7.5", default-features = false } | 28 | heapless = { version = "0.7.5", default-features = false } |
| 29 | rand_core = { version = "0.6.3", default-features = false } | 29 | rand_core = { version = "0.6.3", default-features = false } |
| 30 | embedded-io = { version = "0.3.0", features = ["async"] } | 30 | embedded-io = { version = "0.3.0", features = ["async"] } |
| 31 | static_cell = "1.0" | ||
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 7c53d03cc..3286f5c4d 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -15,22 +15,22 @@ use embassy_stm32::rng::Rng; | |||
| 15 | use embassy_stm32::time::Hertz; | 15 | use embassy_stm32::time::Hertz; |
| 16 | use embassy_stm32::usb::Driver; | 16 | use embassy_stm32::usb::Driver; |
| 17 | use embassy_stm32::{interrupt, Config}; | 17 | use embassy_stm32::{interrupt, Config}; |
| 18 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 19 | use embassy_sync::channel::Channel; | ||
| 18 | use embassy_usb::{Builder, UsbDevice}; | 20 | use embassy_usb::{Builder, UsbDevice}; |
| 19 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; | 21 | use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; |
| 20 | use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; | ||
| 21 | use embassy_util::channel::mpmc::Channel; | ||
| 22 | use embassy_util::Forever; | ||
| 23 | use embedded_io::asynch::{Read, Write}; | 22 | use embedded_io::asynch::{Read, Write}; |
| 24 | use rand_core::RngCore; | 23 | use rand_core::RngCore; |
| 24 | use static_cell::StaticCell; | ||
| 25 | use {defmt_rtt as _, panic_probe as _}; | 25 | use {defmt_rtt as _, panic_probe as _}; |
| 26 | 26 | ||
| 27 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; | 27 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; |
| 28 | 28 | ||
| 29 | macro_rules! forever { | 29 | macro_rules! singleton { |
| 30 | ($val:expr) => {{ | 30 | ($val:expr) => {{ |
| 31 | type T = impl Sized; | 31 | type T = impl Sized; |
| 32 | static FOREVER: Forever<T> = Forever::new(); | 32 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); |
| 33 | FOREVER.put_with(move || $val) | 33 | STATIC_CELL.init_with(move || $val) |
| 34 | }}; | 34 | }}; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| @@ -115,7 +115,7 @@ async fn main(spawner: Spawner) { | |||
| 115 | control_buf: [u8; 128], | 115 | control_buf: [u8; 128], |
| 116 | serial_state: State<'static>, | 116 | serial_state: State<'static>, |
| 117 | } | 117 | } |
| 118 | let res: &mut Resources = forever!(Resources { | 118 | let res: &mut Resources = singleton!(Resources { |
| 119 | device_descriptor: [0; 256], | 119 | device_descriptor: [0; 256], |
| 120 | config_descriptor: [0; 256], | 120 | config_descriptor: [0; 256], |
| 121 | bos_descriptor: [0; 256], | 121 | bos_descriptor: [0; 256], |
| @@ -171,10 +171,10 @@ async fn main(spawner: Spawner) { | |||
| 171 | 171 | ||
| 172 | // Init network stack | 172 | // Init network stack |
| 173 | let device = Device { mac_addr: our_mac_addr }; | 173 | let device = Device { mac_addr: our_mac_addr }; |
| 174 | let stack = &*forever!(Stack::new( | 174 | let stack = &*singleton!(Stack::new( |
| 175 | device, | 175 | device, |
| 176 | config, | 176 | config, |
| 177 | forever!(StackResources::<1, 2, 8>::new()), | 177 | singleton!(StackResources::<1, 2, 8>::new()), |
| 178 | seed | 178 | seed |
| 179 | )); | 179 | )); |
| 180 | 180 | ||
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 48833664a..ff0ec9f42 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32u5-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } |
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index b46300764..3b10da0ad 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32wb-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] } |
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index ae33478af..5f6679f4b 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-stm32wl-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } | 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } |
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index d16e3f5e4..c5e9bb597 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs | |||
| @@ -13,7 +13,7 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 13 | use embassy_stm32::interrupt; | 13 | use embassy_stm32::interrupt; |
| 14 | use embassy_stm32::interrupt::{Interrupt, InterruptExt}; | 14 | use embassy_stm32::interrupt::{Interrupt, InterruptExt}; |
| 15 | use embassy_stm32::subghz::*; | 15 | use embassy_stm32::subghz::*; |
| 16 | use embassy_util::channel::signal::Signal; | 16 | use embassy_sync::signal::Signal; |
| 17 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 18 | ||
| 19 | const PING_DATA: &str = "PING"; | 19 | const PING_DATA: &str = "PING"; |
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index c7f980366..ea61fb921 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml | |||
| @@ -7,7 +7,7 @@ version = "0.1.0" | |||
| 7 | crate-type = ["cdylib"] | 7 | crate-type = ["cdylib"] |
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } | 10 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] } |
| 11 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] } | 11 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] } | 12 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] } |
| 13 | 13 | ||
| @@ -15,4 +15,4 @@ wasm-logger = "0.2.0" | |||
| 15 | wasm-bindgen = "0.2" | 15 | wasm-bindgen = "0.2" |
| 16 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } | 16 | web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } |
| 17 | log = "0.4.11" | 17 | log = "0.4.11" |
| 18 | critical-section = "1.1" | 18 | critical-section = { version = "1.1", features = ["std"] } |
diff --git a/examples/wasm/README.md b/examples/wasm/README.md index 4bed4a797..b7fee2dc8 100644 --- a/examples/wasm/README.md +++ b/examples/wasm/README.md | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | Examples use a CLI tool named `wasm-pack` to build this example: | 3 | Examples use a CLI tool named `wasm-pack` to build this example: |
| 4 | 4 | ||
| 5 | ``` | 5 | ``` |
| 6 | cargo install wasm-pack | 6 | cargo install wasm-pack --version 0.9.1 |
| 7 | ``` | 7 | ``` |
| 8 | 8 | ||
| 9 | ## Building | 9 | ## Building |
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 8740cc488..4d6877ccd 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -4,7 +4,7 @@ name = "embassy-rp-tests" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [dependencies] | 6 | [dependencies] |
| 7 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 7 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 8 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } | 9 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } |
| 10 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits"] } | 10 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits"] } |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 1d12995a2..f1441d00c 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -13,7 +13,7 @@ stm32wb55rg = ["embassy-stm32/stm32wb55rg"] # Nucleo | |||
| 13 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board | 13 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board |
| 14 | 14 | ||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 16 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 17 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 17 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 18 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "tick-32768hz"] } | 18 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "tick-32768hz"] } |
| 19 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } | 19 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } |
