1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
27
28
29
30
31
32
33
34
35
36
37
38
39
40
53
54
55
57
58
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
115
118
122
123
126
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
151
155
156
157
158
159
160
161
162
163
164
165
166
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
216
217
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
248
249
250
251
252
253
254
255
256
257
258
259
260
/* ... */
#include <touchgfx/hal/OSWrappers.hpp>
#include <touchgfx/hal/HAL.hpp>
#include <touchgfx/lcd/LCD.hpp>
#include <cassert>
#include <STM32F4DMA.hpp>
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_dma2d.h"
7 includes
static HAL_StatusTypeDef HAL_DMA2D_SetMode(DMA2D_HandleTypeDef *hdma2d, uint32_t mode, uint32_t color, uint32_t offset)
{
assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_MODE, mode);
MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_CM, color);
MODIFY_REG(hdma2d->Instance->OOR, DMA2D_OOR_LO, offset);
return HAL_OK;
}{ ... }
extern DMA2D_HandleTypeDef hdma2d;
extern "C" {
static void DMA2D_XferCpltCallback(DMA2D_HandleTypeDef* handle)
{
touchgfx::HAL::getInstance()->signalDMAInterrupt();
}{ ... }
static void DMA2D_XferErrorCallback(DMA2D_HandleTypeDef* handle)
{
}{ ... }
}extern "C" { ... }
STM32F4DMA::STM32F4DMA()
: DMA_Interface(dma_queue), dma_queue(queue_storage, sizeof(queue_storage) / sizeof(queue_storage[0]))
{}{ ... }
STM32F4DMA::~STM32F4DMA()
{
HAL_DMA2D_DeInit(&hdma2d);
NVIC_DisableIRQ(DMA2D_IRQn);
}{ ... }
void STM32F4DMA::initialize()
{
hdma2d.Instance = DMA2D;
HAL_DMA2D_Init(&hdma2d);
hdma2d.XferCpltCallback = DMA2D_XferCpltCallback;
hdma2d.XferErrorCallback = DMA2D_XferErrorCallback;
NVIC_EnableIRQ(DMA2D_IRQn);
}{ ... }
volatile bool disableChromArt = false;
BlitOperations STM32F4DMA::getBlitCaps()
{
if (disableChromArt)
{
return static_cast<BlitOperations>(0);
}if (disableChromArt) { ... }
else
{
return static_cast<BlitOperations>(BLIT_OP_FILL
| BLIT_OP_FILL_WITH_ALPHA
| BLIT_OP_COPY
| BLIT_OP_COPY_WITH_ALPHA
| BLIT_OP_COPY_ARGB8888
| BLIT_OP_COPY_ARGB8888_WITH_ALPHA
| BLIT_OP_COPY_A4
| BLIT_OP_COPY_A8);
}else { ... }
}{ ... }
void STM32F4DMA::setupDataCopy(const BlitOp& blitOp)
{
uint32_t dma2dTransferMode = DMA2D_M2M_BLEND;
uint32_t dma2dColorMode = 0;
bool blendingImage = (blitOp.operation == BLIT_OP_COPY_ARGB8888
|| blitOp.operation == BLIT_OP_COPY_ARGB8888_WITH_ALPHA
|| blitOp.operation == BLIT_OP_COPY_WITH_ALPHA);
bool blendingText = (blitOp.operation == BLIT_OP_COPY_A4
|| blitOp.operation == BLIT_OP_COPY_A8);
uint8_t bitDepth = HAL::lcd().bitDepth();
switch (blitOp.operation)
{
case BLIT_OP_COPY_A4:
dma2dColorMode = CM_A4;
break;case BLIT_OP_COPY_A4:
case BLIT_OP_COPY_A8:
dma2dColorMode = CM_A8;
break;case BLIT_OP_COPY_A8:
case BLIT_OP_COPY_WITH_ALPHA:
dma2dTransferMode = DMA2D_M2M_BLEND;
dma2dColorMode = (bitDepth == 16) ? CM_RGB565 : CM_RGB888;
break;case BLIT_OP_COPY_WITH_ALPHA:
case BLIT_OP_COPY_ARGB8888:
case BLIT_OP_COPY_ARGB8888_WITH_ALPHA:
dma2dColorMode = CM_ARGB8888;
break;case BLIT_OP_COPY_ARGB8888_WITH_ALPHA:
default:
dma2dTransferMode = DMA2D_M2M;
dma2dColorMode = (bitDepth == 16) ? CM_RGB565 : CM_RGB888;
break;default
}switch (blitOp.operation) { ... }
hdma2d.Init.Mode = dma2dTransferMode;
hdma2d.Init.ColorMode = (bitDepth == 16) ? DMA2D_RGB565 : DMA2D_RGB888;
hdma2d.Init.OutputOffset = blitOp.dstLoopStride - blitOp.nSteps;
HAL_DMA2D_SetMode(&hdma2d, dma2dTransferMode,
(bitDepth == 16) ? DMA2D_RGB565 : DMA2D_RGB888,
blitOp.dstLoopStride - blitOp.nSteps);
hdma2d.LayerCfg[1].InputColorMode = dma2dColorMode;
hdma2d.LayerCfg[1].InputOffset = blitOp.srcLoopStride - blitOp.nSteps;
if (blendingImage || blendingText)
{
if (blitOp.alpha < 255)
{
hdma2d.LayerCfg[1].AlphaMode = DMA2D_COMBINE_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = blitOp.alpha;
}if (blitOp.alpha < 255) { ... }
else
{
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
}else { ... }
if (blendingText)
{
if (bitDepth == 16)
{
uint32_t red = (((blitOp.color & 0xF800) >> 11) * 255) / 31;
uint32_t green = (((blitOp.color & 0x7E0) >> 5) * 255) / 63;
uint32_t blue = (((blitOp.color & 0x1F)) * 255) / 31;
uint32_t alpha = blitOp.alpha;
hdma2d.LayerCfg[1].InputAlpha = (alpha << 24) | (red << 16) | (green << 8) | blue;
}if (bitDepth == 16) { ... }
else
{
hdma2d.LayerCfg[1].InputAlpha = blitOp.color.getColor32() | (blitOp.alpha << 24);
}else { ... }
}if (blendingText) { ... }
hdma2d.LayerCfg[0].InputOffset = blitOp.dstLoopStride - blitOp.nSteps;
hdma2d.LayerCfg[0].InputColorMode = (bitDepth == 16) ? CM_RGB565 : CM_RGB888;
HAL_DMA2D_ConfigLayer(&hdma2d, 0);
}if (blendingImage || blendingText) { ... }
HAL_DMA2D_ConfigLayer(&hdma2d, 1);
if (blendingImage || blendingText)
{
HAL_DMA2D_BlendingStart_IT(&hdma2d,
(unsigned int)blitOp.pSrc,
(unsigned int)blitOp.pDst,
(unsigned int)blitOp.pDst,
blitOp.nSteps, blitOp.nLoops);
}if (blendingImage || blendingText) { ... }
else
{
HAL_DMA2D_Start_IT(&hdma2d,
(unsigned int)blitOp.pSrc,
(unsigned int)blitOp.pDst,
blitOp.nSteps, blitOp.nLoops);
}else { ... }
}{ ... }
void STM32F4DMA::setupDataFill(const BlitOp& blitOp)
{
uint8_t bitDepth = HAL::lcd().bitDepth();
uint32_t dma2dTransferMode;
uint32_t dma2dColorMode = (bitDepth == 16) ? CM_RGB565 : CM_RGB888;
uint32_t color = 0;
if (bitDepth == 16)
{
uint32_t red = (((blitOp.color & 0xF800) >> 11) * 255) / 31;
uint32_t green = (((blitOp.color & 0x7E0) >> 5) * 255) / 63;
uint32_t blue = (((blitOp.color & 0x1F)) * 255) / 31;
uint32_t alpha = blitOp.alpha;
color = (alpha << 24) | (red << 16) | (green << 8) | blue;
}if (bitDepth == 16) { ... }
else
{
color = (blitOp.alpha << 24) | blitOp.color.getColor32();
}else { ... }
switch (blitOp.operation)
{
case BLIT_OP_FILL_WITH_ALPHA:
dma2dTransferMode = DMA2D_M2M_BLEND;
break;case BLIT_OP_FILL_WITH_ALPHA:
default:
dma2dTransferMode = DMA2D_R2M;
break;default
}switch (blitOp.operation) { ... };
hdma2d.Init.Mode = dma2dTransferMode;
hdma2d.Init.ColorMode = (bitDepth == 16) ? DMA2D_RGB565 : DMA2D_RGB888;
hdma2d.Init.OutputOffset = blitOp.dstLoopStride - blitOp.nSteps;
HAL_DMA2D_SetMode(&hdma2d, dma2dTransferMode,
(bitDepth == 16) ? DMA2D_RGB565 : DMA2D_RGB888,
blitOp.dstLoopStride - blitOp.nSteps);
if (dma2dTransferMode == DMA2D_M2M_BLEND) {
hdma2d.LayerCfg[1].AlphaMode = DMA2D_REPLACE_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = color;
hdma2d.LayerCfg[1].InputColorMode = CM_A8;
hdma2d.LayerCfg[0].InputOffset = blitOp.dstLoopStride - blitOp.nSteps;
hdma2d.LayerCfg[0].InputColorMode = (bitDepth == 16) ? CM_RGB565 : CM_RGB888;
HAL_DMA2D_ConfigLayer(&hdma2d, 0);
}if (dma2dTransferMode == DMA2D_M2M_BLEND) { ... } else {
hdma2d.LayerCfg[1].InputColorMode = dma2dColorMode;
hdma2d.LayerCfg[1].InputOffset = 0;
}else { ... }
HAL_DMA2D_ConfigLayer(&hdma2d, 1);
if (dma2dTransferMode == DMA2D_M2M_BLEND)
HAL_DMA2D_BlendingStart_IT(&hdma2d,
(unsigned int)blitOp.pDst,
(unsigned int)blitOp.pDst,
(unsigned int)blitOp.pDst,
blitOp.nSteps, blitOp.nLoops);
else
HAL_DMA2D_Start_IT(&hdma2d, color, (unsigned int)blitOp.pDst,
blitOp.nSteps, blitOp.nLoops);
}{ ... }