Skip to content

Commit

Permalink
Use embassy-net 0.2
Browse files Browse the repository at this point in the history
Co-Authored-By: Hailey Somerville <hailey@hailey.lol>
  • Loading branch information
bugadani and haileys committed Nov 1, 2023
1 parent aa10cd0 commit c02a07e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 43 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ log = "0.4.18"
embedded-svc = { version = "0.26.1", default-features = false, features = [] }
enumset = { version = "1", default-features = false }
linked_list_allocator = { version = "0.10.5", default-features = false, features = ["const_mut_refs"] }
embedded-io = "0.4.0"
embedded-io = "0.6.1"
fugit = "0.3.7"
heapless = { version = "0.7.16", default-features = false }
num-derive = { version = "0.3", features = ["full-syntax"] }
num-traits = { version = "0.2", default-features = false }
esp-wifi-sys = { version = "0.1.0", path = "../esp-wifi-sys" }
embassy-sync = { version = "0.2.0" }
embassy-sync = { version = "0.4.0" }
embassy-futures = { version = "0.1.0" }
embassy-net-driver = { version = "0.1.0" }
toml-cfg = "0.1.3"
libm = "0.2.7"
cfg-if = "1.0.0"
static_cell = { version = "1", features = ["nightly"] }

embassy-net = { version = "0.1.0", features = ["nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "b82f1e7009bef7e32f0918be5b186188aa5e7109", features = ["macros"] }
embassy-net = { version = "0.2.1", features = ["nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "0db8fcb", features = ["macros"] }
embassy-executor = { version = "0.3.0", package = "embassy-executor", features = ["nightly", "executor-thread", "integrated-timers"] }
embassy-time = { version = "0.1.3", features = ["nightly"] }
futures-util = { version = "0.3.28", default-features = false }
esp-println = { version = "0.6.0" }
esp-backtrace = { version = "0.8.0", features = ["panic-handler", "exception-handler", "print-uart"] }
embedded-hal-async = { version = "1.0.0-rc.1" }
embedded-io-async = { version = "0.6.0" }

# required until https://github.com/esp-rs/esp-hal/pull/891 is released
[patch.crates-io]
Expand Down
19 changes: 8 additions & 11 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ embedded-svc = { workspace = true, optional = true }
enumset = { workspace = true, optional = true }
linked_list_allocator = { workspace = true }
embedded-io.workspace = true
embedded-io-async = { workspace = true, optional = true }
fugit.workspace = true
heapless = { workspace = true, default-features = false }
num-derive = { workspace = true, features = ["full-syntax"] }
num-traits = { workspace = true, default-features = false }
esp-wifi-sys = { version = "0.1.0", path = "../esp-wifi-sys" }
embassy-sync = { workspace = true, optional = true }
embassy-futures = { workspace = true, optional = true }
embassy-net-driver = { workspace = true, optional = true }
embassy-net = { workspace = true, optional = true }
toml-cfg.workspace = true
libm.workspace = true
cfg-if.workspace = true
Expand All @@ -40,18 +41,14 @@ toml-cfg.workspace = true
esp-println = { workspace = true, features = ["log"] }
esp-backtrace = { workspace = true }
embedded-svc.workspace = true
embassy-executor = { workspace = true }
embassy-executor.workspace = true
embassy-time.workspace = true
embassy-futures.workspace = true
futures-util.workspace = true
embassy-net = { workspace = true }
embassy-sync.workspace = true
bleps.workspace = true
embedded-io.workspace = true
embedded-hal-async = { workspace = true }
log = { workspace = true }
embedded-hal-async.workspace = true
log.workspace = true
smoltcp.workspace = true
static_cell = { workspace = true }
static_cell.workspace = true

[features]
default = [ "utils", "log" ]
Expand All @@ -68,7 +65,7 @@ esp32s3 = [ "esp32s3-hal", "esp-wifi-sys/esp32s3", "esp-println/esp32s3", "esp-b
async = [
"dep:embassy-sync",
"dep:embassy-futures",
"embedded-io/async",
"dep:embedded-io-async",
"esp32c3-hal?/embassy",
"esp32c2-hal?/embassy",
"esp32c6-hal?/embassy",
Expand All @@ -84,7 +81,7 @@ async = [
"bleps/async"
]

embassy-net = ["dep:embassy-net-driver", "async"]
embassy-net = ["dep:embassy-net", "async"]

# misc features
coex = []
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/examples/access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mod examples_util;
use examples_util::hal;

use embedded_io::blocking::*;
use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointConfiguration, Configuration, Wifi};

Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mod examples_util;
use examples_util::hal;

use embedded_io::blocking::*;
use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi};

Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/examples/coex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use esp_wifi::{
EspWifiInitFor,
};

use embedded_io::blocking::*;
use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi};

Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/examples/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mod examples_util;
use examples_util::hal;

use embedded_io::blocking::*;
use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi};

Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/examples/static_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mod examples_util;
use examples_util::hal;

use embedded_io::blocking::*;
use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi};

Expand Down
16 changes: 6 additions & 10 deletions esp-wifi/src/ble/controller/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use embedded_io::{
blocking::{Read, Write},
Error, Io,
};
use embedded_io::{Error, ErrorType, Read, Write};

use crate::hal::peripheral::{Peripheral, PeripheralRef};
use crate::EspWifiInitialization;
Expand Down Expand Up @@ -42,7 +39,7 @@ impl Error for BleConnectorError {
}
}

