Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework initialization #194

Merged
merged 9 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,28 @@ esp32s3 = [ "esp32s3-hal", "esp-wifi-sys/esp32s3", "esp-hal-common/esp32s3" ]
esp32s2 = [ "esp32s2-hal", "esp-wifi-sys/esp32s2", "esp-hal-common/esp32s2" ]

# async features
esp32c3-async = [ "esp32c3-hal/embassy", "esp32c3-hal/embassy-time-timg0", "async" ]
esp32c2-async = [ "esp32c2-hal/embassy", "esp32c2-hal/embassy-time-timg0", "async" ]
esp32c6-async = [ "esp32c6-hal/embassy", "esp32c6-hal/embassy-time-timg0", "async" ]
esp32-async = [ "esp32-hal/embassy", "esp32-hal/embassy-time-timg0", "async" ]
esp32s2-async = [ "esp32s2-hal/embassy", "esp32s2-hal/embassy-time-timg0", "async" ]
esp32s3-async = [ "esp32s3-hal/embassy", "esp32s3-hal/embassy-time-timg0", "async" ]
async = [ "dep:embassy-sync", "dep:embassy-futures", "embedded-io/async"]
async = [
"dep:embassy-sync",
"dep:embassy-futures",
"embedded-io/async",
"esp32c3-hal?/embassy",
"esp32c3-hal?/embassy-time-timg0",
"esp32c2-hal?/embassy",
"esp32c2-hal?/embassy-time-timg0",
"esp32c6-hal?/embassy",
"esp32c6-hal?/embassy-time-timg0",
"esp32-hal?/embassy",
"esp32-hal?/embassy-time-timg0",
"esp32s2-hal?/embassy",
"esp32s2-hal?/embassy-time-timg0",
"esp32s3-hal?/embassy",
"esp32s3-hal?/embassy-time-timg0",
]

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

# misc features
coex = []
wifi-logs = []
dump-packets = []
utils = [ "dep:smoltcp" ]
Expand Down
27 changes: 17 additions & 10 deletions esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@ fn main() -> Result<(), String> {
Err(_err) => (),
}

let features: u8 = cfg!(feature = "wifi") as u8 + cfg!(feature = "ble") as u8;
#[cfg(feature = "esp32")]
println!("cargo:rustc-cfg=esp32");

if features == 0 {
return Err("You need to use feature `wifi` and/or `ble`".to_string());
}
#[cfg(feature = "esp32c2")]
println!("cargo:rustc-cfg=esp32c2");

if cfg!(feature = "esp32s2") && cfg!(feature = "ble") {
return Err("BLE is not supported for ESP32-S2".into());
}
#[cfg(feature = "esp32c3")]
println!("cargo:rustc-cfg=esp32c3");

if features >= 2 {
println!("cargo:rustc-cfg=coex");
}
#[cfg(feature = "esp32c6")]
println!("cargo:rustc-cfg=esp32c6");

#[cfg(feature = "esp32s2")]
println!("cargo:rustc-cfg=esp32s2");

#[cfg(feature = "esp32s3")]
println!("cargo:rustc-cfg=esp32s3");

#[cfg(feature = "coex")]
println!("cargo:rustc-cfg=coex");

Ok(())
}
Expand Down
34 changes: 17 additions & 17 deletions esp-wifi/src/ble/btdm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ use crate::{
timer::yield_task,
};

#[cfg(feature = "esp32")]
#[cfg(esp32)]
use esp32_hal as hal;
#[cfg(feature = "esp32c3")]
#[cfg(esp32c3)]
use esp32c3_hal as hal;
#[cfg(feature = "esp32s3")]
#[cfg(esp32s3)]
use esp32s3_hal as hal;

use hal::macros::ram;

#[cfg_attr(feature = "esp32c3", path = "os_adapter_esp32c3.rs")]
#[cfg_attr(feature = "esp32s3", path = "os_adapter_esp32s3.rs")]
#[cfg_attr(feature = "esp32", path = "os_adapter_esp32.rs")]
#[cfg_attr(esp32c3, path = "os_adapter_esp32c3.rs")]
#[cfg_attr(esp32s3, path = "os_adapter_esp32s3.rs")]
#[cfg_attr(esp32, path = "os_adapter_esp32.rs")]
pub(crate) mod ble_os_adapter_chip_specific;

