Skip to content

Commit

Permalink
Typestate devices
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 3, 2023
1 parent e067c3c commit 10a9b48
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 252 deletions.
4 changes: 2 additions & 2 deletions esp-wifi/examples/access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use esp_backtrace as _;
use esp_println::{print, println};
use esp_wifi::initialize;
use esp_wifi::wifi::utils::create_network_interface;
use esp_wifi::wifi::WifiMode;
use esp_wifi::wifi::WifiApDevice;
use esp_wifi::wifi_interface::WifiStack;
use esp_wifi::{current_millis, EspWifiInitFor};
use hal::clock::ClockControl;
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() -> ! {
let wifi = peripherals.WIFI;
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Ap, &mut socket_set_entries).unwrap();
create_network_interface(&init, wifi, WifiApDevice, &mut socket_set_entries).unwrap();
let mut wifi_stack = WifiStack::new(iface, device, sockets, current_millis);

let client_config = Configuration::AccessPoint(AccessPointConfiguration {
Expand Down
10 changes: 5 additions & 5 deletions esp-wifi/examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wi
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::wifi::utils::create_network_interface;
use esp_wifi::wifi::{WifiError, WifiMode};
use esp_wifi::wifi::{WifiError, WifiStaDevice};
use esp_wifi::wifi_interface::WifiStack;
use esp_wifi::{current_millis, initialize, EspWifiInitFor};
use hal::clock::ClockControl;
Expand Down Expand Up @@ -62,7 +62,7 @@ fn main() -> ! {
let wifi = peripherals.WIFI;
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Sta, &mut socket_set_entries).unwrap();
create_network_interface(&init, wifi, WifiStaDevice, &mut socket_set_entries).unwrap();
let wifi_stack = WifiStack::new(iface, device, sockets, current_millis);

let client_config = Configuration::Client(ClientConfiguration {
Expand Down Expand Up @@ -137,7 +137,7 @@ fn main() -> ! {

fn test_download<'a>(
server_address: Ipv4Address,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a>,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a, WifiStaDevice>,
) {
println!("Testing download...");
socket.work();
Expand Down Expand Up @@ -171,7 +171,7 @@ fn test_download<'a>(

fn test_upload<'a>(
server_address: Ipv4Address,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a>,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a, WifiStaDevice>,
) {
println!("Testing upload...");
socket.work();
Expand Down Expand Up @@ -205,7 +205,7 @@ fn test_upload<'a>(

fn test_upload_download<'a>(
server_address: Ipv4Address,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a>,
socket: &mut esp_wifi::wifi_interface::Socket<'a, 'a, WifiStaDevice>,
) {
println!("Testing upload+download...");
socket.work();
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/examples/coex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bleps::{
};

use esp_wifi::{
ble::controller::BleConnector, current_millis, wifi::WifiMode, wifi_interface::WifiStack,
ble::controller::BleConnector, current_millis, wifi::WifiStaDevice, wifi_interface::WifiStack,
EspWifiInitFor,
};

Expand Down Expand Up @@ -61,7 +61,7 @@ fn main() -> ! {

let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Sta, &mut socket_set_entries).unwrap();
create_network_interface(&init, wifi, WifiStaDevice, &mut socket_set_entries).unwrap();
let wifi_stack = WifiStack::new(iface, device, sockets, current_millis);

let client_config = Configuration::Client(ClientConfiguration {
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/examples/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wi
use esp_backtrace as _;
use esp_println::{print, println};
use esp_wifi::wifi::utils::create_network_interface;
use esp_wifi::wifi::{WifiError, WifiMode};
use esp_wifi::wifi::{WifiError, WifiStaDevice};
use esp_wifi::wifi_interface::WifiStack;
use esp_wifi::{current_millis, initialize, EspWifiInitFor};
use hal::clock::ClockControl;
Expand Down Expand Up @@ -51,7 +51,7 @@ fn main() -> ! {
let wifi = peripherals.WIFI;
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Sta, &mut socket_set_entries).unwrap();
create_network_interface(&init, wifi, WifiStaDevice, &mut socket_set_entries).unwrap();
let wifi_stack = WifiStack::new(iface, device, sockets, current_millis);

let client_config = Configuration::Client(ClientConfiguration {
Expand Down
6 changes: 3 additions & 3 deletions esp-wifi/examples/embassy_access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use embassy_time::{Duration, Timer};
use embedded_svc::wifi::{AccessPointConfiguration, Configuration, Wifi};
use esp_backtrace as _;
use esp_println::{print, println};
use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiMode, WifiState};
use esp_wifi::wifi::{WifiApDevice, WifiController, WifiDevice, WifiEvent, WifiState};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::clock::ClockControl;
use hal::Rng;
Expand Down Expand Up @@ -47,7 +47,7 @@ async fn main(spawner: Spawner) -> ! {

let wifi = peripherals.WIFI;
let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiMode::Ap).unwrap();
esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timer_group0.timer0);
Expand Down Expand Up @@ -184,6 +184,6 @@ async fn connection(mut controller: WifiController<'static>) {
}

#[embassy_executor::task]
async fn net_task(stack: &'static Stack<WifiDevice<'static>>) {
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiApDevice>>) {
stack.run().await
}
6 changes: 3 additions & 3 deletions esp-wifi/examples/embassy_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use embassy_time::{with_timeout, Duration, Timer};
use embedded_svc::wifi::{ClientConfiguration, Configuration, Wifi};
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiMode, WifiState};
use esp_wifi::wifi::{WifiApDevice, WifiController, WifiDevice, WifiEvent, WifiState};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::clock::ClockControl;
use hal::Rng;
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn main(spawner: Spawner) -> ! {

let wifi = peripherals.WIFI;
let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiMode::Sta).unwrap();
esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timer_group0.timer0);
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn connection(mut controller: WifiController<'static>) {
}

#[embassy_executor::task]
async fn net_task(stack: &'static Stack<WifiDevice<'static>>) {
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiApDevice>>) {
stack.run().await
}

Expand Down
6 changes: 3 additions & 3 deletions esp-wifi/examples/embassy_dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use embassy_time::{Duration, Timer};
use embedded_svc::wifi::{ClientConfiguration, Configuration, Wifi};
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiMode, WifiState};
use esp_wifi::wifi::{WifiController, WifiDevice, WifiEvent, WifiStaDevice, WifiState};
use esp_wifi::{initialize, EspWifiInitFor};
use hal::clock::ClockControl;
use hal::Rng;
Expand Down Expand Up @@ -48,7 +48,7 @@ async fn main(spawner: Spawner) -> ! {

let wifi = peripherals.WIFI;
let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiMode::Sta).unwrap();
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
embassy::init(&clocks, timer_group0.timer0);
Expand Down Expand Up @@ -166,6 +166,6 @@ async fn connection(mut controller: WifiController<'static>) {
}

#[embassy_executor::task]
async fn net_task(stack: &'static Stack<WifiDevice<'static>>) {
async fn net_task(stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>) {
stack.run().await
}
4 changes: 2 additions & 2 deletions esp-wifi/examples/static_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wi
use esp_backtrace as _;
use esp_println::{print, println};
use esp_wifi::initialize;
use esp_wifi::wifi::WifiMode;
use esp_wifi::wifi::WifiStaDevice;
use esp_wifi::wifi::{utils::create_network_interface, WifiError};
use esp_wifi::wifi_interface::WifiStack;
use esp_wifi::{current_millis, EspWifiInitFor};
Expand Down Expand Up @@ -53,7 +53,7 @@ fn main() -> ! {
let wifi = peripherals.WIFI;
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Sta, &mut socket_set_entries).unwrap();
create_network_interface(&init, wifi, WifiStaDevice, &mut socket_set_entries).unwrap();
let mut wifi_stack = WifiStack::new(iface, device, sockets, current_millis);

let client_config = Configuration::Client(ClientConfiguration {
Expand Down
Loading

0 comments on commit 10a9b48

Please sign in to comment.