Skip to content

Commit 385f479

Browse files
committed
Minimized changes between main
1 parent 3896731 commit 385f479

File tree

17 files changed

+257
-50
lines changed

17 files changed

+257
-50
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Run package build
3939
run: |
4040
export CARGO_BUILD_TARGET=thumbv8m.main-none-eabihf
41-
for crate_dir in wba-bindings; do
41+
for crate_dir in linklayer-bindings; do
4242
echo "::group::Packaging ${crate_dir}"
4343
(
4444
cd build/${crate_dir}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "ble-bindings"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
description = "Raw STM32 WBA BLE stack bindings generated from the ST middleware."
7+
build = "build.rs"
8+
9+
[lib]
10+
path = "src/lib.rs"
11+
12+
[dependencies]
13+
linklayer-bindings = { path = "../linklayer-bindings" }
14+
15+
[features]
16+
default = []
17+
lib_stm32wba_ble_stack_po = []
18+
lib_stm32wba_ble_stack_llo = []
19+
lib_stm32wba_ble_stack_full = []
20+
lib_stm32wba_ble_stack_basic = []
21+
lib_stm32wba_ble_stack_basic_plus = []
22+
lib_lc3 = []
23+
lib_codec_mngr = []
24+
lib_ble_audio = []
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ble-bindings
2+
3+
Raw bindings for the STM32 WBA Bluetooth Low Energy stack. This crate is generated automatically by `stm32-bindings-gen` and is meant to be consumed by higher-level wrappers that expose safe BLE abstractions.
4+
5+
## Overview
6+
7+
The generator ingests the ST middleware headers and prebuilt static libraries, then uses `bindgen` to emit Rust FFI items. Everything in this crate mirrors the original C API one-to-one; you should treat every item as `unsafe` and build ergonomic wrappers in a separate crate.
8+
9+
## Layout
10+
11+
- `src/bindings/`: Modules produced by `bindgen`, containing raw FFI definitions.
12+
- `src/lib/`: Static libraries copied from the STM32CubeWBA distribution. Selecting the proper feature toggles which archives get linked.
13+
- `build.rs`: Registers the static libraries with Cargo based on the enabled features.
14+
15+
## Usage
16+
17+
1. Run `cargo run -p stm32-bindings-gen` so this crate is regenerated under `build/ble-bindings`.
18+
2. Add a path dependency in your Cargo manifest pointing to that directory.
19+
3. Enable the feature corresponding to the static library variant required by your project (e.g. `lib_stm32wba_ble_stack_full`).
20+
4. Wrap the raw FFI functions in a higher-level API before exposing them to the rest of your system.
21+
22+
## Feature Flags
23+
24+
Each `lib_*` feature matches a static archive provided by ST. Enable exactly the variants you need and the build script will emit the proper `cargo:rustc-link-lib` entries.
25+
26+
## Regeneration
27+
28+
If the underlying middleware or binding configuration changes, rerun `cargo run -p stm32-bindings-gen`. The generator will overwrite this crate with the latest bindings, libraries, and metadata.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::path::{Path, PathBuf};
2+
use std::{env, fs, io};
3+
4+
fn add_dir(dir: &Path) -> io::Result<()> {
5+
if !dir.exists() {
6+
return Ok(());
7+
}
8+
9+
println!("cargo:rustc-link-search=native={}", dir.display());
10+
11+
for entry in fs::read_dir(dir)? {
12+
let entry = entry?;
13+
let path = entry.path();
14+
if path.is_dir() {
15+
add_dir(&path)?;
16+
}
17+
}
18+
19+
Ok(())
20+
}
21+
22+
fn main() {
23+
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
24+
let lib_dir = crate_dir.join("src").join("lib");
25+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
26+
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
27+
let is_embedded = target_os == "none" || target_family == "embedded";
28+
29+
if !is_embedded {
30+
return;
31+
}
32+
33+
add_dir(&lib_dir).expect("failed to add link search paths");
34+
35+
env::vars()
36+
.filter_map(|(key, _)| {
37+
key.strip_prefix("CARGO_FEATURE_LIB_")
38+
.map(|suffix| suffix.to_ascii_lowercase())
39+
})
40+
.for_each(|lib| println!("cargo:rustc-link-lib=static={lib}"));
41+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![no_std]
2+
#![allow(non_snake_case)]
3+
#![allow(non_camel_case_types)]
4+
#![allow(non_upper_case_globals)]
5+
#![doc(html_no_source)]
6+
7+
/// Raw bindings generated by `stm32-bindings-gen`.
8+
///
9+
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
10+
/// surface to the STM32 WBA BLE middleware. All items should be treated as
11+
/// `unsafe` and wrapped by higher-level crates before use.
12+
pub mod bindings;
13+
14+
pub use bindings::*;

stm32-bindings-gen/res/wba/Cargo.toml renamed to stm32-bindings-gen/res/linklayer/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "wba-bindings"
2+
name = "linklayer-bindings"
33
version = "0.1.0"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
6-
description = "Unified STM32 WBA wireless stack bindings generated from the ST middleware."
6+
description = "Raw STM32 WBA link-layer bindings generated from the ST middleware."
77
build = "build.rs"
88

99
[lib]
@@ -41,6 +41,6 @@ lib_stm32wba_ble_stack_basic_plus = []
4141
lib_stm32wba_ble_stack_full = []
4242
lib_stm32wba_ble_stack_llo = []
4343
lib_stm32wba_ble_stack_po = []
44-
lib_ble_audio = []
45-
lib_codec_mngr = []
4644
lib_lc3 = []
45+
lib_codec_mngr = []
46+
lib_ble_audio = []

stm32-bindings-gen/res/wba/README.md renamed to stm32-bindings-gen/res/linklayer/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# wba-bindings
1+
# linklayer-bindings
22

3-
Raw bindings for the STM32 WBA wireless middleware (link layer, BLE stack, and IEEE 802.15.4 MAC). This crate is generated automatically by `stm32-bindings-gen` and is intended to be consumed by higher-level wrappers that provide safe abstractions over the radio stacks.
3+
Raw bindings for the STM32 WBA link-layer middleware. This crate is generated automatically by `stm32-bindings-gen` and is intended to be consumed by higher-level wrappers that provide safe abstractions for BLE or IEEE 802.15.4 stacks.
44

55
## Overview
66

@@ -14,7 +14,7 @@ The generator pulls in STM-provided headers and static libraries, then runs `bin
1414

1515
## Usage
1616

17-
1. Ensure `stm32-bindings-gen` has been run so this crate exists in `build/wba-bindings`.
17+
1. Ensure `stm32-bindings-gen` has been run so this crate exists in `build/linklayer-bindings`.
1818
2. Add a path dependency in your Cargo manifest pointing at that directory.
1919
3. Opt into the desired static library variant by enabling the matching `lib_*` feature exposed by this crate.
2020
4. Call the generated functions through `unsafe` code and wrap them in a higher-level API before exposing them to the rest of your application.
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![no_std]
2+
#![allow(non_snake_case)]
3+
#![allow(non_camel_case_types)]
4+
#![allow(non_upper_case_globals)]
5+
#![doc(html_no_source)]
6+
7+
/// Raw bindings generated by `stm32-bindings-gen`.
8+
///
9+
/// The `bindings` module is produced by `bindgen` and exposes a one-to-one FFI
10+
/// surface to the STM32 WBA link-layer middleware. All items should be treated
11+
/// as `unsafe` and wrapped by higher-level crates before use.
12+
pub mod bindings;
13+
14+
pub use bindings::*;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "mac-bindings"
3+
version = "0.1.0"
4+
edition = "2024"
5+
license = "MIT OR Apache-2.0"
6+
description = "Raw STM32 WBA IEEE 802.15.4 MAC bindings generated from the ST middleware."
7+
build = "build.rs"
8+
9+
[lib]
10+
path = "src/lib.rs"
11+
12+
[dependencies]
13+
linklayer-bindings = { path = "../linklayer-bindings" }
14+
15+
[features]
16+
default = []
17+
lib_wba_mac_lib = []

0 commit comments

Comments
 (0)