impl Io for BleConnector<'_> {
impl ErrorType for BleConnector<'_> {
type Error = BleConnectorError;
}

Expand Down Expand Up @@ -90,8 +87,7 @@ pub mod asynch {
use super::{read_hci, send_hci};
use crate::hal::peripheral::{Peripheral, PeripheralRef};
use embassy_sync::waitqueue::AtomicWaker;
use embedded_io::asynch;
use embedded_io::Io;
use embedded_io::ErrorType;

static HCI_WAKER: AtomicWaker = AtomicWaker::new();

Expand All @@ -118,11 +114,11 @@ pub mod asynch {
}
}

impl Io for BleConnector<'_> {
impl ErrorType for BleConnector<'_> {
type Error = BleConnectorError;
}

impl asynch::Read for BleConnector<'_> {
impl embedded_io_async::Read for BleConnector<'_> {
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, BleConnectorError> {
if !have_hci_read_data() {
HciReadyEventFuture.await;
Expand All @@ -145,7 +141,7 @@ pub mod asynch {
}
}

impl asynch::Write for BleConnector<'_> {
impl embedded_io_async::Write for BleConnector<'_> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, BleConnectorError> {
send_hci(buf);
Ok(buf.len())
Expand Down
18 changes: 9 additions & 9 deletions esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ macro_rules! esp_wifi_result {
#[cfg(feature = "embassy-net")]
pub(crate) mod embassy {
use super::*;
use embassy_net_driver::{Capabilities, Driver, RxToken, TxToken};
use embassy_net::driver::{Capabilities, Driver, HardwareAddress, RxToken, TxToken};
use embassy_sync::waitqueue::AtomicWaker;

pub(crate) static TRANSMIT_WAKER: AtomicWaker = AtomicWaker::new();
Expand Down Expand Up @@ -1458,27 +1458,27 @@ pub(crate) mod embassy {
}
}

fn link_state(&mut self, cx: &mut core::task::Context) -> embassy_net_driver::LinkState {
fn link_state(&mut self, cx: &mut core::task::Context) -> embassy_net::driver::LinkState {
LINK_STATE.register(cx.waker());

match self.get_wifi_mode() {
Ok(WifiMode::Sta) => {
if matches!(get_sta_state(), WifiState::StaConnected) {
embassy_net_driver::LinkState::Up
embassy_net::driver::LinkState::Up
} else {
embassy_net_driver::LinkState::Down
embassy_net::driver::LinkState::Down
}
}
Ok(WifiMode::Ap) => {
if matches!(get_ap_state(), WifiState::ApStarted) {
embassy_net_driver::LinkState::Up
embassy_net::driver::LinkState::Up
} else {
embassy_net_driver::LinkState::Down
embassy_net::driver::LinkState::Down
}
}
_ => {
warn!("Unknown wifi mode in link_state");
embassy_net_driver::LinkState::Down
embassy_net::driver::LinkState::Down
}
}
}
Expand All @@ -1494,14 +1494,14 @@ pub(crate) mod embassy {
caps
}

fn ethernet_address(&self) -> [u8; 6] {
fn hardware_address(&self) -> HardwareAddress {
let mut mac = [0; 6];
match self.get_wifi_mode() {
Ok(WifiMode::Ap) => get_ap_mac(&mut mac),
Ok(WifiMode::Sta) => get_sta_mac(&mut mac),
_ => get_sta_mac(&mut mac),
}
mac
HardwareAddress::Ethernet(mac)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions esp-wifi/src/wifi_interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::cell::RefCell;
use core::fmt::Display;
use embedded_io::blocking::{Read, Write};
use embedded_io::Io;
use embedded_io::ErrorType;
use embedded_io::{Read, Write};

use embedded_svc::ipv4;
use smoltcp::iface::{Interface, SocketHandle, SocketSet};
Expand Down Expand Up @@ -612,7 +612,7 @@ impl embedded_io::Error for IoError {
}
}

impl<'s, 'n: 's> Io for Socket<'s, 'n> {
impl<'s, 'n: 's> ErrorType for Socket<'s, 'n> {
type Error = IoError;
}

Expand Down

0 comments on commit c02a07e

Please sign in to comment.