Support for ESP-IDF build
This commit is contained in:
parent
9070e87944
commit
8d9bd1332c
6 changed files with 66 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["matter", "matter_macro_derive", "tools/tlv_tool"]
|
members = ["matter", "matter_macro_derive"]
|
||||||
|
|
||||||
exclude = ["examples/*"]
|
exclude = ["examples/*"]
|
||||||
|
|
||||||
|
|
24
README.md
24
README.md
|
@ -13,13 +13,31 @@ Building the library:
|
||||||
$ cargo build
|
$ cargo build
|
||||||
```
|
```
|
||||||
|
|
||||||
Building the example:
|
Building and running the example (Linux, MacOS X):
|
||||||
|
|
||||||
```
|
```
|
||||||
$ RUST_LOG="matter" cargo run --example onoff_light
|
$ cargo run --example onoff_light
|
||||||
```
|
```
|
||||||
|
|
||||||
With the chip-tool (the current tool for testing Matter) use the Ethernet commissioning mechanism:
|
Building the example (Espressif's ESP-IDF):
|
||||||
|
* Install all build prerequisites described [here](https://github.com/esp-rs/esp-idf-template#prerequisites)
|
||||||
|
* Build with the following command line:
|
||||||
|
```
|
||||||
|
export MCU=esp32; export CARGO_TARGET_XTENSA_ESP32_ESPIDF_LINKER=ldproxy; export RUSTFLAGS="-C default-linker-libraries"; export WIFI_SSID=ssid;export WIFI_PASS=pass; cargo build --example onoff_light --no-default-features --features std,crypto_rustcrypto --target xtensa-esp32-espidf -Zbuild-std=std,panic_abort
|
||||||
|
```
|
||||||
|
* If you are building for a different Espressif MCU, change the `MCU` variable, the `xtensa-esp32-espidf` target and the name of the `CARGO_TARGET_<esp-idf-target-uppercase>_LINKER` variable to match your MCU and its Rust target. Available Espressif MCUs and targets are:
|
||||||
|
* esp32 / xtensa-esp32-espidf
|
||||||
|
* esp32s2 / xtensa-esp32s2-espidf
|
||||||
|
* esp32s3 / xtensa-esp32s3-espidf
|
||||||
|
* esp32c3 / riscv32imc-esp-espidf
|
||||||
|
* esp32c5 / riscv32imc-esp-espidf
|
||||||
|
* esp32c6 / risxcv32imac-esp-espidf
|
||||||
|
* Put in `WIFI_SSID` / `WIFI_PASS` the SSID & password for your wireless router
|
||||||
|
* Flash using the `espflash` utility described in the build prerequsites' link above
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
With the `chip-tool` (the current tool for testing Matter) use the Ethernet commissioning mechanism:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ chip-tool pairing code 12344321 <Pairing-Code>
|
$ chip-tool pairing code 12344321 <Pairing-Code>
|
||||||
|
|
|
@ -31,7 +31,6 @@ use matter::data_model::system_model::descriptor;
|
||||||
use matter::error::Error;
|
use matter::error::Error;
|
||||||
use matter::interaction_model::core::InteractionModel;
|
use matter::interaction_model::core::InteractionModel;
|
||||||
use matter::mdns::{DefaultMdns, DefaultMdnsRunner};
|
use matter::mdns::{DefaultMdns, DefaultMdnsRunner};
|
||||||
use matter::persist;
|
|
||||||
use matter::secure_channel::spake2p::VerifierData;
|
use matter::secure_channel::spake2p::VerifierData;
|
||||||
use matter::transport::network::{Address, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
use matter::transport::network::{Address, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||||
use matter::transport::{
|
use matter::transport::{
|
||||||
|
@ -50,7 +49,6 @@ fn main() -> Result<(), Error> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread.join().unwrap()
|
thread.join().unwrap()
|
||||||
// run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
|
@ -105,11 +103,14 @@ fn run() -> Result<(), Error> {
|
||||||
let psm_path = std::env::temp_dir().join("matter-iot");
|
let psm_path = std::env::temp_dir().join("matter-iot");
|
||||||
info!("Persisting from/to {}", psm_path.display());
|
info!("Persisting from/to {}", psm_path.display());
|
||||||
|
|
||||||
let psm = persist::FilePsm::new(psm_path)?;
|
#[cfg(all(feature = "std", not(target_os = "espidf")))]
|
||||||
|
let psm = matter::persist::FilePsm::new(psm_path)?;
|
||||||
|
|
||||||
let mut buf = [0; 4096];
|
let mut buf = [0; 4096];
|
||||||
let buf = &mut buf;
|
let buf = &mut buf;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "std", not(target_os = "espidf")))]
|
||||||
|
{
|
||||||
if let Some(data) = psm.load("acls", buf)? {
|
if let Some(data) = psm.load("acls", buf)? {
|
||||||
matter.load_acls(data)?;
|
matter.load_acls(data)?;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +118,7 @@ fn run() -> Result<(), Error> {
|
||||||
if let Some(data) = psm.load("fabrics", buf)? {
|
if let Some(data) = psm.load("fabrics", buf)? {
|
||||||
matter.load_fabrics(data)?;
|
matter.load_fabrics(data)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut transport = Transport::new(&matter);
|
let mut transport = Transport::new(&matter);
|
||||||
|
|
||||||
|
@ -180,6 +182,8 @@ fn run() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "std", not(target_os = "espidf")))]
|
||||||
|
{
|
||||||
if let Some(data) = transport.matter().store_fabrics(buf)? {
|
if let Some(data) = transport.matter().store_fabrics(buf)? {
|
||||||
psm.store("fabrics", data)?;
|
psm.store("fabrics", data)?;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +192,7 @@ fn run() -> Result<(), Error> {
|
||||||
psm.store("acls", data)?;
|
psm.store("acls", data)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
Ok::<_, matter::error::Error>(())
|
Ok::<_, matter::error::Error>(())
|
||||||
|
|
|
@ -16,7 +16,6 @@ path = "src/lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["os", "crypto_rustcrypto"]
|
default = ["os", "crypto_rustcrypto"]
|
||||||
#default = ["crypto_rustcrypto"]
|
|
||||||
os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"]
|
os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"]
|
||||||
std = ["alloc", "rand", "qrcode", "async-io", "smol", "esp-idf-sys/std"]
|
std = ["alloc", "rand", "qrcode", "async-io", "smol", "esp-idf-sys/std"]
|
||||||
backtrace = []
|
backtrace = []
|
||||||
|
@ -51,7 +50,6 @@ domain = { version = "0.7.2", default_features = false, features = ["heapless"]
|
||||||
# STD-only dependencies
|
# STD-only dependencies
|
||||||
rand = { version = "0.8.5", optional = true }
|
rand = { version = "0.8.5", optional = true }
|
||||||
qrcode = { version = "0.12", default-features = false, optional = true } # Print QR code
|
qrcode = { version = "0.12", default-features = false, optional = true } # Print QR code
|
||||||
astro-dnssd = { version = "0.3", optional = true } # On Linux needs avahi-compat-libdns_sd, i.e. on Ubuntu/Debian do `sudo apt-get install libavahi-compat-libdnssd-dev`
|
|
||||||
smol = { version = "1.2", optional = true } # =1.2 for compatibility with ESP IDF
|
smol = { version = "1.2", optional = true } # =1.2 for compatibility with ESP IDF
|
||||||
async-io = { version = "=1.12", optional = true } # =1.2 for compatibility with ESP IDF
|
async-io = { version = "=1.12", optional = true } # =1.2 for compatibility with ESP IDF
|
||||||
|
|
||||||
|
@ -72,18 +70,27 @@ crypto-bigint = { version = "0.4", default-features = false, optional = true }
|
||||||
rand_core = { version = "0.6", default-features = false, optional = true }
|
rand_core = { version = "0.6", default-features = false, optional = true }
|
||||||
x509-cert = { version = "0.2.0", default-features = false, features = ["pem"], optional = true } # TODO: requires `alloc`
|
x509-cert = { version = "0.2.0", default-features = false, features = ["pem"], optional = true } # TODO: requires `alloc`
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
astro-dnssd = { version = "0.3" }
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "espidf"))'.dependencies]
|
[target.'cfg(not(target_os = "espidf"))'.dependencies]
|
||||||
mbedtls = { git = "https://github.com/fortanix/rust-mbedtls", optional = true }
|
mbedtls = { git = "https://github.com/fortanix/rust-mbedtls", optional = true }
|
||||||
env_logger = { version = "0.10.0", optional = true }
|
env_logger = { version = "0.10.0", optional = true }
|
||||||
nix = { version = "0.26", features = ["net"], optional = true }
|
nix = { version = "0.26", features = ["net"], optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "espidf")'.dependencies]
|
[target.'cfg(target_os = "espidf")'.dependencies]
|
||||||
esp-idf-sys = { version = "0.33", default-features = false, features = ["native"] }
|
esp-idf-sys = { version = "0.33", default-features = false, features = ["native", "binstart"] }
|
||||||
|
esp-idf-hal = { version = "0.41", features = ["embassy-sync", "critical-section"] }
|
||||||
|
esp-idf-svc = { version = "0.46", features = ["embassy-time-driver"] }
|
||||||
|
embedded-svc = "0.25"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
embuild = "0.31.2"
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "onoff_light"
|
name = "onoff_light"
|
||||||
path = "../examples/onoff_light/src/main.rs"
|
path = "../examples/onoff_light/src/main.rs"
|
||||||
|
|
||||||
[[example]]
|
# [[example]]
|
||||||
name = "speaker"
|
# name = "speaker"
|
||||||
path = "../examples/speaker/src/main.rs"
|
# path = "../examples/speaker/src/main.rs"
|
||||||
|
|
11
matter/build.rs
Normal file
11
matter/build.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use std::env::var;
|
||||||
|
|
||||||
|
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
if var("TARGET").unwrap().ends_with("-espidf") {
|
||||||
|
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
|
||||||
|
embuild::build::LinkArgs::output_propagated("ESP_IDF")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -52,6 +52,8 @@ mod smol_udp {
|
||||||
IpAddr::V6(ip_addr) => self.socket.join_multicast_v6(&ip_addr, 0)?,
|
IpAddr::V6(ip_addr) => self.socket.join_multicast_v6(&ip_addr, 0)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("Joining multicast on {:?}", ip_addr);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue