1#!/usr/bin/env python 2# 3# Create project files for all BTstack embedded examples in WICED/apps/btstack 4 5import os 6import re 7import shutil 8import subprocess 9import sys 10 11# build all template 12build_all = ''' 13SUBDIRS = \\ 14%s 15 16all: 17\techo Building all examples 18\tfor dir in $(SUBDIRS); do \\ 19\t$(MAKE) -C $$dir || exit 1; \\ 20\tdone 21 22clean: 23\techo Cleaning all ports 24\tfor dir in $(SUBDIRS); do \\ 25\t$(MAKE) -C $$dir clean; \\ 26\tdone 27''' 28 29# 30le_examples = [ 31'ancs_client_demo.c', 32'gap_le_advertisements.c', 33'gatt_battery_query.c', 34'gatt_browser.c', 35'hog_keyboard_demo.c', 36'hog_mouse_demo.c', 37'le_counter.c', 38'le_streamer.c', 39'le_streamer_client.c', 40'led_counter.c', 41'sm_pairing_central.c', 42'sm_pairing_peripheral.c', 43] 44 45# get script path 46script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../' 47 48# get btstack root 49btstack_root = script_path + '../../' 50 51## pick correct init script based on your hardware 52# - init script for ATWILC300 SHIELD 53 54subprocess.call("make -C ../../chipset/atwilc3000", shell=True) 55 56# path to examples 57examples_embedded = btstack_root + 'example/' 58 59# path to generated example projects 60projects_path = script_path + "example/" 61 62# path to template 63template_path = script_path + 'example/template/' 64 65print("Creating example projects:") 66 67# iterate over btstack examples 68example_files = os.listdir(examples_embedded) 69 70examples = [] 71 72for file in example_files: 73 if not file.endswith(".c"): 74 continue 75 if not file in le_examples: 76 continue 77 example = file[:-2] 78 examples.append(example) 79 80 # create folder 81 project_folder = projects_path + example + "/" 82 if not os.path.exists(project_folder): 83 os.makedirs(project_folder) 84 85 # check if .gatt file is present 86 gatt_path = examples_embedded + example + ".gatt" 87 gatt_h = "" 88 if os.path.exists(gatt_path): 89 gatt_h = example+'.h' 90 91 # create Makefile 92 shutil.copyfile(template_path + 'Makefile', project_folder + 'Makefile') 93 94 # create upload.cfg 95 with open(project_folder + 'upload.cfg', 'wt') as fout: 96 with open(template_path + 'upload.cfg', 'rt') as fin: 97 for line in fin: 98 if 'flash write_image erase le_counter_flash.elf' in line: 99 fout.write('flash write_image erase %s_flash.elf\n' % example) 100 continue 101 fout.write(line) 102 103 # create Makefile 104 with open(project_folder + 'Makefile', 'wt') as fout: 105 with open(template_path + 'Makefile', 'rt') as fin: 106 for line in fin: 107 if 'le_counter.h: ${BTSTACK_ROOT}/example/le_counter.gatt' in line: 108 fout.write('%s.h: ${BTSTACK_ROOT}/example/%s.gatt\n' % (example,example)) 109 continue 110 if 'all: le_counter.h wilc3000_ble_firmware.h' in line: 111 if len(gatt_h): 112 fout.write("all: %s.h wilc3000_ble_firmware.h\n" % example) 113 else: 114 fout.write("all: le_counter.h wilc3000_ble_firmware.h\n") 115 continue 116 fout.write(line) 117 118 # create config.mk 119 with open(project_folder + 'config.mk', 'wt') as fout: 120 with open(template_path + 'config.mk', 'rt') as fin: 121 for line in fin: 122 if 'TARGET_FLASH=le_counter_flash.elf' in line: 123 fout.write('TARGET_FLASH=%s_flash.elf\n' % example) 124 continue 125 if 'TARGET_SRAM=le_counter_sram.elf' in line: 126 fout.write('TARGET_SRAM=%s_sram.elf\n' % example) 127 continue 128 if 'CSRCS+=${BTSTACK_ROOT_CONFIG}/example/le_counter.c' in line: 129 fout.write('CSRCS+=${BTSTACK_ROOT_CONFIG}/example/%s.c\n' % example) 130 continue 131 if 'INC_PATH += ${BTSTACK_ROOT_CONFIG}/port/samv71-xplained-atwilc3000/example/template' in line: 132 fout.write('INC_PATH += ${BTSTACK_ROOT_CONFIG}/port/samv71-xplained-atwilc3000/example/%s\n' % example) 133 continue 134 fout.write(line) 135 136 print("- %s" % example) 137 138with open(projects_path+'Makefile', 'wt') as fout: 139 fout.write(build_all % ' \\\n'.join(examples)) 140 141print("Projects are ready for compile in example folder. See README for details.") 142