From a681a241a7fbf8bf3193a0d1d2e25f7b3a7e9f18 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 31 Mar 2017 17:58:31 +0200 Subject: [PATCH] esp32: create projects for all BTstack examples --- port/esp32/README.md | 8 +++- port/esp32/create_examples.py | 88 +++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100755 port/esp32/create_examples.py diff --git a/port/esp32/README.md b/port/esp32/README.md index 2777b99b5..f27d840d7 100644 --- a/port/esp32/README.md +++ b/port/esp32/README.md @@ -10,11 +10,15 @@ Status: Initial port. Only SPP + LE Throughput example provided. ## Usage -In port/esp32/template, run +In port/esp32, run + + ./creat_examples.py + +Now, it creates project folders for all examples. Inside an example, e.g. in port/esp32/le_counter, run make -to compile the SPP and LE Streamer example +to compile the example Run diff --git a/port/esp32/create_examples.py b/port/esp32/create_examples.py new file mode 100755 index 000000000..c834c3559 --- /dev/null +++ b/port/esp32/create_examples.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# +# Create project files for all BTstack embedded examples in local port/esp32 folder + +import os +import shutil +import sys +import time +import subprocess + +mk_template = '''# +# BTstack example 'EXAMPLE' for ESP32 port +# +# Generated by TOOL +# On DATE + +PROJECT_NAME := EXAMPLE +EXTRA_COMPONENT_DIRS := components + +include $(IDF_PATH)/make/project.mk +''' + +gatt_update_template = '''#!/bin/sh +DIR=`dirname $0` +BTSTACK_ROOT=$DIR/../../../../btstack +echo "Creating src/EXAMPLE.h from EXAMPLE.gatt" +$BTSTACK_ROOT/tool/compile_gatt.py $BTSTACK_ROOT/example/EXAMPLE.gatt $DIR/main/EXAMPLE.h +''' + +# get script path +script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + +# path to examples +examples_embedded = script_path + "/../../example/" + +# path to zephyr/samples/btstack +apps_btstack = "" + +print("Creating examples in local folder") + +# iterate over btstack examples +for file in os.listdir(examples_embedded): + if not file.endswith(".c"): + continue + + example = file[:-2] + gatt_path = examples_embedded + example + ".gatt" + + # create folder + apps_folder = apps_btstack + example + "/" + if os.path.exists(apps_folder): + shutil.rmtree(apps_folder) + os.makedirs(apps_folder) + + # copy files + for item in ['sdkconfig']: + shutil.copyfile(script_path + '/template/' + item, apps_folder + '/' + item) + + # create Makefile file + with open(apps_folder + "Makefile", "wt") as fout: + fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) + + # copy components folder + shutil.copytree(script_path + '/template/components', apps_folder + '/components') + + # create main folder + main_folder = apps_folder + "main/" + if not os.path.exists(main_folder): + os.makedirs(main_folder) + + # copy example file + shutil.copyfile(examples_embedded + file, apps_folder + "/main/" + example + ".c") + + # add component.mk file to main folder + shutil.copyfile(script_path + '/template/main/component.mk', apps_folder + "/main/component.mk") + + # create update_gatt.sh if .gatt file is present + gatt_path = examples_embedded + example + ".gatt" + if os.path.exists(gatt_path): + update_gatt_script = apps_folder + "update_gatt_db.sh" + with open(update_gatt_script, "wt") as fout: + fout.write(gatt_update_template.replace("EXAMPLE", example)) + os.chmod(update_gatt_script, 0o755) + subprocess.call(update_gatt_script + "> /dev/null", shell=True) + print("- %s including compiled GATT DB" % example) + else: + print("- %s" % example) +