diff --git a/frontend/src/lib/types/deployer.ts b/frontend/src/lib/types/deployer.ts index 4318d50..59dc918 100644 --- a/frontend/src/lib/types/deployer.ts +++ b/frontend/src/lib/types/deployer.ts @@ -33,6 +33,7 @@ export const CMD_END = 0x03; export const CMD_ACK = 0x04; export const CMD_ERR = 0x05; export const CMD_SET_BAUD = 0x06; +export const CMD_RESET = 0x07; export const SUPPORTED_BAUD_RATES = [9600, 19200, 38400]; export const DEFAULT_BAUD_RATE = 9600; diff --git a/velxio-deployer-firmware/main/CMakeLists.txt b/velxio-deployer-firmware/main/CMakeLists.txt index fba34a7..d9bb49a 100644 --- a/velxio-deployer-firmware/main/CMakeLists.txt +++ b/velxio-deployer-firmware/main/CMakeLists.txt @@ -9,6 +9,7 @@ idf_component_register( state_machine.c serial_bridge.c led_button.c + arduino_reset.c INCLUDE_DIRS . ) diff --git a/velxio-deployer-firmware/main/arduino_reset.c b/velxio-deployer-firmware/main/arduino_reset.c new file mode 100644 index 0000000..24b1813 --- /dev/null +++ b/velxio-deployer-firmware/main/arduino_reset.c @@ -0,0 +1,17 @@ +#include "arduino_reset.h" +#include "usb_host.h" +#include "esp_log.h" + +static const char *TAG = "ARDUINO_RESET"; + +/** + * Trigger DTR pulse to reset Arduino. + * Delegates to the existing usb_host_reset_arduino() which drives + * DTR/RTS low → 1ms delay → high → 50ms delay, mirroring avrdude's + * Arduino autoreset sequence. + */ +void arduino_trigger_reset(void) { + ESP_LOGI(TAG, "Triggering Arduino reset via DTR pulse..."); + usb_host_reset_arduino(); + ESP_LOGI(TAG, "Arduino reset pulse complete"); +} diff --git a/velxio-deployer-firmware/main/arduino_reset.h b/velxio-deployer-firmware/main/arduino_reset.h new file mode 100644 index 0000000..5dd98e0 --- /dev/null +++ b/velxio-deployer-firmware/main/arduino_reset.h @@ -0,0 +1,8 @@ +#pragma once + +/** + * Trigger hardware reset on Arduino via DTR pulse. + * Must be called before serial bridge starts to ensure + * Arduino bootloader is ready. + */ +void arduino_trigger_reset(void); diff --git a/velxio-deployer-firmware/main/binary_parser.h b/velxio-deployer-firmware/main/binary_parser.h index 7cf4fd5..d8acc58 100644 --- a/velxio-deployer-firmware/main/binary_parser.h +++ b/velxio-deployer-firmware/main/binary_parser.h @@ -25,6 +25,7 @@ #define CMD_ACK 0x04 #define CMD_ERR 0x05 #define CMD_SET_BAUD 0x06 +#define CMD_RESET 0x07 /** Maximum hex binary buffer size (256 KB — fits largest Arduino sketch). */ #define MAX_HEX_SIZE (256 * 1024) diff --git a/velxio-deployer-firmware/main/ble_service.c b/velxio-deployer-firmware/main/ble_service.c index bef7207..9e39498 100644 --- a/velxio-deployer-firmware/main/ble_service.c +++ b/velxio-deployer-firmware/main/ble_service.c @@ -18,6 +18,7 @@ void ble_store_config_init(void); #include "state_machine.h" #include "services/gatt/ble_svc_gatt.h" #include "ble_service.h" +#include "arduino_reset.h" #include "serial_bridge.h" #include "state_machine.h" #include "binary_parser.h" @@ -91,7 +92,10 @@ static int serial_char_access_cb(uint16_t conn_handle, uint16_t attr_handle, os_mbuf_copydata(ctxt->om, 0, len, data); ESP_LOGI(TAG, "Serial write: len=%d conn=%d", len, conn_handle); - if (len == 5 && data[0] == CMD_SET_BAUD) { + if (len == 1 && data[0] == CMD_RESET) { + ESP_LOGI(TAG, "CMD_RESET: triggering Arduino reset"); + arduino_trigger_reset(); + } else if (len == 5 && data[0] == CMD_SET_BAUD) { uint32_t baud = (uint32_t)data[1] | ((uint32_t)data[2] << 8) | ((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24); ESP_LOGI(TAG, "CMD_SET_BAUD: %lu", (unsigned long)baud);