Skip to content

Commit

Permalink
Update to latest edge-net; proper init for GattResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Sep 11, 2024
1 parent 5aa03c5 commit 8085b5d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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 = "tip" }
Expand Down Expand Up @@ -52,9 +52,9 @@ esp-idf-svc = { version = "0.49.1", default-features = false, features = ["alloc
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", branch = "tip", default-features = false, features = ["std"], optional = true }
edge-nal = "0.2"
edge-nal-std = { version = "0.2", default-features = false, 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 }

[build-dependencies]
embuild = "0.32"
Expand Down
2 changes: 1 addition & 1 deletion examples/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,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(40 * 1024)
.stack_size(55 * 1024)
.spawn(|| {
// Eagerly initialize `async-io` to minimize the risk of stack blowups later on
init_async_io()?;
Expand Down
35 changes: 34 additions & 1 deletion src/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl State {
c2_handle: None,
c2_cccd_handle: None,
connections <- rs_matter::utils::storage::Vec::init(),
response: GattResponse::new(), // TODO
response <- gatt_response::init(),
})
}
}
Expand Down Expand Up @@ -845,3 +845,36 @@ where
Ok(())
}
}

mod gatt_response {
use esp_idf_svc::bt::ble::gatt::GattResponse;
use esp_idf_svc::sys::{esp_gatt_rsp_t, esp_gatt_value_t};

use rs_matter::utils::init::{init, init_from_closure, zeroed, Init};

/// Return an in-place initializer for `GattResponse`.
///
/// Works by initializing the `GattResponse` struct in-place using the `esp_gatt_rsp_t` type,
/// which is possible because `GattResponse` is a `#[repr(transparent)]` newtype over `esp_gatt_rsp_t`.
pub fn init() -> impl Init<GattResponse> {
unsafe {
init_from_closure(|slot: *mut GattResponse| {
let slot = slot as *mut esp_gatt_rsp_t;

init_esp_gatt_response().__init(slot)
})
}
}

fn init_esp_gatt_response() -> impl Init<esp_gatt_rsp_t> {
init!(esp_gatt_rsp_t {
attr_value <- init!(esp_gatt_value_t {
len: 0,
value <- zeroed(),
handle: 0,
offset: 0,
auth_req: 0,
}),
})
}
}

0 comments on commit 8085b5d

Please sign in to comment.