Skip to content

Commit

Permalink
gatt: add gatt file for service
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Dec 23, 2023
1 parent 9f2a4ec commit ba94808
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion examples/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion examples/pico_w/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
39 changes: 39 additions & 0 deletions src/components/bluepad32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/components/bluepad32/bt/uni_bt_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
14 changes: 14 additions & 0 deletions src/components/bluepad32/bt/uni_bt_service.gatt
Original file line number Diff line number Diff line change
@@ -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,


2 changes: 1 addition & 1 deletion src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "."
REQUIRES "${requires}")
REQUIRES "${requires}")

0 comments on commit ba94808

Please sign in to comment.