Skip to content

Commit 879f816

Browse files
committed
More comments for tailoring the example for no_std
1 parent 5b9fd50 commit 879f816

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

examples/onoff_light/src/main.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() -> Result<(), Error> {
5151
thread.join().unwrap()
5252
}
5353

54-
// NOTE: For no_std, name this entry point according to your MCU platform
54+
// NOTE (no_std): For no_std, name this entry point according to your MCU platform
5555
#[cfg(not(feature = "std"))]
5656
#[no_mangle]
5757
fn app_main() {
@@ -100,11 +100,11 @@ fn run() -> Result<(), Error> {
100100
#[cfg(feature = "std")]
101101
let rand = matter::utils::rand::sys_rand;
102102

103-
// NOTE: For no_std, provide your own function here
103+
// NOTE (no_std): For no_std, provide your own function here
104104
#[cfg(not(feature = "std"))]
105105
let epoch = matter::utils::epoch::dummy_epoch;
106106

107-
// NOTE: For no_std, provide your own function here
107+
// NOTE (no_std): For no_std, provide your own function here
108108
#[cfg(not(feature = "std"))]
109109
let rand = matter::utils::rand::dummy_rand;
110110

@@ -175,6 +175,8 @@ fn run() -> Result<(), Error> {
175175
let tx_buf = &mut tx_buf;
176176

177177
let mut io_fut = pin!(async move {
178+
// NOTE (no_std): On no_std, the `UdpListener` implementation is a no-op so you might want to
179+
// replace it with your own UDP stack
178180
let udp = UdpListener::new(SocketAddr::new(
179181
IpAddr::V6(Ipv6Addr::UNSPECIFIED),
180182
matter::MATTER_PORT,
@@ -216,17 +218,21 @@ fn run() -> Result<(), Error> {
216218
Ok::<_, matter::error::Error>(())
217219
});
218220

221+
// NOTE (no_std): On no_std, the `run_udp` is a no-op so you might want to replace it with `run` and
222+
// connect the pipes of the `run` method with your own UDP stack
219223
let mut mdns_fut = pin!(async move { mdns_runner.run_udp().await });
220224

221225
let mut fut = pin!(async move { select(&mut io_fut, &mut mdns_fut).await.unwrap() });
222226

223-
info!("Final future: {:p}", &mut fut);
224-
225-
// NOTE: For no_std, replace with your own no_std way of polling the future
226227
#[cfg(feature = "std")]
227228
smol::block_on(&mut fut)?;
228229

229-
Ok::<_, matter::error::Error>(())
230+
// NOTE (no_std): For no_std, replace with your own more efficient no_std executor,
231+
// because the executor used below is a simple busy-loop poller
232+
#[cfg(not(feature = "std"))]
233+
embassy_futures::block_on(&mut fut)?;
234+
235+
Ok(())
230236
}
231237

232238
fn handler<'a>(matter: &'a Matter<'a>) -> impl Handler + 'a {
@@ -243,12 +249,12 @@ fn handler<'a>(matter: &'a Matter<'a>) -> impl Handler + 'a {
243249
)
244250
}
245251

246-
// NOTE: For no_std, implement here your own way of initializing the logger
252+
// NOTE (no_std): For no_std, implement here your own way of initializing the logger
247253
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
248254
#[inline(never)]
249255
fn initialize_logger() {}
250256

251-
// NOTE: For no_std, implement here your own way of initializing the network
257+
// NOTE (no_std): For no_std, implement here your own way of initializing the network
252258
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
253259
#[inline(never)]
254260
fn initialize_network() -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {

0 commit comments

Comments
 (0)