Skip to content

Commit ff31b59

Browse files
authored
Simplify/clarify some docs/syntax in wifi code (#4294)
* Simplify * Clarify docs * Rename blocking function, fix links to items
1 parent 381c562 commit ff31b59

File tree

7 files changed

+46
-25
lines changed

7 files changed

+46
-25
lines changed

esp-radio/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5353
- The `ieee802154_rx_queue_size` config option has been replaced by a runtime option in `esp_radio::ieee802154::Config` (#4224)
5454
- The default value of `wifi_max_burst_size` has been changed to 3 (#4231)
5555
- Set `ble_ll_sync_cnt` to 0 on C6, C2 and H2 as in esp-idf Kconfig default (#4241)
56+
- `esp_radio::wifi::WifiController::scan_with_config_sync` has been renamed to `scan_with_config` (#4294)
5657

5758
### Fixed
5859

esp-radio/MIGRATING-0.15.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Provide these symbols:
6565

6666
## Scanning Functions
6767

68-
The `scan_with_config_sync_max`, `scan_with_config_sync_max`, `scan_n`, and `scan_n_async` functions have been removed. You can instead use the `scan_with_config_async` or `scan_with_config_sync` funtions while specifying a `max` value in `ScanConfig`.
68+
The `scan_with_config_sync_max`, `scan_with_config_sync_max`, `scan_n`, and `scan_n_async` functions have been removed. You can instead use the `scan_with_config_async` or `scan_with_config` functions while specifying a `max` value in `ScanConfig`.
6969

7070
## Configuration
7171

esp-radio/src/wifi/mod.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ impl WifiController<'_> {
30223022
}
30233023

30243024
/// A blocking wifi network scan with caller-provided scanning options.
3025-
pub fn scan_with_config_sync(
3025+
pub fn scan_with_config(
30263026
&mut self,
30273027
config: ScanConfig<'_>,
30283028
) -> Result<alloc::vec::Vec<AccessPointInfo>, WifiError> {
@@ -3055,6 +3055,9 @@ impl WifiController<'_> {
30553055
}
30563056

30573057
/// Starts the Wi-Fi controller.
3058+
///
3059+
/// This method is not blocking. To check if the controller has started, use the
3060+
/// [`Self::is_started`] method.
30583061
pub fn start(&mut self) -> Result<(), WifiError> {
30593062
unsafe {
30603063
esp_wifi_result!(esp_wifi_start())?;
@@ -3080,21 +3083,31 @@ impl WifiController<'_> {
30803083
}
30813084

30823085
/// Stops the Wi-Fi controller.
3086+
///
3087+
/// This method is not blocking. Use the [`Self::is_started`] method to see if the controller is
3088+
/// still running.
30833089
pub fn stop(&mut self) -> Result<(), WifiError> {
30843090
self.stop_impl()
30853091
}
30863092

30873093
/// Connect Wi-Fi station to the AP.
30883094
///
3089-
/// - If station is connected , call [Self::disconnect] to disconnect.
3090-
/// - Scanning will not be effective until connection between device and the AP is established.
3095+
/// This method is not blocking. Use the [`Self::is_connected`] method to see if the station is
3096+
/// connected.
3097+
///
3098+
/// - If station is connected, call [`Self::disconnect`] to disconnect.
3099+
/// - Calling [`Self::scan_with_config`] or [`Self::scan_with_config_async`] will not be
3100+
/// effective until connection between device and the AP is established.
30913101
/// - If device is scanning and connecting at the same time, it will abort scanning and return a
3092-
/// warning message and error
3102+
/// warning message and error.
30933103
pub fn connect(&mut self) -> Result<(), WifiError> {
30943104
self.connect_impl()
30953105
}
30963106

30973107
/// Disconnect Wi-Fi station from the AP.
3108+
///
3109+
/// This method is not blocking. Use the [`Self::is_connected`] method to see if the station is
3110+
/// still connected.
30983111
pub fn disconnect(&mut self) -> Result<(), WifiError> {
30993112
self.disconnect_impl()
31003113
}
@@ -3104,12 +3117,12 @@ impl WifiController<'_> {
31043117
///
31053118
/// <div class="warning">
31063119
///
3107-
/// - This API should be called after station connected to AP.
31083120
/// - Use this API only in STA or AP-STA mode.
3121+
/// - This API should be called after the station has connected to an access point.
31093122
/// </div>
31103123
///
31113124
/// # Errors
3112-
/// This function returns [WifiError::Unsupported] if the STA side isn't
3125+
/// This function returns [`WifiError::Unsupported`] if the STA side isn't
31133126
/// running. For example, when configured for AP only.
31143127
pub fn rssi(&self) -> Result<i32, WifiError> {
31153128
if self.mode()?.is_sta() {
@@ -3133,9 +3146,9 @@ impl WifiController<'_> {
31333146
/// Set the configuration.
31343147
///
31353148
/// This will set the mode accordingly.
3136-
/// You need to use Wifi::connect() for connecting to an AP.
3149+
/// You need to use [`Self::connect`] for connecting to an AP.
31373150
///
3138-
/// Passing [ModeConfig::None] will disable both, AP and STA mode.
3151+
/// Passing [`ModeConfig::None`] will disable both, AP and STA mode.
31393152
///
31403153
/// If you don't intend to use Wi-Fi anymore at all consider tearing down
31413154
/// Wi-Fi completely.
@@ -3187,7 +3200,7 @@ impl WifiController<'_> {
31873200

31883201
/// Set the Wi-Fi mode.
31893202
///
3190-
/// This will override the mode inferred by [Self::set_config].
3203+
/// This will override the mode inferred by [`Self::set_config`].
31913204
pub fn set_mode(&mut self, mode: WifiMode) -> Result<(), WifiError> {
31923205
esp_wifi_result!(unsafe { esp_wifi_set_mode(mode.into()) })?;
31933206
Ok(())
@@ -3209,8 +3222,8 @@ impl WifiController<'_> {
32093222

32103223
/// Checks if the Wi-Fi controller has started. Returns true if STA and/or AP are started.
32113224
///
3212-
/// This function should be called after the `start` method to verify if the
3213-
/// Wi-Fi has started successfully.
3225+
/// This function should be called after the [`Self::start`] method to verify if the
3226+
/// Wi-Fi controller has started successfully.
32143227
pub fn is_started(&self) -> Result<bool, WifiError> {
32153228
if matches!(
32163229
crate::wifi::sta_state(),
@@ -3226,7 +3239,7 @@ impl WifiController<'_> {
32263239

32273240
/// Checks if the Wi-Fi controller is connected to an AP.
32283241
///
3229-
/// This function should be called after the `connect` method to verify if
3242+
/// This function should be called after the [`Self::connect`] method to verify if
32303243
/// the connection was successful.
32313244
pub fn is_connected(&self) -> Result<bool, WifiError> {
32323245
match crate::wifi::sta_state() {
@@ -3260,7 +3273,9 @@ impl WifiController<'_> {
32603273
Ok(result)
32613274
}
32623275

3263-
/// Async version of [`crate::wifi::WifiController`]'s `start` method
3276+
/// Async version of [`Self::start`].
3277+
///
3278+
/// This function will wait for the Wi-Fi controller to start before returning.
32643279
pub async fn start_async(&mut self) -> Result<(), WifiError> {
32653280
let mut events = enumset::enum_set! {};
32663281

@@ -3281,7 +3296,9 @@ impl WifiController<'_> {
32813296
Ok(())
32823297
}
32833298

3284-
/// Async version of [`crate::wifi::WifiController`]'s `stop` method
3299+
/// Async version of [`Self::stop`].
3300+
///
3301+
/// This function will wait for the Wi-Fi controller to stop before returning.
32853302
pub async fn stop_async(&mut self) -> Result<(), WifiError> {
32863303
let mut events = enumset::enum_set! {};
32873304

@@ -3295,7 +3312,7 @@ impl WifiController<'_> {
32953312

32963313
Self::clear_events(events);
32973314

3298-
crate::wifi::WifiController::stop_impl(self)?;
3315+
self.stop_impl()?;
32993316

33003317
self.wait_for_all_events(events, false).await;
33013318

@@ -3305,11 +3322,13 @@ impl WifiController<'_> {
33053322
Ok(())
33063323
}
33073324

3308-
/// Async version of [`crate::wifi::WifiController`]'s `connect` method
3325+
/// Async version of [`Self::connect`].
3326+
///
3327+
/// This function will wait for the connection to be established before returning.
33093328
pub async fn connect_async(&mut self) -> Result<(), WifiError> {
33103329
Self::clear_events(WifiEvent::StaConnected | WifiEvent::StaDisconnected);
33113330

3312-
let err = crate::wifi::WifiController::connect_impl(self).err();
3331+
let err = self.connect_impl().err();
33133332

33143333
if MultiWifiEventFuture::new(WifiEvent::StaConnected | WifiEvent::StaDisconnected)
33153334
.await
@@ -3321,8 +3340,9 @@ impl WifiController<'_> {
33213340
}
33223341
}
33233342

3324-
/// Async version of [`crate::wifi::WifiController`]'s `Disconnect`
3325-
/// method
3343+
/// Async version of [`Self::disconnect`].
3344+
///
3345+
/// This function will wait for the connection to be closed before returning.
33263346
pub async fn disconnect_async(&mut self) -> Result<(), WifiError> {
33273347
// If not connected, this will do nothing.
33283348
// It will also wait forever for a `StaDisconnected` event that will never come.
@@ -3332,7 +3352,7 @@ impl WifiController<'_> {
33323352
}
33333353

33343354
Self::clear_events(WifiEvent::StaDisconnected);
3335-
crate::wifi::WifiController::disconnect_impl(self)?;
3355+
self.disconnect_impl()?;
33363356
WifiEventFuture::new(WifiEvent::StaDisconnected).await;
33373357

33383358
Ok(())

examples/wifi/dhcp/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn main() -> ! {
9595

9696
println!("Start Wifi Scan");
9797
let scan_config = ScanConfig::default().with_max(10);
98-
let res = controller.scan_with_config_sync(scan_config).unwrap();
98+
let res = controller.scan_with_config(scan_config).unwrap();
9999
for ap in res {
100100
println!("{:?}", ap);
101101
}

examples/wifi/static_ip/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn main() -> ! {
8383

8484
println!("Start Wifi Scan");
8585
let scan_config = ScanConfig::default().with_max(10);
86-
let res = controller.scan_with_config_sync(scan_config).unwrap();
86+
let res = controller.scan_with_config(scan_config).unwrap();
8787
for ap in res {
8888
println!("{:?}", ap);
8989
}

qa-test/src/bin/wifi_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn main() -> ! {
114114

115115
println!("Start Wifi Scan");
116116
let scan_config = ScanConfig::default().with_max(10);
117-
let res = controller.scan_with_config_sync(scan_config).unwrap();
117+
let res = controller.scan_with_config(scan_config).unwrap();
118118
for ap in res {
119119
println!("{:?}", ap);
120120
}

qa-test/src/bin/wifi_csi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() -> ! {
9696
println!("Waiting for CSI data...");
9797
println!("Start Wifi Scan");
9898
let scan_config = ScanConfig::default().with_max(10);
99-
let res = controller.scan_with_config_sync(scan_config).unwrap();
99+
let res = controller.scan_with_config(scan_config).unwrap();
100100
for ap in res {
101101
println!("{:?}", ap);
102102
}

0 commit comments

Comments
 (0)