diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 7db1bbfca..ae96e3ac8 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -93,8 +93,6 @@ async = [ "dep:embassy-sync", "dep:embassy-futures", "dep:embedded-io-async", - "esp-hal/embassy", - "esp-hal/async", ] embassy-net = ["dep:embassy-net-driver", "async"] diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index 8e5394788..2c613144f 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -66,8 +66,8 @@ extern "C" { } static VHCI_HOST_CALLBACK: vhci_host_callback_s = vhci_host_callback_s { - notify_host_send_available: notify_host_send_available, - notify_host_recv: notify_host_recv, + notify_host_send_available, + notify_host_recv, }; extern "C" fn notify_host_send_available() { @@ -81,7 +81,7 @@ extern "C" fn notify_host_recv(data: *mut u8, len: u16) -> i32 { unsafe { let mut buf = [0u8; 256]; - buf[..len as usize].copy_from_slice(&core::slice::from_raw_parts(data, len as usize)); + buf[..len as usize].copy_from_slice(core::slice::from_raw_parts(data, len as usize)); let packet = ReceivedPacket { len: len as u8, @@ -95,10 +95,7 @@ extern "C" fn notify_host_recv(data: *mut u8, len: u16) -> i32 { } }); - dump_packet_info(&core::slice::from_raw_parts( - data as *const u8, - len as usize, - )); + dump_packet_info(core::slice::from_raw_parts(data as *const u8, len as usize)); #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); @@ -108,10 +105,12 @@ extern "C" fn notify_host_recv(data: *mut u8, len: u16) -> i32 { } #[cfg(target_arch = "riscv32")] -static mut G_INTER_FLAGS: [u8; 10] = [0; 10]; +type InterruptsFlagType = u8; #[cfg(target_arch = "xtensa")] -static mut G_INTER_FLAGS: [u32; 10] = [0; 10]; +type InterruptsFlagType = u32; + +static mut G_INTER_FLAGS: [InterruptsFlagType; 10] = [0; 10]; static mut INTERRUPT_DISABLE_CNT: usize = 0; @@ -120,13 +119,18 @@ unsafe extern "C" fn interrupt_enable() { INTERRUPT_DISABLE_CNT -= 1; let flags = G_INTER_FLAGS[INTERRUPT_DISABLE_CNT]; trace!("interrupt_enable {}", flags); - critical_section::release(core::mem::transmute(flags)); + critical_section::release(core::mem::transmute::< + InterruptsFlagType, + critical_section::RestoreState, + >(flags)); } #[ram] unsafe extern "C" fn interrupt_disable() { trace!("interrupt_disable"); - let flags = core::mem::transmute(critical_section::acquire()); + let flags = core::mem::transmute::( + critical_section::acquire(), + ); G_INTER_FLAGS[INTERRUPT_DISABLE_CNT] = flags; INTERRUPT_DISABLE_CNT += 1; trace!("interrupt_disable {}", flags); @@ -191,8 +195,8 @@ unsafe extern "C" fn queue_send(queue: *const (), item: *const (), _block_time_m // assume the size is 8 - shouldn't rely on that let message = item as *const u8; let mut data = [0u8; 8]; - for i in 0..8 as usize { - data[i] = *(message.offset(i as isize)); + for (i, data) in data.iter_mut().enumerate() { + *data = *message.add(i); } trace!("queue posting {:?}", data); @@ -592,7 +596,7 @@ pub fn send_hci(data: &[u8]) { } PACKET_SENT.store(false, Ordering::Relaxed); - API_vhci_host_send_packet(packet.as_ptr() as *const u8, packet.len() as u16); + API_vhci_host_send_packet(packet.as_ptr(), packet.len() as u16); trace!("sent vhci host packet"); dump_packet_info(packet); diff --git a/esp-wifi/src/ble/mod.rs b/esp-wifi/src/ble/mod.rs index 17b59b7ca..bf26fc3d9 100644 --- a/esp-wifi/src/ble/mod.rs +++ b/esp-wifi/src/ble/mod.rs @@ -77,10 +77,11 @@ impl HciOutCollector { if self.index == self.data[3] as usize + 4 { self.ready = true; } - } else if self.kind == HciOutType::Acl && self.index >= 5 { - if self.index == (self.data[3] as usize) + ((self.data[4] as usize) << 8) + 5 { - self.ready = true; - } + } else if self.kind == HciOutType::Acl + && self.index >= 5 + && self.index == (self.data[3] as usize) + ((self.data[4] as usize) << 8) + 5 + { + self.ready = true; } } } @@ -92,6 +93,6 @@ impl HciOutCollector { } fn packet(&self) -> &[u8] { - &self.data[0..(self.index as usize)] + &self.data[0..self.index] } } diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index 12bc6f7fb..91f4ef7f8 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -590,7 +590,9 @@ unsafe extern "C" fn ble_npl_get_time_forever() -> u32 { unsafe extern "C" fn ble_npl_hw_exit_critical(mask: u32) { trace!("ble_npl_hw_exit_critical {}", mask); - critical_section::release(core::mem::transmute(mask as u8)); + critical_section::release(core::mem::transmute::( + mask as u8, + )); } unsafe extern "C" fn ble_npl_hw_enter_critical() -> u32 { @@ -1139,7 +1141,7 @@ fn os_msys_buf_alloc() -> bool { unsafe { OS_MSYS_INIT_1_DATA = crate::compat::malloc::calloc( 1, - core::mem::size_of::() * SYSINIT_MSYS_1_MEMPOOL_SIZE as usize, + core::mem::size_of::() * SYSINIT_MSYS_1_MEMPOOL_SIZE, ) as *mut u32; OS_MSYS_INIT_2_DATA = crate::compat::malloc::calloc( 1, @@ -1223,7 +1225,7 @@ unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) { warn!("Dropping BLE packet"); } - dump_packet_info(&data[..(len + 3) as usize]); + dump_packet_info(&data[..(len + 3)]); }); r_ble_hci_trans_buf_free(cmd); @@ -1332,54 +1334,48 @@ pub fn send_hci(data: &[u8]) { let packet = hci_out.packet(); unsafe { - loop { - const DATA_TYPE_COMMAND: u8 = 1; - const DATA_TYPE_ACL: u8 = 2; + const DATA_TYPE_COMMAND: u8 = 1; + const DATA_TYPE_ACL: u8 = 2; - dump_packet_info(&packet); + dump_packet_info(packet); - critical_section::with(|_cs| { - if packet[0] == DATA_TYPE_COMMAND { - let cmd = r_ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); - core::ptr::copy_nonoverlapping( - &packet[1] as *const _ as *mut u8, // don't send the TYPE - cmd as *mut u8, - packet.len() - 1, - ); + critical_section::with(|_cs| { + if packet[0] == DATA_TYPE_COMMAND { + let cmd = r_ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD); + core::ptr::copy_nonoverlapping( + &packet[1] as *const _ as *mut u8, // don't send the TYPE + cmd as *mut u8, + packet.len() - 1, + ); - let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_cmd_tx)(cmd); + let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_cmd_tx)(cmd); - if res != 0 { - warn!("ble_hci_trans_hs_cmd_tx res == {}", res); - } - } else if packet[0] == DATA_TYPE_ACL { - let om = r_os_msys_get_pkthdr( - packet.len() as u16, - ACL_DATA_MBUF_LEADINGSPACE as u16, - ); - - let res = r_os_mbuf_append( - om, - packet.as_ptr().offset(1), - (packet.len() - 1) as u16, - ); - if res != 0 { - panic!("r_os_mbuf_append returned {}", res); - } - - // this modification of the ACL data packet makes it getting sent and - // received by the other side - *((*om).om_data as *mut u8).offset(1) = 0; - - let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_acl_tx)(om); - if res != 0 { - panic!("ble_hci_trans_hs_acl_tx returned {}", res); - } - trace!("ACL tx done"); + if res != 0 { + warn!("ble_hci_trans_hs_cmd_tx res == {}", res); } - }); - break; - } + } else if packet[0] == DATA_TYPE_ACL { + let om = r_os_msys_get_pkthdr( + packet.len() as u16, + ACL_DATA_MBUF_LEADINGSPACE as u16, + ); + + let res = + r_os_mbuf_append(om, packet.as_ptr().offset(1), (packet.len() - 1) as u16); + if res != 0 { + panic!("r_os_mbuf_append returned {}", res); + } + + // this modification of the ACL data packet makes it getting sent and + // received by the other side + *((*om).om_data as *mut u8).offset(1) = 0; + + let res = unwrap!(ble_hci_trans_funcs_ptr.ble_hci_trans_hs_acl_tx)(om); + if res != 0 { + panic!("ble_hci_trans_hs_acl_tx returned {}", res); + } + trace!("ACL tx done"); + } + }); } hci_out.reset(); diff --git a/esp-wifi/src/ble/os_adapter_esp32.rs b/esp-wifi/src/ble/os_adapter_esp32.rs index f20916a77..d6bc1d785 100644 --- a/esp-wifi/src/ble/os_adapter_esp32.rs +++ b/esp-wifi/src/ble/os_adapter_esp32.rs @@ -274,7 +274,7 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { normal_adv_size: 200, mesh_adv_size: 0, send_adv_reserved_size: 1000, - controller_debug_flag: 0 << 0, + controller_debug_flag: 0, mode: 0x01, // BLE ble_max_conn: 3, bt_max_acl_conn: 0, @@ -320,6 +320,7 @@ pub(crate) fn btdm_controller_mem_init() { // initialize em, .bss section let btdm_dram_regions = BTDM_DRAM_AVAILABLE_REGION.len(); + #[allow(clippy::needless_range_loop)] // the alternative looks worse for i in 1..btdm_dram_regions { if BTDM_DRAM_AVAILABLE_REGION[i].mode != esp_bt_mode_t_ESP_BT_MODE_IDLE { unsafe { @@ -487,7 +488,7 @@ pub(crate) unsafe extern "C" fn coex_schm_curr_phase_get() -> *const () { return crate::binary::include::coex_schm_curr_phase_get() as *const (); #[cfg(not(coex))] - return 0 as *const (); + return core::ptr::null::<()>(); } #[allow(unused_variables)] diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32.rs b/esp-wifi/src/common_adapter/common_adapter_esp32.rs index 51c047dee..353d806a5 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32.rs @@ -52,7 +52,7 @@ pub(crate) unsafe fn phy_enable() { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; @@ -158,9 +158,8 @@ pub(crate) unsafe fn phy_disable_clock() { #[ram] #[no_mangle] unsafe extern "C" fn esp_dport_access_reg_read(reg: u32) -> u32 { - let res = (reg as *mut u32).read_volatile(); // trace!("esp_dport_access_reg_read {:x} => {:x}", reg, res); - res + (reg as *mut u32).read_volatile() } /// ************************************************************************** diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs index 329276154..c79265f60 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs @@ -33,7 +33,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs index 451207f4a..f5b87e326 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs @@ -68,7 +68,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs index 12620f96e..612bbb77d 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs @@ -33,7 +33,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs index 72888b326..25669989a 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs @@ -34,7 +34,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs index b6afcc769..bfbf11093 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs @@ -68,7 +68,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs index b22077add..51e3d34ff 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs @@ -67,7 +67,7 @@ pub(crate) unsafe fn phy_enable() { critical_section::with(|_| { phy_enable_clock(); - if G_IS_PHY_CALIBRATED == false { + if !G_IS_PHY_CALIBRATED { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; diff --git a/esp-wifi/src/common_adapter/mod.rs b/esp-wifi/src/common_adapter/mod.rs index 3ee4e9fce..52e85472f 100644 --- a/esp-wifi/src/common_adapter/mod.rs +++ b/esp-wifi/src/common_adapter/mod.rs @@ -37,11 +37,11 @@ pub(crate) static mut RANDOM_GENERATOR: Option = None; pub(crate) static mut RADIO_CLOCKS: Option = None; pub(crate) fn init_rng(rng: Rng) { - unsafe { RANDOM_GENERATOR = Some(core::mem::transmute(rng)) }; + unsafe { RANDOM_GENERATOR = Some(rng) }; } pub(crate) fn init_radio_clock_control(rcc: hal::peripherals::RADIO_CLK) { - unsafe { RADIO_CLOCKS = Some(core::mem::transmute(rcc)) }; + unsafe { RADIO_CLOCKS = Some(rcc) }; } /// ************************************************************************** @@ -158,8 +158,8 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> crate::binary::c_ let base_mac = crate::hal::efuse::Efuse::get_mac_address(); - for i in 0..6 { - mac.offset(i as isize).write_volatile(base_mac[i]); + for (i, &byte) in base_mac.iter().enumerate() { + mac.add(i).write_volatile(byte); } // ESP_MAC_WIFI_SOFTAP @@ -351,7 +351,14 @@ pub unsafe extern "C" fn ets_timer_setfn( pfunction: *mut crate::binary::c_types::c_void, parg: *mut crate::binary::c_types::c_void, ) { - compat_timer_setfn(ptimer.cast(), core::mem::transmute(pfunction), parg); + compat_timer_setfn( + ptimer.cast(), + core::mem::transmute::< + *mut crate::binary::c_types::c_void, + unsafe extern "C" fn(*mut crate::binary::c_types::c_void), + >(pfunction), + parg, + ); } #[no_mangle] diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index d4b0fc1cd..5fa4a8f4f 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -64,7 +64,7 @@ pub fn sem_create(max: u32, init: u32) -> *mut c_void { memory_fence(); for (i, sem) in CURR_SEM.iter().enumerate() { memory_fence(); - if let None = *sem { + if sem.is_none() { res = i; break; } @@ -134,7 +134,7 @@ pub fn sem_give(semphr: *mut c_void) -> i32 { trace!("semphr_give {:?}", semphr); let sem_idx = semphr as usize - 1; - let res = critical_section::with(|_| unsafe { + critical_section::with(|_| unsafe { if let Some(cnt) = CURR_SEM[sem_idx] { CURR_SEM[sem_idx] = Some(cnt + 1); memory_fence(); @@ -142,9 +142,7 @@ pub fn sem_give(semphr: *mut c_void) -> i32 { } else { 0 } - }); - - res + }) } pub fn thread_sem_get() -> *mut c_void { @@ -165,7 +163,7 @@ pub fn thread_sem_get() -> *mut c_void { pub fn create_recursive_mutex() -> *mut c_void { critical_section::with(|_| unsafe { - let ptr = &mut MUTEXES[MUTEX_IDX_CURRENT] as *mut _ as *mut Mutex; + let ptr = &mut MUTEXES[MUTEX_IDX_CURRENT] as *mut Mutex; (*ptr).recursive = true; MUTEX_IDX_CURRENT += 1; memory_fence(); diff --git a/esp-wifi/src/compat/malloc.rs b/esp-wifi/src/compat/malloc.rs index 19f9daa06..7fb31cda7 100644 --- a/esp-wifi/src/compat/malloc.rs +++ b/esp-wifi/src/compat/malloc.rs @@ -5,7 +5,7 @@ use crate::HEAP; pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { trace!("alloc {}", size); - let total_size = size as usize + 4; + let total_size = size + 4; let layout = Layout::from_size_align_unchecked(total_size, 4); let ptr = critical_section::with(|cs| { @@ -37,7 +37,7 @@ pub unsafe extern "C" fn free(ptr: *mut u8) { let layout = Layout::from_size_align_unchecked(total_size, 4); critical_section::with(|cs| { HEAP.borrow_ref_mut(cs) - .deallocate(core::ptr::NonNull::new_unchecked(ptr as *mut u8), layout) + .deallocate(core::ptr::NonNull::new_unchecked(ptr), layout) }); } @@ -46,7 +46,7 @@ pub unsafe extern "C" fn calloc(number: u32, size: usize) -> *mut u8 { trace!("calloc {} {}", number, size); let total_size = number as usize * size; - let ptr = malloc(total_size) as *mut u8; + let ptr = malloc(total_size); if !ptr.is_null() { for i in 0..total_size as isize { diff --git a/esp-wifi/src/compat/syslog.rs b/esp-wifi/src/compat/syslog.rs index d5f41cc07..e49cd9234 100644 --- a/esp-wifi/src/compat/syslog.rs +++ b/esp-wifi/src/compat/syslog.rs @@ -102,7 +102,7 @@ pub(crate) unsafe fn vsnprintf( let mut format_char = ' '; let mut is_long = 0; let mut found = false; - for c in s.chars().into_iter() { + for c in s.chars() { if !found { if c == '%' { found = true; @@ -111,16 +111,14 @@ pub(crate) unsafe fn vsnprintf( if !found { res_str.append_char(c); } - } else { - if c.is_numeric() || c == '-' || c == 'l' { - if c == 'l' { - is_long = is_long + 1; - } - // ignore - } else { - // a format char - format_char = c; + } else if c.is_numeric() || c == '-' || c == 'l' { + if c == 'l' { + is_long += 1; } + // ignore + } else { + // a format char + format_char = c; } if found && format_char != ' ' { diff --git a/esp-wifi/src/compat/task_runner.rs b/esp-wifi/src/compat/task_runner.rs index 3a7ecc618..4186dc443 100644 --- a/esp-wifi/src/compat/task_runner.rs +++ b/esp-wifi/src/compat/task_runner.rs @@ -26,7 +26,12 @@ pub fn spawn_task( critical_section::with(|_| unsafe { if TASK_SPAWN_QUEUE - .enqueue((core::mem::transmute(task_func), param)) + .enqueue(( + core::mem::transmute::<*mut c_types::c_void, extern "C" fn(*mut c_types::c_void)>( + task_func, + ), + param, + )) .is_ok() { true diff --git a/esp-wifi/src/compat/timer_compat.rs b/esp-wifi/src/compat/timer_compat.rs index d3497f0cf..507a7a1cb 100644 --- a/esp-wifi/src/compat/timer_compat.rs +++ b/esp-wifi/src/compat/timer_compat.rs @@ -165,6 +165,6 @@ pub fn compat_esp_timer_create( debug!("esp_timer_create {:x}", ets_timer as usize); *out_handle = ets_timer as _; - return 0; + 0 }) } diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index c85cce47a..700e32cc8 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -202,7 +202,7 @@ pub struct RxControlInfo { pub rx_state: u32, } -#[cfg(any(esp32c6))] +#[cfg(esp32c6)] #[derive(Debug, Clone, Copy)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct RxControlInfo { @@ -291,8 +291,8 @@ impl<'d> EspNowManager<'d> { pub fn add_peer(&self, peer: PeerInfo) -> Result<(), EspNowError> { let raw_peer = esp_now_peer_info_t { peer_addr: peer.peer_address, - lmk: peer.lmk.unwrap_or_else(|| [0u8; 16]), - channel: peer.channel.unwrap_or_else(|| 0), + lmk: peer.lmk.unwrap_or([0u8; 16]), + channel: peer.channel.unwrap_or(0), ifidx: wifi_interface_t_WIFI_IF_STA, encrypt: peer.encrypt, priv_: core::ptr::null_mut(), @@ -309,8 +309,8 @@ impl<'d> EspNowManager<'d> { pub fn modify_peer(&self, peer: PeerInfo) -> Result<(), EspNowError> { let raw_peer = esp_now_peer_info_t { peer_addr: peer.peer_address, - lmk: peer.lmk.unwrap_or_else(|| [0u8; 16]), - channel: peer.channel.unwrap_or_else(|| 0), + lmk: peer.lmk.unwrap_or([0u8; 16]), + channel: peer.channel.unwrap_or(0), ifidx: wifi_interface_t_WIFI_IF_STA, encrypt: peer.encrypt, priv_: core::ptr::null_mut(), @@ -778,7 +778,7 @@ unsafe extern "C" fn rcv_cb( rx_state: (*rx_cntl).rx_state(), }; - #[cfg(any(esp32c6))] + #[cfg(esp32c6)] let rx_control = RxControlInfo { rssi: (*rx_cntl).rssi(), rate: (*rx_cntl).rate(), @@ -819,7 +819,7 @@ unsafe extern "C" fn rcv_cb( unwrap!(queue.enqueue(ReceivedData { len: slice.len() as u8, - data: data, + data, info, })); @@ -846,7 +846,7 @@ mod asynch { /// This function takes mutable reference to self because the /// implementation of `ReceiveFuture` is not logically thread /// safe. - pub fn receive_async<'r>(&'r mut self) -> ReceiveFuture<'r> { + pub fn receive_async(&mut self) -> ReceiveFuture<'_> { ReceiveFuture(PhantomData) } } @@ -871,7 +871,7 @@ mod asynch { /// implementation of `ReceiveFuture` is not logically thread /// safe. #[must_use] - pub fn receive_async<'r>(&'r mut self) -> ReceiveFuture<'r> { + pub fn receive_async(&mut self) -> ReceiveFuture<'_> { self.receiver.receive_async() } diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index c368222cf..329b2a2b2 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -119,6 +119,7 @@ struct Config { } // Validate the configuration at compile time +#[allow(clippy::assertions_on_constants)] const _: () = { // We explicitely use `core` assert here because this evaluation happens at // compile time and won't bloat the binary diff --git a/esp-wifi/src/preempt/mod.rs b/esp-wifi/src/preempt/mod.rs index ebd7b6017..be2d843e2 100644 --- a/esp-wifi/src/preempt/mod.rs +++ b/esp-wifi/src/preempt/mod.rs @@ -45,4 +45,5 @@ task_stack!(8192, 8192); #[cfg_attr(target_arch = "riscv32", path = "preempt_riscv.rs")] #[cfg_attr(target_arch = "xtensa", path = "preempt_xtensa.rs")] +#[allow(clippy::module_inception)] pub mod preempt; diff --git a/esp-wifi/src/preempt/preempt_riscv.rs b/esp-wifi/src/preempt/preempt_riscv.rs index 9229fe381..9b4a87aae 100644 --- a/esp-wifi/src/preempt/preempt_riscv.rs +++ b/esp-wifi/src/preempt/preempt_riscv.rs @@ -59,10 +59,8 @@ pub fn task_create(task: extern "C" fn()) { let task_stack_size = TASK_STACK_SIZE[i]; // stack must be aligned by 16 - let task_stack_ptr = addr_of!(TASK_STACK) as usize - + (task_stack_size as usize * i as usize) - + task_stack_size as usize - - 4; + let task_stack_ptr = + addr_of!(TASK_STACK) as usize + (task_stack_size * i) + task_stack_size - 4; let stack_ptr = task_stack_ptr - (task_stack_ptr % 0x10); CTX_TASKS[i].trap_frame.sp = stack_ptr; } diff --git a/esp-wifi/src/preempt/preempt_xtensa.rs b/esp-wifi/src/preempt/preempt_xtensa.rs index e432719da..e6da21662 100644 --- a/esp-wifi/src/preempt/preempt_xtensa.rs +++ b/esp-wifi/src/preempt/preempt_xtensa.rs @@ -71,15 +71,14 @@ pub fn task_create(task: extern "C" fn()) { unsafe { let i = allocate_task(); - CTX_TASKS[i].trap_frame.PC = task as u32; + CTX_TASKS[i].trap_frame.PC = task as usize as u32; let task_stack_size = TASK_STACK_SIZE[i]; // stack must be aligned by 16 - let task_stack_ptr = (addr_of!(TASK_STACK) as *const _ as usize - + (task_stack_size as usize * i as usize) - + task_stack_size as usize - - 4) as u32; + let task_stack_ptr = + (addr_of!(TASK_STACK) as *const _ as usize + (task_stack_size * i) + task_stack_size + - 4) as u32; let stack_ptr = task_stack_ptr - (task_stack_ptr % 0x10); CTX_TASKS[i].trap_frame.A1 = stack_ptr; diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index 74cf72cc0..9433fcb4e 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -39,7 +39,9 @@ pub fn setup_timer(systimer: TimeBase) { unsafe { interrupt::bind_interrupt( Interrupt::SYSTIMER_TARGET0, - core::mem::transmute(systimer_target0 as *const ()), + core::mem::transmute::<*const (), unsafe extern "C" fn()>( + systimer_target0 as *const (), + ), ); } @@ -73,7 +75,7 @@ extern "C" fn systimer_target0(trap_frame: &mut TrapFrame) { extern "C" fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { unsafe { // clear FROM_CPU_INTR3 - (&*SystemPeripheral::PTR) + (*SystemPeripheral::PTR) .cpu_intr_from_cpu_3() .modify(|_, w| w.cpu_intr_from_cpu_3().clear_bit()); } @@ -91,7 +93,7 @@ extern "C" fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { pub fn yield_task() { unsafe { - (&*SystemPeripheral::PTR) + (*SystemPeripheral::PTR) .cpu_intr_from_cpu_3() .modify(|_, w| w.cpu_intr_from_cpu_3().set_bit()); } diff --git a/esp-wifi/src/timer/timer_esp32h2.rs b/esp-wifi/src/timer/timer_esp32h2.rs index efcdbd84a..35a74d36f 100644 --- a/esp-wifi/src/timer/timer_esp32h2.rs +++ b/esp-wifi/src/timer/timer_esp32h2.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "ble"))] +#[cfg(feature = "ble")] use crate::{ binary, hal::{interrupt, peripherals::Interrupt}, diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index a98791c8c..732179fe8 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -17,7 +17,7 @@ use enumset::{EnumSet, EnumSetType}; use num_derive::FromPrimitive; use num_traits::FromPrimitive; #[doc(hidden)] -pub use os_adapter::*; +pub(crate) use os_adapter::*; use portable_atomic::{AtomicUsize, Ordering}; #[cfg(feature = "smoltcp")] use smoltcp::phy::{Device, DeviceCapabilities, RxToken, TxToken}; @@ -640,13 +640,13 @@ impl TryFrom for WifiMode { } } -impl Into for WifiMode { - fn into(self) -> wifi_mode_t { +impl From for wifi_mode_t { + fn from(val: WifiMode) -> Self { #[allow(non_upper_case_globals)] - match self { - Self::Sta => wifi_mode_t_WIFI_MODE_STA, - Self::Ap => wifi_mode_t_WIFI_MODE_AP, - Self::ApSta => wifi_mode_t_WIFI_MODE_APSTA, + match val { + WifiMode::Sta => wifi_mode_t_WIFI_MODE_STA, + WifiMode::Ap => wifi_mode_t_WIFI_MODE_AP, + WifiMode::ApSta => wifi_mode_t_WIFI_MODE_APSTA, } } } @@ -989,19 +989,19 @@ static g_wifi_osi_funcs: wifi_osi_funcs_t = wifi_osi_funcs_t { _phy_common_clock_enable: Some(os_adapter_chip_specific::phy_common_clock_enable), _coex_register_start_cb: Some(coex_register_start_cb), - #[cfg(any(esp32c6))] + #[cfg(esp32c6)] _regdma_link_set_write_wait_content: Some( os_adapter_chip_specific::regdma_link_set_write_wait_content_dummy, ), - #[cfg(any(esp32c6))] + #[cfg(esp32c6)] _sleep_retention_find_link_by_id: Some( os_adapter_chip_specific::sleep_retention_find_link_by_id_dummy, ), - #[cfg(any(esp32c6))] + #[cfg(esp32c6)] _sleep_retention_entries_create: Some( os_adapter_chip_specific::sleep_retention_entries_create_dummy, ), - #[cfg(any(esp32c6))] + #[cfg(esp32c6)] _sleep_retention_entries_destroy: Some( os_adapter_chip_specific::sleep_retention_entries_destroy_dummy, ), @@ -1059,8 +1059,8 @@ static mut G_CONFIG: wifi_init_config_t = wifi_init_config_t { tx_buf_type: 1, static_tx_buf_num: crate::CONFIG.static_tx_buf_num as i32, dynamic_tx_buf_num: crate::CONFIG.dynamic_tx_buf_num as i32, - rx_mgmt_buf_type: 0 as i32, - rx_mgmt_buf_num: 0 as i32, + rx_mgmt_buf_type: 0_i32, + rx_mgmt_buf_num: 0_i32, cache_tx_buf_num: 0, csi_enable: 1, ampdu_rx_enable: crate::CONFIG.ampdu_rx_enable as i32, @@ -1223,16 +1223,15 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { ))?; }; - let ps_mode; cfg_if::cfg_if! { if #[cfg(feature = "ps-min-modem")] { - ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; + let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; } else if #[cfg(feature = "ps-max-modem")] { - ps_mode = include::wifi_ps_type_t_WIFI_PS_MAX_MODEM; + let ps_mode = include::wifi_ps_type_t_WIFI_PS_MAX_MODEM; } else if #[cfg(coex)] { - ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; + let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; } else { - ps_mode = include::wifi_ps_type_t_WIFI_PS_NONE; + let ps_mode = include::wifi_ps_type_t_WIFI_PS_NONE; } }; @@ -1244,7 +1243,7 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { cntry_code[2] = crate::CONFIG.country_code_operating_class; let country = wifi_country_t { - cc: core::mem::transmute(cntry_code), // [u8] -> [i8] conversion + cc: core::mem::transmute::<[u8; 3], [i8; 3]>(cntry_code), // [u8] -> [i8] conversion schan: 1, nchan: 13, max_tx_power: 20, @@ -1939,7 +1938,7 @@ impl WifiRxToken { // taken, the function will try to trigger a context switch, which will // fail if we are in a critical section. let buffer = data.as_slice_mut(); - dump_packet_info(&buffer); + dump_packet_info(buffer); f(buffer) } @@ -2051,10 +2050,7 @@ fn apply_sta_config(config: &ClientConfiguration) -> Result<(), WifiError> { password: [0; 64], scan_method: crate::CONFIG.scan_method, bssid_set: config.bssid.is_some(), - bssid: match config.bssid { - Some(bssid_ref) => bssid_ref, - None => [0; 6], - }, + bssid: config.bssid.unwrap_or_default(), channel: config.channel.unwrap_or(0), listen_interval: crate::CONFIG.listen_interval, sort_method: wifi_sort_method_t_WIFI_CONNECT_AP_BY_SIGNAL, diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 03153d772..af0d48b55 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -1984,6 +1984,7 @@ pub unsafe extern "C" fn coex_schm_register_cb_wrapper( /// The calibration value obtained using rtc_clk_cal /// /// ************************************************************************* +#[allow(unused)] pub unsafe extern "C" fn slowclk_cal_get() -> u32 { trace!("slowclk_cal_get"); diff --git a/esp-wifi/src/wifi_interface.rs b/esp-wifi/src/wifi_interface.rs index fa4d1e545..9c2910b77 100644 --- a/esp-wifi/src/wifi_interface.rs +++ b/esp-wifi/src/wifi_interface.rs @@ -229,10 +229,10 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { if let Some(dhcp_handle) = *dhcp_socket_handle_ref { let dhcp_socket = sockets.get_mut::(dhcp_handle); - let connected = match crate::wifi::get_sta_state() { - crate::wifi::WifiState::StaConnected => true, - _ => false, - }; + let connected = matches!( + crate::wifi::get_sta_state(), + crate::wifi::WifiState::StaConnected + ); if connected && !*self.old_connected.borrow() { dhcp_socket.reset(); @@ -248,7 +248,7 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { interface.routes_mut().remove_default_ipv4_route(); } smoltcp::socket::dhcpv4::Event::Configured(config) => { - let dns = config.dns_servers.get(0); + let dns = config.dns_servers.first(); *self.ip_info.borrow_mut() = Some(ipv4::IpInfo { ip: config.address.address().0.into(), subnet: ipv4::Subnet { @@ -402,7 +402,7 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { sockets .get_mut::(dns_handle) .start_query(interface.context(), name, query_type) - .map_err(|e| WifiStackError::DnsQueryError(e)) + .map_err(WifiStackError::DnsQueryError) })?; loop { @@ -427,7 +427,7 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { /// Make sure to regularly call this function. pub fn work(&self) { loop { - if let false = self.with_mut(|interface, device, sockets| { + let did_work = self.with_mut(|interface, device, sockets| { let network_config = self.network_config.borrow().clone(); if let ipv4::Configuration::Client(ipv4::ClientConfiguration::DHCP(_)) = network_config @@ -452,7 +452,9 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { device, sockets, ) - }) { + }); + + if !did_work { break; } } @@ -461,7 +463,7 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> { #[cfg(feature = "tcp")] fn next_local_port(&self) -> u16 { self.local_port.replace_with(|local_port| { - if *local_port >= LOCAL_PORT_MAX { + if *local_port == LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { *local_port + 1 @@ -562,17 +564,13 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Socket<'s, 'n, MODE> { sock.connect(cx, remote_endpoint, self.network.next_local_port()) }); - res.map_err(|e| IoError::ConnectError(e))?; + res.map_err(IoError::ConnectError)?; } loop { let can_send = self.network.with_mut(|_interface, _device, sockets| { let sock = sockets.get_mut::(self.socket_handle); - if sock.can_send() { - true - } else { - false - } + sock.can_send() }); if can_send { @@ -596,17 +594,13 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Socket<'s, 'n, MODE> { sock.listen(port) }); - res.map_err(|e| IoError::ListenError(e))?; + res.map_err(IoError::ListenError)?; } loop { let can_send = self.network.with_mut(|_interface, _device, sockets| { let sock = sockets.get_mut::(self.socket_handle); - if sock.can_send() { - true - } else { - false - } + sock.can_send() }); if can_send { @@ -630,7 +624,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Socket<'s, 'n, MODE> { sock.listen(port) }); - res.map_err(|e| IoError::ListenError(e))?; + res.map_err(IoError::ListenError)?; } self.work(); @@ -796,7 +790,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> Write for Socket<'s, 'n, MODE> { ) }); - if let false = res { + if !res { break; } } @@ -835,11 +829,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> UdpSocket<'s, 'n, MODE> { loop { let can_send = self.network.with_mut(|_interface, _device, sockets| { let sock = sockets.get_mut::(self.socket_handle); - if sock.can_send() { - true - } else { - false - } + sock.can_send() }); if can_send { @@ -892,7 +882,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> UdpSocket<'s, 'n, MODE> { .get_mut::(self.socket_handle) .send_slice(data, endpoint) }) - .map_err(|e| IoError::UdpSendError(e))?; + .map_err(IoError::UdpSendError)?; self.work(); @@ -933,7 +923,7 @@ impl<'s, 'n: 's, MODE: WifiDeviceMode> UdpSocket<'s, 'n, MODE> { self.work(); - res.map_err(|e| IoError::MultiCastError(e)) + res.map_err(IoError::MultiCastError) } /// Delegates to [WifiStack::work] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6f3b8a74f..3012cd7b4 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -499,17 +499,14 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { ], )?, - Package::EspWifi => (), - // TODO lint esp-wifi! - // - // lint_package( - // &path, - // &[ - // "-Zbuild-std=core", - // "--target=riscv32imc-unknown-none-elf", - // "--features=esp32c3", - // ], - // )?, + Package::EspWifi => lint_package( + &path, + &[ + "-Zbuild-std=core", + "--target=riscv32imc-unknown-none-elf", + "--features=esp32c3,wifi-default,ble,esp-now,async,embassy-net", + ], + )?, // We will *not* check the following packages with `clippy`; this // may or may not change in the future: