1#!/usr/bin/env python3 2# 3# Create project files for all BTstack embedded examples in AmbiqSuite/boards/apollo2_evb_am_ble 4 5import os 6import shutil 7import sys 8import time 9import subprocess 10 11makefile_gatt_add_on = ''' 12$(CONFIG)/EXAMPLE.o: $(CONFIG)/EXAMPLE.h 13$(CONFIG)/EXAMPLE.h: ../../../../../third_party/btstack/example/EXAMPLE.gatt 14\t../../../../../third_party/btstack/tool/compile_gatt.py $^ $@ 15''' 16 17# get script path 18script_path = os.path.abspath(os.path.dirname(sys.argv[0])) 19 20# validate AmbiqSuite root by reading VERSION.txt 21am_root = script_path + "/../../../../" 22am_version_txt = "" 23try: 24 with open(am_root + 'VERSION.txt', 'r') as fin: 25 am_version_txt = fin.read() # Read the contents of the file into memory. 26except: 27 pass 28if len(am_version_txt) == 0: 29 print("Cannot find AmbiqSuite root. Make sure BTstack is checked out as AmbiqSuite/third/btstack"); 30 sys.exit(1) 31 32# show WICED version 33print("Found AmbiqSuite SDK version: %s" % am_version_txt) 34 35# path to examples 36examples_embedded = script_path + "/../../example/" 37 38# path to example template 39example_template = script_path + "/example-template/" 40 41# path to AmbiqSuite/boards/apollo2_evb_am_ble/examples 42apps_btstack = am_root + "/boards/apollo2_evb_am_ble/examples/" 43 44print("Creating examples in /boards/apollo2_evb_am_ble/examples:") 45 46LE_EXAMPLES = ["ancs_client_demo", "gap_le_advertisements", "gatt_battery_query", "gatt_browser", "gatt_counter", "gatt_streamer", "le_streamer_client", "sm_pairing_peripheral", "sm_pairing_central"] 47 48# iterate over btstack examples 49for example in LE_EXAMPLES: 50 51 # create example folder 52 apps_folder = apps_btstack + "btstack_" + example + "/" 53 if not os.path.exists(apps_folder): 54 os.makedirs(apps_folder) 55 56 # copy project makefile 57 shutil.copyfile(example_template + "Makefile", apps_folder + "Makefile"); 58 59 # create GCC folder 60 gcc_folder = apps_folder + "/gcc/" 61 if not os.path.exists(gcc_folder): 62 os.makedirs(gcc_folder) 63 64 # add rule to generate .h file in src folder if .gatt is present 65 gatt_path = examples_embedded + example + ".gatt" 66 need_h = False 67 if os.path.exists(gatt_path): 68 # create src folder 69 src_folder = apps_folder + "/src/" 70 if not os.path.exists(src_folder): 71 os.makedirs(src_folder) 72 need_h = True 73 74 # copy makefile and update project name 75 with open(gcc_folder + 'Makefile', "wt") as fout: 76 with open(example_template + 'gcc/Makefile', "rt") as fin: 77 for line in fin: 78 fout.write(line.replace('TARGET := EXAMPLE', 'TARGET := ' + example)) 79 if (need_h): 80 fout.write(makefile_gatt_add_on.replace("EXAMPLE",example)) 81 fout.write("INCLUDES += -I${CONFIG}\n") 82 83 # copy other files 84 for file in ['startup_gcc.c', 'btstack_template.ld']: 85 shutil.copyfile(example_template + "gcc/" + file, apps_folder + "/gcc/" + file); 86 87 88 print("- %s" % example) 89