mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-05 21:59:45 +00:00
esp32: create projects for all BTstack examples
This commit is contained in:
parent
93131000b2
commit
a681a241a7
@ -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
|
||||
|
||||
|
88
port/esp32/create_examples.py
Executable file
88
port/esp32/create_examples.py
Executable file
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user