1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 #include <driver/hal/hal_dma2d_types.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 23 /** @defgroup DMA2D API 24 * @{ 25 */ 26 27 28 /** 29 * @brief initializes the DMA2D system and peripheral registers 30 * - open dma2d sys interrupt enable 31 * - config dma2d work mode/ data format/ offset etc. 32 * 33 * @attention you can reference cli_dma2d.c for all API usage 34 * 35 * @param dma2d_config pointer to a dma2d_config_t structure that contains 36 * the configuration information for the DMA2D. 37 * 38 * Usage example: 39 * 40 * dma2d_config_t dma2d_config = {0}; 41 * dma2d_config.init.mode = DMA2D_R2M; Mode Register to Memory 42 * dma2d_config.init.color_mode = DMA2D_OUTPUT_RGB565; DMA2D Output color mode is ARGB4444 (16 bpp) 43 * dma2d_config.init.output_offset = 0; No offset in output 44 * dma2d_config.init.red_blue_swap = DMA2D_RB_REGULAR; No R&B swap for the output image 45 * dma2d_config.init.alpha_inverted = DMA2D_REGULAR_ALPHA; No alpha inversion for the output image 46 * bk_dma2d_driver_init(&dma2d_config); 47 * 48 * @return 49 * - BK_OK: succeed 50 * - others: other errors. 51 */ 52 bk_err_t bk_dma2d_driver_init(dma2d_config_t *dma2d); 53 54 /** 55 * @brief Deinitializes the DMA2D peripheral registers to their default reset values. 56 * - reset the dma2d driver init reg 57 * 58 * @return 59 * - BK_OK: succeed 60 * - others: other errors. 61 */ 62 bk_err_t bk_dma2d_driver_deinit(void); 63 64 65 /** 66 * @brief Configure the DMA2D background or foreground Layer 67 * include layer offset, color mode, alpha value etc. 68 * 69 * @param 70 * - dma2d Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D. 71 * - LayerIdx DMA2D Layer index. 72 * This parameter can be one of the following values: 73 * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1) 74 * 75 * Usage example: 76 * 77 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].alpha_mode = DMA2D_REPLACE_ALPHA; 78 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_alpha = alpha_value; 79 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_color_mode = DMA2D_INPUT_RGB565; 80 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].input_offset = fg_offline; 81 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].red_blue_swap = DMA2D_RB_REGULAR; 82 * dma2d_config.layer_cfg[DMA2D_FOREGROUND_LAYER].alpha_inverted = DMA2D_REGULAR_ALPHA; 83 * 84 * Background layer Configuration 85 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].alpha_mode = DMA2D_REPLACE_ALPHA; 86 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_alpha = 0x80; 87 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_color_mode = DMA2D_INPUT_RGB565; 88 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].input_offset = bg_offline; 89 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].red_blue_swap = DMA2D_RB_REGULAR; 90 * dma2d_config.layer_cfg[DMA2D_BACKGROUND_LAYER].alpha_inverted = DMA2D_REGULAR_ALPHA; 91 * 92 * bk_dma2d_layer_config(&dma2d_config, DMA2D_FOREGROUND_LAYER); 93 * bk_dma2d_layer_config(&dma2d_config, DMA2D_BACKGROUND_LAYER); 94 * 95 * @return 96 * - BK_OK: succeed 97 * - others: other errors. 98 */ 99 bk_err_t bk_dma2d_layer_config(dma2d_config_t *dma2d, uint32_t layer_idx); 100 101 102 /** 103 * @brief Start the DMA2D Transfer 104 * when you use (bk_dma2d_driver_init) and (bk_dma2d_layer_config) API, then use this API start dma2d work 105 * 106 * @param 107 * - dma2d: Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D. 108 * - pdata: have two means: 109 * - 1: if the Memory-to-Memory or Memory-to-Memory with pixel format select, 110 * should Configure the source memory Buffer address 111 * - 2: if Register-to-Memory mode is selected, 112 * should configure the color value 113 * - dst_addr: The destination memory Buffer address. 114 * - Width: The width of data to be transferred from source to destination (expressed in number of pixels per line). 115 * - Height: The height of data to be transferred from source to destination (expressed in number of lines). 116 * 117 * Usage example: 118 * 119 * dma2d_config_t dma2d_config = {0}; 120 * dma2d_config.init.mode = DMA2D_R2M; Mode Register to Memory 121 * dma2d_config.init.color_mode = DMA2D_OUTPUT_RGB565; DMA2D Output color mode is ARGB4444 (16 bpp) 122 * dma2d_config.init.output_offset = 0; No offset in output 123 * dma2d_config.init.red_blue_swap = DMA2D_RB_REGULAR; No R&B swap for the output image 124 * dma2d_config.init.alpha_inverted = DMA2D_REGULAR_ALPHA; No alpha inversion for the output image 125 * 126 * bk_dma2d_driver_init(&dma2d_config); 127 * bk_dma2d_start_transfer(&dma2d_config, color, (uint32_t)dst_addr, width, high); 128 * 129 * @return 130 * - BK_OK: succeed 131 * - others: other errors. 132 */ 133 bk_err_t bk_dma2d_start_transfer(dma2d_config_t *dma2d, uint32_t pdata, uint32_t dst_addr, uint32_t width, uint32_t height); 134 135 /** 136 * @brief Start the multi-source DMA2D Transfer. 137 * start foreground layer and background layer blending. 138 * 139 * @param - dma2d: Pointer to a dma2d_config_t structure that contains the configuration information for the DMA2D. 140 * - fg_addr: The source memory Buffer address for the foreground layer. 141 * - bg_addr: The source memory Buffer address for the background layer. 142 * - dst_addr: The destination memory Buffer address. 143 * - Width: The width of data to be transferred from source to destination (expressed in number of pixels per line). 144 * - Height: The height of data to be transferred from source to destination (expressed in number of lines). 145 * 146 * Usage example: 147 * 148 * 1: bk_dma2d_driver_init(&dma2d_config); 149 * 2: bk_dma2d_layer_config(&dma2d_config, DMA2D_FOREGROUND_LAYER); 150 * 3: bk_dma2d_layer_config(&dma2d_config, DMA2D_BACKGROUND_LAYER); 151 * 4:bk_dma2d_blending_start(&dma2d_config, (uint32_t)pFgaddr, (uint32_t)pBgaddr, (uint32_t)pDst, xsize ,ysize); 152 * 153 * @attention you can reference cli_dma2d.c for API usage 154 * 155 * @return 156 * - BK_OK: succeed 157 * - others: other errors. 158 */ 159 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); 160 161 /** 162 * @brief this API is check dma2d is transfer busy or not 163 * 164 * @return return 0: transfer stop or transfer done; 165 * - return 1 dma2d is work or transfer not done 166 * 167 * Usage example: 168 * 169 * 1: bk_dma2d_driver_init(&dma2d_config); 170 * 2: bk_dma2d_start_transfer(&dma2d_config, color, (uint32_t)dst_addr, width, high); 171 * 3: while (bk_dma2d_get_transfer_status()) {} 172 * 173 */ 174 bool bk_dma2d_is_transfer_busy(void); 175 176 /** 177 * @brief dma2d int enable. 178 * @param int_type select from dma2d_int_type_t, include int type: 179 * - DMA2D_CFG_ERROR 180 * - DMA2D_CLUT_TRANS_COMPLETE 181 * - DMA2D_CLUT_TRANS_ERROR 182 * - DMA2D_WARTERMARK_INT 183 * - DMA2D_TRANS_COMPLETE 184 * - DMA2D_TRANS_ERROR 185 * @param enable: 1:enable int, 0 disable int 186 * 187 * Usage example: 188 * 189 * bk_dma2d_int_config(DMA2D_TRANS_ERROR | DMA2D_TRANS_COMPLETE ,1); 190 * always use with: bk_dma2d_isr_register(dma2d_isr); 191 * bk_dma2d_int_status_get(); 192 * bk_dma2d_int_status_clear(DMA2D_TRANS_ERROR_STATUS); 193 * bk_dma2d_int_status_clear(DMA2D_TRANS_COMPLETE_STATUS); 194 * 195 * @return 196 * - BK_OK: succeed 197 * - others: other errors. 198 */ 199 bk_err_t bk_dma2d_int_enable(dma2d_int_type_t int_type, bool enable); 200 201 /** 202 * @brief bk_dma2d_int_status_get. 203 * @return return uint32_t value of all int status, 204 * - can used by value & dma2d_int_status_t check which int triggered. 205 * typedef enum 206 * { 207 * DMA2D_TRANS_ERROR_STATUS = 0x1, 208 * DMA2D_TRANS_COMPLETE_STATUS, 209 * DMA2D_WARTERMARK_INT_STATUS, 210 * DMA2D_CLUT_TRANS_ERROR_STATUS, 211 * DMA2D_CLUT_TRANS_COMPLETE_STATUS, 212 * DMA2D_CFG_ERROR_STATUS 213 * }dma2d_int_status_t; 214 * 215 * Usage example: 216 * 217 * uint32_t int_status; 218 * int_status = bk_dma2d_int_status_get(); 219 * if (int_status & DMA2D_CFG_ERROR) { 220 * bk_dma2d_int_status_clear(DMA2D_CFG_ERROR_STATUS); 221 * bk_dma2d_int_config(DMA2D_CFG_ERROR, 0); 222 * } 223 * 224 * @return 225 * - BK_OK: succeed 226 * - others: other errors. 227 */ 228 uint32_t bk_dma2d_int_status_get(void); 229 230 /** 231 * @brief clear dma2d int status 232 * @param int_status select from dma2d_int_status_t include: 233 * DMA2D_TRANS_ERROR_STATUS 234 * DMA2D_TRANS_COMPLETE_STATUS 235 * DMA2D_WARTERMARK_INT_STATUS 236 * DMA2D_CLUT_TRANS_ERROR_STATUS 237 * DMA2D_CLUT_TRANS_COMPLETE_STATUS 238 * DMA2D_CFG_ERROR_STATUS 239 * @return 240 * - BK_OK: succeed 241 * - others: other errors. 242 */ 243 bk_err_t bk_dma2d_int_status_clear(dma2d_int_status_t int_status); 244 245 /** 246 * @brief register dma2d cpu int isr 247 * @param dma2d_isr the function you registr isr 248 * @retval bk_err_t status 249 */ 250 bk_err_t bk_dma2d_isr_register(dma2d_isr_t dma2d_isr); 251 252 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1) 253 /** 254 * @brief register dma2d int type isr 255 open the macro #define USE_HAL_DMA2D_REGISTER_CALLBACKS 1 256 * @param - isr_id based on int type, a int type can register a isr, select from: 257 * typedef enum 258 * { 259 * DMA2D_CFG_ERROR_ISR = 0, 260 * DMA2D_CLUT_TRANS_COMPLETE_ISR, 261 * DMA2D_CLUT_TRANS_ERROR_ISR, 262 * DMA2D_WARTERMARK_INT_ISR, 263 * DMA2D_TRANS_COMPLETE_ISR, 264 * DMA2D_TRANS_ERROR_ISR, 265 * }dm2d_isr_id; 266 * - cb_isr the user register int callback function 267 * @return 268 * - BK_OK: succeed 269 * - others: other errors. 270 */ 271 bk_err_t bk_dma2d_register_int_callback_isr(dm2d_isr_id_t isr_id, dma2d_isr_t cb_isr); 272 #endif 273 274 /** 275 * @brief DMA2D API END 276 */ 277 278 #ifdef __cplusplus 279 } 280 #endif 281 282 283