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

Use bindgen to produce automatic bindings for our C interfaces #6

Open
zsup opened this issue Jan 27, 2016 · 5 comments
Open

Use bindgen to produce automatic bindings for our C interfaces #6

zsup opened this issue Jan 27, 2016 · 5 comments

Comments

@zsup
Copy link
Owner

zsup commented Jan 27, 2016

No description provided.

@japaric
Copy link

japaric commented Jan 29, 2016

I can look into this. What C interfaces require bindings? And which header files are the entry points, i.e. which headers do you directly include in your application, e.g. #include <hal/foo.h>?

@zsup
Copy link
Owner Author

zsup commented Feb 1, 2016

ping @m-mcgowan for comment here

@m-mcgowan
Copy link

Hi @japaric! Our C interfaces are those exported as dynamic linked libraries - you can find them by grepping the source for DYNALIB_FN - ecluding dynalib/inc/dynalib.h which is where the macro is defined.

mbp:firmware mat1$ grep -l -r --include=*.h --exclude=./dynalib/inc/dynalib.h DYNALIB_FN  .
./communication/src/communication_dynalib.h
./hal/inc/hal_dynalib.h
./hal/inc/hal_dynalib_can.h
./hal/inc/hal_dynalib_cellular.h
./hal/inc/hal_dynalib_concurrent.h
./hal/inc/hal_dynalib_core.h
./hal/inc/hal_dynalib_gpio.h
./hal/inc/hal_dynalib_i2c.h
./hal/inc/hal_dynalib_ota.h
./hal/inc/hal_dynalib_peripherals.h
./hal/inc/hal_dynalib_socket.h
./hal/inc/hal_dynalib_spi.h
./hal/inc/hal_dynalib_usart.h
./hal/inc/hal_dynalib_wlan.h
./modules/photon/system-part1/inc/wifi_dynalib.h
./modules/shared/stm32f2xx/inc/module_system_part1_init_dynalib.h
./modules/shared/stm32f2xx/inc/user_dynalib.h
./rt-dynalib/inc/rt_dynalib.h
./services/inc/services_dynalib.h
./system/inc/system_dynalib.h
./system/inc/system_dynalib_cloud.h
./system/inc/system_dynalib_net.h

The dynamic linking is taken care of automatically for you by including these header files and defining DYNALIB_IMPORT. For example see https://github.com/spark/firmware/tree/develop/system-dynalib/src. When the dynamic interface is imported, a statically linked stub is created for each C function that dynamically invokes the target function. I'm guessing that bindgen could then create bindings for these statically linked stubs.

@japaric
Copy link

japaric commented Apr 11, 2016

I finally got around to work on this. I used bindgen on the $module_hal.h headers instead of the dynalibs ones but I think there's no difference in the produced function signatures. You can see my progress here. So far, I've only generated bindings for the gpio and delay modules then tested these bindings on my photon Cargo project (see japaric-archived/photon#3).

Next I'm going to explore building a "rustic" wiring API on top of these HAL bindings. I plan to generate bindings for the other modules (UART, I2C, etc) as I need them. But, if someone wants to play with the other modules right now, let me know and I'll generate the bindings for you!

cc @dbrgn

@dbrgn
Copy link

dbrgn commented Apr 11, 2016

That's cool. As I said, I'll probably give the high level abstraction a stab next week. This week is very busy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants