diff --git a/.vscode/settings.json b/.vscode/settings.json index 1177afa..5bf1c09 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,7 +17,7 @@ //"rust-analyzer.cargo.target": "thumbv7m-none-eabi", // "rust-analyzer.cargo.target": "thumbv7em-none-eabi", //"rust-analyzer.cargo.target": "thumbv7em-none-eabihf", - // "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", + "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", "rust-analyzer.cargo.features": [], "rust-analyzer.linkedProjects": [ "stm32-bindings-gen/Cargo.toml", diff --git a/stm32-bindings-gen/inc/wba_wpan_ble.h b/stm32-bindings-gen/inc/wba_wpan_ble.h new file mode 100644 index 0000000..99f47a0 --- /dev/null +++ b/stm32-bindings-gen/inc/wba_wpan_ble.h @@ -0,0 +1,210 @@ +#define __PACKED_STRUCT struct __attribute__((packed)) +#define __PACKED_UNION union __attribute__((packed)) +#define __STATIC_INLINE static +#define __ALIGNED(x) __attribute__((aligned(x))) + +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file app_ble.h + * @author MCD Application Team + * @brief Header for ble application + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_BLE_H +#define APP_BLE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Includes ------------------------------------------------------------------*/ + +/* Private includes ----------------------------------------------------------*/ +#include "ble_types.h" + /* USER CODE BEGIN Includes */ + + /* USER CODE END Includes */ + + /* Exported types ------------------------------------------------------------*/ + + typedef enum + { + APP_BLE_IDLE, + APP_BLE_LP_CONNECTING, + APP_BLE_CONNECTED_SERVER, + APP_BLE_CONNECTED_CLIENT, + APP_BLE_ADV_FAST, + APP_BLE_ADV_LP, + APP_BLE_ADV_NON_CONN_FAST, + APP_BLE_ADV_NON_CONN_LP, + /* USER CODE BEGIN APP_BLE_ConnStatus_t */ + + /* USER CODE END APP_BLE_ConnStatus_t */ + } APP_BLE_ConnStatus_t; + + /** + * HCI Event Packet Types + */ + typedef __PACKED_STRUCT + { + uint32_t *next; + uint32_t *prev; + } + BleEvtPacketHeader_t; + + typedef __PACKED_STRUCT + { + uint8_t evtcode; + uint8_t plen; + uint8_t payload[1]; + } + BleEvt_t; + + typedef __PACKED_STRUCT + { + uint8_t type; + BleEvt_t evt; + } + BleEvtSerial_t; + + typedef __PACKED_STRUCT __ALIGNED(4) + { + BleEvtPacketHeader_t header; + BleEvtSerial_t evtserial; + } + BleEvtPacket_t; + + typedef enum + { + PROC_GAP_GEN_PHY_TOGGLE, + PROC_GAP_GEN_CONN_TERMINATE, + PROC_GATT_EXCHANGE_CONFIG, + /* USER CODE BEGIN ProcGapGeneralId_t */ + + /* USER CODE END ProcGapGeneralId_t */ + } ProcGapGeneralId_t; + + typedef enum + { + PROC_GAP_PERIPH_ADVERTISE_START_LP, + PROC_GAP_PERIPH_ADVERTISE_START_FAST, + PROC_GAP_PERIPH_ADVERTISE_NON_CONN_START_LP, + PROC_GAP_PERIPH_ADVERTISE_NON_CONN_START_FAST, + PROC_GAP_PERIPH_ADVERTISE_STOP, + PROC_GAP_PERIPH_ADVERTISE_DATA_UPDATE, + PROC_GAP_PERIPH_CONN_PARAM_UPDATE, + /* USER CODE BEGIN ProcGapPeripheralId_t */ + + /* USER CODE END ProcGapPeripheralId_t */ + } ProcGapPeripheralId_t; + + typedef enum + { + PROC_GAP_CENTRAL_SCAN_START, + PROC_GAP_CENTRAL_SCAN_TERMINATE, + /* USER CODE BEGIN ProcGapCentralId_t */ + + /* USER CODE END ProcGapCentralId_t */ + } ProcGapCentralId_t; + +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ +/* ST Manufacturer ID */ +#define ST_MANUF_ID 0x30 + + /* BlueSTSDK Version */ + enum + { + BLUESTSDK_V1 = 0x01, + BLUESTSDK_V2 = 0x02 + }; + + /* BOARD ID */ + enum + { + BOARD_ID_NUCLEO_WBA5X = 0x8B, + BOARD_ID_DK_WBA5X = 0x91, + BOARD_ID_B_WBA5M_WPAN = 0x8D, + BOARD_ID_NUCLEO_WBA6X = 0x8E, + BOARD_ID_DK_WBA6X = 0x92, + BOARD_ID_B_WBA6M_WPAN = 0x93 + }; + + /* FIRMWARE ID */ + enum + { + FW_ID_P2P_SERVER = 0x83, + FW_ID_P2P_ROUTER = 0x85, + FW_ID_DT_SERVER = 0x88, + FW_ID_COC_PERIPH = 0x87, + FW_ID_HEART_RATE = 0x89, + FW_ID_HEALTH_THERMO = 0x8A, + FW_ID_HID = 0x8B, + FW_ID_SENSOR = 0x9C, + FW_ID_GENERIC_HEALTH_SENSOR = 0x9D + }; + +/* USER CODE END EC */ + +/* External variables --------------------------------------------------------*/ +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/* Exported macro ------------------------------------------------------------*/ +#define ADV_INT_MS(x) ((uint16_t)((x) / 0.625f)) +#define SCAN_WIN_MS(x) ((uint16_t)((x) / 0.625f)) +#define SCAN_INT_MS(x) ((uint16_t)((x) / 0.625f)) +#define CONN_INT_MS(x) ((uint16_t)((x) / 1.25f)) +#define CONN_SUP_TIMEOUT_MS(x) ((uint16_t)((x) / 10.0f)) +#define CONN_CE_LENGTH_MS(x) ((uint16_t)((x) / 0.625f)) + +#define HCI_LE_ADVERTISING_REPORT_RSSI(p) \ + (*(int8_t *)((&((hci_le_advertising_report_event_rp0 *)(p))->Advertising_Report[0].Length_Data) + 1 + \ + ((hci_le_advertising_report_event_rp0 *)(p))->Advertising_Report[0].Length_Data)) + /* USER CODE BEGIN EM */ + + /* USER CODE END EM */ + + /* Exported functions prototypes ---------------------------------------------*/ + void APP_BLE_Init(void); + void BleStack_Process_BG(void); + APP_BLE_ConnStatus_t APP_BLE_Get_Server_Connection_Status(void); + void APP_BLE_Procedure_Gap_General(ProcGapGeneralId_t ProcGapGeneralId); + void APP_BLE_Procedure_Gap_Peripheral(ProcGapPeripheralId_t ProcGapPeripheralId); + const uint8_t *BleGetBdAddress(void); + tBleStatus SetGapAppearance(uint16_t appearance); + tBleStatus SetGapDeviceName(uint8_t *devicename, uint8_t devicename_len); + void Ble_UserEvtRx(void); + void APP_BLE_HostNvmStore(void); + /* USER CODE BEGIN EFP */ + + /* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /*APP_BLE_H */ + +#include "ble_core.h" +#include "blestack.h" \ No newline at end of file diff --git a/stm32-bindings-gen/res/Cargo.toml b/stm32-bindings-gen/res/Cargo.toml index e1f9b8f..73b269d 100644 --- a/stm32-bindings-gen/res/Cargo.toml +++ b/stm32-bindings-gen/res/Cargo.toml @@ -51,7 +51,7 @@ cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true } defmt = { version = "0.3.0", optional = true } [features] -default = ["pac"] +default = ["pac", "wba_wpan_mac", "wba_wpan_ble"] wba_wpan_mac = [] wba_wpan_ble = [] diff --git a/stm32-bindings-gen/res/src/bindings/mod.rs b/stm32-bindings-gen/res/src/bindings/mod.rs index b5570eb..f83803b 100644 --- a/stm32-bindings-gen/res/src/bindings/mod.rs +++ b/stm32-bindings-gen/res/src/bindings/mod.rs @@ -1,2 +1,4 @@ +#[cfg(feature = "wba_wpan_ble")] +mod wba_wpan_ble; #[cfg(feature = "wba_wpan_mac")] mod wba_wpan_mac; diff --git a/stm32-bindings-gen/src/lib.rs b/stm32-bindings-gen/src/lib.rs index f160d63..1612516 100644 --- a/stm32-bindings-gen/src/lib.rs +++ b/stm32-bindings-gen/src/lib.rs @@ -1,7 +1,7 @@ use bindgen::callbacks::{ItemInfo, ItemKind, ParseCallbacks}; use std::io::Write; use std::{fs, path::PathBuf}; -use tempfile::NamedTempFile; +use tempfile::{NamedTempFile, TempDir}; #[derive(Debug)] struct UppercaseCallbacks; @@ -45,6 +45,10 @@ impl Gen { fs::create_dir_all(self.opts.out_dir.join("src/bindings")).unwrap(); fs::create_dir_all(self.opts.out_dir.join("src/lib")).unwrap(); + let tmpdir = TempDir::new().unwrap(); + fs::write(tmpdir.path().join("string.h"), "").unwrap(); + // fs::write(tmpdir.path().join("stdint.h"), "").unwrap(); + for lib in &self.libs { let sources_dir = self.opts.sources_dir.join(&lib.sources_dir); @@ -71,6 +75,8 @@ impl Gen { )); } + builder = builder.clang_arg(&format!("-I{}", tmpdir.path().to_str().unwrap())); + if lib.target_triple.to_ascii_lowercase().starts_with("thumb") { builder = builder.clang_arg("-mthumb"); } @@ -96,6 +102,7 @@ impl Gen { let mut file_contents = fs::read_to_string(&out_path).unwrap(); file_contents = file_contents + .replace(":: std :: mem ::", ":: core :: mem ::") .replace("::std::mem::", "::core::mem::") .replace("::std::os::raw::", "::core::ffi::") .replace("::std::option::", "::core::option::"); diff --git a/stm32-bindings-gen/src/main.rs b/stm32-bindings-gen/src/main.rs index f7c4d68..dfd8a29 100644 --- a/stm32-bindings-gen/src/main.rs +++ b/stm32-bindings-gen/src/main.rs @@ -11,14 +11,27 @@ fn main() { sources_dir, }; - let libs = Vec::from([Library { - target_triple: String::from("thumbv8m.main-none-eabihf"), - sources_dir: "STM32CubeWBA".into(), - header: include_bytes!("../inc/wba_wpan_mac.h"), - module: "wba_wpan_mac", - includes: Vec::from(["Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc".into()]), - library: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a".into(), - }]); + let libs = Vec::from([ + Library { + target_triple: String::from("thumbv8m.main-none-eabihf"), + sources_dir: "STM32CubeWBA".into(), + header: include_bytes!("../inc/wba_wpan_mac.h"), + module: "wba_wpan_mac", + includes: Vec::from(["Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc".into()]), + library: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a".into(), + }, + Library { + target_triple: String::from("thumbv8m.main-none-eabihf"), + sources_dir: "STM32CubeWBA".into(), + header: include_bytes!("../inc/wba_wpan_ble.h"), + module: "wba_wpan_ble", + includes: Vec::from([ + "Middlewares/ST/STM32_WPAN/ble/stack/include".into(), + "Middlewares/ST/STM32_WPAN/ble/stack/include/auto".into(), + ]), + library: "Middlewares/ST/STM32_WPAN/ble/stack/lib/stm32wba_ble_stack_full.a".into(), + }, + ]); Gen::new(opts, libs).run_gen(); }