【DigiKey“智造万物,快乐不停”创意大赛】远程监控系统+第5帖 LCD显示
[复制链接]
一LTDC控制器
LTDC全称 LCD-TFT Display Controller,LCD显示控制器,提供了RGB信号和控制信号来直接控制外部LCD显示屏。
一些屏幕称为RGB屏幕,内部没有驱动IC,操作这种屏幕时往往使用MCU内部集成的LCD控制器直接去控制LCD显示,显存空间当然也是在MCU内部,按照空间大小可以选择放在内部SRAM或者外部SDRAM中,如图:
显示应该是这个方式,采用了外置SDRAM
显存指LCD所有像素点数据缓存再传给显示屏,显存的容量至少要能存储显示器一帧的显示数据,分辨率480*272,RGB8888的话,显示一帧数据大小(8+8+8+8)*480*272=4177920bit/8=522,240byte
二 外置SDRAM
SDRAM采用的地址0xc000 0000
uint8_t BSP_SDRAM_Init(void)
{
static uint8_t sdramstatus = SDRAM_ERROR;
/* SDRAM device configuration */
sdramHandle.Instance = FMC_SDRAM_DEVICE;
/* Timing configuration for 100Mhz as SD clock frequency (System clock is up to 200Mhz) */
Timing.LoadToActiveDelay = 2;
Timing.ExitSelfRefreshDelay = 7;
Timing.SelfRefreshTime = 4;
Timing.RowCycleDelay = 7;
Timing.WriteRecoveryTime = 2;
Timing.RPDelay = 2;
Timing.RCDDelay = 2;
sdramHandle.Init.SDBank = FMC_SDRAM_BANK1;
sdramHandle.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
sdramHandle.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
sdramHandle.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH;
sdramHandle.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
sdramHandle.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_2;
sdramHandle.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
sdramHandle.Init.SDClockPeriod = SDCLOCK_PERIOD;
sdramHandle.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
sdramHandle.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
/* SDRAM controller initialization */
BSP_SDRAM_MspInit(&sdramHandle, NULL); /* __weak function can be rewritten by the application */
if(HAL_SDRAM_Init(&sdramHandle, &Timing) != HAL_OK)
{
sdramstatus = SDRAM_ERROR;
}
else
{
sdramstatus = SDRAM_OK;
}
/* SDRAM initialization sequence */
BSP_SDRAM_Initialization_sequence(REFRESH_COUNT);
return sdramstatus;
}
三LCD驱动原理图
背光电源控制IO口为LCD_BL_CTRL即PK3
RGB888(3B):R值8位、G值8位、B值8位
RGB565(2B):R值5位、G值6位、B值5位
显然,RGB888 比 RGB565 表示的颜色更多、LTDC支持RGB888格式,但是RGB888每个像素点需要24bit(3个字节)的显存空间来存储
RK043FN48H的参数
官方推荐的参数配置是这样
/**
* @brief RK043FN48H Size
*/
#define RK043FN48H_WIDTH ((uint16_t)480) /* LCD PIXEL WIDTH */
#define RK043FN48H_HEIGHT ((uint16_t)272) /* LCD PIXEL HEIGHT */
/**
* @brief RK043FN48H Timing
*/
#define RK043FN48H_HSYNC ((uint16_t)41) /* Horizontal synchronization */
#define RK043FN48H_HBP ((uint16_t)13) /* Horizontal back porch */
#define RK043FN48H_HFP ((uint16_t)32) /* Horizontal front porch */
#define RK043FN48H_VSYNC ((uint16_t)10) /* Vertical synchronization */
#define RK043FN48H_VBP ((uint16_t)2) /* Vertical back porch */
#define RK043FN48H_VFP ((uint16_t)2) /* Vertical front porch */
还是有一些不一样的,就这么用吧
四 图形加速器DMA2D
hDma2dHandler.Init.Mode = DMA2D_R2M;
if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
{ /* RGB565 format */
hDma2dHandler.Init.ColorMode = DMA2D_RGB565;
}
else
{ /* ARGB8888 format */
hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
}
hDma2dHandler.Init.OutputOffset = OffLine;
hDma2dHandler.Instance = DMA2D;
/* DMA2D Initialization */
if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK)
整个显示过程原理应该是通过LTDC、DMA2D以及存储器,构成一个完整的液晶控制器,LTDC不断刷新液晶屏,DMA2D搬运图像数据、混合及格式转换,外置的SDRAM存储器作为显存。
五 画线
BSP_LCD_DrawRect(80,120,70,70);
BSP_LCD_DrawCircle(250,150,70);
BSP_LCD_DrawEllipse(380,120,30,40);
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
/* Draw horizontal lines */
BSP_LCD_DrawHLine(Xpos, Ypos, Width);
BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
/* Draw vertical lines */
BSP_LCD_DrawVLine(Xpos, Ypos, Height);
BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
}
六 结果
|