Integrate 802.15.4 into esp-radio more (#4003)

* Integrate 802.15.4 into esp-radio more

* Fix H2

* fmt

* Fix

* Deny combination of 802.15.4 and Wi-Fi
This commit is contained in:
Björn Quentin 2025-08-29 15:10:49 +02:00 committed by GitHub
parent 0d3771cf3a
commit 854941f1b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 38 deletions

View File

@ -147,7 +147,8 @@ coex = []
## Enable WiFi channel state information. See [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv4N18wifi_init_config_t10csi_enableE),
csi = []
## Use IEEE 802.15.4
## Use IEEE 802.15.4.
## Cannot be used together with Wi-Fi.
ieee802154 = ["dep:byte", "dep:ieee802154"]
#! ### Ecosystem Feature Flags
@ -176,6 +177,10 @@ unstable = []
## For development you can enable the `unstable` and the chip feature by adding esp-radio as a dev-dependency.
requires-unstable = []
# These features are considered private and unstable. They are not covered by
# semver guarantees and may change or be removed without notice.
__docs_build = []
[package.metadata.docs.rs]
features = [
"esp32c3",

View File

@ -39,6 +39,11 @@ fn main() -> Result<(), Box<dyn Error>> {
);
}
#[cfg(not(feature = "__docs_build"))]
if cfg!(feature = "ieee802154") && (cfg!(feature = "wifi") || cfg!(feature = "wifi-eap")) {
panic!("\n\n802.15.4 and Wi-Fi won't work together\n\n");
}
if (cfg!(feature = "ble")
|| cfg!(feature = "coex")
|| cfg!(feature = "csi")

View File

@ -347,6 +347,13 @@ pub(crate) unsafe fn phy_disable_clock() {
}
pub(crate) fn phy_calibrate() {
// Set PHY whether in combo module
// For comode mode, phy enable will be not in WiFi RX state
#[cfg(not(any(esp32s2, esp32h2)))]
unsafe {
esp_wifi_sys::include::phy_init_param_set(1);
}
let phy_version = unsafe { get_phy_version_str() };
trace!("phy_version {}", unsafe { str_from_c(phy_version) });

View File

@ -15,12 +15,10 @@
//! [IEEE 802.15.4]: https://en.wikipedia.org/wiki/IEEE_802.15.4
//! [esp-openthread]: https://github.com/esp-rs/esp-openthread
use alloc::vec::Vec;
use core::cell::RefCell;
use byte::{BytesExt, TryRead};
use critical_section::Mutex;
use esp_config::*;
use esp_hal::{clock::PhyClockGuard, peripherals::IEEE802154};
use ieee802154::mac::{self, FooterMode, FrameSerDesContext};
@ -71,14 +69,6 @@ impl From<byte::Error> for Error {
}
}
struct QueueConfig {
rx_queue_size: usize,
}
const CONFIG: QueueConfig = QueueConfig {
rx_queue_size: esp_config_int!(usize, "ESP_RADIO_CONFIG_IEEE802154_RX_QUEUE_SIZE"),
};
/// IEEE 802.15.4 driver configuration
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Config {

View File

@ -9,13 +9,10 @@ use esp_hal::{
peripherals::IEEE802154,
};
use esp_wifi_sys::include::{
esp_phy_calibration_data_t,
esp_phy_calibration_mode_t_PHY_RF_CAL_FULL,
ieee802154_coex_event_t,
ieee802154_coex_event_t_IEEE802154_IDLE,
ieee802154_coex_event_t_IEEE802154_LOW,
ieee802154_coex_event_t_IEEE802154_MIDDLE,
register_chipv7_phy,
};
use super::{
@ -30,22 +27,23 @@ use super::{
pib::*,
};
const PHY_ENABLE_VERSION_PRINT: u32 = 1;
const PHY_ENABLE_VERSION_PRINT: u8 = 1;
const RX_QUEUE_SIZE: usize =
esp_config::esp_config_int!(usize, "ESP_RADIO_CONFIG_IEEE802154_RX_QUEUE_SIZE");
static mut RX_BUFFER: [u8; FRAME_SIZE] = [0u8; FRAME_SIZE];
static RX_QUEUE: Mutex<RefCell<Queue<RawReceived>>> = Mutex::new(RefCell::new(Queue::new()));
static STATE: Mutex<RefCell<Ieee802154State>> = Mutex::new(RefCell::new(Ieee802154State::Idle));
unsafe extern "C" {
fn bt_bb_v2_init_cmplx(print_version: u32); // from libbtbb.a
fn bt_bb_v2_init_cmplx(print_version: u8); // from libbtbb.a
fn bt_bb_set_zb_tx_on_delay(time: u16); // from libbtbb.a
fn esp_coex_ieee802154_ack_pti_set(event: ieee802154_coex_event_t); // from ???
fn esp_coex_ieee802154_txrx_pti_set(event: ieee802154_coex_event_t); // from ???
fn phy_version_print(); // from libphy.a
}
#[derive(Debug, Clone, Copy, PartialEq)]
@ -80,31 +78,16 @@ pub(crate) fn esp_ieee802154_enable(mut radio: IEEE802154<'_>) -> PhyClockGuard<
let phy_clock_guard = radio.enable_phy_clock();
radio.enable_modem_clock(true);
esp_phy_enable();
unsafe {
crate::common_adapter::chip_specific::phy_enable();
}
esp_btbb_enable();
ieee802154_mac_init();
unsafe { phy_version_print() }; // libphy.a
info!("date={:x}", mac_date());
phy_clock_guard
}
fn esp_phy_enable() {
unsafe {
let mut calibration_data = esp_phy_calibration_data_t {
version: [0u8; 4],
mac: [0u8; 6],
opaque: [0u8; 1894],
};
register_chipv7_phy(
core::ptr::null(),
&mut calibration_data as *mut esp_phy_calibration_data_t,
esp_phy_calibration_mode_t_PHY_RF_CAL_FULL,
);
}
}
fn esp_btbb_enable() {
unsafe { bt_bb_v2_init_cmplx(PHY_ENABLE_VERSION_PRINT) };
}
@ -390,7 +373,7 @@ fn ZB_MAC() {
);
critical_section::with(|cs| {
let mut queue = RX_QUEUE.borrow_ref_mut(cs);
if queue.len() <= crate::CONFIG.rx_queue_size {
if queue.len() <= RX_QUEUE_SIZE {
let item = RawReceived {
data: RX_BUFFER,
channel: freq_to_channel(freq()),

View File

@ -219,11 +219,16 @@ impl Package {
if config.contains("bt") {
features.push("ble".to_owned());
}
if config.contains("ieee802154") {
features.push("ieee802154".to_owned());
// allow wifi + 802.15.4
features.push("__docs_build".to_owned());
}
if config.contains("wifi") && config.contains("bt") {
features.push("coex".to_owned());
}
if features.iter().any(|f| {
f == "csi" || f == "ble" || f == "esp-now" || f == "sniffer" || f == "coex"
f == "csi" || f == "ble" || f == "esp-now" || f == "sniffer" || f == "coex" || f == "ieee802154"
}) {
features.push("unstable".to_owned());
}