1 Import("env", "projenv")
4 import upload_via_esp8266_backpack
7 import BFinitPassthrough
8 import ETXinitPassthrough
9 import UnifiedConfiguration
11 def add_target_uploadoption(name
: str, desc
: str) -> None:
12 # Add an upload target 'uploadforce' that forces update if target mismatch
13 # This must be called after UPLOADCMD is set
16 dependencies
="${BUILD_DIR}/${PROGNAME}.bin",
19 actions
=env
['UPLOADCMD']
23 return '%s (%s) %s' % (env
.get('GIT_VERSION'), env
.get('GIT_SHA'), env
.get('REG_DOMAIN'))
25 platform
= env
.get('PIOPLATFORM', '')
26 stm
= platform
in ['ststm32']
28 target_name
= env
['PIOENV'].upper()
29 print("PLATFORM : '%s'" % platform
)
30 print("BUILD ENV: '%s'" % target_name
)
31 print("build version: %s\n\n" % get_version(env
))
33 if platform
in ['espressif8266']:
34 if "_WIFI" in target_name
:
35 env
.Replace(UPLOAD_PROTOCOL
="custom")
36 env
.Replace(UPLOADCMD
=upload_via_esp8266_backpack
.on_upload
)
37 elif "_UART" in target_name
:
39 UPLOADER
="$PROJECT_DIR/python/external/esptool/esptool.py",
42 "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
43 "-c", "esp8266", "--before", "default_reset", "--after", "soft_reset", "write_flash"
46 elif "_BETAFLIGHTPASSTHROUGH" in target_name
:
48 UPLOADER
="$PROJECT_DIR/python/external/esptool/esptool.py",
51 "--passthrough", "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
52 "-c", "esp8266", "--before", "no_reset", "--after", "soft_reset", "write_flash"
55 env
.AddPreAction("upload", BFinitPassthrough
.init_passthrough
)
57 elif platform
in ['espressif32']:
58 if "_WIFI" in target_name
:
59 env
.Replace(UPLOAD_PROTOCOL
="custom")
60 env
.Replace(UPLOADCMD
=upload_via_esp8266_backpack
.on_upload
)
61 elif "_UART" in target_name
:
63 UPLOADER
="$PROJECT_DIR/python/external/esptool/esptool.py",
66 if "_ETX" in target_name
:
67 env
.Replace(UPLOADER
="$PROJECT_DIR/python/external/esptool/esptool.py")
68 env
.AddPreAction("upload", ETXinitPassthrough
.init_passthrough
)
69 elif "_BETAFLIGHTPASSTHROUGH" in target_name
:
70 if "ESP32S3" in target_name
:
72 elif "ESP32C3" in target_name
:
77 UPLOADER
="$PROJECT_DIR/python/external/esptool/esptool.py",
80 "--passthrough", "-b", "$UPLOAD_SPEED", "-p", "$UPLOAD_PORT",
81 "-c", chip
, "--before", "no_reset", "--after", "hard_reset", "write_flash"
84 env
.AddPreAction("upload", BFinitPassthrough
.init_passthrough
)
86 if "_WIFI" in target_name
:
87 add_target_uploadoption("uploadconfirm", "Do not upload, just send confirm")
88 if "_TX_" in target_name
:
89 env
.SetDefault(UPLOAD_PORT
="elrs_tx.local")
91 env
.SetDefault(UPLOAD_PORT
="elrs_rx.local")
93 if platform
!= 'native':
94 add_target_uploadoption("uploadforce", "Upload even if target mismatch")
96 # Remove stale binary so the platform is forced to build a new one and attach options/hardware-layout files
98 os
.remove(env
['PROJECT_BUILD_DIR'] + '/' + env
['PIOENV'] +'/'+ env
['PROGNAME'] + '.bin')
99 except FileNotFoundError
:
101 env
.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", UnifiedConfiguration
.appendConfiguration
)
102 if platform
in ['espressif8266'] and "_WIFI" in target_name
:
103 env
.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp_compress
.compressFirmware
)
105 def copyBootApp0bin(source
, target
, env
):
106 file = os
.path
.join(env
.PioPlatform().get_package_dir("framework-arduinoespressif32"), "tools", "partitions", "boot_app0.bin")
107 shutil
.copy2(file, os
.path
.join(env
['PROJECT_BUILD_DIR'], env
['PIOENV']))
109 if platform
in ['espressif32']:
110 env
.AddPreAction("$BUILD_DIR/${PROGNAME}.bin", copyBootApp0bin
)
112 if platform
in ['espressif32', 'espressif8266']:
113 if not os
.path
.exists('hardware'):
114 elrs_helpers
.git_cmd('clone', 'https://github.com/ExpressLRS/targets', 'hardware')