Skip to content

Commit

Permalink
esp-idf-hal#234
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Aug 22, 2023
1 parent cf0b85c commit e8b7df7
Show file tree
Hide file tree
Showing 30 changed files with 159 additions and 147 deletions.
29 changes: 22 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,35 @@ description = "Implementation of the embedded-svc traits for ESP-IDF (Espressif'
repository = "https://github.com/esp-rs/esp-idf-svc"
license = "MIT OR Apache-2.0"
readme = "README.md"
links = "esp_idf_svc"
build = "build.rs"
documentation = "https://esp-rs.github.io/esp-idf-svc/"
rust-version = "1.66"

[patch.crates-io]
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }

[features]
default = ["std"]
default = ["std", "native", "binstart"]

std = ["alloc", "anyhow/std", "log/std", "esp-idf-sys/std", "esp-idf-hal/std", "embedded-svc/std"]
std = ["alloc", "anyhow/std", "log/std", "esp-idf-hal/std", "embedded-svc/std"]
alloc = ["anyhow", "esp-idf-hal/alloc", "embedded-svc/alloc"]
nightly = ["embedded-svc/nightly"]
nightly = ["embedded-svc/nightly", "esp-idf-hal/nightly"]
experimental = ["embedded-svc/experimental"]
embassy-time-driver = ["embassy-time"]
embassy-time-isr-queue = ["embassy-sync", "embassy-time", "esp-idf-hal/embassy-sync"]
embassy-time-isr-queue = ["embassy-sync", "embassy-time", "embassy-sync"]

# Propagated esp-idf-hal features
embassy-sync = ["esp-idf-hal/embassy-sync", "dep:embassy-sync"]
critical-section = ["esp-idf-hal/critical-section"]
edge-executor = ["esp-idf-hal/edge-executor"]
# The next are propagated from esp-idf-sys via esp-idf-hal
native = ["esp-idf-hal/native"]
pio = ["esp-idf-hal/pio"]
alloc_handler = ["esp-idf-hal/alloc_handler"]
panic_handler = ["esp-idf-hal/panic_handler"]
binstart = ["esp-idf-hal/binstart"]
libstart = ["esp-idf-hal/libstart"]

[dependencies]
heapless = { version = "0.7", default-features = false }
Expand All @@ -30,15 +47,13 @@ log = { version = "0.4", default-features = false }
uncased = "0.9.7"
anyhow = { version = "1", default-features = false, optional = true } # Only used by the deprecated httpd module
embedded-svc = { version = "0.25", default-features = false }
esp-idf-sys = { version = "0.33", default-features = false, features = ["native"] }
esp-idf-hal = { version = "0.41", default-features = false, features = ["esp-idf-sys"] }
embassy-sync = { version = "0.2", optional = true }
embassy-time = { version = "0.1.1", optional = true, features = ["tick-hz-1_000_000"] }
embassy-futures = "0.1"

[build-dependencies]
embuild = "0.31.2"
anyhow = "1"
embuild = "0.31.3"

[dev-dependencies]
anyhow = "1"
Expand Down
13 changes: 3 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
fn main() -> anyhow::Result<()> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;

// Will not be available when built with a CMake-first or a PIO-first build
// We need to output these only when building the examples' binaries anyway
if let Ok(args) = embuild::build::LinkArgs::try_from_env("ESP_IDF") {
args.output();
}

Ok(())
fn main() {
embuild::espidf::sysenv::relay();
embuild::espidf::sysenv::output(); // Only necessary for building the examples
}
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::fmt::{self, Display, Formatter};

use embedded_svc::io::{Error, ErrorKind};

use esp_idf_sys::EspError;
use crate::sys::EspError;

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct EspIOError(pub EspError);
Expand Down
4 changes: 2 additions & 2 deletions src/espnow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ::log::info;

use alloc::boxed::Box;

use esp_idf_sys::*;
use crate::sys::*;

use crate::private::mutex::{Mutex, RawMutex};

Expand Down Expand Up @@ -69,7 +69,7 @@ impl EspNow {
}

pub fn send(&self, peer_addr: [u8; 6], data: &[u8]) -> Result<(), EspError> {
esp!(unsafe { esp_idf_sys::esp_now_send(peer_addr.as_ptr(), data.as_ptr(), data.len(),) })?;
esp!(unsafe { crate::sys::esp_now_send(peer_addr.as_ptr(), data.as_ptr(), data.len(),) })?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use esp_idf_hal::gpio;
))]
use esp_idf_hal::{spi, units::Hertz};

use esp_idf_sys::*;
use crate::sys::*;

