1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
47
48
51
52
53
54
59
60
61
62
63
64
65
74
75
76
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
113
114
115
116
117
118
119
120
121
125
126
129
130
131
132
133
136
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
194
195
196
197
199
200
201
202
203
204
205
206
219
220
221
234
235
236
237
238
239
240
241
242
243
248
249
250
251
252
253
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
324
325
326
327
328
329
330
333
334
335
336
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
409
410
/* ... */
Defines
#include "main.h"
#include "anime.h"
#include "battery_20x35.h"
#include "logo_compo_134x124.h"
#include "icon_camera_60x60.h"
#include "clouds1_124x44.h"
#include "clouds2_124x44.h"
#include "clouds3_124x44.h"
#include "drop_29x35.h"
#include "gauge1_128x126.h"
#include "gauge2_128x126.h"
#include "gauge3_128x126.h"
#include "gyro_36x36.h"
#include "thermo_25x35.h"
#include "bluetooth_30x35.h"
#include "drop_29x35.h"
16 includes
/* ... */
/* ... */
Includes
#define ANIMATION_STATUS_TEXT_POS 30
Private define
static anime_object_t anime_lcd_frame_buffer =
{
(uint32_t *)LCD_FB_START_ADDRESS,
BPP_ARGB8888,
800,
480,
0x00000000,
0,
0
...};
#ifdef USE_CAMERA_IN_ANIMATION
static anime_object_t anime_cam_frame_buffer =
{
(uint32_t*) CAMERA_FB_START_ADDR,
BPP_RGB565,
640,
480,
0x00000000,
0,
0
...};/* ... */
#endif
extern DMA2D_HandleTypeDef hdma2d_eval;
Private variables
static void Animation_SetHint(void);
#ifdef USE_CAMERA_IN_ANIMATION
static uint32_t AnimationCameraFrameBufferRgb565_Init(uint32_t sizeX, uint32_t sizeY, uint32_t argb8888_Value);
#endif
static void anime_draw_object(anime_object_t object, uint16_t pos_x, uint16_t pos_y, uint8_t transparency, anime_object_t buffer);
static void anime_draw_scene(anime_object_t object);
Private function prototypes
/* ... */
static void anime_draw_object(anime_object_t object,
uint16_t pos_x,
uint16_t pos_y,
uint8_t transparency,
anime_object_t buffer)
{
uint32_t bytePerPixel = 0;
if(buffer.bpp == BPP_ARGB8888)
{
bytePerPixel = 4;
}if (buffer.bpp == BPP_ARGB8888) { ... }
else if(buffer.bpp == BPP_RGB888)
{
bytePerPixel = 3;
...}
else if ((buffer.bpp == BPP_RGB565) ||
(buffer.bpp == BPP_ARGB1555) ||
(buffer.bpp == BPP_ARGB4444) ||
(buffer.bpp == BPP_AL88))
{
bytePerPixel = 2;
...}
else if ((buffer.bpp == BPP_L8) ||
(buffer.bpp == BPP_AL44) ||
(buffer.bpp == BPP_A8))
{
bytePerPixel = 1;
}else if ((buffer.bpp == BPP_L8) || (buffer.bpp == BPP_AL44) || (buffer.bpp == BPP_A8)) { ... }
DMA2D->FGMAR = (uint32_t)(object.address);
DMA2D->FGOR = 0x00000000;
if((object.bpp == BPP_ARGB8888) ||
(object.bpp == BPP_ARGB1555) ||
(object.bpp == BPP_ARGB4444) ||
(object.bpp == BPP_AL44) ||
(object.bpp == BPP_AL88) ||
(object.bpp == BPP_A8) ||
(object.bpp == BPP_A4))
{
DMA2D->FGPFCCR = (transparency << 24) + (0x2 << 16) + object.bpp;
}if ((object.bpp == BPP_ARGB8888) || (object.bpp == BPP_ARGB1555) || (object.bpp == BPP_ARGB4444) || (object.bpp == BPP_AL44) || (object.bpp == BPP_AL88) || (object.bpp == BPP_A8) || (object.bpp == BPP_A4)) { ... }
else
{
DMA2D->FGPFCCR = (transparency << 24) + (0x1 << 16) + object.bpp;
}else { ... }
DMA2D->NLR = (object.size_x << 16) + object.size_y;
DMA2D->BGMAR = (uint32_t)(buffer.address) + (bytePerPixel * ((pos_y * buffer.size_x) + pos_x));
DMA2D->BGOR = buffer.size_x - object.size_x;
DMA2D->BGPFCCR = buffer.bpp;
DMA2D->OMAR = DMA2D->BGMAR;
DMA2D->OOR = DMA2D->BGOR;
DMA2D->OPFCCR = DMA2D->BGPFCCR;
DMA2D->IFCR = 0x3F;
DMA2D->CR = 0x00020001;
while (!DMA2D->ISR);
DMA2D->IFCR = 0x02;
}{ ... }
/* ... */
static void anime_draw_scene(anime_object_t object)
{
#ifdef USE_CAMERA_IN_ANIMATION
anime_draw_object(anime_cam_frame_buffer, 0, 0, 0xFF, object);/* ... */
#endif
anime_draw_object(battery_20x35, 50, 50, 0xFF, object);
anime_draw_object(logo_compo_134x124, 666, 356, 0xFF, object);
anime_draw_object(icon_camera_60x60, 209, 159, 0xFF, object);
gauge1_128x126.animation++;
switch(gauge1_128x126.animation)
{
case 1 :
anime_draw_object(gauge1_128x126, 336, 177, 0xFF, object);
break;case 1 :
case 2 :
anime_draw_object(gauge2_128x126, 336, 177, 0xFF, object);
break;case 2 :
default :
anime_draw_object(gauge3_128x126, 336, 177, 0xFF, object);
gauge1_128x126.animation = 0;
break;default
}switch (gauge1_128x126.animation) { ... }
clouds1_124x44.animation++;
switch(clouds1_124x44.animation)
{
case 1 :
anime_draw_object(clouds1_124x44, 600, 50, 0xFF, object);
break;case 1 :
case 2 :
anime_draw_object(clouds2_124x44, 600, 50, 0xFF, object);
break;case 2 :
default :
anime_draw_object(clouds3_124x44, 600, 50, 0xFF, object);
clouds1_124x44.animation = 0;
break;default
}switch (clouds1_124x44.animation) { ... }
anime_draw_object(drop_29x35, 300, 400, 0xFF, object);
anime_draw_object(thermo_25x35, 340, 400, 0xFF, object);
anime_draw_object(gyro_36x36, 370, 400, 0xFF, object);
anime_draw_object(bluetooth_30x35, 415, 400, 0xFF, object);
}{ ... }
Private functions
/* ... */
void Animation_demo (void)
{
uint32_t exit = 0;
uint32_t CameraChangeResolutionAsked = 1;
#ifdef USE_CAMERA_IN_ANIMATION
uint32_t camera_status = CAMERA_OK;
uint32_t argb8888_Value = 0x00556677;
uint32_t CameraResX = CAMERA_VGA_RES_X;
uint32_t CameraResY = CAMERA_VGA_RES_Y;/* ... */
#endif
Animation_SetHint();
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
#ifdef USE_CAMERA_IN_ANIMATION
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS, (uint8_t *)"Wait for camera initialization...", CENTER_MODE);
#endif
while (exit == 0)
{
if(CameraChangeResolutionAsked)
{
CameraChangeResolutionAsked = 0;
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
#ifdef USE_CAMERA_IN_ANIMATION
camera_status = BSP_CAMERA_Init(RESOLUTION_R640x480);
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS, (uint8_t *)" VGA camera stream ", CENTER_MODE);
if (camera_status != CAMERA_OK)
{
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - ANIMATION_STATUS_TEXT_POS - 15, (uint8_t *)" CAMERA INIT ERROR ", CENTER_MODE);
}if (camera_status != CAMERA_OK) { ... }
/* ... */#endif
BSP_LCD_Clear(LCD_COLOR_WHITE);
#ifdef USE_CAMERA_IN_ANIMATION
camera_status = AnimationCameraFrameBufferRgb565_Init(CameraResX,
CameraResY,
argb8888_Value);
BSP_TEST_APPLI_ASSERT(camera_status != CAMERA_OK);
BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FB_START_ADDR);/* ... */
#endif
Camera_AllowDma2dCopyCamFrmBuffToLcdFrmBuff = 0;
...}
BSP_LED_Toggle(LED4);
HAL_Delay(100);
BSP_LED_Toggle(LED2);
HAL_Delay(400);
if(CheckForUserInput() > 0)
{
exit = 1;
}if (CheckForUserInput() > 0) { ... }
anime_draw_scene(anime_lcd_frame_buffer);
}while (exit == 0) { ... }
#ifdef USE_CAMERA_IN_ANIMATION
camera_status = BSP_CAMERA_Stop();
BSP_TEST_APPLI_ASSERT(camera_status != CAMERA_OK);/* ... */
#endif
}{ ... }
/* ... */
static void Animation_SetHint(void)
{
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 90);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_SetFont(&Font24);
BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"ANIMATION EXAMPLE", CENTER_MODE);
BSP_LCD_SetFont(&Font12);
BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)" Press TAMPER button to start ", CENTER_MODE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DrawRect(10, 100, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize() - 110);
BSP_LCD_DrawRect(11, 101, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize() - 112);
}{ ... }
#ifdef USE_CAMERA_IN_ANIMATION
/* ... */
static uint32_t AnimationCameraFrameBufferRgb565_Init(uint32_t sizeX, uint32_t sizeY, uint32_t argb8888_Value)
{
HAL_StatusTypeDef hal_status = HAL_OK;
uint32_t status = CAMERA_ERROR;
if((sizeX <= CAMERA_VGA_RES_X) && (sizeY <= CAMERA_VGA_RES_Y))
{
hdma2d_eval.Init.Mode = DMA2D_R2M;
hdma2d_eval.Init.ColorMode = DMA2D_RGB565;
hdma2d_eval.Init.OutputOffset = 0x0;
hdma2d_eval.Instance = DMA2D;
hal_status = HAL_DMA2D_Init(&hdma2d_eval);
BSP_TEST_APPLI_ASSERT(hal_status != HAL_OK);
hal_status = HAL_DMA2D_Start(&hdma2d_eval,
argb8888_Value,
(uint32_t)CAMERA_FB_START_ADDR,
sizeX,
sizeY);
BSP_TEST_APPLI_ASSERT(hal_status != HAL_OK);
hal_status = HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
BSP_TEST_APPLI_ASSERT(hal_status != HAL_OK);
status = CAMERA_OK;
}if ((sizeX <= CAMERA_VGA_RES_X) && (sizeY <= CAMERA_VGA_RES_Y)) { ... }
return (status);
}AnimationCameraFrameBufferRgb565_Init (uint32_t sizeX, uint32_t sizeY, uint32_t argb8888_Value) { ... }
/* ... */#endif
/* ... */
/* ... */