Skip to content

Commit

Permalink
upgrade to esp-wifi 0.9.1 (#51)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yanshay authored Oct 4, 2024
1 parent c9225fd commit 63eabf6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 133 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
132 changes: 0 additions & 132 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 All @@ -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| {
Expand Down

0 comments on commit 63eabf6

Please sign in to comment.