#ifndef __ILI9341_H__ #define __ILI9341_H__ #ifdef __cplusplus extern "C" { #endif #include "main.h" #include "spi.h" /* 默认竖屏分辨率 */ #define ILI9341_WIDTH 240 #define ILI9341_HEIGHT 320 /* ============================================================ * LCD 控制引脚 * * !!! 重要 !!! * 下面的 LCD_CS_PIN 目前是 GPIO_PIN_12,但 gpio.c 的 * MX_GPIO_Init() 里只把 GPIO_PIN_6 配置成了输出(Output_PP)。 * GPIO_PIN_12 复位后是 Analog 模式,不是输出,直接 * HAL_GPIO_WritePin() 不会对物理引脚产生任何效果。 * * 请确认实际硬件接线: * - 如果 CS 确实接在 PB12,必须在 MX_GPIO_Init() 里把 * GPIO_PIN_12 加入 output push-pull 初始化列表; * - 如果实际接线仍是 PB6,请把下面的宏改回 GPIO_PIN_6。 * 在确认并修复之前,CS 时序不可信,任何"偶发花屏/白屏"的 * 排查都应该先排除这个问题。 * ============================================================ */ #define LCD_CS_PORT GPIOB #define LCD_CS_PIN GPIO_PIN_12 #define LCD_DC_PORT GPIOB #define LCD_DC_PIN GPIO_PIN_7 #define LCD_RST_PORT GPIOB #define LCD_RST_PIN GPIO_PIN_8 #define LCD_BL_PORT GPIOB #define LCD_BL_PIN GPIO_PIN_9 /* RGB565 常用颜色 */ #define ILI9341_BLACK 0x0000 #define ILI9341_WHITE 0xFFFF #define ILI9341_RED 0xF800 #define ILI9341_GREEN 0x07E0 #define ILI9341_BLUE 0x001F #define ILI9341_YELLOW 0xFFE0 #define ILI9341_CYAN 0x07FF #define ILI9341_MAGENTA 0xF81F #define ILI9341_GRAY 0x8410 typedef void (*ILI9341_DmaDoneCallback)(void *user_data); void ILI9341_Init(void); void ILI9341_SetRotation(uint8_t rotation); void ILI9341_FillScreen(uint16_t color); void ILI9341_DrawPixel(uint16_t x, uint16_t y, uint16_t color); void ILI9341_FillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color); void ILI9341_WriteArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *pixels); void ILI9341_WriteArea_DMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *pixels, ILI9341_DmaDoneCallback done_cb, void *user_data); /* * DMA 看门狗:建议从任务(线程)上下文周期性调用,例如放在 * StartDefaultTask 的 for(;;) 循环里、紧跟在 lv_timer_handler() * 之后。绝不能从任何中断服务程序里调用。 * * 新实现里 ILI9341_WriteArea_DMA 本身已经通过信号量+超时 * 做了同步等待和自恢复,正常情况下不需要这个看门狗介入; * 它只是兜底:万一某次调用路径绕过了 WriteArea_DMA 内部的 * 超时保护(例如未来新增的调用方式),仍然能强制恢复 SPI * 状态机,避免 lcd_dma_busy 卡死导致后续所有刷新被永久跳过。 * * timeout_ms 建议 150~200ms(要大于 WriteArea_DMA 内部 * 100ms 的超时阈值,避免互相打架)。 */ void ILI9341_DMA_Watchdog(uint32_t timeout_ms); uint16_t ILI9341_Color565(uint8_t r, uint8_t g, uint8_t b); #ifdef __cplusplus } #endif #endif