huangcm
2025-09-01 53d8e046ac1bf2ebe94f671983e3d3be059df91a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
 * sprite/cartoon/sprite_cartoon.c
 *
 * Copyright (c) 2007-2019 Allwinnertech Co., Ltd.
 * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#include "sprite_cartoon.h"
#include "sprite_cartoon_i.h"
#include "sprite_cartoon_color.h"
#include <sunxi_display2.h>
#include <sunxi_board.h>
#include <boot_gui.h>
#include <sys_partition.h>
 
DECLARE_GLOBAL_DATA_PTR;
 
sprite_cartoon_source  sprite_source;
static uint  progressbar_hd;
static int   last_rate;
 
 
/*
************************************************************************************************************
*
*                                             function
*
*    name          :    sprite_cartoon_screen_set
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sprite_cartoon_screen_set(void)
{
 
   struct canvas *cv = NULL;
   cv = fb_lock(FB_ID_0);
   if (NULL == cv) {
       printf("fb lock for sprite cartoon fail\n");
       return -1;
   }
   if (32 == cv->bpp)
       fb_set_alpha_mode(FB_ID_0, FB_PIXEL_ALPHA_MODE, 0x00);
   else if (24 == cv->bpp)
       fb_set_alpha_mode(FB_ID_0, FB_GLOBAL_ALPHA_MODE, 0xFF);
   sprite_source.screen_width = cv->width;
   sprite_source.screen_height = cv->height;
 
   if ((sprite_source.screen_width < 40) ||
       (sprite_source.screen_height < 40)) {
       printf("sunxi cartoon error: invalid screen width or height\n");
       return -1;
   }
   sprite_source.screen_size =
       sprite_source.screen_width * sprite_source.screen_height * 4;
   sprite_source.screen_buf = (char *)cv->base;
   sprite_source.color = SPRITE_CARTOON_GUI_GREEN;
   fb_unlock(FB_ID_0, NULL, 1);
 
   if (!sprite_source.screen_buf)
       return -1;
   memset(sprite_source.screen_buf, 0, sprite_source.screen_size);
 
   mdelay(5);
   return 0;
}
 
/*
************************************************************************************************************
*
*                                             function
*
*    name          :    sprite_cartoon_screen_set
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sprite_cartoon_test(int op)
{
   int i;
   uint progressbar_hd;
   int screen_width, screen_height;
   int x1, x2, y1, y2;
 
   struct canvas *cv = NULL;
 
   sprite_cartoon_screen_set();
 
   cv = fb_lock(FB_ID_0);
   if (NULL == cv) {
       return 0;
   }
   screen_width = cv->width;
   screen_height = cv->height;
   fb_unlock(FB_ID_0, NULL, 0);
 
   printf("screen_width = %d\n", screen_width);
   printf("screen_height = %d\n", screen_height);
 
   if (op <= 1) {
       x1 = screen_width / 4;
       x2 = x1 * 3;
       y1 = screen_height / 2 - 40;
       y2 = screen_height / 2 + 40;
   } else {
       x1 = screen_width / 2 - screen_width / 16;
       x2 = screen_width / 2 + screen_width / 16;
       y1 = screen_height * 1 / 8;
       y2 = screen_height * 7 / 8;
   }
 
   printf("bar x1: %d y1: %d\n", x1, y1);
   printf("bar x2: %d y2: %d\n", x2, y2);
 
   progressbar_hd = sprite_cartoon_progressbar_create(x1, y1, x2, y2, op);
   sprite_cartoon_progressbar_config(progressbar_hd,
                     SPRITE_CARTOON_GUI_RED,
                     SPRITE_CARTOON_GUI_GREEN, 2);
   sprite_cartoon_progressbar_active(progressbar_hd);
 
   sprite_uichar_init(24);
   sprite_uichar_printf("this is for test\n");
 
   sprite_uichar_printf("bar x1: %d y1: %d\n", x1, y1);
   sprite_uichar_printf("bar x2: %d y2: %d\n", x2, y2);
 
   do {
       for (i = 0; i < 100; i += 50) {
           sprite_cartoon_progressbar_upgrate(progressbar_hd, i);
           mdelay(500);
           sprite_uichar_printf("here %d\n", i);
       }
 
       sprite_uichar_printf("up %d\n", i);
       for (i = 99; i > 0; i -= 50) {
           sprite_cartoon_progressbar_upgrate(progressbar_hd, i);
           mdelay(500);
       }
       sprite_uichar_printf("down %d\n", i);
   }
 
   while (0);
 
   return 0;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :    sprite_cartoon_start
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
uint sprite_cartoon_create(int op)
{
 
   int screen_width, screen_height;
   int x1, x2, y1, y2;
 
   if (sprite_cartoon_screen_set()) {
       printf("sprite cartoon create fail\n");
 
       return -1;
   }
 
   struct canvas *cv = NULL;
   cv = fb_lock(FB_ID_0);
   if (NULL == cv) {
       return 0;
   }
   if (32 == cv->bpp)
       fb_set_alpha_mode(FB_ID_0, FB_PIXEL_ALPHA_MODE, 0x00);
   else if (24 == cv->bpp)
       fb_set_alpha_mode(FB_ID_0, FB_GLOBAL_ALPHA_MODE, 0xFF);
 
   screen_width = cv->width;
   screen_height = cv->height;
   fb_unlock(FB_ID_0, NULL, 0);
 
   printf("screen_width = %d\n", screen_width);
   printf("screen_height = %d\n", screen_height);
 
   if (op <= 1) {
       x1 = screen_width / 4;
       x2 = x1 * 3;
       y1 = screen_height / 2 - 40;
       y2 = screen_height / 2 + 40;
   } else {
       x1 = screen_width / 2 - screen_width / 16;
       x2 = screen_width / 2 + screen_width / 16;
       y1 = screen_height * 1 / 8;
       y2 = screen_height * 7 / 8;
   }
 
   printf("bar x1: %d y1: %d\n", x1, y1);
   printf("bar x2: %d y2: %d\n", x2, y2);
 
   progressbar_hd = sprite_cartoon_progressbar_create(x1, y1, x2, y2, op);
   sprite_cartoon_progressbar_config(progressbar_hd,
                     SPRITE_CARTOON_GUI_RED,
                     SPRITE_CARTOON_GUI_GREEN, 2);
   sprite_cartoon_progressbar_active(progressbar_hd);
   sprite_uichar_init(24);
 
   return 0;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :    sprite_cartoon_start
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sprite_cartoon_upgrade(int rate)
{
 
   if (last_rate == rate) {
       return 0;
   }
   last_rate = rate;
 
   sprite_cartoon_progressbar_upgrate(progressbar_hd, rate);
 
   return 0;
}
/*
************************************************************************************************************
*
*                                             function
*
*    name          :    sprite_cartoon_start
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sprite_cartoon_destroy(void)
{
 
   sprite_cartoon_progressbar_destroy(progressbar_hd);
 
   return 0;
}
 
int do_sunxi_screen_char(cmd_tbl_t *cmdtp, int flag, int argc,
            char *const argv[])
{
   int direction_option = 0;
   if (argc == 2)
       direction_option = simple_strtoul(argv[1], NULL, 10);
 
   return sprite_cartoon_test(direction_option);
}
 
U_BOOT_CMD(
   screen_char,    2,    0,    do_sunxi_screen_char,
   "show default screen chars",
   " [direction]\n"
   "direction:\n"
   "0:left to right\n"
   "1:right to left\n"
   "2:up to down\n"
   "3:down to up\n"
);