Skip to content

Commit 5b9fd50

Browse files
committed
Fix the no_std build
1 parent 62aa692 commit 5b9fd50

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

examples/onoff_light/src/main.rs

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

54+
// NOTE: For no_std, name this entry point according to your MCU platform
5455
#[cfg(not(feature = "std"))]
5556
#[no_mangle]
56-
fn main() {
57+
fn app_main() {
5758
run().unwrap();
5859
}
5960

@@ -93,11 +94,27 @@ fn run() -> Result<(), Error> {
9394

9495
let dev_att = dev_att::HardCodedDevAtt::new();
9596

96-
let matter = Matter::new_default(
97+
#[cfg(feature = "std")]
98+
let epoch = matter::utils::epoch::sys_epoch;
99+
100+
#[cfg(feature = "std")]
101+
let rand = matter::utils::rand::sys_rand;
102+
103+
// NOTE: For no_std, provide your own function here
104+
#[cfg(not(feature = "std"))]
105+
let epoch = matter::utils::epoch::dummy_epoch;
106+
107+
// NOTE: For no_std, provide your own function here
108+
#[cfg(not(feature = "std"))]
109+
let rand = matter::utils::rand::dummy_rand;
110+
111+
let matter = Matter::new(
97112
// vid/pid should match those in the DAC
98113
&dev_det,
99114
&dev_att,
100115
&mdns,
116+
epoch,
117+
rand,
101118
matter::MATTER_PORT,
102119
);
103120

@@ -203,6 +220,10 @@ fn run() -> Result<(), Error> {
203220

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

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

208229
Ok::<_, matter::error::Error>(())
@@ -222,15 +243,27 @@ fn handler<'a>(matter: &'a Matter<'a>) -> impl Handler + 'a {
222243
)
223244
}
224245

225-
#[cfg(not(target_os = "espidf"))]
246+
// NOTE: For no_std, implement here your own way of initializing the logger
247+
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
248+
#[inline(never)]
249+
fn initialize_logger() {}
250+
251+
// NOTE: For no_std, implement here your own way of initializing the network
252+
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
253+
#[inline(never)]
254+
fn initialize_network() -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {
255+
Ok((Ipv4Addr::UNSPECIFIED, Ipv6Addr::UNSPECIFIED, 0))
256+
}
257+
258+
#[cfg(all(feature = "std", not(target_os = "espidf")))]
226259
#[inline(never)]
227260
fn initialize_logger() {
228261
env_logger::init_from_env(
229262
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
230263
);
231264
}
232265

233-
#[cfg(not(target_os = "espidf"))]
266+
#[cfg(all(feature = "std", not(target_os = "espidf")))]
234267
#[inline(never)]
235268
fn initialize_network() -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {
236269
use log::error;

matter/src/crypto/crypto_dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn hkdf_sha256(_salt: &[u8], _ikm: &[u8], _info: &[u8], _key: &mut [u8]) ->
2727
Ok(())
2828
}
2929

30-
#[derive(Clone)]
30+
#[derive(Clone, Debug)]
3131
pub struct Sha256 {}
3232

3333
impl Sha256 {

matter/src/transport/udp.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mod dummy_udp {
150150
use crate::error::*;
151151
use log::{debug, info};
152152

153-
use crate::transport::network::SocketAddr;
153+
use crate::transport::network::{Ipv4Addr, Ipv6Addr, SocketAddr};
154154

155155
pub struct UdpListener {}
156156

@@ -163,7 +163,29 @@ mod dummy_udp {
163163
Ok(listener)
164164
}
165165

166-
pub async fn join_multicast(&mut self, ip_addr: IpAddr) -> Result<(), Error> {
166+
pub fn join_multicast_v6(
167+
&mut self,
168+
multiaddr: Ipv6Addr,
169+
interface: u32,
170+
) -> Result<(), Error> {
171+
info!(
172+
"Pretending to join IPV6 multicast {}/{}",
173+
multiaddr, interface
174+
);
175+
176+
Ok(())
177+
}
178+
179+
pub fn join_multicast_v4(
180+
&mut self,
181+
multiaddr: Ipv4Addr,
182+
interface: Ipv4Addr,
183+
) -> Result<(), Error> {
184+
info!(
185+
"Pretending to join IP multicast {}/{}",
186+
multiaddr, interface
187+
);
188+
167189
Ok(())
168190
}
169191

0 commit comments

Comments
 (0)