refactor(platform): remove printer debug path and fix boot logo behavior

This commit is contained in:
admin
2026-03-01 15:42:17 +08:00
parent 4f574fb65c
commit 809fcf6548
15 changed files with 39 additions and 328 deletions

View File

@@ -191,18 +191,6 @@ typedef struct {
bool ignore_precheck;
} printer_print_options_t;
typedef struct {
uint16_t shift_clock_high_us;
uint16_t shift_clock_low_us;
uint16_t latch_pulse_us;
bool strobe_active_high;
bool boost_active_high;
uint16_t override_strobe_on_us;
uint16_t override_strobe_interval_us;
uint16_t override_motor_step_us;
uint8_t override_steps_per_line;
} printer_debug_config_t;
typedef struct {
bool busy;
bool has_paper;
@@ -219,14 +207,6 @@ typedef uint32_t printer_status_poll_pause_token_t;
esp_err_t printer_protocol_init(void);
esp_err_t printer_protocol_stop(uint32_t timeout_ms);
esp_err_t printer_protocol_get_debug_config(printer_debug_config_t *out_config,
char *err,
size_t err_len);
esp_err_t printer_protocol_set_debug_config(const printer_debug_config_t *config,
bool reset_defaults,
char *err,
size_t err_len);
void printer_protocol_get_runtime_status(printer_runtime_status_t *out_status);
printer_status_poll_pause_token_t printer_protocol_status_poll_pause_acquire(void);
void printer_protocol_status_poll_pause_release(printer_status_poll_pause_token_t *token);

View File

@@ -115,8 +115,7 @@ static BaseType_t printer_create_task_prefer_psram(TaskFunction_t task_fn,
uint32_t stack_size,
UBaseType_t priority,
TaskHandle_t *out_task) {
#if defined(CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) && \
defined(CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM) && \
#if defined(CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM) && \
(configSUPPORT_STATIC_ALLOCATION == 1)
BaseType_t rc = xTaskCreatePinnedToCoreWithCaps(task_fn,
name,

View File

@@ -1,66 +1,10 @@
#include "domain.h"
#include "printer_protocol_internal.h"
#include <stdio.h>
static void write_err(char *err, size_t err_len, const char *msg) {
if (err != NULL && err_len > 0) {
snprintf(err, err_len, "%s", msg);
}
}
esp_err_t printer_protocol_gap_move(uint32_t timeout_ms, char *err, size_t err_len) {
return platform_printer_gap_move(timeout_ms, err, err_len);
}
esp_err_t printer_protocol_get_debug_config(printer_debug_config_t *out_config,
char *err,
size_t err_len) {
if (out_config == NULL) {
write_err(err, err_len, "invalid args");
return ESP_ERR_INVALID_ARG;
}
esp_err_t rc = platform_printer_get_debug_config(&out_config->shift_clock_high_us,
&out_config->shift_clock_low_us,
&out_config->latch_pulse_us,
&out_config->strobe_active_high,
&out_config->boost_active_high,
&out_config->override_strobe_on_us,
&out_config->override_strobe_interval_us,
&out_config->override_motor_step_us,
&out_config->override_steps_per_line);
if (rc != ESP_OK) {
write_err(err, err_len, "get printer debug config failed");
return rc;
}
return ESP_OK;
}
esp_err_t printer_protocol_set_debug_config(const printer_debug_config_t *config,
bool reset_defaults,
char *err,
size_t err_len) {
if (config == NULL && !reset_defaults) {
write_err(err, err_len, "invalid args");
return ESP_ERR_INVALID_ARG;
}
return platform_printer_set_debug_config(config != NULL,
config != NULL ? config->shift_clock_high_us : 0,
config != NULL ? config->shift_clock_low_us : 0,
config != NULL ? config->latch_pulse_us : 0,
config != NULL ? config->strobe_active_high : false,
config != NULL ? config->boost_active_high : false,
config != NULL ? config->override_strobe_on_us : 0,
config != NULL ? config->override_strobe_interval_us : 0,
config != NULL ? config->override_motor_step_us : 0,
config != NULL ? config->override_steps_per_line : 0,
reset_defaults,
err,
err_len);
}
const char *printer_protocol_job_state_str(print_job_state_t state) {
switch (state) {
case PRINT_JOB_STATE_NONE:

View File

@@ -191,8 +191,7 @@ BaseType_t voice_create_task_prefer_psram(TaskFunction_t task_fn,
BaseType_t rc = pdFAIL;
#if defined(CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) && \
defined(CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM) && \
#if defined(CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM) && \
(configSUPPORT_STATIC_ALLOCATION == 1)
rc = xTaskCreatePinnedToCoreWithCaps(task_fn,
name,

View File

@@ -47,28 +47,6 @@ typedef struct {
esp_err_t platform_printer_init(void);
void platform_printer_deinit(void);
esp_err_t platform_printer_get_sensors(platform_printer_sensors_t *out_sensors);
esp_err_t platform_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
uint16_t *out_shift_clock_low_us,
uint16_t *out_latch_pulse_us,
bool *out_strobe_active_high,
bool *out_boost_active_high,
uint16_t *out_override_strobe_on_us,
uint16_t *out_override_strobe_interval_us,
uint16_t *out_override_motor_step_us,
uint8_t *out_override_steps_per_line);
esp_err_t platform_printer_set_debug_config(bool has_config,
uint16_t shift_clock_high_us,
uint16_t shift_clock_low_us,
uint16_t latch_pulse_us,
bool strobe_active_high,
bool boost_active_high,
uint16_t override_strobe_on_us,
uint16_t override_strobe_interval_us,
uint16_t override_motor_step_us,
uint8_t override_steps_per_line,
bool reset_defaults,
char *err,
size_t err_len);
esp_err_t platform_printer_print(const platform_printer_print_request_t *request,
char *err,
size_t err_len);
@@ -76,7 +54,7 @@ esp_err_t platform_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_l
// ---------- display_st7789 ----------
esp_err_t platform_display_init(void);
esp_err_t platform_display_show_test_pattern(void);
esp_err_t platform_display_show_boot_logo(void);
esp_err_t platform_display_show_raster_1bpp(const uint8_t *raster,
size_t raster_len,
uint16_t width,

View File

@@ -13,7 +13,7 @@ esp_err_t platform_lcd_decode_png_rgb565(const uint8_t *png,
char *err,
size_t err_len);
esp_err_t platform_lcd_decode_demo_png(uint16_t **out_pixels,
esp_err_t platform_lcd_decode_logo_png(uint16_t **out_pixels,
uint16_t *out_width,
uint16_t *out_height,
char *err,

View File

@@ -10,7 +10,7 @@ extern "C" {
#endif
esp_err_t lcd_module_init(void);
esp_err_t lcd_module_start_demo(void);
esp_err_t lcd_module_show_boot_logo(void);
esp_err_t lcd_module_show_raster_1bpp(const uint8_t *raster,
size_t raster_len,
uint16_t width,

View File

@@ -126,7 +126,7 @@ fail:
return ret;
}
esp_err_t platform_lcd_decode_demo_png(uint16_t **out_pixels,
esp_err_t platform_lcd_decode_logo_png(uint16_t **out_pixels,
uint16_t *out_width,
uint16_t *out_height,
char *err,

View File

@@ -712,7 +712,7 @@ esp_err_t lcd_module_show_png(const uint8_t *png,
#endif
}
esp_err_t lcd_module_start_demo(void)
esp_err_t lcd_module_show_boot_logo(void)
{
#if !CONFIG_TQ_SCREEN_ENABLE
return ESP_ERR_NOT_SUPPORTED;
@@ -722,17 +722,17 @@ esp_err_t lcd_module_start_demo(void)
return ESP_ERR_TIMEOUT;
}
uint16_t *demo_pixels = NULL;
uint16_t demo_w = 0;
uint16_t demo_h = 0;
uint16_t *logo_pixels = NULL;
uint16_t logo_w = 0;
uint16_t logo_h = 0;
char decode_err[96] = {0};
esp_err_t decode_rc = platform_lcd_decode_demo_png(&demo_pixels,
&demo_w,
&demo_h,
esp_err_t decode_rc = platform_lcd_decode_logo_png(&logo_pixels,
&logo_w,
&logo_h,
decode_err,
sizeof(decode_err));
if (decode_rc != ESP_OK) {
ESP_LOGW(TAG, "demo png decode failed: rc=0x%x msg=%s", (unsigned)decode_rc, decode_err);
ESP_LOGW(TAG, "boot logo decode failed: rc=0x%x msg=%s", (unsigned)decode_rc, decode_err);
lcd_lock_give();
return decode_rc;
}
@@ -741,11 +741,11 @@ esp_err_t lcd_module_start_demo(void)
uint16_t prev_w = s_lcd.preview_w;
uint16_t prev_h = s_lcd.preview_h;
bool clear_before_draw = (s_lcd.preview_pixels == NULL ||
s_lcd.preview_w != demo_w ||
s_lcd.preview_h != demo_h);
s_lcd.preview_pixels = demo_pixels;
s_lcd.preview_w = demo_w;
s_lcd.preview_h = demo_h;
s_lcd.preview_w != logo_w ||
s_lcd.preview_h != logo_h);
s_lcd.preview_pixels = logo_pixels;
s_lcd.preview_w = logo_w;
s_lcd.preview_h = logo_h;
esp_err_t draw_err = lcd_apply_preview_locked(prev_pixels,
prev_w,
@@ -759,7 +759,7 @@ esp_err_t lcd_module_start_demo(void)
}
lcd_lock_give();
if (draw_err != ESP_OK) {
ESP_LOGW(TAG, "demo draw failed: rc=0x%x msg=%s", (unsigned)draw_err, decode_err);
ESP_LOGW(TAG, "boot logo draw failed: rc=0x%x msg=%s", (unsigned)draw_err, decode_err);
return draw_err;
}
return ESP_OK;

View File

@@ -12,9 +12,9 @@ esp_err_t platform_display_init(void)
return lcd_module_init();
}
esp_err_t platform_display_show_test_pattern(void)
esp_err_t platform_display_show_boot_logo(void)
{
return lcd_module_start_demo();
return lcd_module_show_boot_logo();
}
esp_err_t platform_display_show_raster_1bpp(const uint8_t *raster,

View File

@@ -228,15 +228,12 @@ esp_err_t platform_bootstrap_init(void) {
err = platform_display_init();
if (err != ESP_OK) {
ESP_LOGW(TAG, "st7789 init failed: %s", esp_err_to_name(err));
}
#if CONFIG_TQ_SCREEN_TEST_PATTERN_ON_BOOT
else {
err = platform_display_show_test_pattern();
} else {
err = platform_display_show_boot_logo();
if (err != ESP_OK) {
ESP_LOGW(TAG, "st7789 test pattern failed: %s", esp_err_to_name(err));
ESP_LOGW(TAG, "st7789 boot logo failed: %s", esp_err_to_name(err));
}
}
#endif
#endif
s_initialized = true;

View File

@@ -1,7 +1,6 @@
#include "platform.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "driver/gpio.h"
@@ -25,15 +24,12 @@
#endif
#define ADC_RAW_MAX 4095
#define DEBUG_SHIFT_CLOCK_US_MIN 1
#define DEBUG_SHIFT_CLOCK_US_MAX 50
#define DEBUG_LATCH_PULSE_US_MIN 1
#define DEBUG_LATCH_PULSE_US_MAX 50
static const uint16_t k_default_shift_clock_high_us = 5;
static const uint16_t k_default_shift_clock_low_us = 5;
static const uint16_t k_default_latch_pulse_us = 1;
static const bool k_default_strobe_active_high = true;
// Stable timing/polarity values validated on current hardware.
static const uint16_t k_shift_clock_high_us = 5;
static const uint16_t k_shift_clock_low_us = 5;
static const uint16_t k_latch_pulse_us = 1;
static const bool k_strobe_active_high = true;
static const char *TAG = "printer_driver";
static const uint8_t k_print_yield_lines = 8;
@@ -45,22 +41,9 @@ typedef struct {
adc_channel_t channel;
} adc_pin_t;
typedef struct {
uint16_t shift_clock_high_us;
uint16_t shift_clock_low_us;
uint16_t latch_pulse_us;
bool strobe_active_high;
bool boost_active_high;
uint16_t override_strobe_on_us;
uint16_t override_strobe_interval_us;
uint16_t override_motor_step_us;
uint8_t override_steps_per_line;
} direct_debug_config_t;
typedef struct {
bool initialized;
uint8_t motor_phase;
direct_debug_config_t debug;
SemaphoreHandle_t lock;
adc_oneshot_unit_handle_t adc1_handle;
adc_oneshot_unit_handle_t adc2_handle;
@@ -73,28 +56,19 @@ static printer_state_t s_state;
static const uint8_t k_motor_step_table[4] = {0x05, 0x09, 0x0A, 0x06};
static int boost_on_level_locked(void) {
return s_state.debug.boost_active_high ? 1 : 0;
return BOOST_DEFAULT_ACTIVE_HIGH ? 1 : 0;
}
static int boost_off_level_locked(void) {
return s_state.debug.boost_active_high ? 0 : 1;
return BOOST_DEFAULT_ACTIVE_HIGH ? 0 : 1;
}
static int strobe_active_level_locked(void) {
return s_state.debug.strobe_active_high ? 1 : 0;
return k_strobe_active_high ? 1 : 0;
}
static int strobe_idle_level_locked(void) {
return s_state.debug.strobe_active_high ? 0 : 1;
}
static void set_debug_defaults_locked(void) {
memset(&s_state.debug, 0, sizeof(s_state.debug));
s_state.debug.shift_clock_high_us = k_default_shift_clock_high_us;
s_state.debug.shift_clock_low_us = k_default_shift_clock_low_us;
s_state.debug.latch_pulse_us = k_default_latch_pulse_us;
s_state.debug.strobe_active_high = k_default_strobe_active_high;
s_state.debug.boost_active_high = BOOST_DEFAULT_ACTIVE_HIGH != 0;
return k_strobe_active_high ? 0 : 1;
}
static bool is_gpio_valid(int gpio_num) {
@@ -197,14 +171,8 @@ static void safe_drive_off_locked(bool keep_boost_on) {
}
static void pulse_latch_locked(void) {
uint16_t latch_us = s_state.debug.latch_pulse_us;
if (latch_us < DEBUG_LATCH_PULSE_US_MIN) {
latch_us = DEBUG_LATCH_PULSE_US_MIN;
} else if (latch_us > DEBUG_LATCH_PULSE_US_MAX) {
latch_us = DEBUG_LATCH_PULSE_US_MAX;
}
set_gpio_level_if_valid(CONFIG_TQ_PRINT_LAT_PIN, 0);
esp_rom_delay_us(latch_us);
esp_rom_delay_us(k_latch_pulse_us);
set_gpio_level_if_valid(CONFIG_TQ_PRINT_LAT_PIN, 1);
}
@@ -231,28 +199,15 @@ static void motor_step_once_locked(uint16_t step_delay_us) {
}
static void write_line_bits_locked(const uint8_t *line, size_t line_bytes) {
uint16_t high_us = s_state.debug.shift_clock_high_us;
uint16_t low_us = s_state.debug.shift_clock_low_us;
if (high_us < DEBUG_SHIFT_CLOCK_US_MIN) {
high_us = DEBUG_SHIFT_CLOCK_US_MIN;
} else if (high_us > DEBUG_SHIFT_CLOCK_US_MAX) {
high_us = DEBUG_SHIFT_CLOCK_US_MAX;
}
if (low_us < DEBUG_SHIFT_CLOCK_US_MIN) {
low_us = DEBUG_SHIFT_CLOCK_US_MIN;
} else if (low_us > DEBUG_SHIFT_CLOCK_US_MAX) {
low_us = DEBUG_SHIFT_CLOCK_US_MAX;
}
for (size_t i = 0; i < line_bytes; ++i) {
uint8_t byte = line[i];
for (int bit = 7; bit >= 0; --bit) {
int pixel = ((byte >> bit) & 0x01) ? 1 : 0;
set_gpio_level_if_valid(CONFIG_TQ_SPI_SHARED_MOSI_PIN, pixel);
set_gpio_level_if_valid(CONFIG_TQ_SPI_SHARED_CLK_PIN, 1);
esp_rom_delay_us(high_us);
esp_rom_delay_us(k_shift_clock_high_us);
set_gpio_level_if_valid(CONFIG_TQ_SPI_SHARED_CLK_PIN, 0);
esp_rom_delay_us(low_us);
esp_rom_delay_us(k_shift_clock_low_us);
}
}
}
@@ -490,7 +445,6 @@ esp_err_t platform_printer_init(void) {
if (s_state.lock == NULL) {
return ESP_ERR_NO_MEM;
}
set_debug_defaults_locked();
esp_err_t err = ESP_OK;
err = config_output_pin(CONFIG_TQ_PRINT_STB_12_PIN, strobe_idle_level_locked(), "print_stb12");
@@ -591,125 +545,9 @@ esp_err_t platform_printer_get_sensors(platform_printer_sensors_t *out_sensors)
return ESP_OK;
}
esp_err_t platform_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
uint16_t *out_shift_clock_low_us,
uint16_t *out_latch_pulse_us,
bool *out_strobe_active_high,
bool *out_boost_active_high,
uint16_t *out_override_strobe_on_us,
uint16_t *out_override_strobe_interval_us,
uint16_t *out_override_motor_step_us,
uint8_t *out_override_steps_per_line) {
if (out_shift_clock_high_us == NULL || out_shift_clock_low_us == NULL || out_latch_pulse_us == NULL ||
out_strobe_active_high == NULL || out_boost_active_high == NULL || out_override_strobe_on_us == NULL ||
out_override_strobe_interval_us == NULL || out_override_motor_step_us == NULL ||
out_override_steps_per_line == NULL) {
return ESP_ERR_INVALID_ARG;
}
esp_err_t init_rc = platform_printer_init();
if (init_rc != ESP_OK) {
return init_rc;
}
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(500)) != pdTRUE) {
return ESP_ERR_TIMEOUT;
}
*out_shift_clock_high_us = s_state.debug.shift_clock_high_us;
*out_shift_clock_low_us = s_state.debug.shift_clock_low_us;
*out_latch_pulse_us = s_state.debug.latch_pulse_us;
*out_strobe_active_high = s_state.debug.strobe_active_high;
*out_boost_active_high = s_state.debug.boost_active_high;
*out_override_strobe_on_us = s_state.debug.override_strobe_on_us;
*out_override_strobe_interval_us = s_state.debug.override_strobe_interval_us;
*out_override_motor_step_us = s_state.debug.override_motor_step_us;
*out_override_steps_per_line = s_state.debug.override_steps_per_line;
xSemaphoreGive(s_state.lock);
return ESP_OK;
}
esp_err_t platform_printer_set_debug_config(bool has_config,
uint16_t shift_clock_high_us,
uint16_t shift_clock_low_us,
uint16_t latch_pulse_us,
bool strobe_active_high,
bool boost_active_high,
uint16_t override_strobe_on_us,
uint16_t override_strobe_interval_us,
uint16_t override_motor_step_us,
uint8_t override_steps_per_line,
bool reset_defaults,
char *err,
size_t err_len) {
if (!has_config && !reset_defaults) {
write_err(err, err_len, "invalid args");
return ESP_ERR_INVALID_ARG;
}
esp_err_t init_rc = platform_printer_init();
if (init_rc != ESP_OK) {
write_err(err, err_len, "printer driver not initialized");
return init_rc;
}
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(1000)) != pdTRUE) {
write_err(err, err_len, "printer lock timeout");
return ESP_ERR_TIMEOUT;
}
if (reset_defaults) {
set_debug_defaults_locked();
}
if (has_config) {
if (shift_clock_high_us < DEBUG_SHIFT_CLOCK_US_MIN || shift_clock_high_us > DEBUG_SHIFT_CLOCK_US_MAX ||
shift_clock_low_us < DEBUG_SHIFT_CLOCK_US_MIN || shift_clock_low_us > DEBUG_SHIFT_CLOCK_US_MAX) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "shift clock us out of range (1..50)");
return ESP_ERR_INVALID_ARG;
}
if (latch_pulse_us < DEBUG_LATCH_PULSE_US_MIN || latch_pulse_us > DEBUG_LATCH_PULSE_US_MAX) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "latch pulse us out of range (1..50)");
return ESP_ERR_INVALID_ARG;
}
if (override_strobe_on_us != 0 && (override_strobe_on_us < 100 || override_strobe_on_us > 10000)) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "strobe_on_us must be 0 or 100..10000");
return ESP_ERR_INVALID_ARG;
}
if (override_strobe_interval_us > 10000) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "strobe_interval_us must be 0..10000");
return ESP_ERR_INVALID_ARG;
}
if (override_motor_step_us != 0 && (override_motor_step_us < 100 || override_motor_step_us > 20000)) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "motor_step_us must be 0 or 100..20000");
return ESP_ERR_INVALID_ARG;
}
if (override_steps_per_line > 8) {
xSemaphoreGive(s_state.lock);
write_err(err, err_len, "steps_per_line must be 0..8");
return ESP_ERR_INVALID_ARG;
}
s_state.debug.shift_clock_high_us = shift_clock_high_us;
s_state.debug.shift_clock_low_us = shift_clock_low_us;
s_state.debug.latch_pulse_us = latch_pulse_us;
s_state.debug.strobe_active_high = strobe_active_high;
s_state.debug.boost_active_high = boost_active_high;
s_state.debug.override_strobe_on_us = override_strobe_on_us;
s_state.debug.override_strobe_interval_us = override_strobe_interval_us;
s_state.debug.override_motor_step_us = override_motor_step_us;
s_state.debug.override_steps_per_line = override_steps_per_line;
}
safe_drive_off_locked(true);
xSemaphoreGive(s_state.lock);
return ESP_OK;
}
esp_err_t platform_printer_print(const platform_printer_print_request_t *request,
char *err,
size_t err_len) {
char *err,
size_t err_len) {
if (request == NULL || request->raster == NULL || request->width == 0 || request->height == 0) {
write_err(err, err_len, "invalid args");
return ESP_ERR_INVALID_ARG;
@@ -762,19 +600,6 @@ esp_err_t platform_printer_print(const platform_printer_print_request_t *request
? request->motor_steps_per_line
: runtime_policy_printer_steps_per_line();
if (s_state.debug.override_strobe_on_us > 0) {
strobe_on_us = s_state.debug.override_strobe_on_us;
}
if (s_state.debug.override_strobe_interval_us > 0) {
strobe_interval_us = s_state.debug.override_strobe_interval_us;
}
if (s_state.debug.override_motor_step_us > 0) {
motor_step_us = s_state.debug.override_motor_step_us;
}
if (s_state.debug.override_steps_per_line > 0) {
steps_per_line = s_state.debug.override_steps_per_line;
}
rc = ESP_OK;
if (!request->ignore_precheck) {
rc = precheck_before_print_locked(err, err_len);
@@ -855,9 +680,6 @@ esp_err_t platform_printer_gap_move(uint32_t timeout_ms, char *err, size_t err_l
esp_err_t rc = ESP_OK;
uint16_t steps = runtime_policy_printer_gap_steps();
uint16_t step_delay_us = runtime_policy_printer_motor_step_us();
if (s_state.debug.override_motor_step_us > 0) {
step_delay_us = s_state.debug.override_motor_step_us;
}
platform_printer_sensors_t sensors = {0};
sample_sensors_locked(&sensors);