First of all I want to apologize if this is the wrong place to post this.
I have been messing around with Swift Embedded now for a little bit and I'm trying to set up a BLE Gatt server on a ESP32. Im trying to follow this walkthrough but writing in Swift ofc.
Im trying to call BT_CONTROLLER_INIT_CONFIG_DEFAULT() which is a function style macro but I get the following error when compiling:
/Users/naknut/Developer/esp32-ble-swift/main/BLE.swift:6:31: error: cannot find 'BT_CONTROLLER_INIT_CONFIG_DEFAULT' in scope
4 |
5 | init() {
6 | let bluetoothConfig = BT_CONTROLLER_INIT_CONFIG_DEFAULT()
| `- error: cannot find 'BT_CONTROLLER_INIT_CONFIG_DEFAULT' in scope
7 | guard esp_bt_controller_init(bluetoothConfig) == ESP_OK else {
8 | fatalError("initialize controller failed")
/Users/naknut/esp/esp-idf/components/bt/include/esp32c6/include/esp_bt.h:223:9: note: macro 'BT_CONTROLLER_INIT_CONFIG_DEFAULT' unavailable: function like macros not supported
221 | } esp_bt_controller_config_t;
222 |
223 | #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
| `- note: macro 'BT_CONTROLLER_INIT_CONFIG_DEFAULT' unavailable: function like macros not supported
224 | .config_version = CONFIG_VERSION, \
225 | .ble_ll_resolv_list_size = CONFIG_BT_LE_LL_RESOLV_LIST_SIZE, \
Swift's C interop can't directly interact with preprocessor macros except in a few limited situations like literal values. You might be able to wrap the macro invocation in a static inline function from a C header file and import that instead, like:
Absolutely! I don’t really have anything working yet. Just trying to figure out how to get started. But as soon as I have something working I’ll put up a repo and let you know.