Skip to content

Commit

Permalink
Conditionalize on the enabled ESP IDF components and conf
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Apr 30, 2024
1 parent 3481621 commit 7b0db6f
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 167 deletions.
7 changes: 7 additions & 0 deletions src/ble.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#![cfg(all(
not(esp_idf_btdm_ctrl_mode_br_edr_only),
esp_idf_bt_enabled,
esp_idf_bt_bluedroid_enabled,
not(esp32s2)
))]

use core::borrow::Borrow;
use core::cell::RefCell;

Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ extern crate std;
extern crate alloc;

pub use error::*;

#[cfg(feature = "std")]
#[cfg(all(
feature = "std",
esp_idf_comp_nvs_flash_enabled,
esp_idf_comp_esp_netif_enabled,
esp_idf_comp_esp_event_enabled
))]
pub use stack::*;

pub mod ble;
Expand All @@ -26,5 +30,11 @@ pub mod mdns;
pub mod multicast;
pub mod netif;
pub mod nvs;
#[cfg(all(
feature = "std",
esp_idf_comp_nvs_flash_enabled,
esp_idf_comp_esp_netif_enabled,
esp_idf_comp_esp_event_enabled
))]
mod stack;
pub mod wifi;
2 changes: 2 additions & 0 deletions src/mdns.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#![cfg(any(esp_idf_comp_mdns_enabled, esp_idf_comp_espressif__mdns_enabled))]

// TODO
78 changes: 39 additions & 39 deletions src/netif.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![cfg(all(esp_idf_comp_esp_netif_enabled, esp_idf_comp_esp_event_enabled))]

use core::net::{Ipv4Addr, Ipv6Addr};
use core::pin::pin;

use embassy_futures::select::select;
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::mutex::Mutex;
use embassy_time::{Duration, Timer};

use esp_idf_svc::eth::{AsyncEth, EspEth};
use esp_idf_svc::eventloop::EspSystemEventLoop;
use esp_idf_svc::handle::RawHandle;
use esp_idf_svc::netif::{EspNetif, IpEvent};
Expand Down Expand Up @@ -65,42 +64,6 @@ where
}
}

impl<'d, T> NetifAccess for &mut EspEth<'d, T> {
async fn with_netif<F, R>(&self, f: F) -> R
where
F: FnOnce(&EspNetif) -> R,
{
f(self.netif())
}
}

impl<'d, T> NetifAccess for AsyncEth<EspEth<'d, T>> {
async fn with_netif<F, R>(&self, f: F) -> R
where
F: FnOnce(&EspNetif) -> R,
{
f(self.eth().netif())
}
}

pub struct EthNetifAccess<'a, 'd, M, T>(pub &'a Mutex<M, AsyncEth<EspEth<'d, T>>>)
where
M: RawMutex;

impl<'a, 'd, M, T> NetifAccess for EthNetifAccess<'a, 'd, M, T>
where
M: RawMutex,
{
async fn with_netif<F, R>(&self, f: F) -> R
where
F: FnOnce(&EspNetif) -> R,
{
let eth = self.0.lock().await;

f(eth.eth().netif())
}
}

pub fn get_ips(netif: &EspNetif) -> Result<(Ipv4Addr, Ipv6Addr), Error> {
let ip_info = netif.get_ip_info()?;

Expand Down Expand Up @@ -137,3 +100,40 @@ pub fn get_ips(netif: &EspNetif) -> Result<(Ipv4Addr, Ipv6Addr), Error> {

Ok((ipv4, ipv6))
}

#[cfg(esp_idf_comp_esp_eth_enabled)]
#[cfg(any(
all(esp32, esp_idf_eth_use_esp32_emac),
any(
esp_idf_eth_spi_ethernet_dm9051,
esp_idf_eth_spi_ethernet_w5500,
esp_idf_eth_spi_ethernet_ksz8851snl
),
esp_idf_eth_use_openeth
))]
pub mod eth {
use esp_idf_svc::{
eth::{AsyncEth, EspEth},
netif::EspNetif,
};

use super::NetifAccess;

impl<'d, T> NetifAccess for EspEth<'d, T> {
async fn with_netif<F, R>(&self, f: F) -> R
where
F: FnOnce(&EspNetif) -> R,
{
f(self.netif())
}
}

impl<'d, T> NetifAccess for AsyncEth<EspEth<'d, T>> {
async fn with_netif<F, R>(&self, f: F) -> R
where
F: FnOnce(&EspNetif) -> R,
{
f(self.eth().netif())
}
}
}
2 changes: 2 additions & 0 deletions src/nvs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(esp_idf_comp_nvs_flash_enabled)]

use embassy_sync::blocking_mutex::raw::RawMutex;

use esp_idf_svc::nvs::{EspNvs, NvsPartitionId};
Expand Down
Loading

0 comments on commit 7b0db6f

Please sign in to comment.