PPE

支持的芯片[ RTL8721Dx ][ RTL8721F ]

概述

PPE(像素处理引擎)是一款弱化的 2D 图像处理引擎,提供基础的图像处理能力,专为满足嵌入式系统等对资源和成本有严格要求的场景而设计。

PPE 支持常用的像素级操作,如颜色转换、缩放、Alpha 混合、抠色等,可高效完成常见的 2D 图像处理任务,但并不具备复杂 3D 渲染能力。

功能特性

RTL8721Dx:

PPE 有 3 个输入层和 1 个输出层。有以下特性:

  • Alpha 混合

  • 缩放

  • 窗口配置

  • 抠色

  • 像素转换

  • 多输入输出源

备注

  • Alpha 混合功能和缩放功能是并列功能,不能同时使用。

  • 在使用 alpha 混合功能或者缩放功能时,可以同时使用其他功能特性。

Alpha 混合

PPE 支持最高 3 层 alpha 混合功能。

../../_images/ppe_alpha_blending_dplus.jpg

alpha 混合功能计算公式如下:

../../_images/ppe_alpha_blending_formula_dplus.png

缩放

PPE 使用双线性插值算法可以实现良好的缩放效果,最高可放大或者缩小 16 倍。

备注

  • 使用缩放时,不支持可变像素起始位置。

  • 只有第一层支持缩放。

窗口配置

PPE 的窗口配置功能有以下特性:

  • 可变像素起始位置。即可以控制输入窗口在输出窗口的位置。

  • 可变窗口大小。可以配置输入窗口和输出窗口的大小。

  • 可变行宽度。可以实现输入窗口的裁剪功能,和输出窗口的画中画功能。

../../_images/ppe_window.jpg

抠色

当输出窗口的像素符合设定的值时,该像素将会输出 0 值。

像素转换

输入和输出支持多种像素格式,包括 ARGB8888,RGB888, RGB565 等多种常见格式。

支持的所有格式参考文件 ameba_ppe.h 中的 PPE_PIXEL_FORMAT。部分格式如 XRGB8888 中的 X 表示 alpha 值取反,即实际计算时会对 X 值取反进行计算。

多输入输出源

输入地址可以是 PPE 设定的内部像素值,也可以是内存。

输出的地址可以是内存,也可以是 QSPI。通过 QSPI 可以直接将输出显示到外接的屏幕上。

应用示例

RTL8721Dx:

SDK 提供了功能示例帮助开发者了解和使用 PPE :

raw 示例

  • 路径:{SDK}\example\peripheral\raw\Display\PPE\{demo}

以下是对 raw 示例功能的简要说明:

Raw API

PPE Exported Types

enum PPE_PIXEL_SOURCE

PPE Pixel Source Definition.

Values:

/* Pixel data from constant color register. */
PPE_LAYER_SRC_CONST

/* Pixel data read from memory via DMA. */
PPE_LAYER_SRC_FROM_DMA
RTL8721Dx:
enum PPE_GLOBAL_STATE

PPE Global State Definition.

Values:

/* PPE is disabled. */
PPE_STATE_DISABLE = 0

/* PPE is running. */
PPE_STATE_RUNNING = 1
struct PPE_InputLayer_InitTypeDef

PPE Input layer Init Structure Definition.

Public Members

u32 src_addr

Source address of the layer pixel data.

u32 start_x

X coordinate of the top-left pixel in the result window.

u32 start_y

Y coordinate of the top-left pixel in the result window.

u32 width

Width of the input layer in pixels.

u32 height

Height of the input layer in pixels.

u32 const_ABGR8888_value

Constant pixel color in ABGR8888 format, used when src is PPE_LAYER_SRC_CONST.

u32 key_color_value

Transparent (chroma-key) color value.

u32 line_len

Number of bytes between two vertically adjacent pixels in memory (line stride).

PPE_PIXEL_FORMAT format

Pixel format of the input layer; see PPE_PIXEL_FORMAT.

PPE_PIXEL_SOURCE src

Pixel data source; see PPE_PIXEL_SOURCE.

int color_key_en

Color keying enable: 1 to enable, 0 to disable.

struct PPE_LLI_GLB

PPE Global register Format Definition.

Public Members

u32 LL_CFG

Linked list configuration register value.

u32 LLP

Linked list pointer register value.

u32 SCA_RATIO_X

Horizontal scale ratio register value.

u32 SCA_RATIO_Y

Vertical scale ratio register value.

enum PPE_PIXEL_FORMAT

PPE Pixel Format Definition.

Values:

