diff --git a/port/qt-h4/CMakeLists.txt b/port/qt-h4/CMakeLists.txt index 2d0ae1ebd..3c17e60be 100644 --- a/port/qt-h4/CMakeLists.txt +++ b/port/qt-h4/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.12) project(qt-h4 LANGUAGES C CXX) @@ -13,33 +13,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) message("${Qt5_DIR}") -# pkgconfig -find_package(PkgConfig QUIET) - -# portaudio -if (PkgConfig_FOUND) - pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) - if(PORTAUDIO_FOUND) - message("HAVE_PORTAUDIO") - include_directories(${PORTAUDIO_INCLUDE_DIRS}) - link_directories(${PORTAUDIO_LIBRARY_DIRS}) - link_libraries(${PORTAUDIO_LIBRARIES}) - # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO) - SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") - endif() -endif() - -find_package(Qt5Core) -find_package(FindPython3) +find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(Python REQUIRED COMPONENTS Interpreter) # BTstack Root -set(BTSTACK_ROOT "${PROJECT_SOURCE_DIR}/../..") +SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) message("BTSTACK_ROOT: ${BTSTACK_ROOT}") # BTstack include include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc) include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include) include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include) +include_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include) include_directories(${BTSTACK_ROOT}/3rd-party/md5) include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player) include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod) @@ -64,7 +49,7 @@ file(GLOB SOURCES_SRC "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/s file(GLOB SOURCES_BLE "${BTSTACK_ROOT}/src/ble/*.c") file(GLOB SOURCES_GATT "${BTSTACK_ROOT}/src/ble/gatt-service/*.c") file(GLOB SOURCES_CLASSIC "${BTSTACK_ROOT}/src/classic/*.c") -file(GLOB SOURCES_MESH "${BTSTACK_ROOT}/src/mesh/*.c") +file(GLOB SOURCES_MESH "../../src/mesh/*.c" "../../src/mesh/gatt-service/*.c") file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c") file(GLOB SOURCES_MD5 "${BTSTACK_ROOT}/3rd-party/md5/md5.c") file(GLOB SOURCES_UECC "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c") @@ -132,20 +117,17 @@ file(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c") list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) -# select POSIX vs Windows versions +# select files for H4 UART support IF (WIN32) - message("Building for Windows using WinUSB") - set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/windows/hci_transport_h2_winusb.c) + message("Building for Windows with H4 UART") + include_directories(${BTSTACK_ROOT}/platform/windows) + file(GLOB SOURCES_WINDOWS "${BTSTACK_ROOT}/platform/windows/*.c") set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/windows/btstack_stdin_windows.c) - link_libraries( winusb setupapi) ELSE() - message("Building for POSIX using libusb") - - set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/libusb/hci_transport_h2_libusb.c) - set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/posix/btstack_stdin_posix.c ${BTSTACK_ROOT}/platform/posix/btstack_signal.c) - + message("Building for POSIX with H4 UART") list(APPEND SOURCES_POSIX ${BTSTACK_ROOT}/platform/posix/btstack_network_posix.c) list(APPEND SOURCES_POSIX ${BTSTACK_ROOT}/platform/posix/btstack_block_posix.c) + set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/posix/btstack_stdin_posix.c ${BTSTACK_ROOT}/platform/posix/btstack_signal.c) ENDIF() set(SOURCES @@ -154,7 +136,6 @@ set(SOURCES ${SOURCES_BLUEDROID} ${SOURCES_POSIX} ${SOURCES_RIJNDAEL} - ${SOURCES_HCI_USB} ${SOURCES_STDIN} ${SOURCES_SRC} ${SOURCES_BLE} @@ -164,11 +145,42 @@ set(SOURCES ${SOURCES_UECC} ${SOURCES_HXCMOD} ${SOURCES_CHIPSET} + ${SOURCES_WINDOWS} ) list(SORT SOURCES) # create static lib -add_library(btstack-lib STATIC ${SOURCES}) +add_library(btstack STATIC ${SOURCES}) + +# pkgconfig +find_package(PkgConfig QUIET) + +# link libraries for H4 UART support +IF (WIN32) + target_link_libraries(btstack setupapi) +ELSE() + # find pkgconfig + find_package(PkgConfig REQUIRED) + + # libusb + pkg_check_modules(LIBUSB REQUIRED libusb-1.0) + target_include_directories(btstack PUBLIC ${LIBUSB_INCLUDE_DIRS}) + target_link_directories(btstack PUBLIC ${LIBUSB_LIBRARY_DIRS}) + target_link_libraries(btstack ${LIBUSB_LIBRARIES}) +ENDIF() + +# portaudio +if (PkgConfig_FOUND) + pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) + if(PORTAUDIO_FOUND) + message("HAVE_PORTAUDIO") + target_include_directories(btstack PUBLIC ${PORTAUDIO_INCLUDE_DIRS}) + target_link_directories(btstack PUBLIC ${PORTAUDIO_LIBRARY_DIRS}) + target_link_libraries(btstack ${PORTAUDIO_LIBRARIES}) + add_compile_definitions(HAVE_PORTAUDIO) + SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") + endif() +endif() # create targets for all examples file(GLOB EXAMPLES_C "${BTSTACK_ROOT}/example/*.c") @@ -212,5 +224,5 @@ foreach(EXAMPLE_FILE ${EXAMPLES_C}) message("example ${EXAMPLE}") endif() add_executable(${EXAMPLE} ${SOURCES_EXAMPLE} ) - target_link_libraries(${EXAMPLE} btstack-lib Qt5::Core) + target_link_libraries(${EXAMPLE} btstack Qt5::Core) endforeach(EXAMPLE_FILE) diff --git a/port/qt-h4/README.md b/port/qt-h4/README.md index 5f0de4965..2b4e44b92 100644 --- a/port/qt-h4/README.md +++ b/port/qt-h4/README.md @@ -1,10 +1,10 @@ # BTstack Port for QT with H4 Bluetooth Controller -Uses libusb Library on macOS and Linux and WinUSB on Windows. Windows is supported with the MinGW Kit. Windows with MSVC or Embedded (bare metal) platforms not supported yet. + ## Configuration Most Bluetooth Bluetooth Controllers connected via UART/H4 require some special configuration, e.g. to set the UART baud rate, and/or require firmware patches during startup. In this port, we've tried to do most of these automatically based on information gathered from the Bluetooth Controller. Here's some Controller specific details: @@ -30,6 +30,10 @@ On macOS/Linux [libusb-1.0](http://libusb.info) or higher is required, too. When everything is ready, you can open the provided CMakelists.txt project in Qt Creator and run any of the provided examples. See Qt documentation on how to compile on the command line or with other IDEs +You can also compile the project in a shell if you provide the path to the cmake folder of your Qt installation, e.g. on macOS with brew providing QT 5.15.16 + + cmake -DCMAKE_PREFIX_PATH=/opt/homebrew/Cellar/qt@5/5.15.16/lib/cmake/Qt5 .. + ## Running the examples @@ -37,7 +41,7 @@ BTstack's HCI USB transport will try to find a suitable Bluetooth module and use On start, BTstack will try to find a suitable Bluetooth module. It will also print the path to the packet log as well as the USB path. - $ ./le_counter + $ ./gattcounter Packet Log: /tmp/hci_dump.pklg BTstack counter 0001 USB Path: 06 diff --git a/port/qt-usb/CMakeLists.txt b/port/qt-usb/CMakeLists.txt index d8ba3b04c..fe2c50477 100644 --- a/port/qt-usb/CMakeLists.txt +++ b/port/qt-usb/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.12) project(qt-usb LANGUAGES C CXX) @@ -13,33 +13,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) message("${Qt5_DIR}") -find_package(Qt5Core) -include(FindPythonInterp) - -# pkgconfig -find_package(PkgConfig QUIET) - -# portaudio -if (PkgConfig_FOUND) - pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) - if(PORTAUDIO_FOUND) - message("HAVE_PORTAUDIO") - include_directories(${PORTAUDIO_INCLUDE_DIRS}) - link_directories(${PORTAUDIO_LIBRARY_DIRS}) - link_libraries(${PORTAUDIO_LIBRARIES}) - # CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO) - SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") - endif() -endif() +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Python REQUIRED COMPONENTS Interpreter) # BTstack Root -set(BTSTACK_ROOT "../..") +SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..) message("BTSTACK_ROOT: ${BTSTACK_ROOT}") # BTstack include include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc) include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include) include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include) +include_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include) include_directories(${BTSTACK_ROOT}/3rd-party/md5) include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player) include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod) @@ -61,7 +46,7 @@ file(GLOB SOURCES_SRC "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/s file(GLOB SOURCES_BLE "${BTSTACK_ROOT}/src/ble/*.c") file(GLOB SOURCES_GATT "${BTSTACK_ROOT}/src/ble/gatt-service/*.c") file(GLOB SOURCES_CLASSIC "${BTSTACK_ROOT}/src/classic/*.c") -file(GLOB SOURCES_MESH "${BTSTACK_ROOT}/src/mesh/*.c") +file(GLOB SOURCES_MESH "../../src/mesh/*.c" "../../src/mesh/gatt-service/*.c") file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c") file(GLOB SOURCES_MD5 "${BTSTACK_ROOT}/3rd-party/md5/md5.c") file(GLOB SOURCES_UECC "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c") @@ -123,28 +108,17 @@ file(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c") list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF}) -# select POSIX vs Windows versions +# select files for USB support IF (WIN32) message("Building for Windows using WinUSB") - set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/windows/hci_transport_h2_winusb.c) + include_directories(${BTSTACK_ROOT}/platform/windows) + file(GLOB SOURCES_WINDOWS "${BTSTACK_ROOT}/platform/windows/*.c") set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/windows/btstack_stdin_windows.c) - link_libraries( winusb setupapi) ELSE() message("Building for POSIX using libusb") - - # fink pkgconfig - find_package(PkgConfig REQUIRED) - - # libusb - pkg_check_modules(LIBUSB REQUIRED libusb-1.0) - include_directories(${LIBUSB_INCLUDE_DIRS}) - link_directories(${LIBUSB_LIBRARY_DIRS}) - link_libraries(${LIBUSB_LIBRARIES}) - set(SOURCES_HCI_USB ${BTSTACK_ROOT}/platform/libusb/hci_transport_h2_libusb.c) - set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/posix/btstack_stdin_posix.c ${BTSTACK_ROOT}/platform/posix/btstack_signal.c) - list(APPEND SOURCES_POSIX ${BTSTACK_ROOT}/platform/posix/btstack_network_posix.c) + set(SOURCES_STDIN ${BTSTACK_ROOT}/platform/posix/btstack_stdin_posix.c ${BTSTACK_ROOT}/platform/posix/btstack_signal.c) ENDIF() set(SOURCES @@ -162,11 +136,42 @@ set(SOURCES ${SOURCES_CLASSIC} ${SOURCES_UECC} ${SOURCES_HXCMOD} + ${SOURCES_WINDOWS} ) list(SORT SOURCES) # create static lib -add_library(btstack-lib STATIC ${SOURCES}) +add_library(btstack STATIC ${SOURCES}) + +# pkgconfig +find_package(PkgConfig QUIET) + +# link libraries for USB support +IF (WIN32) + target_link_libraries(btstack winusb setupapi) +ELSE() + # find pkgconfig + find_package(PkgConfig REQUIRED) + + # libusb + pkg_check_modules(LIBUSB REQUIRED libusb-1.0) + target_include_directories(btstack PUBLIC ${LIBUSB_INCLUDE_DIRS}) + target_link_directories(btstack PUBLIC ${LIBUSB_LIBRARY_DIRS}) + target_link_libraries(btstack ${LIBUSB_LIBRARIES}) +ENDIF() + +# portaudio +if (PkgConfig_FOUND) + pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) + if(PORTAUDIO_FOUND) + message("HAVE_PORTAUDIO") + target_include_directories(btstack PUBLIC ${PORTAUDIO_INCLUDE_DIRS}) + target_link_directories(btstack PUBLIC ${PORTAUDIO_LIBRARY_DIRS}) + target_link_libraries(btstack ${PORTAUDIO_LIBRARIES}) + add_compile_definitions(HAVE_PORTAUDIO) + SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO") + endif() +endif() # create targets for all examples file(GLOB EXAMPLES_C "${BTSTACK_ROOT}/example/*.c") @@ -210,5 +215,5 @@ foreach(EXAMPLE_FILE ${EXAMPLES_C}) message("example ${EXAMPLE}") endif() add_executable(${EXAMPLE} ${SOURCES_EXAMPLE} ) - target_link_libraries(${EXAMPLE} btstack-lib Qt5::Core) + target_link_libraries(${EXAMPLE} btstack Qt5::Core) endforeach(EXAMPLE_FILE) diff --git a/port/qt-usb/README.md b/port/qt-usb/README.md index cb3378764..fa5a9ff37 100644 --- a/port/qt-usb/README.md +++ b/port/qt-usb/README.md @@ -13,6 +13,10 @@ On macOS/Linux [libusb-1.0](http://libusb.info) or higher is required, too. When everything is ready, you can open the provided CMakelists.txt project in Qt Creator and run any of the provided examples. See Qt documentation on how to compile on the command line or with other IDEs +You can also compile the project in a shell if you provide the path to the cmake folder of your Qt installation, e.g. on macOS with brew providing QT 5.15.16 + + cmake -DCMAKE_PREFIX_PATH=/opt/homebrew/Cellar/qt@5/5.15.16/lib/cmake/Qt5 .. + ## Environment Setup ## Windows @@ -74,7 +78,7 @@ BTstack's HCI USB transport will try to find a suitable Bluetooth module and use On start, BTstack will try to find a suitable Bluetooth module. It will also print the path to the packet log as well as the USB path. - $ ./le_counter + $ ./gatt_counter Packet Log: /tmp/hci_dump.pklg BTstack counter 0001 USB Path: 06 @@ -84,7 +88,7 @@ If you want to run multiple examples at the same time, it helps to fix the path Example running le_streamer and le_streamer_client in two processes, using Bluetooth dongles at USB path 6 and 4: - ./le_streamer -u 6 + ./gatt_streamer_server -u 6 Specified USB Path: 06 Packet Log: /tmp/hci_dump_6.pklg USB Path: 06