DMA2D APIs

[English]

DMA2D Interface

DMA2D Features

  • fill specific color

    Fill part or all of the target image with a specific color

  • mem to mem copy

    Copy part or all of the source image to part or all of the target image

  • mem to mem with pixel conversion

    Copy part or all of the source image to part or all of the target image through pixel format conversion

  • mem to mem with pixel conversionwith and blending

    Part or all of the two source images with different pixel formats are mixed, and the result is copied to the part or the entire target :image with different color formats

DMA2D API Categories

DMA2D API

Description

bk_dma2d_driver_init()

initializes the DMA2D

bk_dma2d_init()

config the DMA2D

bk_dma2d_driver_deinit()

Deinitializes the DMA2D peripheral

bk_dma2d_layer_config()

Configure the background or foreground Layer

bk_dma2d_start_transfer()

Start the DMA2D Transfer

bk_dma2d_start_blending()

Start the multi-source DMA2D Transfer

bk_dma2d_is_transfer_busy()

check dma2d is transfer busy or not

bk_dma2d_int_enable()

clear dma2d int status

bk_dma2d_int_status_clear()

Lcd transfer pixel config

DMA2D Register ISR API

Description

bk_dma2d_isr_register()

register dma2d cpu int isr

bk_dma2d_register_int_callback_isr()

register dma2d int type isr

DMA2D Work Config

1、fill specific color

fill specific color

Figure 1. dma2d_fill_color

2、mem to mem copy

fill specific color

Figure 2. dma2d_mem_to_mem

3、mem to mem with pixel conversion

The Figure API is the same as dma2d_mem_to_mem please reference the API Reference for the different config

4、mem to mem with pixel conversion and blending

fill specific color

Figure 3. dma2d_mem_to_mem_with_pixel_conversion_and_blending

API Reference

Header File

Functions

bk_err_t bk_dma2d_driver_init(void)

initializes the DMA2D system and peripheral registers

     - open dma2d sys interrupt enable

Attention

you can reference cli_dma2d.c for all API usage

Parameters

dma2d_config – pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_init(dma2d_config_t *dma2d)

config dma2d work mode/ data format/ offset etc.

Usage example:

       dma2d_config_t dma2d_config = {0};
       dma2d_config.init.mode = DMA2D_R2M;                     Mode Register to Memory 
       dma2d_config.init.color_mode = DMA2D_OUTPUT_RGB565;       DMA2D Output color mode is ARGB4444 (16 bpp)
       dma2d_config.init.output_offset = 0;            No offset in output 
       dma2d_config.init.red_blue_swap = DMA2D_RB_REGULAR;       No R&B swap for the output image 
       dma2d_config.init.alpha_inverted = DMA2D_REGULAR_ALPHA;   No alpha inversion for the output image
       bk_dma2d_init(&dma2d_config);
Attention

you can reference cli_dma2d.c for all API usage

Parameters

dma2d_config – pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_driver_deinit(void)

Deinitializes the DMA2D peripheral registers to their default reset values.

    - reset the dma2d driver init reg

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_layer_config(dma2d_config_t *dma2d, uint32_t layer_idx)

Configure the DMA2D background or foreground Layer include layer offset, color mode, alpha value etc.

Usage example:

       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].alpha_mode = DMA2D_REPLACE_ALPHA;
       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_alpha = alpha_value; 
       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_color_mode = DMA2D_INPUT_RGB565;
       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_offset = fg_offline;
       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].red_blue_swap  = DMA2D_RB_REGULAR;
       dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].alpha_inverted = DMA2D_REGULAR_ALPHA;

       Background layer Configuration 
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].alpha_mode  = DMA2D_REPLACE_ALPHA;
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_alpha   = 0x80;
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_color_mode = DMA2D_INPUT_RGB565;
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_offset   = bg_offline;
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].red_blue_swap   = DMA2D_RB_REGULAR;
       dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].alpha_inverted  = DMA2D_REGULAR_ALPHA; 

       bk_dma2d_layer_config(&dma2d_config, DMA2D_FOREGROUND_LAYER);
       bk_dma2d_layer_config(&dma2d_config, DMA2D_BACKGROUND_LAYER);

Parameters

dma2d – Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D.

  • LayerIdx DMA2D Layer index. This parameter can be one of the following values: DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_start_transfer(dma2d_config_t *dma2d, uint32_t pdata, uint32_t dst_addr, uint32_t width, uint32_t height)

Start the DMA2D Transfer when you use (bk_dma2d_driver_init) and (bk_dma2d_layer_config) API, then use this API start dma2d work.

  • dst_addr: The destination memory Buffer address.

  • Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).

  • Height: The height of data to be transferred from source to destination (expressed in number of lines).

