Skip to content

Commit ed819f5

Browse files
authored
Thread enhancements (#592)
* Thread SRP client; start/stop methods; various fixes * Remove the commented MCU settings * Cleanup
1 parent 8e26750 commit ed819f5

10 files changed

Lines changed: 1682 additions & 370 deletions

File tree

.cargo/config.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build]
22
target = "riscv32imc-esp-espidf"
3-
# target = "xtensa-esp32-espidf"
3+
#target = "riscv32imac-esp-espidf"
4+
#target = "xtensa-esp32-espidf"
45

56
[target.xtensa-esp32-espidf]
67
linker = "ldproxy"
@@ -25,6 +26,7 @@ rustflags = ["--cfg", "espidf_time64"]
2526
[env]
2627
ESP_IDF_SDKCONFIG_DEFAULTS = ".github/configs/sdkconfig.defaults"
2728
ESP_IDF_VERSION = "v5.3.2"
29+
#ESP_IDF_VERSION = "release/v5.3" Necessary for `Thread::stop`
2830

2931
[unstable]
3032
build-std = ["std", "panic_abort"]

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Breaking
1111
- Implement MQTT outbox limit and get_outbox_size()
1212
- Added argument `subprotocol_list` to `ws_handler` to allow subprotocols to be supported by WebSockets
13+
- Thread enhancements (#592). Specifically:
14+
- Thread SRP (Thread-specific mDNS) is now supported and has a new API so that the user can register/unregister SRP services
15+
- Option to start/stop the Thread stack (methods `Thread::start` / `Thread::stop` in place of the previous `Thread::run`)
16+
- Several callbacks where actually unsound, as they were not `Send + 'static`. Now fixed
17+
- Simplifications:
18+
- `Thread::init` and `Thread::deinit` are now gone
19+
- No option to swap the Thread Netif with a custom one, as it complicates the implementation, and I don't see the use-case (unlike with Wifi)
1320

1421
### Fixed
1522
- Fix wrong conversion from `ScanType` to `u32` in Wi-Fi configuration

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313
links = "esp_idf_svc"
1414
build = "build.rs"
1515
documentation = "https://docs.esp-rs.org/esp-idf-svc/"
16-
rust-version = "1.77"
16+
rust-version = "1.82"
1717

1818
[patch.crates-io]
1919
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }

examples/thread.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ mod example {
5050
let mut thread =
5151
EspThread::new(peripherals.modem, sys_loop.clone(), nvs, mounted_event_fs)?;
5252

53-
thread.init()?;
54-
5553
info!("Thread initialized, now running...");
5654

57-
thread.run()?;
55+
thread.start()?;
5856

59-
Ok(())
57+
loop {
58+
// Keep the main thread alive to allow the Thread Border Router to run
59+
std::thread::sleep(std::time::Duration::from_secs(2));
60+
}
6061
}
6162

6263
fn log_thread_sysloop(

examples/thread_br.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,19 @@ mod example {
141141
wifi.wifi().sta_netif(),
142142
)?;
143143

144-
thread.init()?;
145-
146144
#[cfg(esp32c6)]
147145
thread.init_coex()?;
148146

149147
thread.set_tod_from_cfg()?;
150148

151149
info!("Thread Border Router initialized, now running...");
152150

153-
thread.run()?;
151+
thread.start()?;
154152

155-
Ok(())
153+
loop {
154+
// Keep the main thread alive to allow the Thread Border Router to run
155+
std::thread::sleep(std::time::Duration::from_secs(2));
156+
}
156157
}
157158

158159
fn connect_wifi(wifi: &mut BlockingWifi<EspWifi<'static>>) -> anyhow::Result<()> {

examples/thread_rcp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ mod example {
6060
mounted_event_fs,
6161
)?;
6262

63-
thread.init()?;
64-
6563
info!("Thread RCP initialized, now running...");
6664

67-
thread.run()?;
65+
thread.start()?;
6866

69-
Ok(())
67+
loop {
68+
// Keep the main thread alive to allow the Thread Border Router to run
69+
std::thread::sleep(std::time::Duration::from_secs(2));
70+
}
7071
}
7172

7273
fn log_thread_sysloop(

src/bt/ble/gatt/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'a> From<(esp_gatts_cb_event_t, &'a esp_ble_gatts_cb_param_t)> for GattsEve
269269
conn_id: param.exec_write.conn_id,
270270
addr: param.exec_write.bda.into(),
271271
trans_id: param.exec_write.trans_id,
272-
canceled: param.exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_CANCEL as _,
272+
canceled: param.exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_CANCEL as u8,
273273
}
274274
},
275275
esp_gatts_cb_event_t_ESP_GATTS_MTU_EVT => unsafe {

src/netif.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,13 @@ impl EspNetif {
468468
Ok(netif)
469469
}
470470

471+
pub fn is_netif_up(&self) -> Result<bool, EspError> {
472+
Ok(unsafe { esp_netif_is_netif_up(self.handle) })
473+
}
474+
475+
// TODO: Copy and rename to `is_up_ipv4` and deprecate the `is_up` variant in future
471476
pub fn is_up(&self) -> Result<bool, EspError> {
472-
if !unsafe { esp_netif_is_netif_up(self.handle) } {
477+
if !self.is_netif_up()? {
473478
Ok(false)
474479
} else {
475480
let mut ip_info = Default::default();

0 commit comments

Comments
 (0)