Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In place init #6

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ rust-version = "1.78"
#[patch.'https://github.com/ivmarkov/async-io-mini']
#async-io-mini = { path = "../async-io-mini" }
#[patch.'https://github.com/ivmarkov/rs-matter-stack']
#rs-matter-stack = { path = "../rs-matter-stack", default-features = false, features = ["std"], optional = true }
#rs-matter-stack = { path = "../rs-matter-stack" }

[patch.crates-io]
rs-matter = { git = "https://github.com/ivmarkov/rs-matter", branch = "wifi" }
rs-matter = { git = "https://github.com/ivmarkov/rs-matter", branch = "tip" }
#rs-matter = { path = "../rs-matter/rs-matter" }
#edge-nal = { git = "https://github.com/ivmarkov/edge-net" }
#edge-nal = { path = "../edge-net/edge-nal" }
Expand All @@ -45,15 +45,14 @@ examples = ["default", "esp-idf-svc/binstart", "esp-idf-svc/critical-section"] #
log = { version = "0.4", default-features = false }
heapless = "0.8"
enumset = { version = "1", default-features = false }
scopeguard = { version = "1", default-features = false }
embassy-futures = "0.1"
embassy-sync = "0.6"
embassy-time = { version = "0.3", features = ["generic-queue"] }
esp-idf-svc = { version = "0.49.1", default-features = false, features = ["alloc", "embassy-sync", "embassy-time-driver", "experimental"] }
embedded-svc = { version = "0.28", default-features = false }
rs-matter = { version = "0.1", default-features = false, features = ["rustcrypto"] }
async-io = { version = "=2.0.0", default-features = false } # Workaround for https://github.com/smol-rs/async-lock/issues/84
rs-matter-stack = { git = "https://github.com/ivmarkov/rs-matter-stack", default-features = false, features = ["std"], optional = true }
rs-matter-stack = { git = "https://github.com/ivmarkov/rs-matter-stack", branch = "in-place-init", default-features = false, features = ["std"], optional = true }
edge-nal = "0.3"
edge-nal-std = { version = "0.3", default-features = false, optional = true }

Expand Down
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ use rs_matter::data_model::device_types::DEV_TYPE_ON_OFF_LIGHT;
use rs_matter::data_model::objects::{Dataver, Endpoint, HandlerCompat, Node};
use rs_matter::data_model::system_model::descriptor;
use rs_matter::secure_channel::spake2p::VerifierData;
use rs_matter::utils::init::InitMaybeUninit;
use rs_matter::utils::select::Coalesce;
use rs_matter::CommissioningData;

use rs_matter_stack::persist::DummyPersist;

use static_cell::ConstStaticCell;
use static_cell::StaticCell;

#[path = "dev_att/dev_att.rs"]
mod dev_att;
Expand Down Expand Up @@ -95,9 +96,24 @@ fn run() -> Result<(), anyhow::Error> {
}

async fn matter() -> Result<(), anyhow::Error> {
// Take the Matter stack (can be done only once),
// Initialize the Matter stack (can be done only once),
// as we'll run it in this thread
let stack = MATTER_STACK.take();
let stack = MATTER_STACK
.uninit()
.init_with(EspWifiBleMatterStack::init_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&DEV_ATT,
));