/* 32bpp ABGR 8-8-8-8 format. */
PPE_ABGR8888 = 0x0

/* 32bpp ARGB 8-8-8-8 format. */
PPE_ARGB8888

/* 32bpp XBGR 8-8-8-8 format. */
PPE_XBGR8888

/* 32bpp XRGB 8-8-8-8 format. */
PPE_XRGB8888

/* 32bpp BGRA 8-8-8-8 format. */
PPE_BGRA8888

/* 32bpp RGBA 8-8-8-8 format. */
PPE_RGBA8888

/* 32bpp BGRX 8-8-8-8 format. */
PPE_BGRX8888

/* 32bpp RGBX 8-8-8-8 format. */
PPE_RGBX8888

/* 16bpp ABGR 4-4-4-4 format. */
PPE_ABGR4444

/* 16bpp ARGB 4-4-4-4 format. */
PPE_ARGB4444

/* 16bpp XBGR 4-4-4-4 format. */
PPE_XBGR4444

/* 16bpp XRGB 4-4-4-4 format. */
PPE_XRGB4444

/* 16bpp BGRA 4-4-4-4 format. */
PPE_BGRA4444

/* 16bpp RGBA 4-4-4-4 format. */
PPE_RGBA4444

/* 16bpp BGRX 4-4-4-4 format. */
PPE_BGRX4444

/* 16bpp RGBX 4-4-4-4 format. */
PPE_RGBX4444

/* 8bpp ABGR 2-2-2-2 format. (= 0x10) */
PPE_ABGR2222

/* 8bpp ARGB 2-2-2-2 format. */
PPE_ARGB2222

/* 8bpp XBGR 2-2-2-2 format. */
PPE_XBGR2222

/* 8bpp XRGB 2-2-2-2 format. */
PPE_XRGB2222

/* 8bpp BGRA 2-2-2-2 format. */
PPE_BGRA2222

/* 8bpp RGBA 2-2-2-2 format. */
PPE_RGBA2222

/* 8bpp BGRX 2-2-2-2 format. */
PPE_BGRX2222

/* 8bpp RGBX 2-2-2-2 format. */
PPE_RGBX2222

/* 24bpp ABGR 8-5-6-5 format. */
PPE_ABGR8565

/* 24bpp ARGB 8-5-6-5 format. */
PPE_ARGB8565

/* 24bpp XBGR 8-5-6-5 format. */
PPE_XBGR8565

/* 24bpp XRGB 8-5-6-5 format. */
PPE_XRGB8565

/* 24bpp BGRA 5-6-5-8 format. */
PPE_BGRA5658

/* 24bpp RGBA 5-6-5-8 format. */
PPE_RGBA5658

/* 24bpp BGRX 5-6-5-8 format. */
PPE_BGRX5658

/* 24bpp RGBX 5-6-5-8 format. */
PPE_RGBX5658

/* 16bpp ABGR 1-5-5-5 format. (= 0x20) */
PPE_ABGR1555

/* 16bpp ARGB 1-5-5-5 format. */
PPE_ARGB1555

/* 16bpp XBGR 1-5-5-5 format. */
PPE_XBGR1555

/* 16bpp XRGB 1-5-5-5 format. */
PPE_XRGB1555

/* 16bpp BGRA 5-5-5-1 format. */
PPE_BGRA5551

/* 16bpp RGBA 5-5-5-1 format. */
PPE_RGBA5551

/* 16bpp BGRX 5-5-5-1 format. */
PPE_BGRX5551

/* 16bpp RGBX 5-5-5-1 format. */
PPE_RGBX5551

/* 24bpp BGR 8-8-8 format. */
PPE_BGR888

/* 24bpp RGB 8-8-8 format. */
PPE_RGB888

/* 16bpp BGR 5-6-5 format. */
PPE_BGR565

/* 16bpp RGB 5-6-5 format. */
PPE_RGB565

/* 8bpp alpha-only format. */
PPE_A8

/* 8bpp ignored-alpha format. */
PPE_X8

/* 32bpp ABGR 8-6-6-6 format. */
PPE_ABGR8666 = 0x32

/* 32bpp ARGB 8-6-6-6 format. */
PPE_ARGB8666

/* 32bpp XBGR 8-6-6-6 format. */
PPE_XBGR8666

/* 32bpp XRGB 8-6-6-6 format. */
PPE_XRGB8666

/* 32bpp BGRA 6-6-6-8 format. */
PPE_BGRA6668

/* 32bpp RGBA 6-6-6-8 format. */
PPE_RGBA6668

/* 32bpp BGRX 6-6-6-8 format. */
PPE_BGRX6668

