aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-12-21 08:50:54 +0100
committerUlf Lilleengen <[email protected]>2023-12-21 10:29:57 +0100
commit0acf7b09c3bc9176d00479d601356d8df2537a9b (patch)
tree7a04543c661b38b6aba8893c9150ef8090199ee5 /examples/nrf52840/src
parentd832d45c0ba5f2624a5f5c1e549e2d7fe8bd0e01 (diff)
chore: replace make_static! macro usage with non-macro version
Diffstat (limited to 'examples/nrf52840/src')
-rw-r--r--examples/nrf52840/src/bin/ethernet_enc28j60.rs17
-rw-r--r--examples/nrf52840/src/bin/usb_ethernet.rs32
-rw-r--r--examples/nrf52840/src/bin/usb_serial_multitask.rs20
-rw-r--r--examples/nrf52840/src/bin/wifi_esp_hosted.rs13
4 files changed, 52 insertions, 30 deletions
diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs
index d1b796fab..840a16556 100644
--- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs
+++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs
@@ -14,7 +14,7 @@ use embassy_nrf::{bind_interrupts, peripherals, spim};
14use embassy_time::Delay; 14use embassy_time::Delay;
15use embedded_hal_bus::spi::ExclusiveDevice; 15use embedded_hal_bus::spi::ExclusiveDevice;
16use embedded_io_async::Write; 16use embedded_io_async::Write;
17use static_cell::make_static; 17use static_cell::StaticCell;
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
@@ -70,11 +70,20 @@ async fn main(spawner: Spawner) {
70 let seed = u64::from_le_bytes(seed); 70 let seed = u64::from_le_bytes(seed);
71 71
72 // Init network stack 72 // Init network stack
73 let stack = &*make_static!(Stack::new( 73 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
74 static STACK: StaticCell<
75 Stack<
76 Enc28j60<
77 ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static, peripherals::P0_15>, Delay>,
78 Output<'static, peripherals::P0_13>,
79 >,
80 >,
81 > = StaticCell::new();
82 let stack = STACK.init(Stack::new(
74 device, 83 device,
75 config, 84 config,
76 make_static!(StackResources::<2>::new()), 85 RESOURCES.init(StackResources::<2>::new()),
77 seed 86 seed,
78 )); 87 ));
79 88
80 unwrap!(spawner.spawn(net_task(stack))); 89 unwrap!(spawner.spawn(net_task(stack)));
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs
index b7806f418..de661c019 100644
--- a/examples/nrf52840/src/bin/usb_ethernet.rs
+++ b/examples/nrf52840/src/bin/usb_ethernet.rs
@@ -16,7 +16,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
16use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 16use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
17use embassy_usb::{Builder, Config, UsbDevice}; 17use embassy_usb::{Builder, Config, UsbDevice};
18use embedded_io_async::Write; 18use embedded_io_async::Write;
19use static_cell::make_static; 19use static_cell::StaticCell;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
@@ -71,14 +71,19 @@ async fn main(spawner: Spawner) {
71 config.device_protocol = 0x01; 71 config.device_protocol = 0x01;
72 72
73 // Create embassy-usb DeviceBuilder using the driver and config. 73 // Create embassy-usb DeviceBuilder using the driver and config.
74 static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new();
75 static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new();
76 static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new();
77 static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new();
78 static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new();
74 let mut builder = Builder::new( 79 let mut builder = Builder::new(
75 driver, 80 driver,
76 config, 81 config,
77 &mut make_static!([0; 256])[..], 82 &mut DEVICE_DESC.init([0; 256])[..],
78 &mut make_static!([0; 256])[..], 83 &mut CONFIG_DESC.init([0; 256])[..],
79 &mut make_static!([0; 256])[..], 84 &mut BOS_DESC.init([0; 256])[..],
80 &mut make_static!([0; 128])[..], 85 &mut MSOS_DESC.init([0; 128])[..],
81 &mut make_static!([0; 128])[..], 86 &mut CONTROL_BUF.init([0; 128])[..],
82 ); 87 );
83 88
84 // Our MAC addr. 89 // Our MAC addr.
@@ -87,14 +92,16 @@ async fn main(spawner: Spawner) {
87 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 92 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
88 93
89 // Create classes on the builder. 94 // Create classes on the builder.
90 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); 95 static STATE: StaticCell<State> = StaticCell::new();
96 let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64);
91 97
92 // Build the builder. 98 // Build the builder.
93 let usb = builder.build(); 99 let usb = builder.build();
94 100
95 unwrap!(spawner.spawn(usb_task(usb))); 101 unwrap!(spawner.spawn(usb_task(usb)));
96 102
97 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 103 static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new();
104 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr);
98 unwrap!(spawner.spawn(usb_ncm_task(runner))); 105 unwrap!(spawner.spawn(usb_ncm_task(runner)));
99 106
100 let config = embassy_net::Config::dhcpv4(Default::default()); 107 let config = embassy_net::Config::dhcpv4(Default::default());
@@ -111,12 +118,9 @@ async fn main(spawner: Spawner) {
111 let seed = u64::from_le_bytes(seed); 118 let seed = u64::from_le_bytes(seed);
112 119
113 // Init network stack 120 // Init network stack
114 let stack = &*make_static!(Stack::new( 121 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
115 device, 122 static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
116 config, 123 let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
117 make_static!(StackResources::<2>::new()),
118 seed
119 ));
120 124
121 unwrap!(spawner.spawn(net_task(stack))); 125 unwrap!(spawner.spawn(net_task(stack)));
122 126
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs
index cd4392903..7a7bf962b 100644
--- a/examples/nrf52840/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs
@@ -12,7 +12,7 @@ use embassy_nrf::{bind_interrupts, pac, peripherals, usb};
12use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; 12use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
13use embassy_usb::driver::EndpointError; 13use embassy_usb::driver::EndpointError;
14use embassy_usb::{Builder, Config, UsbDevice}; 14use embassy_usb::{Builder, Config, UsbDevice};
15use static_cell::make_static; 15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18bind_interrupts!(struct Irqs { 18bind_interrupts!(struct Irqs {
@@ -64,17 +64,23 @@ async fn main(spawner: Spawner) {
64 config.device_protocol = 0x01; 64 config.device_protocol = 0x01;
65 config.composite_with_iads = true; 65 config.composite_with_iads = true;
66 66
67 let state = make_static!(State::new()); 67 static STATE: StaticCell<State> = StaticCell::new();
68 let state = STATE.init(State::new());
68 69
69 // Create embassy-usb DeviceBuilder using the driver and config. 70 // Create embassy-usb DeviceBuilder using the driver and config.
71 static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new();
72 static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new();
73 static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new();
74 static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new();
75 static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new();
70 let mut builder = Builder::new( 76 let mut builder = Builder::new(
71 driver, 77 driver,
72 config, 78 config,
73 &mut make_static!([0; 256])[..], 79 &mut DEVICE_DESC.init([0; 256])[..],
74 &mut make_static!([0; 256])[..], 80 &mut CONFIG_DESC.init([0; 256])[..],
75 &mut make_static!([0; 256])[..], 81 &mut BOS_DESC.init([0; 256])[..],
76 &mut make_static!([0; 128])[..], 82 &mut MSOS_DESC.init([0; 128])[..],
77 &mut make_static!([0; 128])[..], 83 &mut CONTROL_BUF.init([0; 128])[..],
78 ); 84 );
79 85
80 // Create classes on the builder. 86 // Create classes on the builder.
diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
index a60822fd9..b56c9bd8d 100644
--- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs
+++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs
@@ -13,7 +13,7 @@ use embassy_nrf::{bind_interrupts, peripherals};
13use embassy_time::Delay; 13use embassy_time::Delay;
14use embedded_hal_bus::spi::ExclusiveDevice; 14use embedded_hal_bus::spi::ExclusiveDevice;
15use embedded_io_async::Write; 15use embedded_io_async::Write;
16use static_cell::make_static; 16use static_cell::StaticCell;
17use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; 17use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _};
18 18
19const WIFI_NETWORK: &str = "EmbassyTest"; 19const WIFI_NETWORK: &str = "EmbassyTest";
@@ -61,8 +61,9 @@ async fn main(spawner: Spawner) {
61 let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); 61 let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config);
62 let spi = ExclusiveDevice::new(spi, cs, Delay); 62 let spi = ExclusiveDevice::new(spi, cs, Delay);
63 63
64 static ESP_STATE: StaticCell<embassy_net_esp_hosted::State> = StaticCell::new();
64 let (device, mut control, runner) = embassy_net_esp_hosted::new( 65 let (device, mut control, runner) = embassy_net_esp_hosted::new(
65 make_static!(embassy_net_esp_hosted::State::new()), 66 ESP_STATE.init(embassy_net_esp_hosted::State::new()),
66 spi, 67 spi,
67 handshake, 68 handshake,
68 ready, 69 ready,
@@ -89,11 +90,13 @@ async fn main(spawner: Spawner) {
89 let seed = u64::from_le_bytes(seed); 90 let seed = u64::from_le_bytes(seed);
90 91
91 // Init network stack 92 // Init network stack
92 let stack = &*make_static!(Stack::new( 93 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
94 static STACK: StaticCell<Stack<hosted::NetDriver<'static>>> = StaticCell::new();
95 let stack = &*STACK.init(Stack::new(
93 device, 96 device,
94 config, 97 config,
95 make_static!(StackResources::<2>::new()), 98 RESOURCES.init(StackResources::<2>::new()),
96 seed 99 seed,
97 )); 100 ));
98 101
99 unwrap!(spawner.spawn(net_task(stack))); 102 unwrap!(spawner.spawn(net_task(stack)));