chore: replace make_static! macro usage with non-macro version

This commit is contained in:
Ulf Lilleengen
2023-12-21 08:50:54 +01:00
parent d832d45c0b
commit 0acf7b09c3
37 changed files with 313 additions and 188 deletions

View File

@ -20,7 +20,7 @@ use embassy_time::{Delay, Duration};
use embedded_hal_bus::spi::ExclusiveDevice;
use embedded_io_async::Write;
use rand::RngCore;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@ -55,7 +55,8 @@ async fn main(spawner: Spawner) {
let w5500_reset = Output::new(p.PIN_20, Level::High);
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
let state = make_static!(State::<8, 8>::new());
static STATE: StaticCell<State<8, 8>> = StaticCell::new();
let state = STATE.init(State::<8, 8>::new());
let (device, runner) = embassy_net_wiznet::new(
mac_addr,
state,
@ -70,11 +71,13 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
make_static!(StackResources::<3>::new()),
seed
RESOURCES.init(StackResources::<3>::new()),
seed,
));
// Launch network task

View File

@ -22,7 +22,7 @@ use embassy_time::{Delay, Duration, Timer};
use embedded_hal_bus::spi::ExclusiveDevice;
use embedded_io_async::Write;
use rand::RngCore;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@ -58,7 +58,8 @@ async fn main(spawner: Spawner) {
let w5500_reset = Output::new(p.PIN_20, Level::High);
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
let state = make_static!(State::<8, 8>::new());
static STATE: StaticCell<State<8, 8>> = StaticCell::new();
let state = STATE.init(State::<8, 8>::new());
let (device, runner) = embassy_net_wiznet::new(
mac_addr,
state,
@ -73,11 +74,13 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
// Launch network task

View File

@ -21,7 +21,7 @@ use embassy_time::{Delay, Duration};
use embedded_hal_bus::spi::ExclusiveDevice;
use embedded_io_async::Write;
use rand::RngCore;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@ -57,7 +57,8 @@ async fn main(spawner: Spawner) {
let w5500_reset = Output::new(p.PIN_20, Level::High);
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
let state = make_static!(State::<8, 8>::new());
static STATE: StaticCell<State<8, 8>> = StaticCell::new();
let state = STATE.init(State::<8, 8>::new());
let (device, runner) = embassy_net_wiznet::new(
mac_addr,
state,
@ -72,11 +73,13 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
// Launch network task

View File

@ -20,7 +20,7 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use rand::RngCore;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@ -55,7 +55,8 @@ async fn main(spawner: Spawner) {
let w5500_reset = Output::new(p.PIN_20, Level::High);
let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
let state = make_static!(State::<8, 8>::new());
static STATE: StaticCell<State<8, 8>> = StaticCell::new();
let state = STATE.init(State::<8, 8>::new());
let (device, runner) = embassy_net_wiznet::new(
mac_addr,
state,
@ -70,11 +71,13 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
embassy_net::Config::dhcpv4(Default::default()),
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
// Launch network task

View File

@ -15,7 +15,7 @@ use embassy_rp::peripherals::UART0;
use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config};
use embassy_time::Timer;
use embedded_io_async::{Read, Write};
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -27,8 +27,10 @@ async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);
let tx_buf = &mut make_static!([0u8; 16])[..];
let rx_buf = &mut make_static!([0u8; 16])[..];
static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
let tx_buf = &mut TX_BUF.init([0; 16])[..];
static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
let rx_buf = &mut RX_BUF.init([0; 16])[..];
let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default());
let (rx, mut tx) = uart.split();

View File

@ -17,7 +17,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
use embassy_usb::{Builder, Config, UsbDevice};
use embedded_io_async::Write;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -65,14 +65,18 @@ async fn main(spawner: Spawner) {
config.device_protocol = 0x01;
// Create embassy-usb DeviceBuilder using the driver and config.
static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new();
static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new();
static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new();
static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new();
let mut builder = Builder::new(
driver,
config,
&mut make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut DEVICE_DESC.init([0; 256])[..],
&mut CONFIG_DESC.init([0; 256])[..],
&mut BOS_DESC.init([0; 256])[..],
&mut [], // no msos descriptors
&mut make_static!([0; 128])[..],
&mut CONTROL_BUF.init([0; 128])[..],
);
// Our MAC addr.
@ -81,14 +85,16 @@ async fn main(spawner: Spawner) {
let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
// Create classes on the builder.
let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
static STATE: StaticCell<State> = StaticCell::new();
let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64);
// Build the builder.
let usb = builder.build();
unwrap!(spawner.spawn(usb_task(usb)));
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new();
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr);
unwrap!(spawner.spawn(usb_ncm_task(runner)));
let config = embassy_net::Config::dhcpv4(Default::default());
@ -102,11 +108,13 @@ async fn main(spawner: Spawner) {
let seed = 1234; // guaranteed random, chosen by a fair dice roll
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
device,
config,
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::{InterruptHandler, Pio};
use embassy_time::Duration;
use embedded_io_async::Write;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -59,7 +59,8 @@ async fn main(spawner: Spawner) {
let mut pio = Pio::new(p.PIO0, Irqs);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = make_static!(cyw43::State::new());
static STATE: StaticCell<cyw43::State> = StaticCell::new();
let state = STATE.init(cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));
@ -79,11 +80,13 @@ async fn main(spawner: Spawner) {
let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
net_device,
config,
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
unwrap!(spawner.spawn(net_task(stack)));

View File

@ -14,7 +14,7 @@ use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::{InterruptHandler, Pio};
use embassy_time::{Duration, Timer};
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -46,7 +46,8 @@ async fn main(spawner: Spawner) {
let mut pio = Pio::new(p.PIO0, Irqs);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = make_static!(cyw43::State::new());
static STATE: StaticCell<cyw43::State> = StaticCell::new();
let state = STATE.init(cyw43::State::new());
let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));

View File

@ -16,7 +16,7 @@ use embassy_rp::bind_interrupts;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::{InterruptHandler, Pio};
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -56,7 +56,8 @@ async fn main(spawner: Spawner) {
let mut pio = Pio::new(p.PIO0, Irqs);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = make_static!(cyw43::State::new());
static STATE: StaticCell<cyw43::State> = StaticCell::new();
let state = STATE.init(cyw43::State::new());
let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));

View File

@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::{InterruptHandler, Pio};
use embassy_time::{Duration, Timer};
use embedded_io_async::Write;
use static_cell::make_static;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -62,7 +62,8 @@ async fn main(spawner: Spawner) {
let mut pio = Pio::new(p.PIO0, Irqs);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = make_static!(cyw43::State::new());
static STATE: StaticCell<cyw43::State> = StaticCell::new();
let state = STATE.init(cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));
@ -82,11 +83,13 @@ async fn main(spawner: Spawner) {
let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
// Init network stack
let stack = &*make_static!(Stack::new(
static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
let stack = &*STACK.init(Stack::new(
net_device,
config,
make_static!(StackResources::<2>::new()),
seed
RESOURCES.init(StackResources::<2>::new()),
seed,
));
unwrap!(spawner.spawn(net_task(stack)));