diff --git a/examples/esp32/CMakeLists.txt b/examples/esp32/CMakeLists.txt index b9d85a30..855decfc 100644 --- a/examples/esp32/CMakeLists.txt +++ b/examples/esp32/CMakeLists.txt @@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 17) set(CMAKE_CXX_STANDARD 17) -set(EXTRA_COMPONENT_DIRS ../../src/components) +set(BLUEPAD32_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) +set(EXTRA_COMPONENT_DIRS ${BLUEPAD32_ROOT}/src/components) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(bluepad32_esp32_example_app) diff --git a/examples/linux/CMakeLists.txt b/examples/linux/CMakeLists.txt index 101511d8..b601d88d 100644 --- a/examples/linux/CMakeLists.txt +++ b/examples/linux/CMakeLists.txt @@ -5,7 +5,8 @@ set(CMAKE_C_STANDARD 17) project(bluepad32_linux_example_app C ASM) -set(BLUEPAD32_ROOT "../..") +set(BLUEPAD32_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) + # To use it from Bluepad32 (up-to-date, with custom patches for controllers): set(BTSTACK_ROOT ${BLUEPAD32_ROOT}/external/btstack) diff --git a/examples/pico_w/CMakeLists.txt b/examples/pico_w/CMakeLists.txt index a7d6de96..b00cb75c 100644 --- a/examples/pico_w/CMakeLists.txt +++ b/examples/pico_w/CMakeLists.txt @@ -7,7 +7,7 @@ else() set(PICO_BOARD "pico_w") endif() -set(BLUEPAD32_ROOT ../..) +set(BLUEPAD32_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) # initialize the SDK based on PICO_SDK_PATH # note: this must happen before project() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72a109da..2e2e5684 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,4 +5,4 @@ set(CMAKE_C_STANDARD 17) set(CMAKE_CXX_STANDARD 17) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(bluepad32-app) +project(bluepad32-app) \ No newline at end of file diff --git a/src/components/bluepad32/CMakeLists.txt b/src/components/bluepad32/CMakeLists.txt index 4bbddf2b..3daa4330 100644 --- a/src/components/bluepad32/CMakeLists.txt +++ b/src/components/bluepad32/CMakeLists.txt @@ -1,3 +1,15 @@ +include(CMakePrintHelpers) + +if (NOT DEFINED BLUEPAD32_ROOT) + set (BLUEPAD32_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) + message(WARNING "BLUEPAD32_ROOT not set. Setting to ${BLUEPAD32_ROOT}") +endif() + +if (NOT DEFINED BTSTACK_ROOT) + set (BTSTACK_ROOT ${BLUEPAD32_ROOT}/external/btstack) + message(WARNING "BTSTACK_ROOT not set. Setting to ${BTSTACK_ROOT}") +endif() + set(srcs "bt/uni_bt.c" "bt/uni_bt_allowlist.c" @@ -95,6 +107,33 @@ if(CONFIG_IDF_TARGET_ESP32) "platform/uni_platform_unijoysticle_singleport.c") endif() +# BLE Service +# to generate .h from .gatt files +if(NOT CMAKE_BUILD_EARLY_EXPANSION) + # CMAKE_BUILD_EARLY_EXPANSION needed in ESP32 to prevent command is not scriptable. + # See: https://esp32.com/viewtopic.php?t=29402 + find_package (Python REQUIRED COMPONENTS Interpreter) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + + set(GATT_FILES + "uni_bt_service.gatt") + + cmake_print_variables(GATT_FILES) + cmake_print_variables(BLUEPAD32_ROOT) + cmake_print_variables(BTSTACK_ROOT) + foreach(GATT_FILE ${GATT_FILES}) + message("Generating GATT DB file") + cmake_print_variables(GATT_FILE) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GATT_FILE}.h + DEPENDS bt/${GATT_FILE} + COMMAND ${Python_EXECUTABLE} + ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${CMAKE_CURRENT_SOURCE_DIR}/bt/${GATT_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${GATT_FILE}.h + ) + list(APPEND srcs ${CMAKE_CURRENT_BINARY_DIR}/${GATT_FILE}.h) + endforeach(GATT_FILE) +endif() + # Valid for ESP-IDF only if(IDF_TARGET) set(requires "nvs_flash" "btstack" "app_update" "esp_timer") diff --git a/src/components/bluepad32/bt/uni_bt_service.c b/src/components/bluepad32/bt/uni_bt_service.c index 48d34724..06f4bb1f 100644 --- a/src/components/bluepad32/bt/uni_bt_service.c +++ b/src/components/bluepad32/bt/uni_bt_service.c @@ -4,6 +4,8 @@ #include "bt/uni_bt_service.h" +#include "uni_bt_service.gatt.h" + static bool service_enabled; void uni_bt_service_init(void) {} diff --git a/src/components/bluepad32/bt/uni_bt_service.gatt b/src/components/bluepad32/bt/uni_bt_service.gatt new file mode 100644 index 00000000..55ff295c --- /dev/null +++ b/src/components/bluepad32/bt/uni_bt_service.gatt @@ -0,0 +1,14 @@ +PRIMARY_SERVICE, GAP_SERVICE +CHARACTERISTIC, GAP_DEVICE_NAME, READ, "LE Streamer" + +PRIMARY_SERVICE, GATT_SERVICE +CHARACTERISTIC, GATT_DATABASE_HASH, READ, + +// Test Service +PRIMARY_SERVICE, 0000FF10-0000-1000-8000-00805F9B34FB +// Test Characteristic A, write_without_response as well as notify +CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, WRITE_WITHOUT_RESPONSE | NOTIFY | DYNAMIC, +// Test Characteristic B, write_without_response as well as notify +CHARACTERISTIC, 0000FF12-0000-1000-8000-00805F9B34FB, WRITE_WITHOUT_RESPONSE | NOTIFY | DYNAMIC, + + diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 1737fd16..e6c578a0 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -10,4 +10,4 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "." - REQUIRES "${requires}") + REQUIRES "${requires}") \ No newline at end of file