From c894dca1b72560abcf8bcddfb43ffd9285d8713c Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 18 Jul 2017 23:14:38 +0200 Subject: [PATCH] max32630-fthr: create project folder with Makefile for each example --- port/Makefile | 2 +- port/max32630-fthr/Makefile | 206 +-------- port/max32630-fthr/Makefile.template | 205 +++++++++ port/max32630-fthr/scripts/create_examples.py | 75 ++++ port/max32630-fthr/scripts/delete_examples.py | 31 ++ port/max32630-fthr/spp_and_le_streamer.c | 400 ------------------ port/max32630-fthr/spp_and_le_streamer.gatt | 12 - port/max32630-fthr/spp_and_le_streamer.h | 63 --- port/max32630-fthr/{ => src}/btstack_config.h | 0 port/max32630-fthr/{ => src}/btstack_port.c | 0 port/max32630-fthr/{ => src}/btstack_port.h | 0 port/max32630-fthr/{ => src}/hal_tick.c | 0 port/max32630-fthr/{ => src}/hal_tick.h | 0 port/max32630-fthr/{ => src}/main.c | 0 14 files changed, 320 insertions(+), 674 deletions(-) create mode 100644 port/max32630-fthr/Makefile.template create mode 100755 port/max32630-fthr/scripts/create_examples.py create mode 100755 port/max32630-fthr/scripts/delete_examples.py delete mode 100644 port/max32630-fthr/spp_and_le_streamer.c delete mode 100644 port/max32630-fthr/spp_and_le_streamer.gatt delete mode 100644 port/max32630-fthr/spp_and_le_streamer.h rename port/max32630-fthr/{ => src}/btstack_config.h (100%) rename port/max32630-fthr/{ => src}/btstack_port.c (100%) rename port/max32630-fthr/{ => src}/btstack_port.h (100%) rename port/max32630-fthr/{ => src}/hal_tick.c (100%) rename port/max32630-fthr/{ => src}/hal_tick.h (100%) rename port/max32630-fthr/{ => src}/main.c (100%) diff --git a/port/Makefile b/port/Makefile index 951497523..faffe140c 100644 --- a/port/Makefile +++ b/port/Makefile @@ -21,7 +21,7 @@ SUBDIRS = \ posix-h4 \ posix-h5 \ stm32-f103rb-nucleo \ - max32630-fthr-cc2564b \ + max32630-fthr \ EXCLUDED = \ pic32-harmony/app.X \ diff --git a/port/max32630-fthr/Makefile b/port/max32630-fthr/Makefile index 9938c4397..2f60f9e16 100644 --- a/port/max32630-fthr/Makefile +++ b/port/max32630-fthr/Makefile @@ -1,200 +1,10 @@ -################################################################################ - # Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. - # Ismail H. Kose - # Permission is hereby granted, free of charge, to any person obtaining a - # copy of this software and associated documentation files (the "Software"), - # to deal in the Software without restriction, including without limitation - # the rights to use, copy, modify, merge, publish, distribute, sublicense, - # and/or sell copies of the Software, and to permit persons to whom the - # Software is furnished to do so, subject to the following conditions: - # - # The above copyright notice and this permission notice shall be included - # in all copies or substantial portions of the Software. - # - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - # IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES - # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - # OTHER DEALINGS IN THE SOFTWARE. - # - # Except as contained in this notice, the name of Maxim Integrated - # Products, Inc. shall not be used except as stated in the Maxim Integrated - # Products, Inc. Branding Policy. - # - # The mere transfer of this software does not imply any licenses - # of trade secrets, proprietary technology, copyrights, patents, - # trademarks, maskwork rights, or any other form of intellectual - # property whatsoever. Maxim Integrated Products, Inc. retains all - # ownership rights. - # - # $Date: 2016-03-23 13:28:53 -0700 (Wed, 23 Mar 2016) $ - # $Revision: 22067 $ - # - ############################################################################### +.phony: examples +all: examples -# Maxim ARM Toolchain and Libraries -# https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html +examples: + scripts/create_examples.py -# This is the name of the build output file -PROJECT=max3263x - -# Specify the target processor -TARGET=MAX3263x -PROJ_CFLAGS+=-DRO_FREQ=96000000 - -# Create Target name variables -TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) -TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) - -CC2564B = bluetooth_init_cc2564B_1.6_BT_Spec_4.1.o - -# Select 'GCC' or 'IAR' compiler -COMPILER=GCC - -ifeq "$(MAXIM_PATH)" "" -LIBS_DIR=/$(subst \,/,$(subst :,,$(HOME))/Maxim/Firmware/$(TARGET_UC)/Libraries) -$(warning "MAXIM_PATH need to be set. Please run setenv bash file in the Maxim Toolchain directory.") -else -LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries) -endif - -CMSIS_ROOT=$(LIBS_DIR)/CMSIS - -# Where to find source files for this test -VPATH=. - -# Where to find header files for this test -IPATH=. - -BOARD_DIR=$(LIBS_DIR)/Boards - -IPATH += board/ -VPATH += board/ - -# Source files for this test (add path to VPATH below) -SRCS = main.c -SRCS += hal_tick.c -SRCS += btstack_port.c -SRCS += spp_and_le_streamer.c -SRCS += board.c -SRCS += stdio.c -SRCS += led.c -SRCS += pb.c -SRCS += max14690n.c - -# Where to find BSP source files -VPATH += $(BOARD_DIR)/Source - -# Where to find BSP header files -IPATH += $(BOARD_DIR)/Include - -# Btstack -BTSTACK_ROOT = ../.. -VPATH += $(BTSTACK_ROOT)/src -VPATH += $(BTSTACK_ROOT)/src/ble -VPATH += $(BTSTACK_ROOT)/src/classic -VPATH += $(BTSTACK_ROOT)/chipset/cc256x -VPATH += ${BTSTACK_ROOT}/platform/embedded -VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service/ -VPATH += $(BTSTACK_ROOT)/port/pegasus-max3263x -VPATH += $(BTSTACK_ROOT)/example - -PROJ_CFLAGS += \ - -I$(BTSTACK_ROOT)/src \ - -I$(BTSTACK_ROOT)/src/ble \ - -I$(BTSTACK_ROOT)/src/classic \ - -I$(BTSTACK_ROOT)/chipset/cc256x \ - -I$(BTSTACK_ROOT)/platform/embedded \ - -I${BTSTACK_ROOT}/port/pegasus-max3263x \ - -I${BTSTACK_ROOT}/src/ble/gatt-service/ \ - -I${BTSTACK_ROOT}/example - -CORE = \ - ad_parser.o \ - btstack_linked_list.o \ - btstack_memory.o \ - btstack_memory_pool.o \ - btstack_run_loop.o \ - btstack_util.o \ - l2cap.o \ - l2cap_signaling.o \ - btstack_run_loop_embedded.o \ - $(CC2564B) \ - hci_transport_h4.o - -COMMON = \ - btstack_chipset_cc256x.o \ - hci.o \ - hci_cmd.o \ - hci_dump.o \ - btstack_uart_block_embedded.o - -CLASSIC = \ - btstack_link_key_db_memory.o \ - rfcomm.o \ - sdp_util.o \ - spp_server.o \ - sdp_server.o \ - sdp_client.o \ - sdp_client_rfcomm.o - -BLE = \ - att_db.o \ - att_server.o \ - le_device_db_memory.o \ - att_dispatch.o \ - sm.o - -ADDITION = - -CORE_OBJ = $(CORE:.c=.o) -COMMON_OBJ = $(COMMON:.c=.o) -BLE_OBJ = $(BLE:.c=.o) -CLASSIC_OBJ = $(CLASSIC:.c=.o) - -SRCS += $(CORE_OBJ) -SRCS += $(COMMON_OBJ) -SRCS += $(BLE_OBJ) -SRCS += $(CLASSIC_OBJ) - -# Enable assertion checking for development -PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE - -# Use this variables to specify and alternate tool path -#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin - -# Use these variables to add project specific tool options -#PROJ_CFLAGS+=--specs=nano.specs -#PROJ_LDFLAGS+=--specs=nano.specs - -# Point this variable to a startup file to override the default file -#STARTUPFILE=start.S - -# Point this variable to a linker file to override the default file -# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld - -# Include the peripheral driver -PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver -include $(PERIPH_DRIVER_DIR)/periphdriver.mk - -################################################################################ -# Include the rules for building for this target. All other makefiles should be -# included before this one. -include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk - -# fetch and convert init scripts -# use bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c -include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc - -#include ${BTSTACK_ROOT}/example/Makefile.inc - -spp_and_le_streamer.h: spp_and_le_streamer.gatt - python ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ - -generate_header_file: spp_and_le_streamer.h - -# The rule to clean out all the build products. -distclean: clean - $(MAKE) -C ${PERIPH_DRIVER_DIR} clean +clean: + scripts/delete_examples.py + @echo "Deleting CC2564B Init Script in src folder" + @rm -rf src/cc256x* bluetooth_init* diff --git a/port/max32630-fthr/Makefile.template b/port/max32630-fthr/Makefile.template new file mode 100644 index 000000000..33ad7430e --- /dev/null +++ b/port/max32630-fthr/Makefile.template @@ -0,0 +1,205 @@ +################################################################################ + # Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + # Ismail H. Kose + # Permission is hereby granted, free of charge, to any person obtaining a + # copy of this software and associated documentation files (the "Software"), + # to deal in the Software without restriction, including without limitation + # the rights to use, copy, modify, merge, publish, distribute, sublicense, + # and/or sell copies of the Software, and to permit persons to whom the + # Software is furnished to do so, subject to the following conditions: + # + # The above copyright notice and this permission notice shall be included + # in all copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + # IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + # OTHER DEALINGS IN THE SOFTWARE. + # + # Except as contained in this notice, the name of Maxim Integrated + # Products, Inc. shall not be used except as stated in the Maxim Integrated + # Products, Inc. Branding Policy. + # + # The mere transfer of this software does not imply any licenses + # of trade secrets, proprietary technology, copyrights, patents, + # trademarks, maskwork rights, or any other form of intellectual + # property whatsoever. Maxim Integrated Products, Inc. retains all + # ownership rights. + # + # $Date: 2016-03-23 13:28:53 -0700 (Wed, 23 Mar 2016) $ + # $Revision: 22067 $ + # + ############################################################################### + +# Maxim ARM Toolchain and Libraries +# https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html + +# This is the name of the build output file +PROJECT=spp_and_le_streamer + +# Specify the target processor +TARGET=MAX3263x +PROJ_CFLAGS+=-DRO_FREQ=96000000 + +# Create Target name variables +TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) +TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) + +CC2564B = bluetooth_init_cc2564B_1.6_BT_Spec_4.1.o + +# Select 'GCC' or 'IAR' compiler +COMPILER=GCC + +ifeq "$(MAXIM_PATH)" "" +LIBS_DIR=/$(subst \,/,$(subst :,,$(HOME))/Maxim/Firmware/$(TARGET_UC)/Libraries) +$(warning "MAXIM_PATH need to be set. Please run setenv bash file in the Maxim Toolchain directory.") +else +LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries) +endif + +CMSIS_ROOT=$(LIBS_DIR)/CMSIS + +# Where to find source files for this test +VPATH= . ../src + +# Where to find header files for this test +IPATH= . ../src + +BOARD_DIR=$(LIBS_DIR)/Boards + +IPATH += ../board/ +VPATH += ../board/ + +# Source files for this test (add path to VPATH below) +SRCS = main.c +SRCS += hal_tick.c +SRCS += btstack_port.c +SRCS += ${PROJECT}.c +SRCS += board.c +SRCS += stdio.c +SRCS += led.c +SRCS += pb.c +SRCS += max14690n.c + +# Where to find BSP source files +VPATH += $(BOARD_DIR)/Source + +# Where to find BSP header files +IPATH += $(BOARD_DIR)/Include + +# BTstack +BTSTACK_ROOT = ../../.. +VPATH += $(BTSTACK_ROOT)/src +VPATH += $(BTSTACK_ROOT)/src/ble +VPATH += $(BTSTACK_ROOT)/src/classic +VPATH += $(BTSTACK_ROOT)/chipset/cc256x +VPATH += ${BTSTACK_ROOT}/platform/embedded +VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service/ +VPATH += $(BTSTACK_ROOT)/port/pegasus-max3263x +VPATH += $(BTSTACK_ROOT)/example + +PROJ_CFLAGS += \ + -I$(BTSTACK_ROOT)/src \ + -I$(BTSTACK_ROOT)/src/ble \ + -I$(BTSTACK_ROOT)/src/classic \ + -I$(BTSTACK_ROOT)/chipset/cc256x \ + -I$(BTSTACK_ROOT)/platform/embedded \ + -I${BTSTACK_ROOT}/port/pegasus-max3263x \ + -I${BTSTACK_ROOT}/src/ble/gatt-service/ \ + -I${BTSTACK_ROOT}/example + +CORE = \ + ad_parser.o \ + btstack_linked_list.o \ + btstack_memory.o \ + btstack_memory_pool.o \ + btstack_run_loop.o \ + btstack_util.o \ + l2cap.o \ + l2cap_signaling.o \ + btstack_run_loop_embedded.o \ + $(CC2564B) \ + hci_transport_h4.o + +COMMON = \ + btstack_chipset_cc256x.o \ + hci.o \ + hci_cmd.o \ + hci_dump.o \ + btstack_uart_block_embedded.o + +CLASSIC = \ + btstack_link_key_db_memory.o \ + rfcomm.o \ + sdp_util.o \ + spp_server.o \ + sdp_server.o \ + sdp_client.o \ + sdp_client_rfcomm.o + +BLE = \ + att_db.o \ + att_server.o \ + le_device_db_memory.o \ + att_dispatch.o \ + sm.o + +ADDITION = + +CORE_OBJ = $(CORE:.c=.o) +COMMON_OBJ = $(COMMON:.c=.o) +BLE_OBJ = $(BLE:.c=.o) +CLASSIC_OBJ = $(CLASSIC:.c=.o) + +SRCS += $(CORE_OBJ) +SRCS += $(COMMON_OBJ) +SRCS += $(BLE_OBJ) +SRCS += $(CLASSIC_OBJ) + +# Enable assertion checking for development +PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE + +# Use this variables to specify and alternate tool path +#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin + +# Use these variables to add project specific tool options +#PROJ_CFLAGS+=--specs=nano.specs +#PROJ_LDFLAGS+=--specs=nano.specs + +# Point this variable to a startup file to override the default file +#STARTUPFILE=start.S + +# Point this variable to a linker file to override the default file +# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld + +%.h: %.gatt + python ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ + +all: spp_and_le_streamer.h + +# Include the peripheral driver +PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver +include $(PERIPH_DRIVER_DIR)/periphdriver.mk + +################################################################################ +# Include the rules for building for this target. All other makefiles should be +# included before this one. +include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk + +# fetch and convert init scripts +# use bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c +# include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc + +#include ${BTSTACK_ROOT}/example/Makefile.inc + +rm-compiled-gatt-file: + rm -f spp_and_le_counter.h + +clean: rm-compiled-gatt-file + +# The rule to clean out all the build products. +distclean: clean + $(MAKE) -C ${PERIPH_DRIVER_DIR} clean diff --git a/port/max32630-fthr/scripts/create_examples.py b/port/max32630-fthr/scripts/create_examples.py new file mode 100755 index 000000000..ec03d374e --- /dev/null +++ b/port/max32630-fthr/scripts/create_examples.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# Create project files for all BTstack embedded examples in WICED/apps/btstack + +import os +import re +import shutil +import subprocess +import sys + +# get script path +script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../' + +# get btstack root +btstack_root = script_path + '../../' + +## pick correct init script based on your hardware +# - init script for CC2564B +cc256x_init_script = 'bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c' + +subprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True) + +# fetch init script +# print("Creating init script %s" % cc256x_init_script) +# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}' +# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script) +# print(make_command) +# subprocess.call(make_command) + +# path to examples +examples_embedded = btstack_root + 'example/' + +# path to generated example projects +projects_path = script_path + +# path to template +template_path = script_path + 'Makefile.template' + +print("Creating example projects:") + +# iterate over btstack examples +example_files = os.listdir(examples_embedded) + +for file in example_files: + if not file.endswith(".c"): + continue + example = file[:-2] + + # create folder + project_folder = projects_path + example + "/" + if not os.path.exists(project_folder): + os.makedirs(project_folder) + + # check if .gatt file is present + gatt_path = examples_embedded + example + ".gatt" + gatt_h = "" + if os.path.exists(gatt_path): + gatt_h = example+'.h' + + # create makefile + with open(project_folder + 'Makefile', 'wt') as fout: + with open(template_path, 'rt') as fin: + for line in fin: + if 'PROJECT=spp_and_le_streamer' in line: + fout.write('PROJECT=%s\n' % example) + continue + if 'all: spp_and_le_streamer.h' in line: + if len(gatt_h): + fout.write("all: %s\n" % gatt_h) + continue + fout.write(line) + + print("- %s" % example) + +print("Projects are ready for compile. See README for details.") diff --git a/port/max32630-fthr/scripts/delete_examples.py b/port/max32630-fthr/scripts/delete_examples.py new file mode 100755 index 000000000..28e38f3ed --- /dev/null +++ b/port/max32630-fthr/scripts/delete_examples.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# +# Delete project files for all BTstack embedded examples in local port/esp32 folder + +import os +import shutil +import sys +import time +import subprocess + +# get script path +script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + +# path to examples +examples_embedded = script_path + "/../../../example/" + +# path to port/esp32 +apps_btstack = "" + +print("Deleting examples in local folder") + +# iterate over btstack examples +for file in os.listdir(examples_embedded): + if not file.endswith(".c"): + continue + example = file[:-2] + apps_folder = apps_btstack + example + "/" + if os.path.exists(apps_folder): + shutil.rmtree(apps_folder) + print("- %s" % example) + diff --git a/port/max32630-fthr/spp_and_le_streamer.c b/port/max32630-fthr/spp_and_le_streamer.c deleted file mode 100644 index e98bf85a9..000000000 --- a/port/max32630-fthr/spp_and_le_streamer.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright (C) 2014 BlueKitchen GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * 4. Any redistribution, use, or modification is done solely for - * personal benefit and not for any commercial purpose or for - * monetary gain. - * - * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS - * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Please inquire about commercial licensing options at - * contact@bluekitchen-gmbh.com - * - */ - -// ***************************************************************************** -/* EXAMPLE_START(spp_and_le_streamer): Dual mode example - * - * @text The SPP and LE Streamer example combines the Bluetooth Classic SPP Streamer - * and the Bluetooth LE Streamer into a single application. - * - * In this Section, we only point out the differences to the individual examples - * and how how the stack is configured. - */ -// ***************************************************************************** - -#include -#include -#include -#include -#include - -#include "btstack.h" -#include "spp_and_le_streamer.h" - -int btstack_main(int argc, const char * argv[]); - -#define RFCOMM_SERVER_CHANNEL 1 -#define HEARTBEAT_PERIOD_MS 1000 - -#define TEST_COD 0x1234 -#define NUM_ROWS 25 -#define NUM_COLS 40 -#define DATA_VOLUME (10 * 1000 * 1000) - -/* - * @section Advertisements - * - * @text The Flags attribute in the Advertisement Data indicates if a device is in dual-mode or not. - * Flag 0x06 indicates LE General Discoverable, BR/EDR not supported although we're actually using BR/EDR. - * In the past, there have been problems with Anrdoid devices when the flag was not set. - * Setting it should prevent the remote implementation to try to use GATT over LE/EDR, which is not - * implemented by BTstack. So, setting the flag seems like the safer choice (while it's technically incorrect). - */ -/* LISTING_START(advertisements): Advertisement data: Flag 0x06 indicates LE-only device */ -const uint8_t adv_data[] = { - // Flags general discoverable, BR/EDR not supported - 0x02, 0x01, 0x06, - // Name - 0x0c, 0x09, 'L', 'E', ' ', 'S', 't', 'r', 'e', 'a', 'm', 'e', 'r', -}; - -static btstack_packet_callback_registration_t hci_event_callback_registration; - -uint8_t adv_data_len = sizeof(adv_data); - -static uint8_t test_data[NUM_ROWS * NUM_COLS]; - -// SPP -static uint8_t spp_service_buffer[150]; - -static uint16_t spp_test_data_len; -static uint16_t rfcomm_mtu; -static uint16_t rfcomm_cid = 0; -// static uint32_t data_to_send = DATA_VOLUME; - -// LE -static uint16_t att_mtu; -static int counter = 'A'; -static int le_notification_enabled; -static uint16_t le_test_data_len; -static hci_con_handle_t le_connection_handle; - -/* - * @section Track throughput - * @text We calculate the throughput by setting a start time and measuring the amount of - * data sent. After a configurable REPORT_INTERVAL_MS, we print the throughput in kB/s - * and reset the counter and start time. - */ - -/* LISTING_START(tracking): Tracking throughput */ -#define REPORT_INTERVAL_MS 3000 -static uint32_t test_data_transferred; -static uint32_t test_data_start; - -static void test_reset(void){ - test_data_start = btstack_run_loop_get_time_ms(); - test_data_transferred = 0; -} - -static void test_track_transferred(int bytes_sent){ - test_data_transferred += bytes_sent; - // evaluate - uint32_t now = btstack_run_loop_get_time_ms(); - uint32_t time_passed = now - test_data_start; - if (time_passed < REPORT_INTERVAL_MS) return; - // print speed - int bytes_per_second = test_data_transferred * 1000 / time_passed; - printf("%u bytes -> %u.%03u kB/s\n", (int) test_data_transferred, (int) bytes_per_second / 1000, bytes_per_second % 1000); - - // restart - test_data_start = now; - test_data_transferred = 0; -} -/* LISTING_END(tracking): Tracking throughput */ - - -static void spp_create_test_data(void){ - int x,y; - for (y=0;y 'Z') counter = 'A'; - memset(test_data, counter, sizeof(test_data)); - - // send - att_server_notify(le_connection_handle, ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t*) test_data, le_test_data_len); - - // track - test_track_transferred(le_test_data_len); - - // request next send event - att_server_request_can_send_now_event(le_connection_handle); -} - -/* - * @section Packet Handler - * - * @text The packet handler of the combined example is just the combination of the individual packet handlers. - */ - -static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ - UNUSED(channel); - - bd_addr_t event_addr; - uint8_t rfcomm_channel_nr; - - switch (packet_type) { - case HCI_EVENT_PACKET: - switch (hci_event_packet_get_type(packet)) { - - case HCI_EVENT_PIN_CODE_REQUEST: - // inform about pin code request - printf("Pin code request - using '0000'\n"); - hci_event_pin_code_request_get_bd_addr(packet, event_addr); - gap_pin_code_response(event_addr, "0000"); - break; - - case HCI_EVENT_USER_CONFIRMATION_REQUEST: - // inform about user confirmation request - printf("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", little_endian_read_32(packet, 8)); - printf("SSP User Confirmation Auto accept\n"); - break; - - case HCI_EVENT_DISCONNECTION_COMPLETE: - le_notification_enabled = 0; - break; - - case HCI_EVENT_LE_META: - switch (hci_event_le_meta_get_subevent_code(packet)) { - case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: - le_test_data_len = ATT_DEFAULT_MTU - 3; - le_connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet); - break; - } - break; - - case ATT_EVENT_MTU_EXCHANGE_COMPLETE: - att_mtu = att_event_mtu_exchange_complete_get_MTU(packet); - printf("ATT MTU = %u\n", att_mtu); - le_test_data_len = att_mtu - 3; - if (le_test_data_len > sizeof(test_data)){ - le_test_data_len = sizeof(test_data); - } - break; - - case ATT_EVENT_CAN_SEND_NOW: - le_streamer(); - break; - - case RFCOMM_EVENT_INCOMING_CONNECTION: - // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) - rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr); - rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet); - rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet); - printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr)); - rfcomm_accept_connection(rfcomm_cid); - break; - - case RFCOMM_EVENT_CHANNEL_OPENED: - // data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16) - if (rfcomm_event_channel_opened_get_status(packet)) { - printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet)); - } else { - rfcomm_cid = rfcomm_event_channel_opened_get_rfcomm_cid(packet); - rfcomm_mtu = rfcomm_event_channel_opened_get_max_frame_size(packet); - printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, rfcomm_mtu); - - spp_test_data_len = rfcomm_mtu; - if (spp_test_data_len > sizeof(test_data)){ - spp_test_data_len = sizeof(test_data); - } - - test_reset(); - rfcomm_request_can_send_now_event(rfcomm_cid); - } - break; - - case RFCOMM_EVENT_CAN_SEND_NOW: - spp_send_packet(); - break; - - case RFCOMM_EVENT_CHANNEL_CLOSED: - printf("RFCOMM channel closed\n"); - rfcomm_cid = 0; - break; - - default: - break; - } - break; - - case RFCOMM_DATA_PACKET: - test_track_transferred(size); -#if 0 - printf("RCV: '"); - for (i=0;i - -const uint8_t profile_data[] = -{ - // 0x0001 PRIMARY_SERVICE-GAP_SERVICE - 0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18, - // 0x0002 CHARACTERISTIC-GAP_DEVICE_NAME-READ - 0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x02, 0x03, 0x00, 0x00, 0x2a, - // 0x0003 VALUE-GAP_DEVICE_NAME-READ-'Max32630FTHR LE Streamer' - 0x20, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x2a, 0x4d, 0x61, 0x78, 0x33, 0x32, 0x36, 0x33, 0x30, 0x46, 0x54, 0x48, 0x52, 0x20, 0x4c, 0x45, 0x20, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x65, 0x72, - - // 0x0004 PRIMARY_SERVICE-GATT_SERVICE - 0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x01, 0x18, - // 0x0005 CHARACTERISTIC-GATT_SERVICE_CHANGED-READ - 0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x02, 0x06, 0x00, 0x05, 0x2a, - // 0x0006 VALUE-GATT_SERVICE_CHANGED-READ-'' - 0x08, 0x00, 0x02, 0x00, 0x06, 0x00, 0x05, 0x2a, - // Test Service - - // 0x0007 PRIMARY_SERVICE-0000FF10-0000-1000-8000-00805F9B34FB - 0x18, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00, 0x28, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x10, 0xff, 0x00, 0x00, - // Test Characteristic, only notify - // 0x0008 CHARACTERISTIC-0000FF11-0000-1000-8000-00805F9B34FB-NOTIFY - 0x1b, 0x00, 0x02, 0x00, 0x08, 0x00, 0x03, 0x28, 0x10, 0x09, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00, - // 0x0009 VALUE-0000FF11-0000-1000-8000-00805F9B34FB-NOTIFY-'' - 0x16, 0x00, 0x10, 0x02, 0x09, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00, - // 0x000a CLIENT_CHARACTERISTIC_CONFIGURATION - 0x0a, 0x00, 0x0a, 0x01, 0x0a, 0x00, 0x02, 0x29, 0x00, 0x00, - // Test Characterisitic, only write_without_response - // 0x000b CHARACTERISTIC-0000FF12-0000-1000-8000-00805F9B34FB-WRITE_WITHOUT_RESPONSE | DYNAMIC - 0x1b, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x28, 0x04, 0x0c, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x12, 0xff, 0x00, 0x00, - // 0x000c VALUE-0000FF12-0000-1000-8000-00805F9B34FB-WRITE_WITHOUT_RESPONSE | DYNAMIC-'' - 0x16, 0x00, 0x04, 0x03, 0x0c, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x12, 0xff, 0x00, 0x00, - - // END - 0x00, 0x00, -}; // total size 126 bytes - - -// -// list service handle ranges -// -#define ATT_SERVICE_GAP_SERVICE_START_HANDLE 0x0001 -#define ATT_SERVICE_GAP_SERVICE_END_HANDLE 0x0003 -#define ATT_SERVICE_GATT_SERVICE_START_HANDLE 0x0004 -#define ATT_SERVICE_GATT_SERVICE_END_HANDLE 0x0006 -#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_START_HANDLE 0x0007 -#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_END_HANDLE 0x000c - -// -// list mapping between characteristics and handles -// -#define ATT_CHARACTERISTIC_GAP_DEVICE_NAME_01_VALUE_HANDLE 0x0003 -#define ATT_CHARACTERISTIC_GATT_SERVICE_CHANGED_01_VALUE_HANDLE 0x0006 -#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE 0x0009 -#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE 0x000a -#define ATT_CHARACTERISTIC_0000FF12_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE 0x000c diff --git a/port/max32630-fthr/btstack_config.h b/port/max32630-fthr/src/btstack_config.h similarity index 100% rename from port/max32630-fthr/btstack_config.h rename to port/max32630-fthr/src/btstack_config.h diff --git a/port/max32630-fthr/btstack_port.c b/port/max32630-fthr/src/btstack_port.c similarity index 100% rename from port/max32630-fthr/btstack_port.c rename to port/max32630-fthr/src/btstack_port.c diff --git a/port/max32630-fthr/btstack_port.h b/port/max32630-fthr/src/btstack_port.h similarity index 100% rename from port/max32630-fthr/btstack_port.h rename to port/max32630-fthr/src/btstack_port.h diff --git a/port/max32630-fthr/hal_tick.c b/port/max32630-fthr/src/hal_tick.c similarity index 100% rename from port/max32630-fthr/hal_tick.c rename to port/max32630-fthr/src/hal_tick.c diff --git a/port/max32630-fthr/hal_tick.h b/port/max32630-fthr/src/hal_tick.h similarity index 100% rename from port/max32630-fthr/hal_tick.h rename to port/max32630-fthr/src/hal_tick.h diff --git a/port/max32630-fthr/main.c b/port/max32630-fthr/src/main.c similarity index 100% rename from port/max32630-fthr/main.c rename to port/max32630-fthr/src/main.c