feat: support ESP32-S3 new board bring-up
This commit is contained in:
@@ -18,6 +18,7 @@ static const char *TAG = "domain_cal";
|
||||
#define DOMAIN_CALIBRATION_STEP_TIMEOUT_MS 1500
|
||||
#define DOMAIN_TURNTABLE_LIMIT_SEARCH_MAX_DEG 330.0f
|
||||
#define DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG 180.0f
|
||||
#define DOMAIN_TURNTABLE_RETURN_CHUNK_DEG 90.0f
|
||||
#define DOMAIN_TURNTABLE_HOME_ANGLE_DEG 0.0f
|
||||
|
||||
static float clamp_positive_default(float value, float default_value)
|
||||
@@ -110,6 +111,32 @@ static esp_err_t calibration_rotate_and_track(float delta, int rotate_speed_us,
|
||||
return domain_apply_rotation_delta(delta);
|
||||
}
|
||||
|
||||
static esp_err_t calibration_return_from_limit(float search_direction,
|
||||
int rotate_speed_us,
|
||||
TickType_t start_tick,
|
||||
TickType_t timeout_ticks)
|
||||
{
|
||||
float remaining_deg = DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG;
|
||||
while (remaining_deg > 0.0f) {
|
||||
float chunk_deg = remaining_deg < DOMAIN_TURNTABLE_RETURN_CHUNK_DEG ?
|
||||
remaining_deg :
|
||||
DOMAIN_TURNTABLE_RETURN_CHUNK_DEG;
|
||||
int remaining_timeout_ms = calibration_remaining_timeout_ms(start_tick, timeout_ticks);
|
||||
if (remaining_timeout_ms <= 0) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
esp_err_t err = calibration_rotate_and_track(-search_direction * chunk_deg,
|
||||
rotate_speed_us,
|
||||
remaining_timeout_ms);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
remaining_deg -= chunk_deg;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *config, int timeout_ms)
|
||||
{
|
||||
int effective_timeout_ms = timeout_ms > 0 ? timeout_ms : DOMAIN_CALIBRATION_TIMEOUT_MS;
|
||||
@@ -157,17 +184,17 @@ esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *co
|
||||
int rotate_speed_us = domain_get_rotate_speed_us();
|
||||
|
||||
ESP_LOGI(TAG,
|
||||
"Limit calibration start step=%.1f sweep=%.1f search=%s",
|
||||
"Boot motor test start: KEY1/SW1 search step=%.1f sweep=%.1f direction=%s",
|
||||
step_angle,
|
||||
max_sweep,
|
||||
calibration.search_clockwise ? "clockwise" : "counterclockwise");
|
||||
|
||||
if (is_calibration_switch_active(&calibration)) {
|
||||
ESP_LOGI(TAG, "Limit switch active at start; treating current position as 6 o'clock");
|
||||
int return_timeout_ms = calibration_step_timeout_ms(start_tick, timeout_ticks);
|
||||
err = calibration_rotate_and_track(-direction * DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG,
|
||||
rotate_speed_us,
|
||||
return_timeout_ms);
|
||||
ESP_LOGI(TAG, "KEY1/SW1 pressed at motor-test start; treating current position as 6 o'clock");
|
||||
err = calibration_return_from_limit(direction,
|
||||
rotate_speed_us,
|
||||
start_tick,
|
||||
timeout_ticks);
|
||||
if (err != ESP_OK) {
|
||||
domain_runtime_stepper_power_off();
|
||||
domain_direction_unlock_state();
|
||||
@@ -206,11 +233,13 @@ esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *co
|
||||
}
|
||||
|
||||
if (is_calibration_switch_active(&calibration)) {
|
||||
ESP_LOGI(TAG, "Limit switch detected after %.1f deg; current position is 6 o'clock", total_sweep);
|
||||
int return_timeout_ms = calibration_step_timeout_ms(start_tick, timeout_ticks);
|
||||
err = calibration_rotate_and_track(-direction * DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG,
|
||||
rotate_speed_us,
|
||||
return_timeout_ms);
|
||||
ESP_LOGI(TAG,
|
||||
"KEY1/SW1 press detected after %.1f deg; current position is 6 o'clock",
|
||||
total_sweep);
|
||||
err = calibration_return_from_limit(direction,
|
||||
rotate_speed_us,
|
||||
start_tick,
|
||||
timeout_ticks);
|
||||
if (err != ESP_OK) {
|
||||
domain_runtime_stepper_power_off();
|
||||
domain_direction_unlock_state();
|
||||
@@ -226,6 +255,6 @@ esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *co
|
||||
|
||||
domain_runtime_stepper_power_off();
|
||||
domain_direction_unlock_state();
|
||||
ESP_LOGW(TAG, "Limit switch not found after %.1f deg search", total_sweep);
|
||||
ESP_LOGW(TAG, "KEY1/SW1 not pressed during %.1f deg motor test", total_sweep);
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
@@ -761,7 +761,14 @@ esp_err_t domain_runtime_calibration_switch_init(void)
|
||||
config.active_level,
|
||||
config.pullup_enabled,
|
||||
config.pulldown_enabled);
|
||||
return domain_runtime_digital_input_configure(&config);
|
||||
esp_err_t err = domain_runtime_digital_input_configure(&config);
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG,
|
||||
"KEY1/SW1 ready gpio=%d initial_state=%s",
|
||||
config.gpio_num,
|
||||
domain_runtime_digital_input_is_active(&config) ? "pressed" : "released");
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
bool domain_runtime_calibration_switch_is_active(void)
|
||||
|
||||
Reference in New Issue
Block a user