Skip to content

Commit

Permalink
esp32: re-implement integrate_btstack in python as rsync is missing i…
Browse files Browse the repository at this point in the history
…n prebuild esp-idf windows toolchain
  • Loading branch information
mringwal committed Oct 9, 2017
1 parent 3d244bf commit 9c7c30e
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 107 deletions.
8 changes: 5 additions & 3 deletions port/esp32/README.md
Expand Up @@ -12,9 +12,11 @@ Status: Basic port incl. all examples. BTstack runs on dedicated FreeRTOS thread


In port/esp32, run In port/esp32, run


./integrate_btstack.sh ./integrate_btstack.py


The script will copy parts of the BTstack tree into the ESP-IDF as $IDF_PATH/components/btstack and then create project folders for all examples. Each example project folder, e.g. port/esp32/examples/spp_and_le_counter, contains a Makefile. Please run the command again after updating the BTstack tree to also update the copy in the ESP-IDF. The script will copy parts of the BTstack tree into the ESP-IDF as $IDF_PATH/components/btstack and then create project folders for all examples.

Each example project folder, e.g. port/esp32/examples/spp_and_le_counter, contains a Makefile. Please run the command again after updating the BTstack tree (e.g. by git pull) to also update the copy in the ESP-IDF.


To compile an example, run: To compile an example, run:


Expand All @@ -34,7 +36,7 @@ You can quit the monitor with CTRL-].


## Old Make Versions ## Old Make Versions


Compilation fails with older versions of the make tool, e.g. make 3.8.1 (from 2006) providedby the current Xcode 9 on macOS. Compilation fails with older versions of the make tool, e.g. make 3.8.1 (from 2006) provided by the current Xcode 9 on macOS.
Interestingly, if you run make a second time, it completes the compilation. Interestingly, if you run make a second time, it completes the compilation.


## Configuration ## Configuration
Expand Down
141 changes: 73 additions & 68 deletions port/esp32/create_examples.py
Expand Up @@ -31,71 +31,76 @@
COMPONENT_EXTRA_CLEAN = EXAMPLE.h COMPONENT_EXTRA_CLEAN = EXAMPLE.h
''' '''


# get script path def create_examples(script_path):
script_path = os.path.abspath(os.path.dirname(sys.argv[0])) # path to examples

examples_embedded = script_path + "/../../example/"
# path to examples
examples_embedded = script_path + "/../../example/" # path to samples

example_folder = script_path + "/example/"
# path to samples
example_folder = script_path + "/example/" print("Creating examples folder")

if not os.path.exists(example_folder):
print("Creating examples folder") os.makedirs(example_folder)
if not os.path.exists(example_folder):
os.makedirs(example_folder) print("Creating examples in examples folder")


print("Creating examples in examples folder") # iterate over btstack examples

for file in os.listdir(examples_embedded):
# iterate over btstack examples if not file.endswith(".c"):
for file in os.listdir(examples_embedded): continue
if not file.endswith(".c"): if file in ['panu_demo.c', 'sco_demo_util.c']:
continue continue
if file in ['panu_demo.c', 'sco_demo_util.c']:
continue example = file[:-2]

gatt_path = examples_embedded + example + ".gatt"
example = file[:-2]
gatt_path = examples_embedded + example + ".gatt" # create folder

apps_folder = example_folder + example + "/"
# create folder if os.path.exists(apps_folder):
apps_folder = example_folder + example + "/" shutil.rmtree(apps_folder)
if os.path.exists(apps_folder): os.makedirs(apps_folder)
shutil.rmtree(apps_folder)
os.makedirs(apps_folder) # copy files

for item in ['sdkconfig', 'set_port.sh']:
# copy files shutil.copyfile(script_path + '/template/' + item, apps_folder + '/' + item)
for item in ['sdkconfig', 'set_port.sh']:
shutil.copyfile(script_path + '/template/' + item, apps_folder + '/' + item) # mark set_port.sh as executable

os.chmod(apps_folder + '/set_port.sh', 0o755)
# mark set_port.sh as executable
os.chmod(apps_folder + '/set_port.sh', 0o755) # create Makefile file

with open(apps_folder + "Makefile", "wt") as fout:
# create Makefile file fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c")))
with open(apps_folder + "Makefile", "wt") as fout:
fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) # create main folder

