Skip to content

Commit 6bbac0b

Browse files
authored
Merge pull request #72 from ivmarkov/sequential-embassy-net
no_std + async support
2 parents 4b85887 + 91e1329 commit 6bbac0b

File tree

130 files changed

+12337
-8542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+12337
-8542
lines changed

.github/workflows/test-linux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
crypto-backend: ['crypto_openssl', 'crypto_rustcrypto', 'crypto_mbedtls']
18+
crypto-backend: ['rustcrypto', 'mbedtls', 'openssl']
1919

2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Build
23-
run: cd matter; cargo build --verbose --no-default-features --features ${{matrix.crypto-backend}}
23+
run: cd matter; cargo build --no-default-features --features ${{matrix.crypto-backend}}
2424
- name: Run tests
25-
run: cd matter; cargo test --verbose --no-default-features --features ${{matrix.crypto-backend}} -- --test-threads=1
25+
run: cd matter; cargo test --no-default-features --features os,${{matrix.crypto-backend}} -- --test-threads=1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target
22
Cargo.lock
33
.vscode
4+
.embuild

Cargo.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
[workspace]
2-
members = ["matter", "matter_macro_derive", "boxslab", "tools/tlv_tool"]
2+
resolver = "2"
3+
members = ["matter", "matter_macro_derive"]
34

4-
exclude = ["examples/*"]
5+
exclude = ["examples/*", "tools/tlv_tool"]
6+
7+
# For compatibility with ESP IDF
8+
[patch.crates-io]
9+
polling = { git = "https://github.com/esp-rs-compat/polling" }
10+
socket2 = { git = "https://github.com/esp-rs-compat/socket2" }
11+
12+
[profile.release]
13+
opt-level = 3
14+
15+
[profile.dev]
16+
debug = true
17+
opt-level = 3

README.md

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,44 @@
55
[![Test Linux (OpenSSL)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml)
66
[![Test Linux (mbedTLS)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml)
77

8-
## Important Note
9-
10-
All development work is now ongoing in two other branches ([no_std](https://github.com/project-chip/matter-rs/tree/no_std) and [sequential](https://github.com/project-chip/matter-rs/tree/sequential) - explained below). The plan is one of these two branches to become the new `main`.
11-
12-
We highly encourage users to try out both of these branches (there is a working `onoff_light` example in both) and provide feedback.
13-
14-
### [no_std](https://github.com/project-chip/matter-rs/tree/no_std)
15-
16-
The purpose of this branch - as the name suggests - is to introduce `no_std` compatibility to the `matter-rs` library, so that it is possible to target constrained environments like MCUs which more often than not have no support for the Rust Standard library (threads, network sockets, filesystem and so on).
17-
18-
We have been successful in this endeavour. The library now only requires Rust `core` and runs on e.g. ESP32 baremental Rust targets.
19-
When `matter-rs` is used on targets that do not support the Rust Standard Library, user is expected to provide the following:
20-
21-
- A `rand` function that can fill a `&[u8]` slice with random data
22-
- An `epoch` function (a "current time" utility); note that since this utility is only used for measuring timeouts, it is OK to provide a function that e.g. measures elapsed millis since system boot, rather than something that tries to adhere to the UNIX epoch (1/1/1970)
23-
- An MCU-specific UDP stack that the user would need to connect to the `matter-rs` library
24-
25-
Besides just having `no_std` compatibility, the `no_std` branch does not need an allocator. I.e. all structures internal to the `matter-rs` librarty are statically allocated.
26-
27-
Last but not least, the `no_std` branch by itself does **not** do any IO. In other words, it is "compute only" (as in, "give me a network packet and I'll produce one or more that you have to send; how you receive/send those is up to you"). Ditto for persisting fabrics and ACLs - it is up to the user to listen the matter stack for changes to those and persist.
28-
29-
### [sequential](https://github.com/project-chip/matter-rs/tree/sequential)
30-
31-
The `sequential` branch builds on top of the work implemented in the `no_std` branch by utilizing code implemented as `async` functions and methods. Committing to `async` has multiple benefits:
32-
33-
- (Internal for the library) We were able to turn several explicit state machines into implicit ones (after all, `async` is primarily about generating state machines automatically based on "sequential" user codee that uses the async/await language constructs - hence the name of the branch)
34-
- (External, for the user) The ergonomics of the Exchange API in this branch (in other words, the "transport aspect of the Matter CSA spec) is much better, approaching that of dealing with regular TCP/IP sockets in the Rust Standard Library. This is only possible by utilizing async functions and methods, because - let's not forget - `matter-rs` needs to run on MCUs where native threading and task scheduling capabilities might not even exist, hence "sequentially-looking" request/response interaction can only be expressed asynchronously, or with explicit state machines.
35-
- Certain pending concepts are much easier to implement via async functions and methods:
36-
- Re-sending packets which were not acknowledged by the receiver yet (the MRP protocol as per the Matter spec)
37-
- The "initiator" side of an exchange (think client clusters)
38-
- This branch provides facilities to implement asynchronous read, write and invoke handling for server clusters, which is beneficial in certain scenarios (i.e. brdige devices)
39-
40-
The `async` metaphor however comes with a bit higher memory usage, due to not enough optimizations being implemented yet in the rust language when the async code is transpiled to state machines.
41-
428
## Build
439

44-
Building the library:
10+
### Building the library
4511

4612
```
4713
$ cargo build
4814
```
4915

50-
Building the example:
16+
### Building and running the example (Linux, MacOS X)
17+
18+
```
19+
$ cargo run --example onoff_light
20+
```
21+
22+
### Building the example (Espressif's ESP-IDF)
5123

24+
* Install all build prerequisites described [here](https://github.com/esp-rs/esp-idf-template#prerequisites)
25+
* Build with the following command line:
5226
```
53-
$ RUST_LOG="matter" cargo run --example onoff_light
27+
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 esp-idf --target xtensa-esp32-espidf -Zbuild-std=std,panic_abort
5428
```
29+
* 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:
30+
* esp32 / xtensa-esp32-espidf
31+
* esp32s2 / xtensa-esp32s2-espidf
32+
* esp32s3 / xtensa-esp32s3-espidf
33+
* esp32c3 / riscv32imc-esp-espidf
34+
* esp32c5 / riscv32imc-esp-espidf
35+
* esp32c6 / risxcv32imac-esp-espidf
36+
* Put in `WIFI_SSID` / `WIFI_PASS` the SSID & password for your wireless router
37+
* Flash using the `espflash` utility described in the build prerequsites' link above
38+
39+
### Building the example (ESP32-XX baremetal or RP2040)
40+
41+
Coming soon!
42+
43+
## Test
5544

56-
With the chip-tool (the current tool for testing Matter) use the Ethernet commissioning mechanism:
45+
With the `chip-tool` (the current tool for testing Matter) use the Ethernet commissioning mechanism:
5746

5847
```
5948
$ chip-tool pairing code 12344321 <Pairing-Code>

boxslab/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

boxslab/src/lib.rs

Lines changed: 0 additions & 237 deletions
This file was deleted.

examples/onoff_light/src/dev_att.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
use matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher};
19-
use matter::error::Error;
19+
use matter::error::{Error, ErrorCode};
2020

2121
pub struct HardCodedDevAtt {}
2222

@@ -159,7 +159,7 @@ impl DevAttDataFetcher for HardCodedDevAtt {
159159
data.copy_from_slice(src);
160160
Ok(src.len())
161161
} else {
162-
Err(Error::NoSpace)
162+
Err(ErrorCode::NoSpace.into())
163163
}
164164
}
165165
}

0 commit comments

Comments
 (0)