aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840/src/bin
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-05-31 23:49:00 +0000
committerGitHub <[email protected]>2023-05-31 23:49:00 +0000
commitc036eab62c2221bd8f458bd6edd1562dfcdb8421 (patch)
tree605b3eb96ea10120f7e8bf0741bcc34daab8e9ec /examples/nrf52840/src/bin
parentd7d66bd74f2ef1bc8903b15df630ddbb8fe97df4 (diff)
parent1d8321b821d114b369d5a087a1a7a6600228b032 (diff)
Merge pull request #1523 from embassy-rs/static-cell
Use make_static! from static-cell v1.1
Diffstat (limited to 'examples/nrf52840/src/bin')
-rw-r--r--examples/nrf52840/src/bin/usb_ethernet.rs32
-rw-r--r--examples/nrf52840/src/bin/usb_serial_multitask.rs23
2 files changed, 21 insertions, 34 deletions
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs
index 786025c43..1065f5b5d 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::asynch::Write; 18use embedded_io::asynch::Write;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
@@ -27,15 +27,6 @@ bind_interrupts!(struct Irqs {
27 27
28type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 28type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
29 29
30macro_rules! singleton {
31 ($val:expr) => {{
32 type T = impl Sized;
33 static STATIC_CELL: StaticCell<T> = StaticCell::new();
34 let (x,) = STATIC_CELL.init(($val,));
35 x
36 }};
37}
38
39const MTU: usize = 1514; 30const MTU: usize = 1514;
40 31
41#[embassy_executor::task] 32#[embassy_executor::task]
@@ -83,11 +74,11 @@ async fn main(spawner: Spawner) {
83 let mut builder = Builder::new( 74 let mut builder = Builder::new(
84 driver, 75 driver,
85 config, 76 config,
86 &mut singleton!([0; 256])[..], 77 &mut make_static!([0; 256])[..],
87 &mut singleton!([0; 256])[..], 78 &mut make_static!([0; 256])[..],
88 &mut singleton!([0; 256])[..], 79 &mut make_static!([0; 256])[..],
89 &mut singleton!([0; 128])[..], 80 &mut make_static!([0; 128])[..],
90 &mut singleton!([0; 128])[..], 81 &mut make_static!([0; 128])[..],
91 ); 82 );
92 83
93 // Our MAC addr. 84 // Our MAC addr.
@@ -96,14 +87,14 @@ async fn main(spawner: Spawner) {
96 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 87 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
97 88
98 // Create classes on the builder. 89 // Create classes on the builder.
99 let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); 90 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
100 91
101 // Build the builder. 92 // Build the builder.
102 let usb = builder.build(); 93 let usb = builder.build();
103 94
104 unwrap!(spawner.spawn(usb_task(usb))); 95 unwrap!(spawner.spawn(usb_task(usb)));
105 96
106 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); 97 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
107 unwrap!(spawner.spawn(usb_ncm_task(runner))); 98 unwrap!(spawner.spawn(usb_ncm_task(runner)));
108 99
109 let config = embassy_net::Config::Dhcp(Default::default()); 100 let config = embassy_net::Config::Dhcp(Default::default());
@@ -120,7 +111,12 @@ async fn main(spawner: Spawner) {
120 let seed = u64::from_le_bytes(seed); 111 let seed = u64::from_le_bytes(seed);
121 112
122 // Init network stack 113 // Init network stack
123 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 114 let stack = &*make_static!(Stack::new(
115 device,
116 config,
117 make_static!(StackResources::<2>::new()),
118 seed
119 ));
124 120
125 unwrap!(spawner.spawn(net_task(stack))); 121 unwrap!(spawner.spawn(net_task(stack)));
126 122
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs
index ac22d9499..cd4392903 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::StaticCell; 15use static_cell::make_static;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18bind_interrupts!(struct Irqs { 18bind_interrupts!(struct Irqs {
@@ -20,15 +20,6 @@ bind_interrupts!(struct Irqs {
20 POWER_CLOCK => usb::vbus_detect::InterruptHandler; 20 POWER_CLOCK => usb::vbus_detect::InterruptHandler;
21}); 21});
22 22
23macro_rules! singleton {
24 ($val:expr) => {{
25 type T = impl Sized;
26 static STATIC_CELL: StaticCell<T> = StaticCell::new();
27 let (x,) = STATIC_CELL.init(($val,));
28 x
29 }};
30}
31
32type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 23type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
33 24
34#[embassy_executor::task] 25#[embassy_executor::task]
@@ -73,17 +64,17 @@ async fn main(spawner: Spawner) {
73 config.device_protocol = 0x01; 64 config.device_protocol = 0x01;
74 config.composite_with_iads = true; 65 config.composite_with_iads = true;
75 66
76 let state = singleton!(State::new()); 67 let state = make_static!(State::new());
77 68
78 // Create embassy-usb DeviceBuilder using the driver and config. 69 // Create embassy-usb DeviceBuilder using the driver and config.
79 let mut builder = Builder::new( 70 let mut builder = Builder::new(
80 driver, 71 driver,
81 config, 72 config,
82 &mut singleton!([0; 256])[..], 73 &mut make_static!([0; 256])[..],
83 &mut singleton!([0; 256])[..], 74 &mut make_static!([0; 256])[..],
84 &mut singleton!([0; 256])[..], 75 &mut make_static!([0; 256])[..],
85 &mut singleton!([0; 128])[..], 76 &mut make_static!([0; 128])[..],
86 &mut singleton!([0; 128])[..], 77 &mut make_static!([0; 128])[..],
87 ); 78 );
88 79
89 // Create classes on the builder. 80 // Create classes on the builder.