树莓派DPI接口介绍

DPI(并行显示接口)  

所有带有40路表头(A+、B+、Pi2、Pi3、Zero)和计算模块的树莓派板上均提供最高24位的并行RGB接口。该接口允许并行的RGB显示器以RGB24(红色、绿色和蓝色8位)或RGB666(每种颜色6位)或RGB565(红色5位、绿色6位和蓝色5位)的形式连接到树莓派GPIO。 该接口由图形处理器固件控制,用户可以通过特殊的配置参数和启用正确的Linux设备树覆盖来对其进行编程。 GPIO引脚

在树莓派GPIO的存储体0上可选择的替代功能之一是DPI(显示并行接口),它是一个简单的时钟并行接口(最多8位的R、G和B;时钟、使能、hsync和vsync)。该接口可作为GPIO组0上的备用功能2 (ALT2)使用:
请注意,在565、666或24位模式下,DPI输出引脚上的颜色值有多种呈现方式(参见下表和下面dpi_output_format参数的output_format部分):    禁用其他GPIO外设

请注意,必须禁用所有其他使用冲突GPIO引脚的外设覆盖。在配置文件中,注意注释掉或反转任何启用I2C或SPI的数据参数:   
dtparam=i2c_arm=off
dtparam=spi=off
控制输出格式

输出格式(时钟、颜色格式、同步极性、使能)可以通过传递给config.txt中dpi_output_format参数的幻数(前缀为0x的无符号整数或十六进制值)来控制,该参数由以下字段创建:

output_format          = (dpi_output_format >>  0) & 0xf;
rgb_order              = (dpi_output_format >>  4) & 0xf;

output_enable_mode     = (dpi_output_format >>  8) & 0x1;
invert_pixel_clock     = (dpi_output_format >>  9) & 0x1;

hsync_disable          = (dpi_output_format >> 12) & 0x1;
vsync_disable          = (dpi_output_format >> 13) & 0x1;
output_enable_disable  = (dpi_output_format >> 14) & 0x1;

hsync_polarity         = (dpi_output_format >> 16) & 0x1;
vsync_polarity         = (dpi_output_format >> 17) & 0x1;
output_enable_polarity = (dpi_output_format >> 18) & 0x1;

hsync_phase            = (dpi_output_format >> 20) & 0x1;
vsync_phase            = (dpi_output_format >> 21) & 0x1;
output_enable_phase    = (dpi_output_format >> 22) & 0x1;

output_format:
   1: DPI_OUTPUT_FORMAT_9BIT_666
   2: DPI_OUTPUT_FORMAT_16BIT_565_CFG1
   3: DPI_OUTPUT_FORMAT_16BIT_565_CFG2
   4: DPI_OUTPUT_FORMAT_16BIT_565_CFG3
   5: DPI_OUTPUT_FORMAT_18BIT_666_CFG1
   6: DPI_OUTPUT_FORMAT_18BIT_666_CFG2
   7: DPI_OUTPUT_FORMAT_24BIT_888

rgb_order:
   1: DPI_RGB_ORDER_RGB
   2: DPI_RGB_ORDER_BGR
   3: DPI_RGB_ORDER_GRB
   4: DPI_RGB_ORDER_BRG

output_enable_mode:
   0: DPI_OUTPUT_ENABLE_MODE_DATA_VALID
   1: DPI_OUTPUT_ENABLE_MODE_COMBINED_SYNCS

invert_pixel_clock:
   0: RGB Data changes on rising edge and is stable at falling edge
   1: RGB Data changes on falling edge and is stable at rising edge.

hsync/vsync/output_enable_polarity:
   0: default for HDMI mode
   1: inverted

hsync/vsync/oe phases:
   0: DPI_PHASE_POSEDGE
   1: DPI_PHASE_NEGEDGE

注意,单个位字段都充当“反转默认行为”。

控制时间和分辨率

