MIPI-DSI视频模式
This scenario describes how to configure a STM32 DSIHOST in Video Mode and TouchGFX Generator when using a display with Display Serial Interface (DSI).
The example used in this article will be for 24-bit RGB888 framebuffer format and goes through configurations in STM32CubeMX and exemplifies with generated code.
Configuration
LTDC 配置
- 模式
- 将
显示类型
设置为RGB888(24位)-DSI模式
- 将
- 层设置
- 将
层数
设置为1层 - 设置
0层-像素格式
设置为RGB888 - 设置
0层- Alpha混合常数
为255
- 将
- NVIC 设置
- 启用LCD-TFT全局中断
DSIHOST 配置
- 模式
- 将
DSIHost
设置为_*视频模式**
- 将
- 显示接口
- 将
色彩格式
设置为“RGB888(24位)- DSI模式” - 其余配置取决于所选的LCD HW
- 将
- NVIC 设置
- DSIHOST无需全局中断,应禁用。
TouchGFX Generator
- 模式
- 启用图形应用程序
- TouchGFX Generator
- 将
显示/接口
设置为并行RGB(LTDC),因为这仍是应用程序与之通信的控制器。 - 将
应用计时源
设置为LTDC
- 将
User Code
The TouchGFX Generator can generate a full TouchGFX AL that configures the LTDC to transfer pixels through the DSI Host controller from the framebuffer memory to the display and synchronize the display with the TouchGFX Engine. Only minor adjustments may be required as described below.
DSIHOST / LTDC初始化顺序
对MX_DSIHOST_DSI_Init()
的调用必须在MX_LTDC_Init()
之前完成。 This should be handled by STM32CubeMX. If this is not correct, take care to fix the order in a user code section.
After calling HAL_DSI_Start()
, switch DSIHOST clock to the DSIPHY
source:
static void MX_DSIHOST_DSI_Init(void)
{
...
/* Switch to DSI PHY PLL clock */
RCC_PeriphCLKInitTypeDef PeriphClkInit;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_DSI;
PeriphClkInit.DsiClockSelection = RCC_DSICLKSOURCE_DSIPHY;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
/* USER CODE END DSIHOST_Init 2 */
...
}
用户必须在MX_LTDC_Init()
函数的末尾添加特定于所用LCD控制器的必要初始化代码。 That code will be based on the DSI HAL APIs HAL_DSI_ShortWrite()
and HAL_DSI_LongWrite()
:
static void MX_LTDC_Init(void)
{
...
/* USER CODE BEGIN LTDC_Init 2 */
// Specific LCD controller's initialization code
...
// Exit Sleep Mode
if (HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P0, DSI_EXIT_SLEEP_MODE, 0x00) != HAL_OK)
{
Error_Handler();
}
HAL_Delay(120);
/* USER CODE END LTDC_Init 2 */
...
}
更新了DSI视频模式的TouchGFXHAL类
The generated code for the LTDC interrupt is identical to the code generated when using Parallel RGB display interface.
One way to prevent the MIPI DSI display from turning on until we've rendered the first frame in the application is to guard the function TouchGFXHAL::endFrame
to keep the display off until first frame is rendered by TouchGFX. TouchGFXHAL::endFrame()
可像下面这样更新,通过配置为PWM输出的HW定时器启用LCD及其背光。
void TouchGFXHAL::endFrame()
{
if (!display_on)
{
display_on = true;
/* Enable the LCD, Send Display on DCS command to display */
HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P1, DSI_SET_DISPLAY_ON, 0x00);
/* Start PWM Timer channel */
(void)HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_2);
/* Enable Backlight by setting Brightness to 100% */
__HAL_TIM_SET_COMPARE(&htim8, TIM_CHANNEL_2, 2U * 100);
}
TouchGFXGeneratedHAL::endFrame();
}
Supported Framebuffer Strategies
- Single
- Double
- Partial - LTDC driven display
Further reading
Reference implementation
The TouchGFX Board Setup STM32U5G9J DK1 includes a reference implementation running DSI Video Mode in RGB888 24-bit framebuffer format.