// Take some generic ESP-IDF stuff we'll need later
let sysloop = EspSystemEventLoop::take()?;
Expand All @@ -124,7 +140,9 @@ async fn matter() -> Result<(), anyhow::Error> {
.chain(
LIGHT_ENDPOINT_ID,
descriptor::ID,
HandlerCompat(descriptor::DescriptorCluster::new(Dataver::new_rand(stack.matter().rand()))),
HandlerCompat(descriptor::DescriptorCluster::new(Dataver::new_rand(
stack.matter().rand(),
))),
);

// Run the Matter stack with our handler
Expand Down Expand Up @@ -182,21 +200,9 @@ async fn matter() -> Result<(), anyhow::Error> {
/// The Matter stack is allocated statically to avoid
/// program stack blowups.
/// It is also a mandatory requirement when the `WifiBle` stack variation is used.
static MATTER_STACK: ConstStaticCell<EspWifiBleMatterStack<()>> =
ConstStaticCell::new(EspWifiBleMatterStack::new_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&dev_att::HardCodedDevAtt::new(),
));
static MATTER_STACK: StaticCell<EspWifiBleMatterStack<()>> = StaticCell::new();

static DEV_ATT: dev_att::HardCodedDevAtt = dev_att::HardCodedDevAtt::new();

/// Endpoint 0 (the root endpoint) always runs
/// the hidden Matter system clusters, so we pick ID=1
Expand Down
42 changes: 23 additions & 19 deletions examples/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ use rs_matter::data_model::device_types::DEV_TYPE_ON_OFF_LIGHT;
use rs_matter::data_model::objects::{Dataver, Endpoint, HandlerCompat, Node};
use rs_matter::data_model::system_model::descriptor;
use rs_matter::secure_channel::spake2p::VerifierData;
use rs_matter::utils::init::InitMaybeUninit;
use rs_matter::utils::select::Coalesce;
use rs_matter::CommissioningData;

use rs_matter_stack::persist::DummyPersist;

use static_cell::ConstStaticCell;
use static_cell::StaticCell;

#[path = "dev_att/dev_att.rs"]
mod dev_att;
Expand All @@ -46,7 +47,7 @@ fn main() -> Result<(), anyhow::Error> {
// confused by the low priority of the ESP IDF main task
// Also allocate a very large stack (for now) as `rs-matter` futures do occupy quite some space
let thread = std::thread::Builder::new()
.stack_size(70 * 1024)
.stack_size(55 * 1024)
.spawn(|| {
// Eagerly initialize `async-io` to minimize the risk of stack blowups later on
init_async_io()?;
Expand Down Expand Up @@ -74,9 +75,24 @@ fn run() -> Result<(), anyhow::Error> {
}

async fn matter() -> Result<(), anyhow::Error> {
// Take the Matter stack (can be done only once),
// Initialize the Matter stack (can be done only once),
// as we'll run it in this thread
let stack = MATTER_STACK.take();
let stack = MATTER_STACK
.uninit()
.init_with(EspWifiBleMatterStack::init_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&DEV_ATT,
));

// Take some generic ESP-IDF stuff we'll need later
let sysloop = EspSystemEventLoop::take()?;
Expand Down Expand Up @@ -163,21 +179,9 @@ async fn matter() -> Result<(), anyhow::Error> {
/// The Matter stack is allocated statically to avoid
/// program stack blowups.
/// It is also a mandatory requirement when the `WifiBle` stack variation is used.
static MATTER_STACK: ConstStaticCell<EspWifiBleMatterStack<()>> =
ConstStaticCell::new(EspWifiBleMatterStack::new_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&dev_att::HardCodedDevAtt::new(),
));
static MATTER_STACK: StaticCell<EspWifiBleMatterStack<()>> = StaticCell::new();

static DEV_ATT: dev_att::HardCodedDevAtt = dev_att::HardCodedDevAtt::new();

/// Endpoint 0 (the root endpoint) always runs
/// the hidden Matter system clusters, so we pick ID=1
Expand Down
42 changes: 23 additions & 19 deletions examples/light_eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ use rs_matter::data_model::device_types::DEV_TYPE_ON_OFF_LIGHT;
use rs_matter::data_model::objects::{Dataver, Endpoint, HandlerCompat, Node};
use rs_matter::data_model::system_model::descriptor;
use rs_matter::secure_channel::spake2p::VerifierData;
use rs_matter::utils::init::InitMaybeUninit;
use rs_matter::utils::select::Coalesce;
use rs_matter::CommissioningData;

use rs_matter_stack::persist::DummyPersist;

use static_cell::ConstStaticCell;
use static_cell::StaticCell;

#[path = "dev_att/dev_att.rs"]
mod dev_att;
Expand All @@ -56,7 +57,7 @@ fn main() -> Result<(), anyhow::Error> {
// confused by the low priority of the ESP IDF main task
// Also allocate a very large stack (for now) as `rs-matter` futures do occupy quite some space
let thread = std::thread::Builder::new()
.stack_size(65 * 1024)
.stack_size(40 * 1024)
.spawn(|| {
// Eagerly initialize `async-io` to minimize the risk of stack blowups later on
init_async_io()?;
Expand Down Expand Up @@ -84,9 +85,24 @@ fn run() -> Result<(), anyhow::Error> {
}

async fn matter() -> Result<(), anyhow::Error> {
// Take the Matter stack (can be done only once),
// Initialize the Matter stack (can be done only once),
// as we'll run it in this thread
let stack = MATTER_STACK.take();
let stack = MATTER_STACK
.uninit()
.init_with(EspEthMatterStack::init_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&DEV_ATT,
));

// Take some generic ESP-IDF stuff we'll need later
let sysloop = EspSystemEventLoop::take()?;
Expand Down Expand Up @@ -187,21 +203,9 @@ async fn matter() -> Result<(), anyhow::Error> {

/// The Matter stack is allocated statically to avoid
/// program stack blowups.
static MATTER_STACK: ConstStaticCell<EspEthMatterStack<()>> =
ConstStaticCell::new(EspEthMatterStack::new_default(
&BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
serial_no: "aabbccdd",
device_name: "MyLight",
product_name: "ACME Light",
vendor_name: "ACME",
},
&dev_att::HardCodedDevAtt::new(),
));
static MATTER_STACK: StaticCell<EspEthMatterStack<()>> = StaticCell::new();

static DEV_ATT: dev_att::HardCodedDevAtt = dev_att::HardCodedDevAtt::new();

/// Endpoint 0 (the root endpoint) always runs
/// the hidden Matter system clusters, so we pick ID=1
Expand Down
Loading
Loading