Skip to content

Commit

Permalink
Esp32c2 coex (esp-rs#347)
Browse files Browse the repository at this point in the history
* Support COEX on ESP32-C2

* Fix script

* Remove WiFi scan from COEX example
  • Loading branch information
bjoernQ committed May 23, 2024
1 parent ad42075 commit 536f6a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> Result<(), String> {
"#
);
}
#[cfg(all(feature = "coex", any(feature = "esp32s2", feature = "esp32c2")))]
#[cfg(all(feature = "coex", any(feature = "esp32s2")))]
{
panic!(
r#"
Expand Down
21 changes: 6 additions & 15 deletions esp-wifi/examples/coex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use esp_wifi::{

use embedded_io::*;
use embedded_svc::ipv4::Interface;
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi};
use embedded_svc::wifi::{ClientConfiguration, Configuration, Wifi};

use esp_backtrace as _;
use esp_println::{print, println};
use esp_wifi::initialize;
use esp_wifi::wifi::{utils::create_network_interface, WifiError};
use esp_wifi::wifi::utils::create_network_interface;
use hal::{clock::ClockControl, Rng};
use hal::{peripherals::Peripherals, prelude::*};
use smoltcp::{iface::SocketStorage, wire::IpAddress, wire::Ipv4Address};
Expand Down Expand Up @@ -59,7 +59,7 @@ fn main() -> ! {
let wifi = peripherals.WIFI;
let bluetooth = peripherals.BT;

let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let mut socket_set_entries: [SocketStorage; 2] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiStaDevice, &mut socket_set_entries).unwrap();
let wifi_stack = WifiStack::new(iface, device, sockets, current_millis);
Expand All @@ -74,15 +74,6 @@ fn main() -> ! {

controller.start().unwrap();
println!("is wifi started: {:?}", controller.is_started());

println!("Start Wifi Scan");
let res: Result<(heapless::Vec<AccessPointInfo, 10>, usize), WifiError> = controller.scan_n();
if let Ok((res, _count)) = res {
for ap in res {
println!("{:?}", ap);
}
}

println!("{:?}", controller.get_capabilities());
println!("wifi_connect {:?}", controller.connect());

Expand Down Expand Up @@ -138,8 +129,8 @@ fn main() -> ! {

println!("Start busy loop on main");

let mut rx_buffer = [0u8; 1536];
let mut tx_buffer = [0u8; 1536];
let mut rx_buffer = [0u8; 128];
let mut tx_buffer = [0u8; 128];
let mut socket = wifi_stack.get_socket(&mut rx_buffer, &mut tx_buffer);

loop {
Expand All @@ -157,7 +148,7 @@ fn main() -> ! {

let wait_end = current_millis() + 20 * 1000;
loop {
let mut buffer = [0u8; 512];
let mut buffer = [0u8; 128];
if let Ok(len) = socket.read(&mut buffer) {
let to_print = unsafe { core::str::from_utf8_unchecked(&buffer[..len]) };
print!("{}", to_print);
Expand Down
1 change: 1 addition & 0 deletions esp-wifi/src/ble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) unsafe extern "C" fn malloc(size: u32) -> *mut crate::binary::c_types
crate::compat::malloc::malloc(size as usize).cast()
}

#[cfg(any(esp32, esp32c3, esp32s3))]
pub(crate) unsafe extern "C" fn malloc_internal(size: u32) -> *mut crate::binary::c_types::c_void {
crate::compat::malloc::malloc(size as usize).cast()
}
Expand Down
5 changes: 4 additions & 1 deletion esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub enum InternalWifiError {
EspErrWifiTxDisallow = 0x3016,
}

#[cfg(all(coex, any(esp32, esp32c3, esp32c6, esp32s3)))]
#[cfg(all(coex, any(esp32, esp32c2, esp32c3, esp32c6, esp32s3)))]
static mut G_COEX_ADAPTER_FUNCS: coex_adapter_funcs_t = coex_adapter_funcs_t {
_version: include::COEX_ADAPTER_VERSION as i32,
_task_yield_from_isr: Some(task_yield_from_isr),
Expand Down Expand Up @@ -339,6 +339,9 @@ static mut G_COEX_ADAPTER_FUNCS: coex_adapter_funcs_t = coex_adapter_funcs_t {
_int_disable: Some(wifi_int_disable),
#[cfg(esp32)]
_int_enable: Some(wifi_int_restore),

#[cfg(esp32c2)]
_slowclk_cal_get: Some(slowclk_cal_get),
};

#[cfg(coex)]
Expand Down

0 comments on commit 536f6a9

Please sign in to comment.