Usage example:

       dma2d_config_t dma2d_config = {0};
       dma2d_config.init.mode   = DMA2D_R2M;                     Mode Register to Memory 
       dma2d_config.init.color_mode = DMA2D_OUTPUT_RGB565;       DMA2D Output color mode is ARGB4444 (16 bpp)
       dma2d_config.init.output_offset = 0;          No offset in output 
       dma2d_config.init.red_blue_swap = DMA2D_RB_REGULAR;       No R&B swap for the output image 
       dma2d_config.init.alpha_inverted = DMA2D_REGULAR_ALPHA;   No alpha inversion for the output image

       bk_dma2d_driver_init(&dma2d_config);
       bk_dma2d_start_transfer(&dma2d_config, color, (uint32_t)dst_addr, width, high);

Parameters

dma2d, : – Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D.

  • pdata: have two means:

    • 1: if the Memory-to-Memory or Memory-to-Memory with pixel format select, should Configure the source memory Buffer address

    • 2: if Register-to-Memory mode is selected, should configure the color value

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_start_blending(dma2d_config_t *dma2d, uint32_t fg_addr, uint32_t bg_addr, uint32_t dst_addr, uint32_t width, uint32_t height)

Start the multi-source DMA2D Transfer. start foreground layer and background layer blending.

Usage example:

       1: bk_dma2d_driver_init(&dma2d_config);
       2: bk_dma2d_layer_config(&dma2d_config, DMA2D_FOREGROUND_LAYER);
       3: bk_dma2d_layer_config(&dma2d_config, DMA2D_BACKGROUND_LAYER);
       4:bk_dma2d_blending_start(&dma2d_config, (uint32_t)pFgaddr, (uint32_t)pBgaddr, (uint32_t)pDst, xsize ,ysize);

Attention

you can reference cli_dma2d.c for API usage

Parameters

- – dma2d: Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D.

  • fg_addr: The source memory Buffer address for the foreground layer.

  • bg_addr: The source memory Buffer address for the background layer.

  • dst_addr: The destination memory Buffer address.

  • Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).

  • Height: The height of data to be transferred from source to destination (expressed in number of lines).

Returns

  • BK_OK: succeed

  • others: other errors.

bool bk_dma2d_is_transfer_busy(void)

this API is check dma2d is transfer busy or not

Usage example:

       1: bk_dma2d_driver_init(&dma2d_config);
       2: bk_dma2d_start_transfer(&dma2d_config, color, (uint32_t)dst_addr, width, high); 
       3: while (bk_dma2d_get_transfer_status()) {}

Returns

return 0: transfer stop or transfer done;

  • return 1 dma2d is work or transfer not done

bk_err_t bk_dma2d_int_enable(dma2d_int_type_t int_type, bool enable)

dma2d int enable.

Usage example:

       bk_dma2d_int_config(DMA2D_TRANS_ERROR | DMA2D_TRANS_COMPLETE ,1);
       always use with:  bk_dma2d_isr_register(dma2d_isr);
                         bk_dma2d_int_status_get();
                         bk_dma2d_int_status_clear(DMA2D_TRANS_ERROR_STATUS);
                         bk_dma2d_int_status_clear(DMA2D_TRANS_COMPLETE_STATUS);

Parameters
  • int_type – select from dma2d_int_type_t, include int type:

    • DMA2D_CFG_ERROR

    • DMA2D_CLUT_TRANS_COMPLETE

    • DMA2D_CLUT_TRANS_ERROR

    • DMA2D_WARTERMARK_INT

    • DMA2D_TRANS_COMPLETE

    • DMA2D_TRANS_ERROR

  • enable, : – 1:enable int, 0 disable int

Returns

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_dma2d_int_status_get(void)

bk_dma2d_int_status_get.

Usage example:

         uint32_t int_status;
         int_status = bk_dma2d_int_status_get();
         if (int_status & DMA2D_CFG_ERROR) {
            bk_dma2d_int_status_clear(DMA2D_CFG_ERROR_STATUS);
            bk_dma2d_int_config(DMA2D_CFG_ERROR, 0);
         }

Returns

return uint32_t value of all int status,

  • can used by value & dma2d_int_status_t check which int triggered. typedef enum { DMA2D_TRANS_ERROR_STATUS = 0x1, DMA2D_TRANS_COMPLETE_STATUS, DMA2D_WARTERMARK_INT_STATUS, DMA2D_CLUT_TRANS_ERROR_STATUS, DMA2D_CLUT_TRANS_COMPLETE_STATUS, DMA2D_CFG_ERROR_STATUS }dma2d_int_status_t;

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_int_status_clear(dma2d_int_status_t int_status)