static BT_RECEIVE_QUEUE: Mutex<RefCell<SimpleQueue<ReceivedPacket, 10>>> =
Expand All @@ -49,10 +49,10 @@ extern "C" {
fn btdm_osi_funcs_register(osi_funcs: *const ()) -> i32;
fn btdm_controller_get_compile_version() -> *const u8;

#[cfg(any(feature = "esp32c3", feature = "esp32s3"))]
#[cfg(any(esp32c3, esp32s3))]
fn btdm_controller_init(config_opts: *const esp_bt_controller_config_t) -> i32;

#[cfg(feature = "esp32")]
#[cfg(esp32)]
fn btdm_controller_init(
config_mask: u32,
config_opts: *const esp_bt_controller_config_t,
Expand Down Expand Up @@ -326,10 +326,10 @@ unsafe extern "C" fn is_in_isr() -> i32 {

#[ram]
unsafe extern "C" fn cause_sw_intr_to_core(_core: i32, _intr_no: i32) -> i32 {
#[cfg(any(feature = "esp32c3", feature = "esp32s3"))]
#[cfg(any(esp32c3, esp32s3))]
todo!("cause_sw_intr_to_core is not implemented for this target");

#[cfg(feature = "esp32")]
#[cfg(esp32)]
{
log::trace!("cause_sw_intr_to_core {} {}", _core, _intr_no);
let intr = 1 << _intr_no;
Expand Down Expand Up @@ -423,22 +423,22 @@ unsafe extern "C" fn read_efuse_mac(mac: *const ()) -> i32 {
crate::common_adapter::read_mac(mac as *mut _, 2)
}

#[cfg(feature = "esp32")]
#[cfg(esp32)]
unsafe extern "C" fn set_isr13(n: i32, handler: unsafe extern "C" fn(), arg: *const ()) -> i32 {
ble_os_adapter_chip_specific::set_isr(n, handler, arg)
}

#[cfg(feature = "esp32")]
#[cfg(esp32)]
unsafe extern "C" fn interrupt_l3_disable() {
// log::info!("unimplemented interrupt_l3_disable");
}

#[cfg(feature = "esp32")]
#[cfg(esp32)]
unsafe extern "C" fn interrupt_l3_restore() {
// log::info!("unimplemented interrupt_l3_restore");
}

#[cfg(feature = "esp32")]
#[cfg(esp32)]
unsafe extern "C" fn custom_queue_create(
_len: u32,
_item_size: u32,
Expand Down Expand Up @@ -486,10 +486,10 @@ pub(crate) fn ble_init() {

ble_os_adapter_chip_specific::disable_sleep_mode();

#[cfg(any(feature = "esp32c3", feature = "esp32s3"))]
#[cfg(any(esp32c3, esp32s3))]
let res = btdm_controller_init(&mut cfg as *mut esp_bt_controller_config_t);

#[cfg(feature = "esp32")]
#[cfg(esp32)]
let res = btdm_controller_init(
(1 << 3) | (1 << 4),
&mut cfg as *mut esp_bt_controller_config_t,
Expand All @@ -506,7 +506,7 @@ pub(crate) fn ble_init() {

crate::common_adapter::chip_specific::phy_enable();

#[cfg(feature = "esp32")]
#[cfg(esp32)]
{
extern "C" {
fn btdm_rf_bb_init_phase2();
Expand Down
13 changes: 13 additions & 0 deletions esp-wifi/src/ble/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use embedded_io::{
};
use esp_hal_common::peripheral::{Peripheral, PeripheralRef};

use crate::EspWifiInitialization;

use super::{read_hci, read_next, send_hci};

pub struct BleConnector<'d> {
Expand All @@ -12,8 +14,13 @@ pub struct BleConnector<'d> {

impl<'d> BleConnector<'d> {
pub fn new(
init: &EspWifiInitialization,
device: impl Peripheral<P = esp_hal_common::radio::Bluetooth> + 'd,
) -> BleConnector<'d> {
if !init.is_ble() {
panic!("Not initialized for BLE use");
}

Self {
_device: device.into_ref(),
}
Expand Down Expand Up @@ -77,6 +84,7 @@ pub mod asynch {
use core::task::Poll;

use crate::ble::ble::have_hci_read_data;
use crate::EspWifiInitialization;

use super::BleConnectorError;
use super::{read_hci, send_hci};
Expand All @@ -97,8 +105,13 @@ pub mod asynch {

impl<'d> BleConnector<'d> {
pub fn new(
init: &EspWifiInitialization,
device: impl Peripheral<P = esp_hal_common::radio::Bluetooth> + 'd,
) -> BleConnector<'d> {
if !init.is_ble() {
panic!("Not initialized for BLE use");
}

Self {
_device: device.into_ref(),
}
Expand Down
8 changes: 4 additions & 4 deletions esp-wifi/src/ble/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#[cfg(any(feature = "esp32", feature = "esp32c3", feature = "esp32s3"))]
#[cfg(any(esp32, esp32c3, esp32s3))]
pub(crate) mod btdm;

#[cfg(any(feature = "esp32c2"))]
#[cfg(any(esp32c2))]
pub(crate) mod npl;

use core::mem::MaybeUninit;

#[cfg(any(feature = "esp32", feature = "esp32c3", feature = "esp32s3"))]
#[cfg(any(esp32, esp32c3, esp32s3))]
use self::btdm as ble;

#[cfg(any(feature = "esp32c2"))]
#[cfg(any(esp32c2))]
use self::npl as ble;

pub(crate) use ble::ble_init;
Expand Down
2 changes: 1 addition & 1 deletion esp-wifi/src/ble/npl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::compat::common::StrBuf;
use crate::compat::queue::SimpleQueue;
use crate::timer::yield_task;

#[cfg_attr(feature = "esp32c2", path = "os_adapter_esp32c2.rs")]
#[cfg_attr(esp32c2, path = "os_adapter_esp32c2.rs")]
pub(crate) mod ble_os_adapter_chip_specific;

const TIME_FOREVER: u32 = u32::MAX;
Expand Down
36 changes: 18 additions & 18 deletions esp-wifi/src/common_adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ use log::trace;

use crate::compat::common::*;

#[cfg(feature = "esp32")]
#[cfg(esp32)]
use esp32_hal as hal;
#[cfg(feature = "esp32c2")]
#[cfg(esp32c2)]
use esp32c2_hal as hal;
#[cfg(feature = "esp32c3")]
#[cfg(esp32c3)]
use esp32c3_hal as hal;
#[cfg(feature = "esp32c6")]
#[cfg(esp32c6)]
use esp32c6_hal as hal;
#[cfg(feature = "esp32s2")]
#[cfg(esp32s2)]
use esp32s2_hal as hal;
#[cfg(feature = "esp32s3")]
#[cfg(esp32s3)]
use esp32s3_hal as hal;

use hal::system::RadioClockControl;
use hal::Rng;

use hal::macros::ram;

#[cfg_attr(feature = "esp32c3", path = "common_adapter_esp32c3.rs")]
#[cfg_attr(feature = "esp32c2", path = "common_adapter_esp32c2.rs")]
#[cfg_attr(feature = "esp32c6", path = "common_adapter_esp32c6.rs")]
#[cfg_attr(feature = "esp32", path = "common_adapter_esp32.rs")]
#[cfg_attr(feature = "esp32s3", path = "common_adapter_esp32s3.rs")]
#[cfg_attr(feature = "esp32s2", path = "common_adapter_esp32s2.rs")]
#[cfg_attr(esp32c3, path = "common_adapter_esp32c3.rs")]
#[cfg_attr(esp32c2, path = "common_adapter_esp32c2.rs")]
#[cfg_attr(esp32c6, path = "common_adapter_esp32c6.rs")]
#[cfg_attr(esp32, path = "common_adapter_esp32.rs")]
#[cfg_attr(esp32s3, path = "common_adapter_esp32s3.rs")]
#[cfg_attr(esp32s2, path = "common_adapter_esp32s2.rs")]
pub(crate) mod chip_specific;

#[cfg_attr(feature = "esp32c3", path = "phy_init_data_esp32c3.rs")]
#[cfg_attr(feature = "esp32c2", path = "phy_init_data_esp32c2.rs")]
#[cfg_attr(feature = "esp32c6", path = "phy_init_data_esp32c6.rs")]
#[cfg_attr(feature = "esp32", path = "phy_init_data_esp32.rs")]
#[cfg_attr(feature = "esp32s3", path = "phy_init_data_esp32s3.rs")]
#[cfg_attr(feature = "esp32s2", path = "phy_init_data_esp32s2.rs")]
#[cfg_attr(esp32c3, path = "phy_init_data_esp32c3.rs")]
#[cfg_attr(esp32c2, path = "phy_init_data_esp32c2.rs")]
#[cfg_attr(esp32c6, path = "phy_init_data_esp32c6.rs")]
#[cfg_attr(esp32, path = "phy_init_data_esp32.rs")]
#[cfg_attr(esp32s3, path = "phy_init_data_esp32s3.rs")]
#[cfg_attr(esp32s2, path = "phy_init_data_esp32s2.rs")]
pub(crate) mod phy_init_data;

pub(crate) static mut RANDOM_GENERATOR: Option<Rng> = None;
Expand Down
Loading