aboutsummaryrefslogtreecommitdiff
path: root/cyw43/src/control.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-12-19 16:08:06 +0100
committerUlf Lilleengen <[email protected]>2023-12-19 16:08:06 +0100
commit39c166ef9b754c5caa44ef4dd4a4e216078dbcea (patch)
treecece1955c41b80d92bd8056cc265a91cf3d0cf79 /cyw43/src/control.rs
parent5e76c8b41a05c89652a6c53061107482adc4125f (diff)
docs: document public apis for cyw43 driver
Diffstat (limited to 'cyw43/src/control.rs')
-rw-r--r--cyw43/src/control.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs
index 826edfe1a..311fcb08c 100644
--- a/cyw43/src/control.rs
+++ b/cyw43/src/control.rs
@@ -12,17 +12,23 @@ use crate::ioctl::{IoctlState, IoctlType};
12use crate::structs::*; 12use crate::structs::*;
13use crate::{countries, events, PowerManagementMode}; 13use crate::{countries, events, PowerManagementMode};
14 14
15/// Control errors.
15#[derive(Debug)] 16#[derive(Debug)]
16pub struct Error { 17pub struct Error {
18 /// Status code.
17 pub status: u32, 19 pub status: u32,
18} 20}
19 21
22/// Multicast errors.
20#[derive(Debug)] 23#[derive(Debug)]
21pub enum AddMulticastAddressError { 24pub enum AddMulticastAddressError {
25 /// Not a multicast address.
22 NotMulticast, 26 NotMulticast,
27 /// No free address slots.
23 NoFreeSlots, 28 NoFreeSlots,
24} 29}
25 30
31/// Control driver.
26pub struct Control<'a> { 32pub struct Control<'a> {
27 state_ch: ch::StateRunner<'a>, 33 state_ch: ch::StateRunner<'a>,
28 events: &'a Events, 34 events: &'a Events,
@@ -38,6 +44,7 @@ impl<'a> Control<'a> {
38 } 44 }
39 } 45 }
40 46
47 /// Initialize WiFi controller.
41 pub async fn init(&mut self, clm: &[u8]) { 48 pub async fn init(&mut self, clm: &[u8]) {
42 const CHUNK_SIZE: usize = 1024; 49 const CHUNK_SIZE: usize = 1024;
43 50
@@ -154,6 +161,7 @@ impl<'a> Control<'a> {
154 self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; 161 self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await;
155 } 162 }
156 163
164 /// Set power management mode.
157 pub async fn set_power_management(&mut self, mode: PowerManagementMode) { 165 pub async fn set_power_management(&mut self, mode: PowerManagementMode) {
158 // power save mode 166 // power save mode
159 let mode_num = mode.mode(); 167 let mode_num = mode.mode();
@@ -166,6 +174,7 @@ impl<'a> Control<'a> {
166 self.ioctl_set_u32(86, 0, mode_num).await; 174 self.ioctl_set_u32(86, 0, mode_num).await;
167 } 175 }
168 176
177 /// Join an unprotected network with the provided ssid.
169 pub async fn join_open(&mut self, ssid: &str) -> Result<(), Error> { 178 pub async fn join_open(&mut self, ssid: &str) -> Result<(), Error> {
170 self.set_iovar_u32("ampdu_ba_wsize", 8).await; 179 self.set_iovar_u32("ampdu_ba_wsize", 8).await;
171 180
@@ -183,6 +192,7 @@ impl<'a> Control<'a> {
183 self.wait_for_join(i).await 192 self.wait_for_join(i).await
184 } 193 }
185 194
195 /// Join an protected network with the provided ssid and passphrase.
186 pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) -> Result<(), Error> { 196 pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) -> Result<(), Error> {
187 self.set_iovar_u32("ampdu_ba_wsize", 8).await; 197 self.set_iovar_u32("ampdu_ba_wsize", 8).await;
188 198
@@ -250,16 +260,19 @@ impl<'a> Control<'a> {
250 } 260 }
251 } 261 }
252 262
263 /// Set GPIO pin on WiFi chip.
253 pub async fn gpio_set(&mut self, gpio_n: u8, gpio_en: bool) { 264 pub async fn gpio_set(&mut self, gpio_n: u8, gpio_en: bool) {
254 assert!(gpio_n < 3); 265 assert!(gpio_n < 3);
255 self.set_iovar_u32x2("gpioout", 1 << gpio_n, if gpio_en { 1 << gpio_n } else { 0 }) 266 self.set_iovar_u32x2("gpioout", 1 << gpio_n, if gpio_en { 1 << gpio_n } else { 0 })
256 .await 267 .await
257 } 268 }
258 269
270 /// Start open access point.
259 pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) { 271 pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) {
260 self.start_ap(ssid, "", Security::OPEN, channel).await; 272 self.start_ap(ssid, "", Security::OPEN, channel).await;
261 } 273 }
262 274
275 /// Start WPA2 protected access point.
263 pub async fn start_ap_wpa2(&mut self, ssid: &str, passphrase: &str, channel: u8) { 276 pub async fn start_ap_wpa2(&mut self, ssid: &str, passphrase: &str, channel: u8) {
264 self.start_ap(ssid, passphrase, Security::WPA2_AES_PSK, channel).await; 277 self.start_ap(ssid, passphrase, Security::WPA2_AES_PSK, channel).await;
265 } 278 }
@@ -494,13 +507,14 @@ impl<'a> Control<'a> {
494 } 507 }
495} 508}
496 509
510/// WiFi network scanner.
497pub struct Scanner<'a> { 511pub struct Scanner<'a> {
498 subscriber: EventSubscriber<'a>, 512 subscriber: EventSubscriber<'a>,
499 events: &'a Events, 513 events: &'a Events,
500} 514}
501 515
502impl Scanner<'_> { 516impl Scanner<'_> {
503 /// wait for the next found network 517 /// Wait for the next found network.
504 pub async fn next(&mut self) -> Option<BssInfo> { 518 pub async fn next(&mut self) -> Option<BssInfo> {
505 let event = self.subscriber.next_message_pure().await; 519 let event = self.subscriber.next_message_pure().await;
506 if event.header.status != EStatus::PARTIAL { 520 if event.header.status != EStatus::PARTIAL {