clear dma2d int status

Parameters

int_status – select from dma2d_int_status_t include: DMA2D_TRANS_ERROR_STATUS DMA2D_TRANS_COMPLETE_STATUS DMA2D_WARTERMARK_INT_STATUS DMA2D_CLUT_TRANS_ERROR_STATUS DMA2D_CLUT_TRANS_COMPLETE_STATUS DMA2D_CFG_ERROR_STATUS

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_dma2d_isr_register(dma2d_isr_t dma2d_isr)

register dma2d cpu int isr

Parameters

dma2d_isr – the function you registr isr

Return values

bk_err_t – status

bk_err_t bk_dma2d_blend(dma2d_blend_t *dma2d_blend)

config dma2d blend

Parameters

- – dma2d_blend struct to config blend params

Returns

  • BK_OK: succeed

  • others: other errors.

void bk_dma2d_memcpy_or_pixel_convert(dma2d_memcpy_pfc_t *pixel_convert)

config dma2d pixel revert

Parameters

- – dma2d_pixel_convert_t struct to config pixel convert params

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t dma2d_fill(dma2d_fill_t *fill)

config dma2d fill color

Parameters

-dma2d_fill_t struct to config dma2d fill params

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t dma2d_start_transfer(void)

start dma2d transfer

Returns

  • BK_OK: succeed

  • others: other errors.

API Typedefs

Header File

Structures

struct dma2d_init_t

DMA2D Init structure definition.

Public Members

dma2d_mode_t mode

Configures the DMA2D transfer mode.his parameter can be one value of DMA2D_Mode.

uint32_t color_mode

 Configures the color format of the output image.
This parameter can be one value of DMA2D_Output_Color_Mode.

uint32_t output_offset

Specifies the Offset value. This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0x3FFF.

uint32_t alpha_inverted

Select regular or inverted alpha value for the output pixel format converter. This parameter can be one value of DMA2D_Alpha_Inverted.

uint32_t line_offset_mode

Configures how is expressed the line offset for the foreground, background and output. This parameter can be one value of DMA2D_Line_Offset_Mode.

uint32_t red_blue_swap

Select regular mode (RGB or ARGB) or swap mode (BGR or ABGR) for the output pixel format converter. This parameter can be one value of DMA2D_RB_Swap.

rgb888_dataout_reverse_t data_reverse

in output rgb888 formart, reverse data byte by byte..

dma2d_trans_ability_t trans_ability

set defult MAX_TRANS_256BYTES

struct dma2d_layer_cfg_t

DMA2D Layer structure definition

Public Members

uint32_t input_offset

Configures the DMA2D foreground or background offset. This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0x3FFF.

uint32_t input_color_mode

Configures the DMA2D foreground or background color mode. This parameter can be one value of DMA2D_Input_Color_Mode.

uint32_t alpha_mode

Configures the DMA2D foreground or background alpha mode.This parameter can be one value of DMA2D_Alpha_Mode.

uint32_t input_color

Specifies color value in case of A8 or A4 color mode.

Note

In case of A8 or A4 color mode (ARGB), this parameter must be a number between Min_Data = 0x00000000 and Max_Data = 0xFFFFFF where

  • Inputcolor[16:23] is the red value RED[0:7]

  • Inputcolor[8:15] is the green value GREEN[0:7]

  • Inputcolor[0:7] is the blue value BLUE[0:7].

uint32_t alpha_inverted

Select regular or inverted alpha value.This parameter can be one value of DMA2D_Alpha_Inverted.

uint32_t red_blue_swap

Select regular mode (RGB or ARGB) or swap mode (BGR or ABGR). This parameter can be one value of DMA2D_RB_Swap.

struct dma2d_config_t

Public Members

dma2d_init_t init

dma2d init config, is the value of struct dma2d_init_t

dma2d_layer_cfg_t layer_cfg[MAX_DMA2D_LAYER]

dma2d layer config, is the value of struct dma2d_layer_cfg_t the param MAX_DMA2D_LAYER is select from DMA2D_BACKGROUND_LAYER and DMA2D_FOREGROUND_LAYER

struct dma2d_blend_t

Public Members

void *pfg_addr

The source memory Buffer address for the foreground layer..

void *pbg_addr

he source memory Buffer address for the background layer…

void *pdst_addr

The output memory Buffer address ..

input_color_mode_t fg_color_mode

fg color mode..

input_color_mode_t bg_color_mode

bg color mode..

out_color_mode_t dst_color_mode

out color mode..

uint32_t fg_offline

