mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	use platformio upload
This commit is contained in:
		| @@ -298,45 +298,13 @@ def upload_using_platformio(config, port): | ||||
|     return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args) | ||||
|  | ||||
|  | ||||
| def update_progress(progress=0, done=False, log_message=""): | ||||
|     import click | ||||
|  | ||||
|     del done, log_message  # Unused parameters | ||||
|     if progress == 0: | ||||
|         return | ||||
|  | ||||
|     if progress % 40 == 0: | ||||
|         click.echo("#", nl=True) | ||||
|     else: | ||||
|         click.echo("#", nl=False) | ||||
|  | ||||
|  | ||||
| def upload_adafruit_nrfutil(config, port): | ||||
| def nrf52_upload_using_platformio(config, port): | ||||
|     from esphome import platformio_api | ||||
|     from pathlib import Path | ||||
|     from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial | ||||
|     from nordicsemi.dfu.dfu_transport import DfuEvent | ||||
|     from nordicsemi.dfu.dfu import Dfu | ||||
|     import serial | ||||
|  | ||||
|     idedata = platformio_api.get_idedata(config) | ||||
|     dfu_package = str(Path(idedata.firmware_elf_path).with_suffix(".zip")) | ||||
|     ser = serial.Serial(port, 2400) | ||||
|     time.sleep(DfuTransportSerial.SERIAL_PORT_OPEN_WAIT_TIME) | ||||
|     ser.setDTR(True) | ||||
|     time.sleep(DfuTransportSerial.DTR_RESET_WAIT_TIME) | ||||
|     ser.close() | ||||
|  | ||||
|     time.sleep(2) | ||||
|  | ||||
|     serial_backend = DfuTransportSerial(port) | ||||
|     serial_backend.register_events_callback(DfuEvent.PROGRESS_EVENT, update_progress) | ||||
|     dfu = Dfu(dfu_package, dfu_transport=serial_backend) | ||||
|  | ||||
|     try: | ||||
|         dfu.dfu_send_images() | ||||
|     except Exception as e: | ||||
|         raise EsphomeError(f"Unable to send image: {e}") | ||||
|     upload_args = ["-t", "upload"] | ||||
|     if port is not None: | ||||
|         upload_args += ["--upload-port", port] | ||||
|     return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args) | ||||
|  | ||||
|  | ||||
| def upload_program(config, args, host): | ||||
| @@ -352,7 +320,7 @@ def upload_program(config, args, host): | ||||
|             return upload_using_platformio(config, host) | ||||
|  | ||||
|         if CORE.target_platform in (PLATFORM_NRF52): | ||||
|             return upload_adafruit_nrfutil(config, host) | ||||
|             return nrf52_upload_using_platformio(config, host) | ||||
|  | ||||
|         raise EsphomeError(f"Unknown target platform: {CORE.target_platform}") | ||||
|  | ||||
|   | ||||
| @@ -10,12 +10,12 @@ void __wrap_tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { | ||||
|  | ||||
|   // DTR = false is counted as disconnected | ||||
|   if (!dtr) { | ||||
|     // touch2400 only with first CDC instance (Serial) | ||||
|     // touch1200 only with first CDC instance (Serial) | ||||
|     if (itf == 0) { | ||||
|       cdc_line_coding_t coding; | ||||
|       tud_cdc_get_line_coding(&coding); | ||||
|  | ||||
|       if (coding.bit_rate == 2400) { | ||||
|       if (coding.bit_rate == 1200) { | ||||
|         goto_dfu = true; | ||||
|       } | ||||
|     } | ||||
|   | ||||
| @@ -81,3 +81,6 @@ async def to_code(config): | ||||
|     cg.add_platformio_option("platform", conf[CONF_PLATFORM_VERSION]) | ||||
|     # make sure that firmware.zip is created | ||||
|     cg.add_platformio_option("board_upload.protocol", "nrfutil") | ||||
|     cg.add_platformio_option("board_upload.use_1200bps_touch", "true") | ||||
|     cg.add_platformio_option("board_upload.require_upload_port", "true") | ||||
|     cg.add_platformio_option("board_upload.wait_for_upload_port", "true") | ||||
|   | ||||
| @@ -23,6 +23,8 @@ void arch_init() { | ||||
| } | ||||
| void arch_feed_wdt() { /* TODO */ } | ||||
|  | ||||
| void arch_restart() { /* TODO */ } | ||||
|  | ||||
| void nrf52GetMacAddr(uint8_t *mac) | ||||
| { | ||||
|     const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user