esp-rs / esp32-hal

A hardware abstraction layer for the esp32 written in Rust.
Apache License 2.0
193 stars 28 forks source link

Using bindgen for an interface to the WiFi blobs #3

Open MabezDev opened 5 years ago

MabezDev commented 5 years ago

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.

HarkonenBade commented 4 years ago

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.

MabezDev commented 4 years ago

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 commented 4 years ago

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:

arjanmels commented 4 years ago

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 commented 4 years ago

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

MabezDev commented 4 years ago

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