for partical copy this is to calculate start addr based on fg frame addr, uint by pixel

uint32_t bg_offline

for partical copy this is to calculate start addr based on bg frame addr, uint by pixel

uint32_t dest_offline

for partical copy this is to calculate output addr based on dst frame addr, uint by pixel

uint32 xsize

dma2d blend x size..

uint32 ysize

dma2d blend y size..

uint8_t fg_alpha_value

config fg alpha..

uint8_t bg_alpha_value

config bg alpha.

uint8_t red_bule_swap

DMA2D_RB_SWAP or DMA2D_RB_REGULAR

struct dma2d_memcpy_pfc_t

Public Members

void *input_addr

The image memcpy or pixel convert src addr

void *output_addr

The mage memcpy or pixel convert dst addr

uint16_t src_frame_width

memcpy or pfc src image width

uint16_t src_frame_height

imemcpy or pfc src image height

uint16_t src_frame_xpos

src img start copy/pfc x pos

uint16_t src_frame_ypos

src img start copy/pfc y pos

uint16_t dst_frame_width

memcpy to dst image, the dst image width

uint16_t dst_frame_height

memcpy to dst image, the dst image height

uint16_t dst_frame_xpos

dma2d fill x pos based on frame_xsize

uint16_t dst_frame_ypos

dma2d fill y pos based on frame_ysize

uint16_t dma2d_width

dma2d memcpy or pfc width

uint16_t dma2d_height

dma2d memcpy or pfc height

input_color_mode_t input_color_mode

The pixel convert src color mode

out_color_mode_t output_color_mode

The pixel convert dst color mode

uint8_t input_alpha

src data alpha, depend on alpha_mode

uint8_t output_alpha

dst data alpha,depend on alpha_mode

uint8_t input_red_blue_swap

src img red blue swap, select DMA2D_RB_SWAP or DMA2D_RB_REGULAR

uint8_t output_red_blue_swap

src img red blue swap, select DMA2D_RB_SWAP or DMA2D_RB_REGULAR

struct dma2d_fill_t

Public Members

void *frameaddr

dma2d fill frame baseaddr , normally LCD start frame addr

uint16_t frame_xsize

img/lcd x size

uint16_t frame_ysize

img/lcd y size

uint16_t xpos

dma2d fill x pos based on frame_xsize

uint16_t ypos

dma2d fill y pos based on frame_ysize

uint16_t width

dma2d fill width

uint16_t high

dma2d fill height

uint32_t color

dma2d fill color

Macros

BK_ERR_DMA2D_NOT_INIT

dma2d macos define

LCD driver not init

USE_HAL_DMA2D_REGISTER_CALLBACKS

if use int type isr register, set this value 1. always use with API bk_dma2d_register_int_callback_isr

DMA2D_OCOLR_WHITE

define Mode_RGB565 white Value

DMA2D_OCOLR_BLACK

define Mode_RGB565 black Value

DMA2D_OCOLR_BLUE_1

define Mode_ARGB8888/RGB888 Blue Value

DMA2D_OCOLR_GREEN_1

define Mode_ARGB8888/RGB888 Green Value

DMA2D_OCOLR_RED_1

define Mode_ARGB8888/RGB888 Red Value

DMA2D_OCOLR_YELLOW_1

define Mode_ARGB8888/RGB888 yellow Value

DMA2D_OCOLR_ALPHA_1

define Mode_ARGB8888/RGB888Alpha Channel Value

DMA2D_OCOLR_BLUE_2

define Mode_RGB565 Blue Value

DMA2D_OCOLR_GREEN_2

define Mode_RGB565 Green Value

DMA2D_OCOLR_RED_2

define Mode_RGB565Red Value

DMA2D_OCOLR_BLUE_3

define Mode_ARGB1555 Blue Value

DMA2D_OCOLR_GREEN_3

define Mode_ARGB1555Green Value

DMA2D_OCOLR_RED_3

define Mode_ARGB1555 Red Value

DMA2D_OCOLR_ALPHA_3

define Mode_ARGB1555 Alpha Channel Value

DMA2D_OCOLR_BLUE_4

define Mode_ARGB4444 Blue Value

DMA2D_OCOLR_GREEN_4

define Mode_ARGB4444 Green Value

DMA2D_OCOLR_RED_4

define Mode_ARGB4444 Red Value

DMA2D_OCOLR_ALPHA_4

define Mode_ARGB4444 Alpha Channel Value

DMA2D_BACKGROUND_LAYER

DMA2D Background Layer (layer 0)

DMA2D_FOREGROUND_LAYER

DMA2D Foreground Layer (layer 1)

MAX_DMA2D_LAYER

DMA2D maximum number of layers

DMA2D_REGULAR_ALPHA

No modification of the alpha channel value

DMA2D_INVERTED_ALPHA

Invert the alpha channel value

DMA2D_RB_REGULAR

Select regular mode (RGB or ARGB)

DMA2D_RB_SWAP

Select swap mode (BGR or ABGR)

DMA2D_ISR_NUM

Type Definitions

typedef void (*dma2d_isr_t)(void)

Enumerations

enum dm2d_isr_id_t

if USE_HAL_DMA2D_REGISTER_CALLBACKS = 1, define int isr register id

Values:

enumerator DMA2D_CFG_ERROR_ISR
enumerator DMA2D_CLUT_TRANS_COMPLETE_ISR
enumerator DMA2D_CLUT_TRANS_ERROR_ISR
enumerator DMA2D_WARTERMARK_INT_ISR
enumerator DMA2D_TRANS_COMPLETE_ISR
enumerator DMA2D_TRANS_ERROR_ISR
enum dma2d_mode_t

DMA2D enum defines.

DMA2D_Mode

Values:

enumerator DMA2D_M2M

DMA2D memory to memory transfer mode

enumerator DMA2D_M2M_PFC

DMA2D memory to memory with pixel format conversion transfer mode

enumerator DMA2D_M2M_BLEND

DMA2D memory to memory with blending transfer mode

enumerator DMA2D_R2M

DMA2D register to memory transfer mode

enumerator DMA2D_M2M_BLEND_FG

DMA2D memory to memory with blending transfer mode and fixed color FG

enumerator DMA2D_M2M_BLEND_BG

DMA2D memory to memory with blending transfer mode and fixed color BG

enum rgb888_dataout_reverse_t

Values:

enumerator NO_REVERSE

in output rgb888 formart, not reverse data byte by byte

enumerator REVERSE

in output rgb888 formart, reverse data byte by byte

enum out_color_mode_t

DMA2D_Output_Color_Mode

Values:

enumerator DMA2D_OUTPUT_ARGB8888

ARGB8888 DMA2D color mode

enumerator DMA2D_OUTPUT_RGB888

RGB888 DMA2D color mode

enumerator DMA2D_OUTPUT_RGB565

RGB565 DMA2D color mode

enumerator DMA2D_OUTPUT_ARGB1555

ARGB1555 DMA2D color mode

enumerator DMA2D_OUTPUT_ARGB4444

ARGB4444 DMA2D color mode

enum input_color_mode_t

DMA2D_Input_Color_Mode

Values:

enumerator DMA2D_INPUT_ARGB8888

ARGB8888 DMA2D color mode

enumerator DMA2D_INPUT_RGB888

RGB888 DMA2D color mode

enumerator DMA2D_INPUT_RGB565

RGB565 DMA2D color mode

enumerator DMA2D_INPUT_ARGB1555

ARGB1555 DMA2D color mode

enumerator DMA2D_INPUT_ARGB4444

ARGB4444 DMA2D color mode

enumerator DMA2D_INPUT_L8
enumerator DMA2D_INPUT_AL44
enumerator DMA2D_INPUT_AL88
enumerator DMA2D_INPUT_L4
enumerator DMA2D_INPUT_A8
enumerator DMA2D_INPUT_A4
enum dma2d_int_type_t

dma2d int type

Values:

enumerator DMA2D_CFG_ERROR
enumerator DMA2D_CLUT_TRANS_COMPLETE
enumerator DMA2D_CLUT_TRANS_ERROR
enumerator DMA2D_WARTERMARK_INT
enumerator DMA2D_TRANS_COMPLETE
enumerator DMA2D_TRANS_ERROR
enumerator DMA2D_ALL_INI
enum dma2d_int_status_t

dma2d int status

Values:

enumerator DMA2D_TRANS_ERROR_STATUS
enumerator DMA2D_TRANS_COMPLETE_STATUS
enumerator DMA2D_WARTERMARK_INT_STATUS
enumerator DMA2D_CLUT_TRANS_ERROR_STATUS
enumerator DMA2D_CLUT_TRANS_COMPLETE_STATU
enumerator DMA2D_CFG_ERROR_STATUS
enum dma2d_trans_ability_t

Values:

enumerator MAX_TRANS_256BYTES
enumerator TRANS_192BYTES
enumerator TRANS_128BYTES
enumerator TRANS_64BYTES
enum blend_alpha_mode_t

Values:

enumerator DMA2D_NO_MODIF_ALPHA
enumerator DMA2D_REPLACE_ALPHA
enumerator DMA2D_COMBINE_ALPHA