feat(ble-deployer): add CMD_RESET for Arduino DTR pulse reset
This commit is contained in:
parent
bba06933bd
commit
a18d3f660c
|
|
@ -33,6 +33,7 @@ export const CMD_END = 0x03;
|
||||||
export const CMD_ACK = 0x04;
|
export const CMD_ACK = 0x04;
|
||||||
export const CMD_ERR = 0x05;
|
export const CMD_ERR = 0x05;
|
||||||
export const CMD_SET_BAUD = 0x06;
|
export const CMD_SET_BAUD = 0x06;
|
||||||
|
export const CMD_RESET = 0x07;
|
||||||
|
|
||||||
export const SUPPORTED_BAUD_RATES = [9600, 19200, 38400];
|
export const SUPPORTED_BAUD_RATES = [9600, 19200, 38400];
|
||||||
export const DEFAULT_BAUD_RATE = 9600;
|
export const DEFAULT_BAUD_RATE = 9600;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ idf_component_register(
|
||||||
state_machine.c
|
state_machine.c
|
||||||
serial_bridge.c
|
serial_bridge.c
|
||||||
led_button.c
|
led_button.c
|
||||||
|
arduino_reset.c
|
||||||
INCLUDE_DIRS
|
INCLUDE_DIRS
|
||||||
.
|
.
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#define CMD_ACK 0x04
|
#define CMD_ACK 0x04
|
||||||
#define CMD_ERR 0x05
|
#define CMD_ERR 0x05
|
||||||
#define CMD_SET_BAUD 0x06
|
#define CMD_SET_BAUD 0x06
|
||||||
|
#define CMD_RESET 0x07
|
||||||
|
|
||||||
/** Maximum hex binary buffer size (256 KB — fits largest Arduino sketch). */
|
/** Maximum hex binary buffer size (256 KB — fits largest Arduino sketch). */
|
||||||
#define MAX_HEX_SIZE (256 * 1024)
|
#define MAX_HEX_SIZE (256 * 1024)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ void ble_store_config_init(void);
|
||||||
#include "state_machine.h"
|
#include "state_machine.h"
|
||||||
#include "services/gatt/ble_svc_gatt.h"
|
#include "services/gatt/ble_svc_gatt.h"
|
||||||
#include "ble_service.h"
|
#include "ble_service.h"
|
||||||
|
#include "arduino_reset.h"
|
||||||
#include "serial_bridge.h"
|
#include "serial_bridge.h"
|
||||||
#include "state_machine.h"
|
#include "state_machine.h"
|
||||||
#include "binary_parser.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);
|
os_mbuf_copydata(ctxt->om, 0, len, data);
|
||||||
ESP_LOGI(TAG, "Serial write: len=%d conn=%d", len, conn_handle);
|
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 baud = (uint32_t)data[1] | ((uint32_t)data[2] << 8) |
|
||||||
((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24);
|
((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24);
|
||||||
ESP_LOGI(TAG, "CMD_SET_BAUD: %lu", (unsigned long)baud);
|
ESP_LOGI(TAG, "CMD_SET_BAUD: %lu", (unsigned long)baud);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue