Remove Forever, switch to static_cell.

This commit is contained in:
Dario Nieuwenhuis
2022-08-22 15:51:44 +02:00
parent 1b95990258
commit 478f472784
45 changed files with 139 additions and 220 deletions

View File

@ -28,3 +28,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
heapless = { version = "0.7.5", default-features = false }
rand_core = { version = "0.6.3", default-features = false }
embedded-io = { version = "0.3.0", features = ["async"] }
static_cell = "1.0"

View File

@ -19,18 +19,18 @@ use embassy_usb::{Builder, UsbDevice};
use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_util::channel::mpmc::Channel;
use embassy_util::Forever;
use embedded_io::asynch::{Read, Write};
use rand_core::RngCore;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
macro_rules! forever {
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static FOREVER: Forever<T> = Forever::new();
FOREVER.put_with(move || $val)
static STATIC_CELL: StaticCell<T> = StaticCell::new();
STATIC_CELL.init_with(move || $val)
}};
}
@ -115,7 +115,7 @@ async fn main(spawner: Spawner) {
control_buf: [u8; 128],
serial_state: State<'static>,
}
let res: &mut Resources = forever!(Resources {
let res: &mut Resources = singleton!(Resources {
device_descriptor: [0; 256],
config_descriptor: [0; 256],
bos_descriptor: [0; 256],
@ -171,10 +171,10 @@ async fn main(spawner: Spawner) {
// Init network stack
let device = Device { mac_addr: our_mac_addr };
let stack = &*forever!(Stack::new(
let stack = &*singleton!(Stack::new(
device,
config,
forever!(StackResources::<1, 2, 8>::new()),
singleton!(StackResources::<1, 2, 8>::new()),
seed
));