use crate::eventloop::{
EspEventLoop, EspSubscription, EspSystemEventLoop, EspTypedEventDeserializer,
Expand Down
4 changes: 2 additions & 2 deletions src/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use esp_idf_hal::cpu::Core;
use esp_idf_hal::delay::TickType;
use esp_idf_hal::interrupt;

use esp_idf_sys::*;
use crate::sys::*;

use crate::handle::RawHandle;
use crate::private::cstr::RawCstrs;
Expand Down Expand Up @@ -985,7 +985,7 @@ mod async_wait {
use embedded_svc::utils::asyncify::event_bus::{AsyncEventBus, AsyncSubscription};
use embedded_svc::utils::asyncify::timer::{AsyncTimer, AsyncTimerService};

use esp_idf_sys::{esp, EspError, ESP_ERR_TIMEOUT};
use crate::sys::{esp, EspError, ESP_ERR_TIMEOUT};

use log::debug;

Expand Down
1 change: 1 addition & 0 deletions src/hal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use esp_idf_hal::*;
2 changes: 1 addition & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use embedded_svc::http::client::*;
use embedded_svc::http::*;
use embedded_svc::io::{Io, Read, Write};

use esp_idf_sys::*;
use crate::sys::*;

use uncased::{Uncased, UncasedStr};

Expand Down
22 changes: 11 additions & 11 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use embedded_svc::http::*;
use embedded_svc::io::{Io, Read, Write};
use embedded_svc::utils::http::server::registration::{ChainHandler, ChainRoot};

use esp_idf_sys::*;
use crate::sys::*;

use uncased::{Uncased, UncasedStr};

Expand Down Expand Up @@ -243,7 +243,7 @@ type CloseHandler = Box<dyn Fn(ffi::c_int) + Send>;

pub struct EspHttpServer {
sd: httpd_handle_t,
registrations: Vec<(CString, esp_idf_sys::httpd_uri_t)>,
registrations: Vec<(CString, crate::sys::httpd_uri_t)>,
}

impl EspHttpServer {
Expand Down Expand Up @@ -331,17 +331,17 @@ impl EspHttpServer {
// Maybe its better to always call httpd_stop because httpd_ssl_stop directly wraps httpd_stop anyways
// https://github.com/espressif/esp-idf/blob/e6fda46a02c41777f1d116a023fbec6a1efaffb9/components/esp_https_server/src/https_server.c#L268
#[cfg(not(esp_idf_esp_https_server_enable))]
esp!(unsafe { esp_idf_sys::httpd_stop(self.sd) })?;
esp!(unsafe { crate::sys::httpd_stop(self.sd) })?;

// httpd_ssl_stop doesn't return EspErr for some reason. It returns void.
#[cfg(all(esp_idf_esp_https_server_enable, esp_idf_version_major = "4"))]
unsafe {
esp_idf_sys::httpd_ssl_stop(self.sd)
crate::sys::httpd_ssl_stop(self.sd)
};

// esp-idf version 5 does return EspErr
#[cfg(all(esp_idf_esp_https_server_enable, not(esp_idf_version_major = "4")))]
esp!(unsafe { esp_idf_sys::httpd_ssl_stop(self.sd) })?;
esp!(unsafe { crate::sys::httpd_ssl_stop(self.sd) })?;

CLOSE_HANDLERS.lock().remove(&(self.sd as u32));

Expand Down Expand Up @@ -382,7 +382,7 @@ impl EspHttpServer {
..Default::default()
};

esp!(unsafe { esp_idf_sys::httpd_register_uri_handler(self.sd, &conf) })?;
esp!(unsafe { crate::sys::httpd_register_uri_handler(self.sd, &conf) })?;

info!(
"Registered Httpd server handler {:?} for URI \"{}\"",
Expand Down Expand Up @@ -514,7 +514,7 @@ impl<'a> Read for EspHttpRequest<'a> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
if !buf.is_empty() {
let fd = unsafe { httpd_req_to_sockfd(self.0) };
let len = unsafe { esp_idf_sys::read(fd, buf.as_ptr() as *mut _, buf.len()) };
let len = unsafe { crate::sys::read(fd, buf.as_ptr() as *mut _, buf.len()) };

Ok(len as _)
} else {
Expand All @@ -527,7 +527,7 @@ impl<'a> Write for EspHttpRequest<'a> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
if !buf.is_empty() {
let fd = unsafe { httpd_req_to_sockfd(self.0) };
let len = unsafe { esp_idf_sys::write(fd, buf.as_ptr() as *const _, buf.len()) };
let len = unsafe { crate::sys::write(fd, buf.as_ptr() as *const _, buf.len()) };

Ok(len as _)
} else {
Expand Down Expand Up @@ -908,7 +908,7 @@ pub mod ws {
use embedded_svc::utils::mutex::{Condvar, Mutex};
use embedded_svc::ws::callback_server::*;

use esp_idf_sys::*;
use crate::sys::*;

use crate::private::common::Newtype;
use crate::private::cstr::to_cstring_arg;
Expand Down Expand Up @@ -1247,7 +1247,7 @@ pub mod ws {
..Default::default()
};

esp!(unsafe { esp_idf_sys::httpd_register_uri_handler(self.sd, &conf) })?;
esp!(unsafe { crate::sys::httpd_register_uri_handler(self.sd, &conf) })?;

{
let mut all_close_handlers = CLOSE_HANDLERS.lock();
Expand Down Expand Up @@ -1330,10 +1330,10 @@ pub mod ws {
}

pub mod asyncify {
use crate::sys::EspError;
use embedded_svc::utils::asyncify::ws::server::{
AsyncAcceptor, AsyncReceiver, AsyncSender, Processor,
};
use esp_idf_sys::EspError;

pub type EspHttpWsProcessor<const N: usize, const F: usize> =
Processor<N, F, crate::private::mutex::RawCondvar, super::EspHttpWsConnection>;
Expand Down
Loading

0 comments on commit e8b7df7

Please sign in to comment.