因为STM32F7的探索板上因为各种原因,也没有手册.只能按照他给的参数来了.因为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 */
LTDC的初始化复杂程度,并不比SDRAM简单.首先SDRAM先自行初始化上,首先我定义了一下RGB565_480x272的变量在SDRAM,SDRAM的空间因此被我占用了480*272*2个字节,也就是65280个32位.定义方法需要特别提醒一下:
uint32_t RGB565_480x272[65280] __attribute__((at(0xC0000000)));
然后250K的空间,突然就被分割掉了,好可惜呢.然后初始化这个变量.
for(tmpmrd = 0; tmpmrd < 65280; tmpmrd++) { RGB565_480x272[tmpmrd] = 0xFFFFFFFF; }
特别要注意的是,自己新建工程,要添加MSP初始化,初始化各种时钟,比如下面的SAI1时钟,也是LTDC时钟.
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 192; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
其他参数只能照搬,接着有层次设置.第一层第二层什么的,这是为了LTDC才引入的吧.其他Layer(只有一层)按照默认先配置一下.逐步试验功能.默认设置:
/* Layer1 Configuration ------------------------------------------------------*/ /* Windowing configuration */ /* In this case all the active display area is used to display a picture then : Horizontal start = horizontal synchronization + Horizontal back porch = 43 Vertical start = vertical synchronization + vertical back porch = 12 Horizontal stop = Horizontal start + window width -1 = 43 + 480 -1 Vertical stop = Vertical start + window height -1 = 12 + 272 -1 */ pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 480; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 272; /* Pixel Format configuration*/ pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; /* Start Address configuration : frame buffer is located at FLASH memory */ pLayerCfg.FBStartAdress = (uint32_t)&RGB565_480x272; /* Alpha constant (255 == totally opaque) */ pLayerCfg.Alpha = 255; /* Default Color configuration (configure A,R,G,B component values) : no background color */ pLayerCfg.Alpha0 = 0; /* fully transparent */ pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; /* Configure blending factors */ pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; /* Configure the number of lines and number of pixels per line */ pLayerCfg.ImageWidth = 480; pLayerCfg.ImageHeight = 272;
如果改变得更小的一点的范围呢?比如如下:
pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 320; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 240;
同时记得修改:
pLayerCfg.ImageWidth = 320; pLayerCfg.ImageHeight = 240;
发现实际情况是:
设置一下全局背景颜色:
hltdc_F.Init.Backcolor.Blue = 0; hltdc_F.Init.Backcolor.Green = 255; hltdc_F.Init.Backcolor.Red = 0;
再设置一下透明度:
pLayerCfg.Alpha = 100;
大概变成这样:
如果透明度是240,背景颜色更难看得到,前景黄色越明显,可见层1是层叠在背景上的.LTDC不算困难,如何做漂亮的图,才是困难.