mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 11:37:44 +08:00
feat: refine remote states and PRTS LCD refresh
- add remote NOT_READY/READY/PROTECT state flow and matching LED/status display - speed up TFT hardware SPI DMA flush path and larger LVGL partial refresh buffer - reduce page/menu redraw artifacts and center the PRTS status title
This commit is contained in:
@@ -28,6 +28,9 @@ typedef enum
|
||||
|
||||
static bool tft_initialized = false;
|
||||
static bool tft_transfer_ok = true;
|
||||
static volatile bool tft_dma_active = false;
|
||||
static TFT_TransferDoneCallback tft_dma_callback = NULL;
|
||||
static void *tft_dma_context = NULL;
|
||||
|
||||
static const uint8_t tft_font5x7[][TFT_FONT_H] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* space */
|
||||
@@ -107,6 +110,31 @@ static void tft_backlight_on(void)
|
||||
HAL_GPIO_WritePin(TFT_BLK_GPIO_Port, TFT_BLK_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
static void tft_dma_finish(bool ok)
|
||||
{
|
||||
TFT_TransferDoneCallback callback = tft_dma_callback;
|
||||
void *context = tft_dma_context;
|
||||
|
||||
if (!tft_dma_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tft_dma_active = false;
|
||||
tft_dma_callback = NULL;
|
||||
tft_dma_context = NULL;
|
||||
if (!ok)
|
||||
{
|
||||
tft_transfer_ok = false;
|
||||
}
|
||||
tft_cs_high();
|
||||
|
||||
if (callback != NULL)
|
||||
{
|
||||
callback(context, ok);
|
||||
}
|
||||
}
|
||||
|
||||
static void tft_bus_init(void)
|
||||
{
|
||||
#if TFT_USE_SOFT_SPI
|
||||
@@ -278,6 +306,51 @@ void TFT_WriteColorData(const uint8_t *data, uint32_t len)
|
||||
tft_cs_high();
|
||||
}
|
||||
|
||||
bool TFT_WriteColorDataDMA(const uint8_t *data,
|
||||
uint32_t len,
|
||||
TFT_TransferDoneCallback callback,
|
||||
void *context)
|
||||
{
|
||||
if (data == NULL || len == 0U || len > UINT16_MAX || tft_dma_active || TFT_SPI_UNIT.hdmatx == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
tft_cs_low();
|
||||
tft_dc_data();
|
||||
tft_dma_callback = callback;
|
||||
tft_dma_context = context;
|
||||
tft_dma_active = true;
|
||||
|
||||
if (HAL_SPI_Transmit_DMA(&TFT_SPI_UNIT, (uint8_t *) data, (uint16_t) len) != HAL_OK)
|
||||
{
|
||||
tft_dma_active = false;
|
||||
tft_dma_callback = NULL;
|
||||
tft_dma_context = NULL;
|
||||
tft_transfer_ok = false;
|
||||
tft_cs_high();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if (hspi == &TFT_SPI_UNIT)
|
||||
{
|
||||
tft_dma_finish(true);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if (hspi == &TFT_SPI_UNIT)
|
||||
{
|
||||
tft_dma_finish(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool TFT_IsReady(void)
|
||||
{
|
||||
return tft_initialized && tft_transfer_ok;
|
||||
@@ -599,8 +672,12 @@ const char *TFT_RobotModeText(RobotMode_t mode)
|
||||
return "ERROR";
|
||||
case REMOTE_NOT_CONNECTED:
|
||||
return "REMOTE OFF";
|
||||
case REMOTE_CONNECTED:
|
||||
return "REMOTE ON";
|
||||
case REMOTE_NOT_READY:
|
||||
return "NOT READY";
|
||||
case REMOTE_READY:
|
||||
return "READY";
|
||||
case REMOTE_PROTECT:
|
||||
return "PROTECT";
|
||||
case AUTO_SHOOTING_MODE:
|
||||
return "AUTO SHOOT";
|
||||
case IMU_CALIBERATION_MODE:
|
||||
@@ -619,7 +696,11 @@ static uint16_t tft_mode_color(RobotMode_t mode)
|
||||
case SYS_ERROR_OCCURRED:
|
||||
case REMOTE_NOT_CONNECTED:
|
||||
return TFT_COLOR_RED;
|
||||
case REMOTE_CONNECTED:
|
||||
case REMOTE_NOT_READY:
|
||||
return TFT_COLOR_WHITE;
|
||||
case REMOTE_READY:
|
||||
return TFT_COLOR_MAGENTA;
|
||||
case REMOTE_PROTECT:
|
||||
return TFT_COLOR_YELLOW;
|
||||
case AUTO_SHOOTING_MODE:
|
||||
return TFT_COLOR_CYAN;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*TFT_TransferDoneCallback)(void *context, bool ok);
|
||||
|
||||
#define TFT_USE_HORIZONTAL 2U
|
||||
#define TFT_USE_SOFT_SPI 0U
|
||||
#define TFT_HW_SPI_BYTE_MODE 0U
|
||||
@@ -91,6 +93,10 @@ void TFT_DrawString(uint16_t x, uint16_t y, const char *text, uint16_t fc, uint1
|
||||
void TFT_ShowStatus(float temperature_c, RobotMode_t mode);
|
||||
bool TFT_IsReady(void);
|
||||
void TFT_WriteColorData(const uint8_t *data, uint32_t len);
|
||||
bool TFT_WriteColorDataDMA(const uint8_t *data,
|
||||
uint32_t len,
|
||||
TFT_TransferDoneCallback callback,
|
||||
void *context);
|
||||
const char *TFT_RobotModeText(RobotMode_t mode);
|
||||
|
||||
void LCD_Init(void);
|
||||
|
||||
Reference in New Issue
Block a user