Fix the no_std build
This commit is contained in:
parent
62aa69202f
commit
5b9fd502c7
3 changed files with 62 additions and 7 deletions
|
@ -51,9 +51,10 @@ fn main() -> Result<(), Error> {
|
|||
thread.join().unwrap()
|
||||
}
|
||||
|
||||
// NOTE: For no_std, name this entry point according to your MCU platform
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[no_mangle]
|
||||
fn main() {
|
||||
fn app_main() {
|
||||
run().unwrap();
|
||||
}
|
||||
|
||||
|
@ -93,11 +94,27 @@ fn run() -> Result<(), Error> {
|
|||
|
||||
let dev_att = dev_att::HardCodedDevAtt::new();
|
||||
|
||||
let matter = Matter::new_default(
|
||||
#[cfg(feature = "std")]
|
||||
let epoch = matter::utils::epoch::sys_epoch;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
let rand = matter::utils::rand::sys_rand;
|
||||
|
||||
// NOTE: For no_std, provide your own function here
|
||||
#[cfg(not(feature = "std"))]
|
||||
let epoch = matter::utils::epoch::dummy_epoch;
|
||||
|
||||
// NOTE: For no_std, provide your own function here
|
||||
#[cfg(not(feature = "std"))]
|
||||
let rand = matter::utils::rand::dummy_rand;
|
||||
|
||||
let matter = Matter::new(
|
||||
// vid/pid should match those in the DAC
|
||||
&dev_det,
|
||||
&dev_att,
|
||||
&mdns,
|
||||
epoch,
|
||||
rand,
|
||||
matter::MATTER_PORT,
|
||||
);
|
||||
|
||||
|
@ -203,6 +220,10 @@ fn run() -> Result<(), Error> {
|
|||
|
||||
let mut fut = pin!(async move { select(&mut io_fut, &mut mdns_fut).await.unwrap() });
|
||||
|
||||
info!("Final future: {:p}", &mut fut);
|
||||
|
||||
// NOTE: For no_std, replace with your own no_std way of polling the future
|
||||
#[cfg(feature = "std")]
|
||||
smol::block_on(&mut fut)?;
|
||||
|
||||
Ok::<_, matter::error::Error>(())
|
||||
|
@ -222,7 +243,19 @@ fn handler<'a>(matter: &'a Matter<'a>) -> impl Handler + 'a {
|
|||
)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "espidf"))]
|
||||
// NOTE: For no_std, implement here your own way of initializing the logger
|
||||
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
|
||||
#[inline(never)]
|
||||
fn initialize_logger() {}
|
||||
|
||||
// NOTE: For no_std, implement here your own way of initializing the network
|
||||
#[cfg(all(not(feature = "std"), not(target_os = "espidf")))]
|
||||
#[inline(never)]
|
||||
fn initialize_network() -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {
|
||||
Ok((Ipv4Addr::UNSPECIFIED, Ipv6Addr::UNSPECIFIED, 0))
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", not(target_os = "espidf")))]
|
||||
#[inline(never)]
|
||||
fn initialize_logger() {
|
||||
env_logger::init_from_env(
|
||||
|
@ -230,7 +263,7 @@ fn initialize_logger() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "espidf"))]
|
||||
#[cfg(all(feature = "std", not(target_os = "espidf")))]
|
||||
#[inline(never)]
|
||||
fn initialize_network() -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {
|
||||
use log::error;
|
||||
|
|
|
@ -27,7 +27,7 @@ pub fn hkdf_sha256(_salt: &[u8], _ikm: &[u8], _info: &[u8], _key: &mut [u8]) ->
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Sha256 {}
|
||||
|
||||
impl Sha256 {
|
||||
|
|
|
@ -150,7 +150,7 @@ mod dummy_udp {
|
|||
use crate::error::*;
|
||||
use log::{debug, info};
|
||||
|
||||
use crate::transport::network::SocketAddr;
|
||||
use crate::transport::network::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||
|
||||
pub struct UdpListener {}
|
||||
|
||||
|
@ -163,7 +163,29 @@ mod dummy_udp {
|
|||
Ok(listener)
|
||||
}
|
||||
|
||||
pub async fn join_multicast(&mut self, ip_addr: IpAddr) -> Result<(), Error> {
|
||||
pub fn join_multicast_v6(
|
||||
&mut self,
|
||||
multiaddr: Ipv6Addr,
|
||||
interface: u32,
|
||||
) -> Result<(), Error> {
|
||||
info!(
|
||||
"Pretending to join IPV6 multicast {}/{}",
|
||||
multiaddr, interface
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn join_multicast_v4(
|
||||
&mut self,
|
||||
multiaddr: Ipv4Addr,
|
||||
interface: Ipv4Addr,
|
||||
) -> Result<(), Error> {
|
||||
info!(
|
||||
"Pretending to join IP multicast {}/{}",
|
||||
multiaddr, interface
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue