From 95732adfe51e67269fd3785ffcf38c55407490f8 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Tue, 11 Apr 2023 10:50:35 +0200 Subject: [PATCH] Use types from `core::ffi::` --- esp-wifi-sys/src/c_types.rs | 24 +++++++++---------- esp-wifi/src/ble/btdm.rs | 10 +++++++- esp-wifi/src/ble/npl.rs | 2 +- .../common_adapter/common_adapter_esp32c2.rs | 5 +++- .../common_adapter/common_adapter_esp32c3.rs | 5 +++- .../common_adapter/common_adapter_esp32c6.rs | 5 +++- esp-wifi/src/common_adapter/mod.rs | 2 +- esp-wifi/src/wifi/mod.rs | 2 +- esp-wifi/src/wifi/os_adapter.rs | 10 ++++---- 9 files changed, 41 insertions(+), 24 deletions(-) diff --git a/esp-wifi-sys/src/c_types.rs b/esp-wifi-sys/src/c_types.rs index 4d885e45..48681fc9 100644 --- a/esp-wifi-sys/src/c_types.rs +++ b/esp-wifi-sys/src/c_types.rs @@ -5,17 +5,17 @@ dead_code )] -pub type c_uint = u32; -pub type c_int = i32; -pub type c_ulonglong = u32; -pub type c_longlong = i32; -pub type c_uchar = u8; +pub type c_uint = core::ffi::c_uint; +pub type c_int = core::ffi::c_int; +pub type c_ulonglong = core::ffi::c_ulonglong; +pub type c_longlong = core::ffi::c_longlong; +pub type c_uchar = core::ffi::c_uchar; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_schar = i8; -pub type c_char = u8; -pub type c_long = i32; -pub type c_ulong = u32; +pub type c_short = core::ffi::c_short; +pub type c_ushort = core::ffi::c_ushort; +pub type c_schar = core::ffi::c_schar; +pub type c_char = core::ffi::c_char; +pub type c_long = core::ffi::c_long; +pub type c_ulong = core::ffi::c_ulong; -pub enum c_void {} +pub type c_void = core::ffi::c_void; diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index 6128c20e..7e538bb2 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -296,7 +296,15 @@ unsafe extern "C" fn task_create( *(handle as *mut usize) = 0; // we will run it in task 0 - queue_work(func, name, stack_depth, param, prio, handle, core_id); + queue_work( + func, + name as *const i8, + stack_depth, + param, + prio, + handle, + core_id, + ); 1 } diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index 08c90ae7..2510db18 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -361,7 +361,7 @@ unsafe extern "C" fn task_create( task_handle: *const crate::binary::c_types::c_void, core_id: u32, ) -> i32 { - let name_str = StrBuf::from(name); + let name_str = StrBuf::from(name as *const u8); log::trace!( "task_create {:p} {} {} {:p} {} {:p} {}", task_func, diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs index 697dde0c..cdb86069 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs @@ -32,7 +32,10 @@ pub(crate) unsafe fn phy_enable() { [0u8; core::mem::size_of::()]; let phy_version = get_phy_version_str(); - trace!("phy_version {}", StrBuf::from(phy_version).as_str_ref()); + trace!( + "phy_version {}", + StrBuf::from(phy_version as *const u8).as_str_ref() + ); let init_data = &PHY_INIT_DATA_DEFAULT; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs index 503a407e..24206f91 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs @@ -32,7 +32,10 @@ pub(crate) unsafe fn phy_enable() { [0u8; core::mem::size_of::()]; let phy_version = get_phy_version_str(); - trace!("phy_version {}", StrBuf::from(phy_version).as_str_ref()); + trace!( + "phy_version {}", + StrBuf::from(phy_version as *const u8).as_str_ref() + ); let init_data = &PHY_INIT_DATA_DEFAULT; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs index e6eb38f9..9eff44b4 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs @@ -32,7 +32,10 @@ pub(crate) unsafe fn phy_enable() { [0u8; core::mem::size_of::()]; let phy_version = get_phy_version_str(); - trace!("phy_version {}", StrBuf::from(phy_version).as_str_ref()); + trace!( + "phy_version {}", + StrBuf::from(phy_version as *const u8).as_str_ref() + ); let init_data = &PHY_INIT_DATA_DEFAULT; diff --git a/esp-wifi/src/common_adapter/mod.rs b/esp-wifi/src/common_adapter/mod.rs index f49ed772..376c1073 100644 --- a/esp-wifi/src/common_adapter/mod.rs +++ b/esp-wifi/src/common_adapter/mod.rs @@ -382,7 +382,7 @@ pub unsafe extern "C" fn pp_printf(s: *const u8, args: ...) { } // #define ESP_EVENT_DEFINE_BASE(id) esp_event_base_t id = #id -static mut EVT: u8 = 0; +static mut EVT: i8 = 0; #[no_mangle] static mut WIFI_EVENT: esp_event_base_t = unsafe { &EVT }; diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 8fbb2e5d..223b6d2d 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -644,7 +644,7 @@ pub fn wifi_start() -> Result<(), WifiError> { let cntry_code = [b'C', b'N', 0]; let country = wifi_country_t { - cc: cntry_code, + cc: core::mem::transmute(cntry_code), schan: 1, nchan: 13, max_tx_power: 20, diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 1b098910..173d4426 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -698,7 +698,7 @@ pub unsafe extern "C" fn task_create_pinned_to_core( ) -> i32 { trace!("task_create_pinned_to_core task_func {:p} name {} stack_depth {} param {:p} prio {}, task_handle {:p} core_id {}", task_func, - StrBuf::from(name).as_str_ref(), + StrBuf::from(name as *const u8).as_str_ref(), stack_depth, param, prio, @@ -1090,7 +1090,7 @@ pub unsafe extern "C" fn phy_update_country_info( country: *const crate::binary::c_types::c_char, ) -> crate::binary::c_types::c_int { // not implemented in original code - trace!("phy_update_country_info {}", *country as char); + trace!("phy_update_country_info {}", *country as u8 as char); -1 } @@ -1516,7 +1516,7 @@ pub unsafe extern "C" fn log_write( return; #[cfg(target_arch = "riscv32")] - syslog(_level, _format, _args); + syslog(_level, _format as *const u8, _args); } /**************************************************************************** @@ -1548,7 +1548,7 @@ pub unsafe extern "C" fn log_writev( #[cfg(target_arch = "xtensa")] #[allow(unreachable_code)] { - let s = StrBuf::from(_format); + let s = StrBuf::from(_format as *const u8); log::info!("{}", s.as_str_ref()); } @@ -1556,7 +1556,7 @@ pub unsafe extern "C" fn log_writev( #[allow(unreachable_code)] { let _args = core::mem::transmute(_args); - syslog(_level, _format, _args); + syslog(_level, _format as *const u8, _args); } }