Skip to content

Commit

Permalink
upgrade to esp-wifi 0.9.1
Browse files Browse the repository at this point in the history
removed duplicate functions
increased heap memory
updated examples cargo.toml
  • Loading branch information
yanshay committed Oct 3, 2024
1 parent c9225fd commit e63d9a4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cfg.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[esp-wifi]
heap_size = 95000 # use 110k by default
heap_size = 112640 # use 110k by default
# heap_size = 73728 # uncomment this to use 72k for esp32-s2/c2
116 changes: 0 additions & 116 deletions esp-mbedtls/src/compat/mod.rs
Original file line number Diff line number Diff line change
@@ -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::<i32>();
write!(res_str, "{}", v).ok();
} else {
let v = args.arg::<i32>();
write!(res_str, "{}", v).ok();
}
}

'u' => {
let v = args.arg::<u32>();
write!(res_str, "{}", v).ok();
}

'p' => {
let v = args.arg::<u32>();
write!(res_str, "0x{:x}", v).ok();
}

'X' => {
let v = args.arg::<u32>();
write!(res_str, "{:02x}", (v & 0xff000000) >> 24).ok();
}

'x' => {
let v = args.arg::<u32>();
write!(res_str, "{:02x}", v).ok();
}

's' => {
let v = args.arg::<u32>() 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::<u8>();
if v != 0 {
write!(res_str, "{}", v as char).ok();
}
}

_ => {
write!(res_str, "<UNKNOWN{}>", 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() }
Expand Down

0 comments on commit e63d9a4

Please sign in to comment.