Skip to content

Commit

Permalink
Merge branch 'esp-rs:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo13C authored Jan 2, 2025
2 parents 0b9d2f3 + 776b5cc commit 513b18a
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 43 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci-esp-idf-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- xtensa-esp32s2-espidf
- xtensa-esp32s3-espidf
idf-version:
- v5.3.2
- release/v5.3
- release/v5.4
- master
steps:
Expand Down Expand Up @@ -55,28 +55,28 @@ jobs:
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo clippy --features nightly,experimental --no-deps --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort -- -Dwarnings

- name: Build | Compile
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Build | Compile, experimental, nightly, no_std
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --no-default-features --features nightly,experimental --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Build | Compile, experimental, nightly, alloc
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --no-default-features --features nightly,experimental,alloc --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Setup | ldproxy
Expand All @@ -87,11 +87,10 @@ jobs:
chmod a+x $HOME/.cargo/bin/ldproxy
- name: Build | Examples
if: matrix.target != 'riscv32imac-esp-espidf'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }} ${{ '-C default-linker-libraries' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
WIFI_SSID: "ssid"
WIFI_PASS: "pass"
ESP_DEVICE_IP: "192.168.1.250"
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:
- v4.4.8
- v5.1.2
- v5.2.3
# Commented out until this gets resolved:
# https://github.com/espressif/esp-idf/issues/14174#issuecomment-2558527855
# - v5.3.2
- v5.3.2
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
Expand All @@ -53,34 +51,39 @@ jobs:
default: true

- name: Build | Fmt Check
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
run: cargo fmt -- --check

- name: Build | Clippy
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo clippy --features nightly,experimental --no-deps --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort -- -Dwarnings

- name: Build | Compile
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Build | Compile, experimental, nightly, no_std
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --no-default-features --features nightly,experimental --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Build | Compile, experimental, nightly, alloc
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
run: cargo build --no-default-features --features nightly,experimental,alloc --target ${{ matrix.target }} -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort

- name: Setup | ldproxy
Expand All @@ -91,11 +94,11 @@ jobs:
chmod a+x $HOME/.cargo/bin/ldproxy
- name: Build | Examples
if: matrix.target != 'riscv32imac-esp-espidf'
if: matrix.target != 'riscv32imac-esp-espidf' || matrix.idf-version != 'v4.4.8'
env:
ESP_IDF_VERSION: ${{ matrix.idf-version }}
ESP_IDF_SDKCONFIG_DEFAULTS: "${{ github.workspace }}/.github/configs/sdkconfig.defaults"
RUSTFLAGS: "${{ startsWith(matrix.idf-version, 'v5') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }} ${{ '-C default-linker-libraries' }}"
RUSTFLAGS: "${{ !startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time64' || startsWith(matrix.idf-version, 'v4') && '--cfg espidf_time32' }}"
WIFI_SSID: "ssid"
WIFI_PASS: "pass"
ESP_DEVICE_IP: "192.168.1.250"
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.50.0] - 2025-01-02

### Deprecated
- `EspFirmwareInfoLoader` use `EspFirmwareInfoLoad` instead
Expand All @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Expose src_addr and dst_addr in espnow recv cb (#525)

### Added
- Compatibility with ESP-IDF v5.3.X
- feat(eth): Implement alternative polling mode (#452)
- SD Card driver; SD Card host drivers (SPI and SDMMC) (#454)
- Make EspAsyncMqttClient::wrap public. (#462)
Expand All @@ -34,6 +35,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add option to specify initial caps for the MQTT async adaptor vectors
- Allow using esp timer with skip_unhandled_events (#526)
- OTA - Implements a new type `EspFirmwareInfoLoad` that has a reduced memory consumption (#531)
- Added set_promiscuous function in EthDriver (#246)
- Added set_promiscuous, is_promiscuous functions in WifiDriver (#246)
- Blocking and buffered StdIo (#541) - i.e. easy reading/input from `std::io::stdin`
- Added source_ipv4, source_ipv6 function in EspHttpRawConnection (#538)

### Fixed
- The alloc::Vec version stomps the scan state from Done to Idle. (#459)
Expand All @@ -52,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bugfix: crash on MQTT async client restart
- Fix missing newline if CONFIG_LOG_COLORS=n is set (#521)
- gatekeep mdns ipv6 behind feature flag (#523)
- Fix emac_rx stack overflow when log verbosity is increased (#535)

## [0.49.1] - 2024-07-09
### Fixed
Expand Down
13 changes: 4 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "esp-idf-svc"
version = "0.49.1"
version = "0.50.0"
authors = ["Ivan Markov <[email protected]>"]
edition = "2021"
resolver = "2"
Expand All @@ -18,11 +18,6 @@ rust-version = "1.77"
[lib]
harness = false

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

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

Expand Down Expand Up @@ -52,18 +47,18 @@ log = { version = "0.4", default-features = false }
uncased = { version = "0.9.7", default-features = false }
embedded-hal-async = { version = "1", default-features = false }
embedded-svc = { version = "0.28", default-features = false }
esp-idf-hal = { version = "0.44", default-features = false }
esp-idf-hal = { version = "0.45", default-features = false }
embassy-time-driver = { version = "0.1", optional = true, features = ["tick-hz-1_000_000"] }
embassy-futures = "0.1"
embedded-storage = { version = "0.3", optional = true }
futures-io = { version = "0.3", optional = true }

[build-dependencies]
embuild = "0.32"
embuild = "0.33"

[dev-dependencies]
anyhow = "1"
esp-idf-sys = { version = "0.35", features = ["binstart"] }
esp-idf-sys = { version = "0.36", features = ["binstart"] }
futures = "0.3"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false, features = ["alloc"] }
Expand Down
52 changes: 52 additions & 0 deletions examples/stdin_read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! A simple example of how to read from the ESP-IDF console
use esp_idf_hal::gpio::AnyIOPin;
use esp_idf_svc::hal::peripherals::Peripherals;
use esp_idf_svc::hal::uart::UartDriver;
use esp_idf_svc::io::vfs::BlockingStdIo;
use esp_idf_svc::sys::EspError;

use std::io::Write;

fn main() -> Result<(), EspError> {
esp_idf_svc::sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();

// NOTE: This example assumes that the console configuration is not altered by the user
// by using non-default `CONFIG_ESP_CONSOLE_*` settings in `sdkconfig.defaults`
//
// The default configuration is:
// - UART0
// - 115200 baud rate
// - 8N1
// - RTS/CTS disabled
// - No flow control
// - The default TX/RX pins for UART0 (1 & 3 for ESP32, 17 & 16 for ESP32-S2 and so on.)

let peripherals = Peripherals::take()?;

let uart_driver = UartDriver::new(
peripherals.uart0,
// Change this to the correct UART0 TX pin for your MCU if you are not using esp32
peripherals.pins.gpio1,
// Change this to the correct UART0 RX pin for your MCU if you are not using esp32
peripherals.pins.gpio3,
Option::<AnyIOPin>::None,
Option::<AnyIOPin>::None,
&Default::default(),
)?;

// Keep it around till the end of your program
// If you drop it, the console will go back to non-blocking UART mode
let _blocking_io = BlockingStdIo::uart(uart_driver)?;

loop {
print!("Enter a message: ");
std::io::stdout().flush().unwrap();

let mut buffer = String::new();
std::io::stdin().read_line(&mut buffer).unwrap();

println!("You entered: {}", buffer);
}
}
3 changes: 2 additions & 1 deletion src/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ where
#[cfg(esp32c2)]
version_num: unsafe { crate::sys::esp_ble_get_chip_rev_version() },
#[cfg(esp32c6)]
version_num: unsafe { crate::sys::efuse_hal_chip_revision() },
#[allow(clippy::unnecessary_cast)]
version_num: unsafe { crate::sys::efuse_hal_chip_revision() as _ },
#[cfg(not(esp32c2))]
cpu_freq_mhz: crate::sys::CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ as _,
ignore_wl_for_direct_adv: 0,
Expand Down
25 changes: 24 additions & 1 deletion src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,29 @@ impl<'d, T> EthDriver<'d, T> {
Ok(())
}

/// Enables or disables promiscuous mode for the [`EthDriver`].
///
/// When promiscuous mode is enabled, the driver captures all Ethernet frames
/// on the network, regardless of their destination MAC address. This is useful for
/// debugging or monitoring purposes.
pub fn set_promiscuous(&mut self, state: bool) -> Result<(), EspError> {
esp!(unsafe {
esp_eth_ioctl(
self.handle(),
esp_eth_io_cmd_t_ETH_CMD_S_PROMISCUOUS,
&raw const state as *mut _,
)
})?;

if state {
log::info!("Driver set in promiscuous mode");
} else {
log::info!("Driver set in non-promiscuous mode");
}

Ok(())
}

fn eth_default_config(mac: *mut esp_eth_mac_t, phy: *mut esp_eth_phy_t) -> esp_eth_config_t {
esp_eth_config_t {
mac,
Expand Down Expand Up @@ -1071,7 +1094,7 @@ impl<'d, T> EthDriver<'d, T> {
fn eth_mac_default_config(_mdc: i32, _mdio: i32) -> eth_mac_config_t {
eth_mac_config_t {
sw_reset_timeout_ms: 100,
rx_task_stack_size: 2048,
rx_task_stack_size: 4096,
rx_task_prio: 15,
flags: 0,
}
Expand Down
60 changes: 60 additions & 0 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
use core::cell::UnsafeCell;
use core::fmt::Debug;
use core::marker::PhantomData;
#[cfg(esp_idf_lwip_ipv4)]
use core::net::Ipv4Addr;
#[cfg(esp_idf_lwip_ipv6)]
use core::net::Ipv6Addr;
use core::sync::atomic::{AtomicBool, Ordering};
use core::time::*;
use core::{ffi, ptr};
Expand Down Expand Up @@ -801,6 +805,62 @@ impl EspHttpRawConnection<'_> {

Ok(())
}

/// Retrieves the source IPv4 of the request.
///
/// The IPv4 is retrieved using the underlying session socket.
#[cfg(esp_idf_lwip_ipv4)]
pub fn source_ipv4(&self) -> Result<Ipv4Addr, EspError> {
unsafe {
let sockfd = httpd_req_to_sockfd(self.handle());

if sockfd == -1 {
return Err(EspError::from_infallible::<ESP_FAIL>());
}

let mut addr = sockaddr_in {
sin_len: core::mem::size_of::<sockaddr_in>() as _,
sin_family: AF_INET as _,
..Default::default()
};

esp!(lwip_getpeername(
sockfd,
&mut addr as *mut _ as *mut _,
&mut core::mem::size_of::<sockaddr_in>() as *mut _ as *mut _,
))?;

Ok(Ipv4Addr::from(u32::from_be(addr.sin_addr.s_addr)))
}
}

/// Retrieves the source IPv6 of the request.
///
/// The IPv6 is retrieved using the underlying session socket.
#[cfg(esp_idf_lwip_ipv6)]
pub fn source_ipv6(&self) -> Result<Ipv6Addr, EspError> {
unsafe {
let sockfd = httpd_req_to_sockfd(self.handle());

if sockfd == -1 {
return Err(EspError::from_infallible::<ESP_FAIL>());
}

let mut addr = sockaddr_in6 {
sin6_len: core::mem::size_of::<sockaddr_in6>() as _,
sin6_family: AF_INET6 as _,
..Default::default()
};

esp!(lwip_getpeername(
sockfd,
&mut addr as *mut _ as *mut _,
&mut core::mem::size_of::<sockaddr_in6>() as *mut _ as *mut _,
))?;

Ok(Ipv6Addr::from(addr.sin6_addr.un.u8_addr))
}
}
}

impl RawHandle for EspHttpRawConnection<'_> {
Expand Down
Loading

0 comments on commit 513b18a

Please sign in to comment.