esp32-hal icon indicating copy to clipboard operation
esp32-hal copied to clipboard

Using bindgen for an interface to the WiFi blobs

Open MabezDev opened this issue 5 years ago • 6 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.

MabezDev avatar Mar 18 '19 14:03 MabezDev

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.

HarkonenBade avatar Dec 23 '19 21:12 HarkonenBade

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.

MabezDev avatar Dec 24 '19 13:12 MabezDev

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
  • [x] 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.
  • [x] ISR management, Required work in xtensa-lx6-rt I think.
  • [x] For mutex's/ semaphores we should be able to get away with the spin lock crate.
  • [x] 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

MabezDev avatar Dec 24 '19 13:12 MabezDev

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.

arjanmels avatar Jul 17 '20 08:07 arjanmels

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.)

arjanmels avatar Sep 11 '20 18:09 arjanmels

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

MabezDev avatar Sep 12 '20 10:09 MabezDev