Generate some C bindings

This commit is contained in:
David Goodlad 2019-04-23 22:54:38 +10:00
parent f737e1c4ab
commit d639d3b5e4
5 changed files with 38 additions and 1 deletions

2
.cargo/config Normal file
View file

@ -0,0 +1,2 @@
[build]
target = "thumbv7m-none-eabi"

View file

@ -3,6 +3,7 @@ name = "rtl8710-sdk"
version = "0.1.0" version = "0.1.0"
authors = ["David Goodlad <david@goodlad.net>"] authors = ["David Goodlad <david@goodlad.net>"]
edition = "2018" edition = "2018"
links = "sdk"
[dependencies] [dependencies]
cty = "0.2" cty = "0.2"

View file

@ -294,7 +294,6 @@ fn main() {
.compile("sdk"); .compile("sdk");
println!("cargo:rustc-link-search=native=vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/"); println!("cargo:rustc-link-search=native=vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/");
println!("cargo:rustc-link-lib=sdk");
println!("cargo:rustc-link-lib=_platform"); println!("cargo:rustc-link-lib=_platform");
println!("cargo:rustc-link-lib=_wlan"); println!("cargo:rustc-link-lib=_wlan");
println!("cargo:rustc-link-lib=_http"); println!("cargo:rustc-link-lib=_http");
@ -304,4 +303,29 @@ fn main() {
println!("cargo:rustc-link-lib=_websocket"); println!("cargo:rustc-link-lib=_websocket");
println!("cargo:rustc-link-lib=_xmodem"); println!("cargo:rustc-link-lib=_xmodem");
println!("cargo:rustc-link-lib=_mdns"); println!("cargo:rustc-link-lib=_mdns");
let bindings = bindgen::Builder::default()
.header("include/wrapper.h")
.whitelist_function("wifi_manager_init")
.whitelist_function("wifi_off")
.whitelist_function("wifi_on")
.whitelist_function("wifi_scan_networks")
.whitelist_function("vTaskStartScheduler")
.whitelist_function("pvPortMalloc")
.whitelist_function("vPortFree")
.whitelist_type("rtw_mode_t")
.whitelist_type("rtw_scan_result_t")
.whitelist_type("rtw_scan_result_handler_t")
.clang_arg("-Iinclude")
.clang_args(STDLIB_INCLUDE_PATHS.iter().map(|path| format!("-I{}", path)))
.clang_args(SDK_INCLUDE_PATHS.iter().map(|path| format!("-I{}", path)))
.use_core()
.ctypes_prefix("cty")
.rustfmt_bindings(true)
.generate()
.expect("Unable to generate C SDK bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings.rs!");
} }

8
src/bindings.rs Normal file
View file

@ -0,0 +1,8 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use cty;
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

View file

@ -1,5 +1,7 @@
#![no_std] #![no_std]
pub mod bindings;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]