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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
/**
* @file include/gdisp/lld/gdisp_lld.h
* @brief GDISP Graphic Driver subsystem low level driver header.
*
* @addtogroup GDISP
* @{
*/
#ifndef _GDISP_LLD_H
#define _GDISP_LLD_H
#if GFX_USE_GDISP || defined(__DOXYGEN__)
#if GDISP_MULTIPLE_DRIVERS && defined(GDISP_LLD_DECLARATIONS)
// include hardware definitions
#include "gdisp_lld_config.h"
#endif
/*===========================================================================*/
/* Error checks. */
/*===========================================================================*/
#if !GDISP_MULTIPLE_DRIVERS || defined(GDISP_LLD_DECLARATIONS)
/**
* @name GDISP hardware accelerated support
* @{
*/
/**
* @brief Hardware streaming interface is supported.
* @details If set to @p FALSE software emulation is used.
* @note Either GDISP_HARDWARE_STREAM or GDISP_HARDWARE_DRAWPIXEL must be provided by the driver
*/
#ifndef GDISP_HARDWARE_STREAM
#define GDISP_HARDWARE_STREAM FALSE
#endif
/**
* @brief Hardware streaming requires an explicit end call.
* @details If set to @p FALSE if an explicit stream end call is not required.
*/
#ifndef GDISP_HARDWARE_STREAM_END
#define GDISP_HARDWARE_STREAM_END FALSE
#endif
/**
* @brief Hardware accelerated draw pixel.
* @details If set to @p FALSE software emulation is used.
* @note Either GDISP_HARDWARE_STREAM or GDISP_HARDWARE_DRAWPIXEL must be provided by the driver
*/
#ifndef GDISP_HARDWARE_DRAWPIXEL
#define GDISP_HARDWARE_DRAWPIXEL FALSE
#endif
/**
* @brief Hardware accelerated screen clears.
* @details If set to @p FALSE software emulation is used.
* @note This clears the entire display surface regardless of the clipping area currently set
*/
#ifndef GDISP_HARDWARE_CLEARS
#define GDISP_HARDWARE_CLEARS FALSE
#endif
/**
* @brief Hardware accelerated rectangular fills.
* @details If set to @p FALSE software emulation is used.
*/
#ifndef GDISP_HARDWARE_FILLS
#define GDISP_HARDWARE_FILLS FALSE
#endif
/**
* @brief Hardware accelerated fills from an image.
* @details If set to @p FALSE software emulation is used.
*/
#ifndef GDISP_HARDWARE_BITFILLS
#define GDISP_HARDWARE_BITFILLS FALSE
#endif
/**
* @brief Hardware accelerated scrolling.
* @details If set to @p FALSE there is no support for scrolling.
*/
#ifndef GDISP_HARDWARE_SCROLL
#define GDISP_HARDWARE_SCROLL FALSE
#endif
/**
* @brief Reading back of pixel values.
* @details If set to @p FALSE there is no support for pixel read-back.
*/
#ifndef GDISP_HARDWARE_PIXELREAD
#define GDISP_HARDWARE_PIXELREAD FALSE
#endif
/**
* @brief The driver supports one or more control commands.
* @details If set to @p FALSE there is no support for control commands.
*/
#ifndef GDISP_HARDWARE_CONTROL
#define GDISP_HARDWARE_CONTROL FALSE
#endif
/**
* @brief The driver supports a non-standard query.
* @details If set to @p FALSE there is no support for non-standard queries.
*/
#ifndef GDISP_HARDWARE_QUERY
#define GDISP_HARDWARE_QUERY FALSE
#endif
/**
* @brief The driver supports a clipping in hardware.
* @details If set to @p FALSE there is no support for non-standard queries.
* @note If this is defined the driver must perform its own clipping on all calls to
* the driver and respond appropriately if a parameter is outside the display area.
* @note If this is not defined then the software ensures that all calls to the
* driver do not exceed the display area (provided GDISP_NEED_CLIP or GDISP_NEED_VALIDATION
* has been set).
*/
#ifndef GDISP_HARDWARE_CLIP
#define GDISP_HARDWARE_CLIP FALSE
#endif
/** @} */
#endif
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
typedef struct GDISPDriver {
GDISPControl g;
#if GDISP_MULTIPLE_DRIVERS
const struct GDISPVMT const * vmt;
#endif
uint16_t flags;
#define GDISP_FLG_INSTREAM 0x0001
// Multithread Mutex
#if GDISP_NEED_MULTITHREAD
gfxMutex mutex;
#endif
// Software clipping
#if (GDISP_MULTIPLE_DRIVERS || !GDISP_HARDWARE_CLIP) && (GDISP_NEED_CLIP || GDISP_NEED_VALIDATION)
coord_t clipx0, clipy0;
coord_t clipx1, clipy1; /* not inclusive */
#endif
// Driver call parameters
struct {
coord_t x, y;
coord_t cx, cy;
coord_t x1, y1;
coord_t x2, y2;
color_t color;
void *ptr;
} p;
// In call working buffers
#if GDISP_NEED_TEXT
// Text rendering parameters
struct {
font_t font;
color_t color;
color_t bgcolor;
coord_t clipx0, clipy0;
coord_t clipx1, clipy1;
} t;
#endif
#if GDISP_LINEBUF_SIZE != 0 && ((GDISP_NEED_SCROLL && !GDISP_HARDWARE_SCROLL) || (!GDISP_HARDWARE_STREAM && GDISP_HARDWARE_BITFILLS))
// A pixel line buffer
color_t linebuf[GDISP_LINEBUF_SIZE];
#endif
} GDISPDriver;
#if !GDISP_MULTIPLE_DRIVERS || defined(GDISP_LLD_DECLARATIONS)
#if GDISP_MULTIPLE_DRIVERS
#define LLDSPEC static
#else
#define LLDSPEC
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize the driver.
* @return TRUE if successful.
* @param[in] g The driver structure
* @param[out] g->g The driver must fill in the GDISPControl structure
*/
LLDSPEC bool_t gdisp_lld_init(GDISPDriver *g);
#if GDISP_HARDWARE_STREAM
/**
* @brief Start a streamed operation
* @pre GDISP_HARDWARE_STREAM is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The window position
* @param[in] g->p.cx,g->p.cy The window size
*
* @note The parameter variables must not be altered by the driver.
* @note Streaming operations that wrap the defined window have
* undefined results.
*/
LLDSPEC void gdisp_lld_stream_start(GDISPDriver *g);
/**
* @brief Send a pixel to the current streaming position and then increment that position
* @pre GDISP_HARDWARE_STREAM is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.color The color to display at the curent position
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_stream_color(GDISPDriver *g);
#if GDISP_HARDWARE_STREAM_READ
/**
* @brief Read a pixel from the current streaming position and then increment that position
* @return The color at the current position
* @pre GDISP_HARDWARE_STREAM and GDISP_HARDWARE_STREAM_READ is TRUE
*
* @param[in] g The driver structure
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC color_t gdisp_lld_stream_read(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_STREAM_END
/**
* @brief End the current streaming operation
* @pre GDISP_HARDWARE_STREAM and GDISP_HARDWARE_STREAM_END is TRUE
*
* @param[in] g The driver structure
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_stream_stop(GDISPDriver *g);
#endif
#endif
#if GDISP_HARDWARE_DRAWPIXEL
/**
* @brief Draw a pixel
* @pre GDISP_HARDWARE_DRAWPIXEL is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The pixel position
* @param[in] g->p.color The color to set
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_draw_pixel(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_CLEARS
/**
* @brief Clear the screen using the defined color
* @pre GDISP_HARDWARE_CLEARS is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.color The color to set
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_clear(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_FILLS
/**
* @brief Fill an area with a single color
* @pre GDISP_HARDWARE_FILLS is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The area position
* @param[in] g->p.cx,g->p.cy The area size
* @param[in] g->p.color The color to set
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_fill_area(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_BITFILLS
/**
* @brief Fill an area using a bitmap
* @pre GDISP_HARDWARE_BITFILLS is TRUE
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The area position
* @param[in] g->p.cx,g->p.cy The area size
* @param[in] g->p.x1,g->p.y1 The starting position in the bitmap
* @param[in] g->p.x2 The width of a bitmap line
* @param[in] g->p.ptr The pointer to the bitmap
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_blit_area(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_PIXELREAD
/**
* @brief Read a pixel from the display
* @return The color at the defined position
* @pre GDISP_HARDWARE_PIXELREAD is TRUE (and the application needs it)
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The pixel position
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC color_t gdisp_lld_get_pixel_color(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_SCROLL && GDISP_NEED_SCROLL
/**
* @brief Scroll an area of the screen
* @pre GDISP_HARDWARE_SCROLL is TRUE (and the application needs it)
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The area position
* @param[in] g->p.cx,g->p.cy The area size
* @param[in] g->p.y1 The number of lines to scroll (positive or negative)
*
* @note The parameter variables must not be altered by the driver.
* @note This can be easily implemented if the hardware supports
* display area to display area copying.
* @note Clearing the exposed area on the scroll operation is not
* needed as the high level code handles this.
*/
LLDSPEC void gdisp_lld_vertical_scroll(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_CONTROL && GDISP_NEED_CONTROL
/**
* @brief Control some feature of the hardware
* @pre GDISP_HARDWARE_CONTROL is TRUE (and the application needs it)
*
* @param[in] g The driver structure
* @param[in] g->p.x The operation to perform
* @param[in] g->p.ptr The operation parameter
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_control(GDISPDriver *g);
#endif
#if GDISP_HARDWARE_QUERY && GDISP_NEED_QUERY
/**
* @brief Query some feature of the hardware
* @return The information requested (typecast as void *)
* @pre GDISP_HARDWARE_QUERY is TRUE (and the application needs it)
*
* @param[in] g The driver structure
* @param[in] g->p.x What to query
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void *gdisp_lld_query(GDISPDriver *g); // Uses p.x (=what);
#endif
#if GDISP_HARDWARE_CLIP && (GDISP_NEED_CLIP || GDISP_NEED_VALIDATION)
/**
* @brief Set the hardware clipping area
* @pre GDISP_HARDWARE_CLIP is TRUE (and the application needs it)
*
* @param[in] g The driver structure
* @param[in] g->p.x,g->p.y The area position
* @param[in] g->p.cx,g->p.cy The area size
*
* @note The parameter variables must not be altered by the driver.
*/
LLDSPEC void gdisp_lld_set_clip(GDISPDriver *g);
#endif
#ifdef __cplusplus
}
#endif
#endif // !GDISP_MULTIPLE_DRIVERS || defined(GDISP_LLD_DECLARATIONS)
#if GDISP_MULTIPLE_DRIVERS
typedef struct GDISPVMT {
bool_t (*init)(GDISPDriver *g);
void (*streamstart)(GDISPDriver *g); // Uses p.x,p.y p.cx,p.cy
void (*streamcolor)(GDISPDriver *g); // Uses p.color
color_t (*streamread)(GDISPDriver *g); // Uses no parameters
void (*streamstop)(GDISPDriver *g); // Uses no parameters
void (*pixel)(GDISPDriver *g); // Uses p.x,p.y p.color
void (*clear)(GDISPDriver *g); // Uses p.color
void (*fill)(GDISPDriver *g); // Uses p.x,p.y p.cx,p.cy p.color
void (*blit)(GDISPDriver *g); // Uses p.x,p.y p.cx,p.cy p.x1,p.y1 (=srcx,srcy) p.x2 (=srccx), p.ptr (=buffer)
color_t (*get)(GDISPDriver *g); // Uses p.x,p.y
void (*vscroll)(GDISPDriver *g); // Uses p.x,p.y p.cx,p.cy, p.y1 (=lines) p.color
void (*control)(GDISPDriver *g); // Uses p.x (=what) p.ptr (=value)
void *(*query)(GDISPDriver *g); // Uses p.x (=what);
void (*setclip)(GDISPDriver *g); // Uses p.x,p.y p.cx,p.cy
} GDISPVMT;
#ifdef GDISP_LLD_DECLARATIONS
#define GDISP_DRIVER_STRUCT_INIT {{0}, &VMT}
static const GDISPVMT VMT = {
gdisp_lld_init,
#if GDISP_HARDWARE_STREAM
gdisp_lld_stream_start,
gdisp_lld_stream_color,
gdisp_lld_stream_read,
#if GDISP_HARDWARE_STREAM_END
gdisp_lld_stream_stop,
#else
0,
#endif
#else
0, 0, 0,
#endif
#if GDISP_HARDWARE_DRAWPIXEL
gdisp_lld_draw_pixel,
#else
0,
#endif
#if GDISP_HARDWARE_CLEARS
gdisp_lld_clear,
#else
0,
#endif
#if GDISP_HARDWARE_FILLS
gdisp_lld_fill_area,
#else
0,
#endif
#if GDISP_HARDWARE_BITFILLS
gdisp_lld_blit_area,
#else
0,
#endif
#if GDISP_HARDWARE_PIXELREAD
gdisp_lld_get_pixel_color,
#else
0,
#endif
#if GDISP_HARDWARE_SCROLL && GDISP_NEED_SCROLL
gdisp_lld_vertical_scroll,
#else
0,
#endif
#if GDISP_HARDWARE_CONTROL && GDISP_NEED_CONTROL
gdisp_lld_control,
#else
0,
#endif
#if GDISP_HARDWARE_QUERY && GDISP_NEED_QUERY
gdisp_lld_query,
#else
0,
#endif
#if GDISP_HARDWARE_CLIP && (GDISP_NEED_CLIP || GDISP_NEED_VALIDATION)
gdisp_lld_set_clip,
#else
0,
#endif
};
GDISPDriver GDISP_DRIVER_STRUCT = {{0}, &VMT};
#else
#define gdisp_lld_init(g) g->vmt->init(g)
#define gdisp_lld_stream_start(g) g->vmt->streamstart(g)
#define gdisp_lld_stream_color(g) g->vmt->streamcolor(g)
#define gdisp_lld_stream_read(g) g->vmt->streamread(g)
#define gdisp_lld_stream_stop(g) g->vmt->streamstop(g)
#define gdisp_lld_draw_pixel(g) g->vmt->pixel(g)
#define gdisp_lld_clear(g) g->vmt->clear(g)
#define gdisp_lld_fill_area(g) g->vmt->fill(g)
#define gdisp_lld_blit_area(g) g->vmt->blit(g)
#define gdisp_lld_get_pixel_color(g) g->vmt->get(g)
#define gdisp_lld_vertical_scroll(g) g->vmt->vscroll(g)
#define gdisp_lld_control(g) g->vmt->control(g)
#define gdisp_lld_query(g) g->vmt->query(g)
#define gdisp_lld_set_clip(g) g->vmt->setclip(g)
extern GDISPDriver GDISP_DRIVER_STRUCT;
#endif // GDISP_LLD_DECLARATIONS
#else // GDISP_MULTIPLE_DRIVERS
#ifdef GDISP_LLD_DECLARATIONS
GDISPDriver GDISP_DRIVER_STRUCT;
#else
extern GDISPDriver GDISP_DRIVER_STRUCT;
#endif
#endif // GDISP_MULTIPLE_DRIVERS
/* Verify information for packed pixels and define a non-packed pixel macro */
#if !GDISP_PACKED_PIXELS
#define gdispPackPixels(buf,cx,x,y,c) { ((color_t *)(buf))[(y)*(cx)+(x)] = (c); }
#elif !GDISP_HARDWARE_BITFILLS
#error "GDISP: packed pixel formats are only supported for hardware accelerated drivers."
#elif GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_RGB888 \
&& GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_RGB444 \
&& GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_RGB666 \
&& GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_CUSTOM
#error "GDISP: A packed pixel format has been specified for an unsupported pixel format."
#endif
/* Support routine for packed pixel formats */
#if !defined(gdispPackPixels) || defined(__DOXYGEN__)
/**
* @brief Pack a pixel into a pixel buffer.
* @note This function performs no buffer boundary checking
* regardless of whether GDISP_NEED_CLIP has been specified.
*
* @param[in] buf The buffer to put the pixel in
* @param[in] cx The width of a pixel line
* @param[in] x, y The location of the pixel to place
* @param[in] color The color to put into the buffer
*
* @api
*/
void gdispPackPixels(const pixel_t *buf, coord_t cx, coord_t x, coord_t y, color_t color);
#endif
#endif /* GFX_USE_GDISP */
#endif /* _GDISP_LLD_H */
/** @} */
|