main_folder = apps_folder + "main/"
# create main folder if not os.path.exists(main_folder):
main_folder = apps_folder + "main/" os.makedirs(main_folder)
if not os.path.exists(main_folder):
os.makedirs(main_folder) # copy example file

shutil.copyfile(examples_embedded + file, apps_folder + "/main/" + example + ".c")
# copy example file
shutil.copyfile(examples_embedded + file, apps_folder + "/main/" + example + ".c") # add sco_demo_util.c for audio examples

if example in ['hfp_ag_demo','hfp_hf_demo', 'hsp_ag_demo', 'hsp_hf_demo']:
# add sco_demo_util.c for audio examples shutil.copy(examples_embedded + 'sco_demo_util.c', apps_folder + '/main/')
if example in ['hfp_ag_demo','hfp_hf_demo', 'hsp_ag_demo', 'hsp_hf_demo']: shutil.copy(examples_embedded + 'sco_demo_util.h', apps_folder + '/main/')
shutil.copy(examples_embedded + 'sco_demo_util.c', apps_folder + '/main/')
shutil.copy(examples_embedded + 'sco_demo_util.h', apps_folder + '/main/') # add component.mk file to main folder

main_component_mk = apps_folder + "/main/component.mk"
# add component.mk file to main folder shutil.copyfile(script_path + '/template/main/component.mk', main_component_mk)
main_component_mk = apps_folder + "/main/component.mk"
shutil.copyfile(script_path + '/template/main/component.mk', main_component_mk) # add rules to compile gatt db if .gatt file is present

gatt_path = examples_embedded + example + ".gatt"
# add rules to compile gatt db if .gatt file is present if os.path.exists(gatt_path):
gatt_path = examples_embedded + example + ".gatt" shutil.copy(gatt_path, apps_folder + "/main/" + example + ".gatt")
if os.path.exists(gatt_path): with open(main_component_mk, "a") as fout:
shutil.copy(gatt_path, apps_folder + "/main/" + example + ".gatt") fout.write(component_mk_gatt_add_on.replace("EXAMPLE", example))
with open(main_component_mk, "a") as fout: print("- %s including GATT DB compilation rules" % example)
fout.write(component_mk_gatt_add_on.replace("EXAMPLE", example)) else:
print("- %s including GATT DB compilation rules" % example) print("- %s" % example)
else:
print("- %s" % example) if __name__ == '__main__':
# get script path
script_path = os.path.abspath(os.path.dirname(sys.argv[0]))
create_examples(script_path)


52 changes: 52 additions & 0 deletions port/esp32/integrate_btstack.py
@@ -0,0 +1,52 @@
#!/usr/bin/env python

#
# Add btstack component to esp-idf
#

import os
import sys
import shutil
import create_examples

if not 'IDF_PATH' in os.environ:
print('Error: IDF_PATH not defined. Please set IDF_PATH as described here:\nhttp://esp-idf.readthedocs.io/en/latest/get-started/index.html#get-started-get-esp-idf');
sys.exit(10)

IDF_PATH=os.environ['IDF_PATH']
print("IDF_PATH=%s" % IDF_PATH)

IDF_COMPONENTS=IDF_PATH + "/components"

if not os.path.exists(IDF_COMPONENTS):
print("Error: No components folder at $IDF_PATH/components, please check IDF_PATH")
sys.exit(10)

IDF_BTSTACK=IDF_COMPONENTS+"/btstack"

if os.path.exists(IDF_BTSTACK):
print("Deleting old BTstack component %s" % IDF_BTSTACK)
shutil.rmtree(IDF_BTSTACK)

# get local dir
local_dir = os.path.abspath(os.path.dirname(sys.argv[0]))

# create components/btstack
print("Creating BTstack component at %s" % IDF_COMPONENTS)
shutil.copytree(local_dir+'/components/btstack', IDF_BTSTACK)

dirs_to_copy = [
'src',
'3rd-party/bluedroid',
'3rd-party/hxcmod-player',
'platform/freertos',
'platform/embedded',
'tool'
]

for dir in dirs_to_copy:
print('- %s' % dir)
shutil.copytree(local_dir + '/../../' + dir, IDF_BTSTACK + '/' + dir)

# create example/btstack
create_examples.create_examples(local_dir)
36 changes: 0 additions & 36 deletions port/esp32/integrate_btstack.sh

This file was deleted.

0 comments on commit 9c7c30e

Please sign in to comment.