1*6ccd8248SMilanka Ringwald#!/usr/bin/env python3 20af04ee4SMatthias Ringwald# 30af04ee4SMatthias Ringwald# Create project files for all BTstack embedded examples in WICED/apps/btstack 40af04ee4SMatthias Ringwald 50af04ee4SMatthias Ringwaldimport os 60af04ee4SMatthias Ringwaldimport re 70af04ee4SMatthias Ringwaldimport shutil 80af04ee4SMatthias Ringwaldimport subprocess 90af04ee4SMatthias Ringwaldimport sys 100af04ee4SMatthias Ringwald 110af04ee4SMatthias Ringwald# build all template 120af04ee4SMatthias Ringwaldbuild_all = ''' 130af04ee4SMatthias RingwaldSUBDIRS = \\ 140af04ee4SMatthias Ringwald%s 150af04ee4SMatthias Ringwald 160af04ee4SMatthias Ringwaldall: 170af04ee4SMatthias Ringwald\techo Building all examples 180af04ee4SMatthias Ringwald\tfor dir in $(SUBDIRS); do \\ 190af04ee4SMatthias Ringwald\t$(MAKE) -C $$dir || exit 1; \\ 200af04ee4SMatthias Ringwald\tdone 210af04ee4SMatthias Ringwald 220af04ee4SMatthias Ringwaldclean: 230af04ee4SMatthias Ringwald\techo Cleaning all ports 240af04ee4SMatthias Ringwald\tfor dir in $(SUBDIRS); do \\ 250af04ee4SMatthias Ringwald\t$(MAKE) -C $$dir clean; \\ 260af04ee4SMatthias Ringwald\tdone 270af04ee4SMatthias Ringwald''' 280af04ee4SMatthias Ringwald 29d0ec3fbfSMatthias Ringwald# 30d0ec3fbfSMatthias Ringwaldle_examples = [ 31d0ec3fbfSMatthias Ringwald'ancs_client_demo.c', 32d0ec3fbfSMatthias Ringwald'gap_le_advertisements.c', 33d0ec3fbfSMatthias Ringwald'gatt_battery_query.c', 34d0ec3fbfSMatthias Ringwald'gatt_browser.c', 35d0ec3fbfSMatthias Ringwald'hog_keyboard_demo.c', 36d0ec3fbfSMatthias Ringwald'hog_mouse_demo.c', 37bdc352b1SMatthias Ringwald'gatt_counter.c', 38bdc352b1SMatthias Ringwald'gatt_streamer.c', 39d0ec3fbfSMatthias Ringwald'le_streamer_client.c', 40d0ec3fbfSMatthias Ringwald'led_counter.c', 41d0ec3fbfSMatthias Ringwald'sm_pairing_central.c', 42d0ec3fbfSMatthias Ringwald'sm_pairing_peripheral.c', 43d0ec3fbfSMatthias Ringwald] 44d0ec3fbfSMatthias Ringwald 450af04ee4SMatthias Ringwald# get script path 460af04ee4SMatthias Ringwaldscript_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../' 470af04ee4SMatthias Ringwald 480af04ee4SMatthias Ringwald# get btstack root 490af04ee4SMatthias Ringwaldbtstack_root = script_path + '../../' 500af04ee4SMatthias Ringwald 510af04ee4SMatthias Ringwald# path to examples 520af04ee4SMatthias Ringwaldexamples_embedded = btstack_root + 'example/' 530af04ee4SMatthias Ringwald 540af04ee4SMatthias Ringwald# path to generated example projects 550af04ee4SMatthias Ringwaldprojects_path = script_path + "example/" 560af04ee4SMatthias Ringwald 570af04ee4SMatthias Ringwald# path to template 580af04ee4SMatthias Ringwaldtemplate_path = script_path + 'example/template/' 590af04ee4SMatthias Ringwald 600af04ee4SMatthias Ringwaldprint("Creating example projects:") 610af04ee4SMatthias Ringwald 620af04ee4SMatthias Ringwald# iterate over btstack examples 630af04ee4SMatthias Ringwaldexample_files = os.listdir(examples_embedded) 640af04ee4SMatthias Ringwald 650af04ee4SMatthias Ringwaldexamples = [] 660af04ee4SMatthias Ringwald 670af04ee4SMatthias Ringwaldfor file in example_files: 680af04ee4SMatthias Ringwald if not file.endswith(".c"): 690af04ee4SMatthias Ringwald continue 70d0ec3fbfSMatthias Ringwald if not file in le_examples: 710af04ee4SMatthias Ringwald continue 720af04ee4SMatthias Ringwald example = file[:-2] 730af04ee4SMatthias Ringwald examples.append(example) 740af04ee4SMatthias Ringwald 750af04ee4SMatthias Ringwald # create folder 760af04ee4SMatthias Ringwald project_folder = projects_path + example + "/" 770af04ee4SMatthias Ringwald if not os.path.exists(project_folder): 780af04ee4SMatthias Ringwald os.makedirs(project_folder) 790af04ee4SMatthias Ringwald 800af04ee4SMatthias Ringwald # check if .gatt file is present 810af04ee4SMatthias Ringwald gatt_path = examples_embedded + example + ".gatt" 820af04ee4SMatthias Ringwald gatt_h = "" 830af04ee4SMatthias Ringwald if os.path.exists(gatt_path): 840af04ee4SMatthias Ringwald gatt_h = example+'.h' 850af04ee4SMatthias Ringwald 860af04ee4SMatthias Ringwald # create Makefile 870af04ee4SMatthias Ringwald shutil.copyfile(template_path + 'Makefile', project_folder + 'Makefile') 880af04ee4SMatthias Ringwald 890af04ee4SMatthias Ringwald # create upload.cfg 900af04ee4SMatthias Ringwald with open(project_folder + 'upload.cfg', 'wt') as fout: 910af04ee4SMatthias Ringwald with open(template_path + 'upload.cfg', 'rt') as fin: 920af04ee4SMatthias Ringwald for line in fin: 930af04ee4SMatthias Ringwald if 'flash write_image erase le_counter_flash.elf' in line: 940af04ee4SMatthias Ringwald fout.write('flash write_image erase %s_flash.elf\n' % example) 950af04ee4SMatthias Ringwald continue 960af04ee4SMatthias Ringwald fout.write(line) 970af04ee4SMatthias Ringwald 980af04ee4SMatthias Ringwald # create Makefile 990af04ee4SMatthias Ringwald with open(project_folder + 'Makefile', 'wt') as fout: 1000af04ee4SMatthias Ringwald with open(template_path + 'Makefile', 'rt') as fin: 1010af04ee4SMatthias Ringwald for line in fin: 1020f165ceaSMatthias Ringwald if 'le_counter.h: ${BTSTACK_ROOT}/example/le_counter.gatt' in line: 1030f165ceaSMatthias Ringwald fout.write('%s.h: ${BTSTACK_ROOT}/example/%s.gatt\n' % (example,example)) 1040af04ee4SMatthias Ringwald continue 105895b2d2aSMatthias Ringwald if 'all: le_counter.h wilc3000_ble_firmware.h' in line: 1060af04ee4SMatthias Ringwald if len(gatt_h): 107895b2d2aSMatthias Ringwald fout.write("all: %s.h wilc3000_ble_firmware.h\n" % example) 1080af04ee4SMatthias Ringwald else: 109a66bb805SMatthias Ringwald fout.write("all: wilc3000_ble_firmware.h\n") 1100af04ee4SMatthias Ringwald continue 1110af04ee4SMatthias Ringwald fout.write(line) 1120af04ee4SMatthias Ringwald 1130af04ee4SMatthias Ringwald # create config.mk 1140af04ee4SMatthias Ringwald with open(project_folder + 'config.mk', 'wt') as fout: 1150af04ee4SMatthias Ringwald with open(template_path + 'config.mk', 'rt') as fin: 1160af04ee4SMatthias Ringwald for line in fin: 1170af04ee4SMatthias Ringwald if 'TARGET_FLASH=le_counter_flash.elf' in line: 1180af04ee4SMatthias Ringwald fout.write('TARGET_FLASH=%s_flash.elf\n' % example) 1190af04ee4SMatthias Ringwald continue 1200af04ee4SMatthias Ringwald if 'TARGET_SRAM=le_counter_sram.elf' in line: 1210af04ee4SMatthias Ringwald fout.write('TARGET_SRAM=%s_sram.elf\n' % example) 1220af04ee4SMatthias Ringwald continue 1230f165ceaSMatthias Ringwald if 'CSRCS+=${BTSTACK_ROOT_CONFIG}/example/le_counter.c' in line: 1240f165ceaSMatthias Ringwald fout.write('CSRCS+=${BTSTACK_ROOT_CONFIG}/example/%s.c\n' % example) 1250f165ceaSMatthias Ringwald continue 1260f165ceaSMatthias Ringwald if 'INC_PATH += ${BTSTACK_ROOT_CONFIG}/port/samv71-xplained-atwilc3000/example/template' in line: 1270f165ceaSMatthias Ringwald fout.write('INC_PATH += ${BTSTACK_ROOT_CONFIG}/port/samv71-xplained-atwilc3000/example/%s\n' % example) 1280af04ee4SMatthias Ringwald continue 1290af04ee4SMatthias Ringwald fout.write(line) 1300af04ee4SMatthias Ringwald 1310af04ee4SMatthias Ringwald print("- %s" % example) 1320af04ee4SMatthias Ringwald 1330af04ee4SMatthias Ringwaldwith open(projects_path+'Makefile', 'wt') as fout: 1340af04ee4SMatthias Ringwald fout.write(build_all % ' \\\n'.join(examples)) 1350af04ee4SMatthias Ringwald 1360af04ee4SMatthias Ringwaldprint("Projects are ready for compile in example folder. See README for details.") 137