在2018年8月或更高版本的固件中,以前用于设置dpi计时的hdmi计时配置条目已被新的DPI计时参数取代。如果dpi _ timings参数不存在,系统将返回使用hdmi _ timings参数以确保向后兼容。如果两者都不存在并且请求定制模式,则使用VGAp60的默认参数集。

dpi_group和dpi_mode配置参数用于设置预定模式(如HDMI所使用的DMT或CEA模式),或者用户可以生成定制模式。

要生成自定义DPI模式,请从这里开始。

如果您设置了自定义DPI模式,请在配置中使用:

dpi_group=2
dpi_mode=87

这将告诉驱动程序为dpi面板使用自定义的DPI定时(旧固件使用hdmi定时)。 dpi _ timings参数被指定为一组以空格分隔的参数:

dpi_timings=<h_active_pixels> <h_sync_polarity> <h_front_porch> <h_sync_pulse> <h_back_porch> <v_active_lines> <v_sync_polarity> <v_front_porch> <v_sync_pulse> <v_back_porch> <v_sync_offset_a> <v_sync_offset_b> <pixel_rep> <frame_rate> <interlaced> <pixel_freq> <aspect_ratio>

<h_active_pixels> = horizontal pixels (width)
<h_sync_polarity> = invert hsync polarity
<h_front_porch>   = horizontal forward padding from DE acitve edge
<h_sync_pulse>    = hsync pulse width in pixel clocks
<h_back_porch>    = vertical back padding from DE active edge
<v_active_lines>  = vertical pixels height (lines)
<v_sync_polarity> = invert vsync polarity
<v_front_porch>   = vertical forward padding from DE active edge
<v_sync_pulse>    = vsync pulse width in pixel clocks
<v_back_porch>    = vertical back padding from DE active edge
<v_sync_offset_a> = leave at zero
<v_sync_offset_b> = leave at zero
<pixel_rep>       = leave at zero
<frame_rate>      = screen refresh rate in Hz
<interlaced>      = leave at zero
<pixel_freq>      = clock frequency (width*height*framerate)
<aspect_ratio>    = *

* The aspect ratio can be set to one of eight values (choose closest for your screen):

HDMI_ASPECT_4_3 = 1
HDMI_ASPECT_14_9 = 2
HDMI_ASPECT_16_9 = 3
HDMI_ASPECT_5_4 = 4
HDMI_ASPECT_16_10 = 5
HDMI_ASPECT_15_9 = 6
HDMI_ASPECT_21_9 = 7
HDMI_ASPECT_64_27 = 8

Overlays

一个Linux设备树覆盖图用于将GPIO引脚切换到正确的模式(替代功能2)。如前所述,GPU负责驱动DPI显示器。因此没有Linux驱动程序;覆盖图只是简单地正确设置GPIO alt功能。 提供全功能DPI (dpi24.dtb),将所有28个GPIOs设置为ALT2模式,提供全24位彩色总线以及h和v同步、使能和像素时钟。请注意,这使用了所有的第0排GPIO引脚。 提供第二个覆盖层(vga666.dtb),用于在666模式下驱动vga监视器信号,该模式不需要时钟和de引脚(GPIO 0和1),并且只需要GPIO 4-21用于彩色(使用模式5)。 这些覆盖是相当琐碎的,用户可以编辑它们来创建一个定制的覆盖,只启用特定用例所需的引脚。例如,如果在RGB565模式(模式2)下使用的是使用vsync、hsync、pclk和de的dpi显示器,则可以编辑dpi24.dtb覆盖,以便GPIOs 20-27不会切换到DPI模式,因此可以用于其他目的。
config.txt设置示例

Gert VGA666 adaptor

dtoverlay=vga666
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=82

800x480 LCD 面板

dtoverlay=dpi24
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=800
framebuffer_height=480
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=87
dpi_output_format=0x6f005
dpi_timings=800 0 40 48 88 480 0 13 3 32 0 0 0 60 0 32000000 6