/* 32bpp RGBX 6-6-6-8 format. */
PPE_RGBX6668
struct PPE_ResultLayer_InitTypeDef

PPE Result layer Init Structure Definition.

Public Members

u32 src_addr

Destination address for the composited output.

u32 width

Width of the output image in pixels.

u32 height

Height of the output image in pixels.

u32 line_len

Number of bytes between two vertically adjacent pixels in memory (line stride).

PPE_PIXEL_FORMAT format

Pixel format of the output layer; see PPE_PIXEL_FORMAT.

PPE_ADDR_TYPE type

Address type of the output buffer; see PPE_ADDR_TYPE.

enum PPE_ADDR_TYPE

PPE Result Layer Address Type.

Values:

/* Address in internal memory. */
PPE_ADDR_MEM

/* Address in QSPI flash. */
PPE_ADDR_QSPI
enum PPE_ARBURST

PPE Arburst Definition.

Values:

/* AXI FIXED burst type. */
PPE_ARBURST_FIX

/* AXI INCR burst type. */
PPE_ARBURST_INCR
enum PPE_DMA_HANDSHAKE

PPE DMA Handshake Definition.

Values:

/* Hardware DMA handshake mode. */
PPE_DMA_HW_HANDSHAKE

/* Software DMA handshake mode. */
PPE_DMA_SW_HANDSHAKE
struct PPE_InitTypeDef

PPE Function Structure Definition.

Public Members

u32 function

PPE function mode selection; see PPE_FUNCTION_ALPHA_BLEND and PPE_FUNCTION_SCALE.

u32 blend_layer_num

Number of input layers used for alpha blending.

struct PPE_LLI_LAYER

PPE LLI Layer Format Definition.

Public Members

u32 LAYER_ADDR

Address of the first pixel.

u32 LAYER_POS

Position of the first pixel in the result window.

u32 LAYER_WINSIZE

Window size: height[31:16] and width[15:0] in pixels.

u32 LAYER_CONST_PIX

Constant pixel value in ABGR8888 format.

PPE Exported Constants

/* Check if PPE channel index is valid (0-16). */
#define IS_PPE_CHN_INDEX (((chn) < 17) && ((chn) >= 0))

/* Check if PPE alpha blend layer count is valid (< 16). */
#define IS_PPE_ALPHA_BLEND_LAYER_NUM ((layer_num) < 16)

/* Index of the PPE result (output) layer. */
#define PPE_RESULT_LAYER_INDEX 0

/* Index of PPE input layer 1. */
#define PPE_INPUT_LAYER1_INDEX 1

/* Index of PPE input layer 2. */
#define PPE_INPUT_LAYER2_INDEX 2

/* Index of PPE input layer 3. */
#define PPE_INPUT_LAYER3_INDEX 3

/* Bit mask for PPE result layer selection. */
#define PPE_RESULT_LAYER_BIT ((u32)0x1 << PPE_RESULT_LAYER_INDEX)

/* Bit mask for PPE input layer 1 selection. */
#define PPE_INPUT_LAYER1_BIT ((u32)0x1 << PPE_INPUT_LAYER1_INDEX)

/* Bit mask for PPE input layer 2 selection. */
#define PPE_INPUT_LAYER2_BIT ((u32)0x1 << PPE_INPUT_LAYER2_INDEX)

/* Bit mask for PPE input layer 3 selection. */
#define PPE_INPUT_LAYER3_BIT ((u32)0x1 << PPE_INPUT_LAYER3_INDEX)
RTL8721Dx:
/* PPE function mode: alpha blending. */
#define PPE_FUNCTION_ALPHA_BLEND ((u32)0x0)

/* PPE function mode: scaling. */
#define PPE_FUNCTION_SCALE ((u32)0x1)

/* Check if PPE function selection is valid. */
#define IS_PPE_FUNCTION (((func) == PPE_FUNCTION_ALPHA_BLEND) || ((func) == PPE_FUNCTION_SCALE))

PPE Exported Functions

void PPE_AutoClearCmd(int NewState)

Enable or disable auto clear after loading.

参数:
  • NewState -- The new state. This parameter can be: ENABLE or DISABLE.

void PPE_AutoReloadClrLayerAll(void)

Clear all auto reload layers.

void PPE_AutoReloadSetLayer(u32 layers)

Configure auto reload layers.

参数:
  • layers --

    Auto reload layers. This parameter can be one or combinations of the following values:

    • PPE_RESULT_LAYER_BIT: result layer.

    • PPE_INPUT_LAYER1_BIT: input layer1.

    • PPE_INPUT_LAYER2_BIT: input layer2.

    • PPE_INPUT_LAYER3_BIT: input layer3.

