From 63eabf6c62659b3dda3cb50d44998b5f52be34b6 Mon Sep 17 00:00:00 2001 From: yanshay Date: Fri, 4 Oct 2024 21:45:27 +0300 Subject: [PATCH] upgrade to esp-wifi 0.9.1 (#51) * upgrade to esp-wifi 0.9.1 removed duplicate functions increased heap memory updated examples cargo.toml * reduced heap size back, will not run but will compile on esp32 the increased size of the heap does not compile. * removed unused StrBuf::from --- Cargo.toml | 2 +- esp-mbedtls/src/compat/mod.rs | 132 ---------------------------------- 2 files changed, 1 insertion(+), 133 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4573ea8..9721331 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ embassy-net = { version = "0.4.0", features = [ ], optional = true } -esp-wifi = { version = "0.8.0", features = [ +esp-wifi = { version = "0.9.1", features = [ "phy-enable-usb", "embedded-svc", "wifi-default", diff --git a/esp-mbedtls/src/compat/mod.rs b/esp-mbedtls/src/compat/mod.rs index a6965e7..d05b33c 100644 --- a/esp-mbedtls/src/compat/mod.rs +++ b/esp-mbedtls/src/compat/mod.rs @@ -1,123 +1,7 @@ -use core::ffi::VaListImpl; -use core::fmt::Write; - /// Implements edge-nal traits #[cfg(feature = "edge-nal")] pub mod edge_nal_compat; -#[no_mangle] -pub unsafe extern "C" fn snprintf(dst: *mut u8, n: u32, format: *const u8, args: ...) -> i32 { - vsnprintf(dst, n, format, args) -} - -#[no_mangle] -extern "C" fn vsnprintf( - dst: *mut u8, - _max_len: u32, - format: *const u8, - mut args: VaListImpl, -) -> i32 { - unsafe { - let fmt_str_ptr = format; - let mut res_str = StrBuf::new(); - - let strbuf = StrBuf::from(fmt_str_ptr); - let s = strbuf.as_str_ref(); - - let mut format_char = ' '; - let mut is_long = false; - let mut found = false; - for c in s.chars().into_iter() { - if !found { - if c == '%' { - found = true; - } - - if !found { - res_str.append_char(c); - } - } else { - if c.is_numeric() || c == '-' || c == 'l' || c == 'z' || c == '#' { - if c == 'l' { - is_long = true; - } - // ignore - } else { - // a format char - format_char = c; - } - } - - if found && format_char != ' ' { - // have to format an arg - match format_char { - 'd' => { - if is_long { - let v = args.arg::(); - write!(res_str, "{}", v).ok(); - } else { - let v = args.arg::(); - write!(res_str, "{}", v).ok(); - } - } - - 'u' => { - let v = args.arg::(); - write!(res_str, "{}", v).ok(); - } - - 'p' => { - let v = args.arg::(); - write!(res_str, "0x{:x}", v).ok(); - } - - 'X' => { - let v = args.arg::(); - write!(res_str, "{:02x}", (v & 0xff000000) >> 24).ok(); - } - - 'x' => { - let v = args.arg::(); - write!(res_str, "{:02x}", v).ok(); - } - - 's' => { - let v = args.arg::() as *const i8; - let str = core::ffi::CStr::from_ptr(v); - let str = match str.to_str() { - Ok(str) => str, - Err(_err) => "Invalid", - }; - write!(res_str, "{}", str).ok(); - } - - 'c' => { - let v = args.arg::(); - if v != 0 { - write!(res_str, "{}", v as char).ok(); - } - } - - _ => { - write!(res_str, "", format_char).ok(); - } - } - - format_char = ' '; - found = false; - is_long = false; - } - } - - // TODO apply max_len - core::ptr::copy_nonoverlapping(res_str.buffer.as_ptr(), dst, res_str.len); - let idx = res_str.len as isize; - *(dst.offset(idx)) = 0; - - idx as i32 - } -} - #[no_mangle] extern "C" fn rand() -> crate::c_ulong { unsafe { crate::random() } @@ -136,22 +20,6 @@ impl StrBuf { } } - pub unsafe fn from(c_str: *const u8) -> StrBuf { - let mut res = StrBuf { - buffer: [0u8; 512], - len: 0, - }; - - let mut idx: usize = 0; - while *(c_str.offset(idx as isize)) != 0 { - res.buffer[idx] = *(c_str.offset(idx as isize)); - idx += 1; - } - - res.len = idx; - res - } - pub fn append(&mut self, s: &str) { let mut idx: usize = self.len; s.chars().for_each(|c| {