Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roadmap and FAQs #1

Open
9 of 13 tasks
kassane opened this issue Mar 19, 2024 · 1 comment
Open
9 of 13 tasks

Roadmap and FAQs #1

kassane opened this issue Mar 19, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@kassane
Copy link
Owner

kassane commented Mar 19, 2024

TODO

  • bluetooth
  • bootloader
  • partition
  • lwip
  • peripherals (led, gpio, adc, uart, etc...)
  • netif
  • mqtt
  • wifi
  • http
  • tls (mbedtls)
  • freertos (tasks, queue, semaphore, etc...)
  • pthread

mini-FAQ

So Zig can read C headers. Why manual wrappers?

Indeed @cImport/@cInclude doesn't access C types directly, but it converts to zig binding automatically (like binding-rs).
However, there have been some limits to support at the moment, in particular when converting macros (difficult to parse).
One example is ESP_LOGx, which has been done manually, since the original version provided in esp_log.h has become untranslatable.
see: zig doc - @cImport vs translate-c


So why not use microzig to make the project fully zig-written?

I am currently using zig v0.12.0-dev (nightly/master) and the microzig project does not support this version yet.
see: ZigEmbeddedGroup/microzig#178
The use of regz (svd converter) will also need to be evaluated, since it is under development and not all peripherals are guaranteed during translation.
see: ZigEmbeddedGroup/microzig#180


Why did you add C++ example using Zig?

Isn't it clear?
Okay, so instead of using crosstool-NG you switch to zig c++/clang++, but only with libc++ (LLVM C++ ABI) and not libstdc++ (GNU C++ ABI).
However, the final binary will still be compiled via cmake with crosstool-NG and libgcc (compiler ABI), not compiler-rt (compiler ABI).
see: kubo39/esp32-resource#1

Note: Zig (the toolchain) doesn't just prefer its own language!

@kassane kassane added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed question Further information is requested labels Mar 19, 2024
@kassane kassane pinned this issue Mar 19, 2024
@kassane
Copy link
Owner Author

kassane commented Mar 20, 2024

Although the readme claims to support v4.4 to 5.x, it is actually being tested on 5.3-dev.

The last commit added a wrapper to handle the IDF version. The main idea was to read the esp_idf_version.h header, but zig couldn't find it even though it had access to the include path.

pub const Version = struct {
major: u32 = 0,
minor: u32 = 0,
patch: u32 = 0,
pub fn get() Version {
var final_version: Version = undefined;
const idf_version = std.mem.span(esp_get_idf_version());
if (!std.mem.startsWith(u8, idf_version, "v"))
return .{};
// skip [0] == 'v' and remove [idf_version.len - 4] == "-dev"
var it = if (std.mem.endsWith(u8, idf_version, "-dev"))
std.mem.split(u8, idf_version[1 .. idf_version.len - 4], ".")
else
std.mem.split(u8, idf_version[1..], ".");
final_version.major = std.fmt.parseUnsigned(u32, it.first(), 10) catch |err|
@panic(@errorName(err));
while (it.next()) |token| {
if (!std.ascii.isDigit(token[0]))
continue;
const digit = std.fmt.parseUnsigned(u32, token, 10) catch |err|
@panic(@errorName(err));
final_version.minor = digit;
if (digit != final_version.minor)
final_version.patch = digit;
}
return final_version;
}
pub fn toString(self: Version, allocator: std.mem.Allocator) []const u8 {
const idf_version = std.mem.span(esp_get_idf_version());
// e.g.: v4.0.0 or commit-hash: g5d5f5c3
if (!std.mem.startsWith(u8, idf_version, "v"))
return idf_version
else
return std.fmt.allocPrint(allocator, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch }) catch |err|
@panic(@errorName(err));
}
};

The idea of managing multiple versions of functions could be done in a similar way to crc_xx, depending on the version of the IDF.

pub fn esp_rom_crc32(crc: u32, buf: [*:0]const u8, len: u32) u32 {
return switch (builtin.cpu.arch.endian()) {
.little => esp_rom_crc32_le(crc, buf, len),
else => esp_rom_crc32_be(crc, buf, len),
};
}
extern fn esp_rom_crc32_be(crc: u32, buf: [*:0]const u8, len: u32) u32;
extern fn esp_rom_crc32_le(crc: u32, buf: [*:0]const u8, len: u32) u32;

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant