esp-rs / esp32-hal

A hardware abstraction layer for the esp32 written in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using bindgen for an interface to the WiFi blobs

MabezDev opened this issue · comments

The static libs found in $IDF/components/esp32/lib link against the headers inside $IDF/components/esp32/include, using bindgen we should be able to wrap the c functions in a Rusty way.

commented

I started poking at this a bit, we might have issues interfacing with them as at least the wifi one seems to use some sort of async task structure? As I'm not sure if we can easily ensure that the required baggage for that is around in a rust program.

Hmm it will be quite awkward, but just about doable I think. One of the idf developers replied to me about the wifi libs on reddit that explains a little bit more.

I suspect we may need more info, hopefully espressif don't mind helping on that front.

Essentially we need to reimplement this file https://github.com/espressif/esp-idf/blob/master/components/esp32/esp_adapter.c , but it's not quite that straight forward as implementing requires:

  • NVS driver
  • Allocation, not sure how that will work with rust's #[global_allocator] or would we need to roll our own.
  • Queue creation should be pretty simple, but there needs to a conversion wrapper that converts * void to The actual type that we can store on the rust side, I'm hoping only one type gets queued else this might get tricky.
  • ISR management, Required work in xtensa-lx6-rt I think.
  • For mutex's/ semaphores we should be able to get away with the spin lock crate.
  • Timers, we should be able to use model our code on the ets_timer functions in the idf that use the hardware timers
  • Power & coex functions, should be reasonably simple to implement

I have made a start at: https://github.com/arjanmels/esp32-wifi. Bindgen is up and running and I can call some basic functions. Will start on the OS wrapper for the wifi_init function next.

I chose to make it a separate crate since it pulls in esp-idf binary blobs and I didn't want to pollute the esp32-hal with that. We need to see later how to handle the bluetooth, if that can be a separate crate, or needs to be in this crate as there may be some close cooperation.

I have transferred my esp32_wifi repo to esp-rs: https://github.com/esp-rs/esp32-wifi.
Status: It allows todo wifi scan, but currently still returns 0 AP found. (Not certain what the problem is, I think all essential compatibility functions are in place, might be teh PHY not enabled properly.)

Oh excellent! I started something similar, but will now put my efforts into esp-rs/esp32-wifi!