display-dma2d  4.1.0
display-dma2d
ui_drawing_dma2d.h
1 /*
2  * C
3  *
4  * Copyright 2019-2023 MicroEJ Corp. All rights reserved.
5  * Use of this source code is governed by a BSD-style license that can be found with this software.
6  */
7 
8 #if !defined UI_DRAWING_DMA2D_H
9 #define UI_DRAWING_DMA2D_H
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /*
15  * @file
16  * @brief Implementation of a set of ui_drawing.h drawing functions (MicroUI library). These are
17  * implementations over the STM32 DMA2D (ChromART) and the destination buffer format is the format
18  * specified in the VEE port. When the drawing cannot be performed by the GPU, the software
19  * implementation is used insted.
20  *
21  * This library provides the implementation of ui_drawing.h "UI_DRAWING_fillRectangle()" and
22  * "UI_DRAWING_drawImage()" functions. The third feature "memcpy" is useful when a copy from frame
23  * buffer to back buffer is required after the call to "LLUI_DISPLAY_IMPL_flush()".
24  *
25  * How to use this library:
26  * - Set the define DRAWING_DMA2D_BPP to 16, 24 or 32 (project global define)
27  * - Set the define STM32F4XX, STM32F7XX or STM32H7XX (project global define)
28  * - Configures the cache management: see ui_drawing_dma2d_configuration.h
29  * - Call "UI_DRAWING_DMA2D_initialize()" during "LLUI_DISPLAY_IMPL_initialize()"
30  * - Redirect the STM32 DMA2D interrupt routine to "UI_DRAWING_DMA2D_IRQHandler()"
31  * - Call "UI_DRAWING_DMA2D_configure_memcpy()" in "LLUI_DISPLAY_IMPL_flush()" before enabling LCD interrupt (optional).
32  * - Call "UI_DRAWING_DMA2D_start_memcpy()" in LCD interrupt (optional).
33  *
34  * @author MicroEJ Developer Team
35  * @version 4.1.0
36  */
37 
38 // --------------------------------------------------------------------------------
39 // Includes
40 // --------------------------------------------------------------------------------
41 
42 #include <LLUI_DISPLAY_impl.h>
43 
44 #include "ui_drawing.h"
45 
46 #ifdef STM32F4XX
47 #include "stm32f4xx_hal.h"
48 #endif
49 
50 #ifdef STM32F7XX
51 #include "stm32f7xx_hal.h"
52 #endif
53 
54 #ifdef STM32H7XX
55 #include "stm32h7xx_hal.h"
56 #endif
57 
58 // --------------------------------------------------------------------------------
59 // Defines
60 // --------------------------------------------------------------------------------
61 
62 #if !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
63 
64 /*
65  * The functions UI_DRAWING_DMA2D_xxx() are directly called by LLUI_PAINTER_impl.c
66  * and LLDW_PAINTER_impl.c. This file overrides each function independently to use the
67  * DMA2D.
68  */
69 
70 #define UI_DRAWING_DMA2D_fillRectangle UI_DRAWING_fillRectangle
71 #define UI_DRAWING_DMA2D_drawImage UI_DRAWING_drawImage
72 #define UI_DRAWING_DMA2D_copyImage UI_DRAWING_copyImage
73 #define UI_DRAWING_DMA2D_drawRegion UI_DRAWING_drawRegion
74 
75 #else // !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
76 
77 /*
78  * The functions UI_DRAWING_DMA2D_xxx() are indirectly called through some tables.
79  * The functions have got the identifier "0" as suffix. This file overrides each function
80  * independently to use the DMA2D.
81  */
82 
83 #define UI_DRAWING_DMA2D_fillRectangle UI_DRAWING_fillRectangle_0
84 #define UI_DRAWING_DMA2D_drawImage UI_DRAWING_drawImage_0
85 #define UI_DRAWING_DMA2D_copyImage UI_DRAWING_copyImage_0
86 #define UI_DRAWING_DMA2D_drawRegion UI_DRAWING_drawRegion_0
87 
88 #endif // !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
89 
90 // -----------------------------------------------------------------------------
91 // Types
92 // -----------------------------------------------------------------------------
93 
94 /*
95  * @brief Feature "memcpy" data. The function "UI_DRAWING_DMA2D_configure_memcpy()" fills
96  * it with the given arguments. In a second time, this structure must be given to
97  * "UI_DRAWING_DMA2D_start_memcpy()".
98  */
99 typedef struct {
100  uint8_t* src_address;
101  uint8_t* dest_address;
102  uint16_t width;
103  uint16_t height;
105 
106 // --------------------------------------------------------------------------------
107 // Public API
108 // --------------------------------------------------------------------------------
109 
110 /*
111  * @brief Initializes this library.
112  *
113  * @param[in] binary_semaphore_handle a binary semaphore. It must initialized in such
114  * a way that the semaphore must first be 'given' before it can be 'taken'.
115  */
116 void UI_DRAWING_DMA2D_initialize(void* binary_semaphore_handle);
117 
118 /*
119  * @brief STM32 HAL DMA2D implementation. DMA2D IRQ handler must call this function.
120  * This function calls the STM32 HAL DMA2D "HAL_DMA2D_IRQHandler()" function. Then it
121  * calls the LLUI_DISPLAY "LLUI_DISPLAY_notifyAsynchronousDrawingEnd" or "LLUI_DISPLAY_flushDone"
122  * callbacks to notify the graphical engine about the current status.
123  */
124 void UI_DRAWING_DMA2D_IRQHandler(void);
125 
126 /*
127  * @brief Configures the copy from frame buffer to back buffer just after a flush.
128  *
129  * @param[in] srcAddr the address of the buffer to copy.
130  * @param[in] destAddr the address of the destination buffer.
131  * @param[in] xmin the top-left X coordinate of the rectangle to copy.
132  * @param[in] ymin the top-left Y coordinate of the rectangle to copy.
133  * @param[in] xmax the bottom-right X coordinate of the rectangle to copy.
134  * @param[in] ymax the bottom-right Y coordinate of the rectangle to copy.
135  * @param[in] stride the buffer row stride in pixels (usually equal to the buffer width)
136  * @param[in] memcpy_data the internal representation of the memcpy to perform.
137  */
138 void UI_DRAWING_DMA2D_configure_memcpy(uint8_t* srcAddr, uint8_t* destAddr, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax, uint32_t stride, DRAWING_DMA2D_memcpy* memcpy_data);
139 
140 /*
141  * @brief Starts the copy previously configured by a call to "DRAWING_DMA2D_configure_memcpy()".
142  *
143  * @param[in] memcpy_data the internal representation of the memcpy to perform.
144  */
145 void UI_DRAWING_DMA2D_start_memcpy(DRAWING_DMA2D_memcpy* memcyp_data);
146 
147 // --------------------------------------------------------------------------------
148 // ui_drawing.h API
149 // (the function names differ according to the available number of destination formats)
150 // --------------------------------------------------------------------------------
151 
152 /*
153  * @brief Implementation of fillRectangle over the DMA2D. See ui_drawing.h
154  */
155 DRAWING_Status UI_DRAWING_DMA2D_fillRectangle(MICROUI_GraphicsContext* gc, jint x1, jint y1, jint x2, jint y2);
156 
157 /*
158  * @brief Implementation of drawImage over the DMA2D. See ui_drawing.h
159  */
160 DRAWING_Status UI_DRAWING_DMA2D_drawImage(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint regionX, jint regionY, jint width, jint height, jint x, jint y, jint alpha);
161 
162 /*
163  * @brief Implementation of copyImage over the DMA2D. See ui_drawing.h
164  */
165 DRAWING_Status UI_DRAWING_DMA2D_copyImage(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint regionX, jint regionY, jint width, jint height, jint x, jint y);
166 
167 /*
168  * @brief Implementation of drawRegion over the DMA2D. See ui_drawing.h
169  */
170 DRAWING_Status UI_DRAWING_DMA2D_drawRegion(MICROUI_GraphicsContext* gc, jint regionX, jint regionY, jint width, jint height, jint x, jint y, jint alpha);
171 
172 // --------------------------------------------------------------------------------
173 // EOF
174 // --------------------------------------------------------------------------------
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 #endif // UI_DRAWING_DMA2D_H