display-dma2d  5.0.1
display-dma2d
ui_drawing_dma2d.h
1 /*
2  * C
3  *
4  * Copyright 2019-2024 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  * @author MicroEJ Developer Team
22  * @version 5.0.1
23  */
24 
25 // --------------------------------------------------------------------------------
26 // Includes
27 // --------------------------------------------------------------------------------
28 
29 #include <LLUI_DISPLAY_impl.h>
30 
31 #include "ui_drawing.h"
33 
34 #ifdef STM32F4XX
35 #include "stm32f4xx_hal.h"
36 #endif
37 
38 #ifdef STM32F7XX
39 #include "stm32f7xx_hal.h"
40 #endif
41 
42 #ifdef STM32H7XX
43 #include "stm32h7xx_hal.h"
44 #endif
45 
46 // --------------------------------------------------------------------------------
47 // Defines
48 // --------------------------------------------------------------------------------
49 
50 #if !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
51 
52 /*
53  * The functions UI_DRAWING_DMA2D_xxx() are directly called by LLUI_PAINTER_impl.c
54  * and LLDW_PAINTER_impl.c. This file overrides each function independently to use the
55  * DMA2D.
56  */
57 
58 #define UI_DRAWING_DMA2D_fillRectangle UI_DRAWING_fillRectangle
59 #define UI_DRAWING_DMA2D_drawImage UI_DRAWING_drawImage
60 #define UI_DRAWING_DMA2D_copyImage UI_DRAWING_copyImage
61 #define UI_DRAWING_DMA2D_drawRegion UI_DRAWING_drawRegion
62 
63 #else // !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
64 
65 /*
66  * The functions UI_DRAWING_DMA2D_xxx() are indirectly called through some tables.
67  * The functions have got the identifier "0" as suffix. This file overrides each function
68  * independently to use the DMA2D.
69  */
70 
71 #define UI_DRAWING_DMA2D_fillRectangle UI_DRAWING_fillRectangle_0
72 #define UI_DRAWING_DMA2D_drawImage UI_DRAWING_drawImage_0
73 #define UI_DRAWING_DMA2D_copyImage UI_DRAWING_copyImage_0
74 #define UI_DRAWING_DMA2D_drawRegion UI_DRAWING_drawRegion_0
75 
76 #endif // !defined(LLUI_GC_SUPPORTED_FORMATS) || (LLUI_GC_SUPPORTED_FORMATS <= 1)
77 
78 // -----------------------------------------------------------------------------
79 // Types
80 // -----------------------------------------------------------------------------
81 
82 /*
83  * @brief Feature "memcpy" data. The function "UI_DRAWING_DMA2D_configure_memcpy()" fills
84  * it with the given arguments. In a second time, this structure must be given to
85  * "UI_DRAWING_DMA2D_start_memcpy()".
86  */
87 typedef struct {
88  uint8_t* src_address;
89  uint8_t* dest_address;
90  uint16_t width;
91  uint16_t height;
93 
94 // --------------------------------------------------------------------------------
95 // Public API
96 // --------------------------------------------------------------------------------
97 
98 /*
99  * @brief Initializes this library.
100  *
101  * @param[in] binary_semaphore_handle a binary semaphore. It must initialized in such
102  * a way that the semaphore must first be 'given' before it can be 'taken'.
103  */
104 void UI_DRAWING_DMA2D_initialize(void* binary_semaphore_handle);
105 
106 /*
107  * @brief STM32 HAL DMA2D implementation. DMA2D IRQ handler must call this function.
108  * This function calls the STM32 HAL DMA2D "HAL_DMA2D_IRQHandler()" function. Then it
109  * calls the LLUI_DISPLAY "LLUI_DISPLAY_notifyAsynchronousDrawingEnd" or "LLUI_DISPLAY_flushDone"
110  * callbacks to notify the graphical engine about the current status.
111  */
112 void UI_DRAWING_DMA2D_IRQHandler(void);
113 
114 /*
115  * @brief Configures the copy from a buffer to another buffer just.
116  *
117  * @param[in] srcAddr the address of the buffer to copy.
118  * @param[in] destAddr the address of the destination buffer.
119  * @param[in] xmin the top-left X coordinate of the rectangle to copy.
120  * @param[in] ymin the top-left Y coordinate of the rectangle to copy.
121  * @param[in] xmax the bottom-right X coordinate of the rectangle to copy.
122  * @param[in] ymax the bottom-right Y coordinate of the rectangle to copy.
123  * @param[in] stride the buffer row stride in pixels (usually equal to the buffer width)
124  * @param[in] memcpy_data the internal representation of the memcpy to perform.
125  */
126 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);
127 
128 /*
129  * @brief Starts the copy previously configured by a call to "DRAWING_DMA2D_configure_memcpy()".
130  *
131  * @param[in] memcpy_data the internal representation of the memcpy to perform.
132  */
133 void UI_DRAWING_DMA2D_start_memcpy(DRAWING_DMA2D_memcpy* memcyp_data);
134 
135 /*
136  * @brief Notifies the end of the copy (callback called by the the framework).
137  *
138  * The caller of memcpy should implement this function to be notified about the end of
139  * the copy. A default implementation is available which does noting.
140  *
141  * @param[in] from_isr true when this function is called under an interrupt context.
142  */
143 void UI_DRAWING_DMA2D_memcpy_callback(bool from_isr);
144 
145 // --------------------------------------------------------------------------------
146 // ui_drawing.h API
147 // (the function names differ according to the available number of destination formats)
148 // --------------------------------------------------------------------------------
149 
150 /*
151  * @brief Implementation of fillRectangle over the DMA2D. See ui_drawing.h
152  */
153 DRAWING_Status UI_DRAWING_DMA2D_fillRectangle(MICROUI_GraphicsContext* gc, jint x1, jint y1, jint x2, jint y2);
154 
155 /*
156  * @brief Implementation of drawImage over the DMA2D. See ui_drawing.h
157  */
158 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);
159 
160 /*
161  * @brief Implementation of copyImage over the DMA2D. See ui_drawing.h
162  */
163 DRAWING_Status UI_DRAWING_DMA2D_copyImage(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint regionX, jint regionY, jint width, jint height, jint x, jint y);
164 
165 /*
166  * @brief Implementation of drawRegion over the DMA2D. See ui_drawing.h
167  */
168 DRAWING_Status UI_DRAWING_DMA2D_drawRegion(MICROUI_GraphicsContext* gc, jint regionX, jint regionY, jint width, jint height, jint x, jint y, jint alpha);
169 
170 // --------------------------------------------------------------------------------
171 // EOF
172 // --------------------------------------------------------------------------------
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 #endif // UI_DRAWING_DMA2D_H
This file provides the configuration of ui_drawing_dma2d.c.