int PPE_ChannelInactiveCheck(u8 chn_id)

Check if a layer is inactive.

参数:
  • chn_id -- The layer number to be checked.

返回:

Layer inactive status:

  • 0: the layer is active

  • 1: the layer is inactive

void PPE_ClearINTPendingBit(u32 PPE_INT)

Clear specific interrupt status.

参数:
  • PPE_INT -- Specifies the PPE interrupt type. This parameter can be one or combinations of PPE_INTR_ST.

void PPE_Cmd(int state)

Enable or disable PPE.

参数:
  • state -- The state of PPE. This parameter can be ENABLE or DISABLE.

备注

DISABLE may have no effect on some platforms.

u32 PPE_GetAllIntStatus(void)

Get all interrupt status.

返回:

Current PPE interrupt status.

u32 PPE_GetGlobalState(void)

Get PPE global state.

返回:

One of PPE_GLOBAL_STATE.

u32 PPE_GetValid(void)

Get the setting valid value for polling.

返回:

Set valid bit status:

  • 0: User can call PPE_SetValid() to tell PPE the settings are valid

  • 1: Settings valid bit is set

void PPE_InitInputLayer(u8 id, PPE_InputLayer_InitTypeDef *layer_init_struct)

Initialize specific input layer.

参数:
  • id -- Input layer number. Can be PPE_INPUT_LAYER1_INDEX or PPE_INPUT_LAYER2_INDEX or PPE_INPUT_LAYER3_INDEX.

  • layer_init_struct -- Pointer to a PPE_InputLayer_InitTypeDef structure that contains the configuration information for the specified input layer.

void PPE_InitResultLayer(PPE_ResultLayer_InitTypeDef *layer_init_struct)

Initialize result layer.

参数:
  • layer_init_struct -- Pointer to a PPE_ResultLayer_InitTypeDef structure that contains the configuration information for the result layer.

void PPE_InputLayer_StructInit(PPE_InputLayer_InitTypeDef *layer_init_struct)

Fill each layer_init_struct member with its default value.

参数:
void PPE_LLSetLayer(u32 layers)

Set layers used by the first linked list item.

参数:
  • layers --

    Linked list layers. This parameter can be one or combinations of the following values:

    • PPE_RESULT_LAYER_BIT: result layer.

    • PPE_INPUT_LAYER1_BIT: input layer1.

    • PPE_INPUT_LAYER2_BIT: input layer2.

    • PPE_INPUT_LAYER3_BIT: input layer3.

void PPE_MaskAllInt(void)

Mask all interrupt.

void PPE_MaskINTConfig(u32 PPE_INT_MSK, int NewState)

Enable or disable the specified interrupt.

参数:
  • PPE_INT_MSK -- Specifies the PPE interrupt type. This parameter can be one or combinations of PPE_INTR_ST.

  • NewState -- The new state. This parameter can be: ENABLE or DISABLE.

void PPE_ResultLayer_StructInit(PPE_ResultLayer_InitTypeDef *layer_init_struct)

Fill each layer_init_struct member with its default value.

参数:
void PPE_Resume(void)

Resume PPE from suspend state.

void PPE_SetLLP(u32 lli)

Set the LLP value to the pointer of the first linked list item.

参数:
  • lli -- Pointer to the first linked list item. Must align to 4 bytes.

void PPE_SetLine(u32 line)

Set line index for line over interrupt.

参数:
  • line -- The line index.

void PPE_SetValid(void)

Tell PPE the settings are valid for the auto reload function.

void PPE_Suspend(void)

Suspend PPE.

RTL8721Dx:
void PPE_Abort(void)

Abort PPE.

void PPE_Init(PPE_InitTypeDef *PPE_init_struct)

Initialize the PPE peripheral according to the specified parameters in the PPE_init_struct.

参数:
  • PPE_init_struct -- Pointer to a PPE_InitTypeDef structure that contains the configuration information for the specified PPE peripheral.

void PPE_SetScaleRation(float scale_x, float scale_y)

Set the scale ratio.

参数:
  • scale_x -- Scale ratio in the X direction. No smaller than 1/16.

  • scale_y -- Scale ratio in the Y direction. No smaller than 1/16.

void PPE_StructInit(PPE_InitTypeDef *PPE_init_struct)

Fill each PPE_init_struct member with its default value.

参数:
  • PPE_init_struct -- Pointer to a PPE_InitTypeDef structure which will be initialized.