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
|
/**
* \file
*
* \brief Monochrome graphic library API header file
*
* Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#ifndef GFX_MONO_H
#define GFX_MONO_H
#include <stdint.h>
#include "compiler.h"
#ifndef PROGMEM_DECLARE
# define PROGMEM_DECLARE(type, name) const type name
# define PROGMEM_T const
# define PROGMEM_PTR_T const *
# define PROGMEM_READ_BYTE(x) *(x)
# define PROGMEM_STRING_T const char*
#endif
/**
* \defgroup asfdoc_common2_gfx_mono Monochrome graphical display system
*
* See \ref asfdoc_common2_gfx_mono_quickstart.
*
* This library provides an interface to drawing graphics on monochrome
* graphical displays
*
* The graphics drivers consists of the following:
* - Display driver interface (gfx_mono.h)
* - General graphics drawing primitives (gfx_mono_generic.h)
* - Display specific implementation (ex. gfx_mono_ug_2832hsweg04.h)
*
* The generic drawing primitives is a library of functions for drawing
* graphics primitives such as lines, rectangles and circles. It uses other
* functions implemented by the display driver for drawing the primitives. The
* implementation of these functions can optionally be used by a display
* driver, but if the hardware of the display allows faster handling of any of
* the primitives, the display driver can implement it directly.
*
* The display specific drivers provides an interface to the graphical display.
* It implements the low level communication with the display hardware, putting
* pixels on the display and drawing primitives such as lines, circles and
* rectangles. Depending on the display driver implementation, drawing the
* graphics primitives might be handled by the generic graphics drawing
* primitives rather than the display driver itself.
*
* \section asfdoc_common2_gfx_mono_examples Examples
* The following examples are available for the driver:
* - \ref asfdoc_common2_gfx_mono_quickstart
* - \ref asfdoc_common2_gfx_mono_sysfont_example
* - \ref asfdoc_common2_gfx_mono_spinner_example
*
* \section asfdoc_common2_gfx_mono_api_overview API Overview
*
* \note The functions in the library are not interrupt safe.
* @{
*/
typedef uint8_t gfx_mono_color_t;
typedef uint8_t gfx_coord_t;
/** Pixel operations */
enum gfx_mono_color {
/** Pixel is cleared */
GFX_PIXEL_CLR = 0,
/** Pixel is set on screen (OR) */
GFX_PIXEL_SET = 1,
/** Pixel is XORed */
GFX_PIXEL_XOR = 2,
};
/** Bitmap types */
enum gfx_mono_bitmap_type {
/** Bitmap stored in SRAM */
GFX_MONO_BITMAP_RAM,
/** Bitmap stored in progmem */
GFX_MONO_BITMAP_PROGMEM
};
/* Cannot be moved to top, as they use the bitmap and color enums. */
#ifdef USE_SDL
# include "gfx_mono_sdl.h"
#elif defined(GFX_MONO_C12832_A1Z)
# include "gfx_mono_c12832_a1z.h"
#elif defined(GFX_MONO_UG_2832HSWEG04)
# include "gfx_mono_ug_2832hsweg04.h"
#else
/* NULL driver by default */
# include "gfx_mono_null.h"
#endif
#include "gfx_mono_generic.h"
/** \name Circle Sector Definitions */
/** @{ */
/** Bitmask for drawing circle octant 0. */
#define GFX_OCTANT0 (1 << 0)
/** Bitmask for drawing circle octant 1. */
#define GFX_OCTANT1 (1 << 1)
/** Bitmask for drawing circle octant 2. */
#define GFX_OCTANT2 (1 << 2)
/** Bitmask for drawing circle octant 3. */
#define GFX_OCTANT3 (1 << 3)
/** Bitmask for drawing circle octant 4. */
#define GFX_OCTANT4 (1 << 4)
/** Bitmask for drawing circle octant 5. */
#define GFX_OCTANT5 (1 << 5)
/** Bitmask for drawing circle octant 6. */
#define GFX_OCTANT6 (1 << 6)
/** Bitmask for drawing circle octant 7. */
#define GFX_OCTANT7 (1 << 7)
/** Bitmask for drawing circle quadrant 0. */
#define GFX_QUADRANT0 (GFX_OCTANT0 | GFX_OCTANT1)
/** Bitmask for drawing circle quadrant 1. */
#define GFX_QUADRANT1 (GFX_OCTANT2 | GFX_OCTANT3)
/** Bitmask for drawing circle quadrant 2. */
#define GFX_QUADRANT2 (GFX_OCTANT4 | GFX_OCTANT5)
/** Bitmask for drawing circle quadrant 3. */
#define GFX_QUADRANT3 (GFX_OCTANT6 | GFX_OCTANT7)
/** Bitmask for drawing left half of circle. */
#define GFX_LEFTHALF (GFX_QUADRANT3 | GFX_QUADRANT0)
/** Bitmask for drawing top half of circle. */
#define GFX_TOPHALF (GFX_QUADRANT0 | GFX_QUADRANT1)
/** Bitmask for drawing right half of circle. */
#define GFX_RIGHTHALF (GFX_QUADRANT1 | GFX_QUADRANT2)
/** Bitmask for drawing bottom half of circle. */
#define GFX_BOTTOMHALF (GFX_QUADRANT2 | GFX_QUADRANT3)
/** Bitmask for drawing whole circle. */
#define GFX_WHOLE 0xFF
/** @} */
/** \name Graphic Drawing Primitives */
/** @{ */
/**
* \def gfx_mono_draw_horizontal_line(x, y, length, color)
* \brief Draw a horizontal line, one pixel wide.
*
* \param[in] x X coordinate of leftmost pixel.
* \param[in] y Y coordinate of the line.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/
/**
* \def gfx_mono_draw_vertical_line(x, y, length, color)
* \brief Draw a vertical line, one pixel wide.
*
* \param[in] x X coordinate of the line.
* \param[in] y Y coordinate of the topmost pixel.
* \param[in] length Length of the line in pixels.
* \param[in] color Pixel operation of the line.
*/
/**
* \def gfx_mono_draw_line(x1, y1, x2, y2, color)
* \brief Draw a line between two arbitrary points.
*
* \param[in] x1 Start X coordinate.
* \param[in] y1 Start Y coordinate.
* \param[in] x2 End X coordinate.
* \param[in] y2 End Y coordinate.
* \param[in] color Pixel operation of the line.
*/
/**
* \def gfx_mono_draw_rect(x, y, width, height, color)
* \brief Draw an outline of a rectangle.
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line.
*/
/**
* \def gfx_mono_draw_filled_rect(x, y, width, height, color)
* \brief Draw a filled rectangle.
*
* \param[in] x X coordinate of the left side.
* \param[in] y Y coordinate of the top side.
* \param[in] width Width of the rectangle.
* \param[in] height Height of the rectangle.
* \param[in] color Pixel operation of the line
*/
/**
* \def gfx_mono_draw_circle(x, y, radius, color, octant_mask)
* \brief Draw an outline of a circle or arc.
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The octant_mask parameter is a bitmask that decides which octants of
* the circle to draw. Use the GFX_OCTANTn, GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] octant_mask Bitmask indicating which octants to draw.
*/
/**
* \def gfx_mono_draw_filled_circle(x, y, radius, color, quadrant_mask)
* \brief Draw a filled circle or sector.
*
* The radius is the distance from the center to the circumference,
* which means that the total width or height of a circle will be
* (radius*2+1).
*
* The quadrant_mask parameter is a bitmask that decides which quadrants
* of the circle to draw. Use the GFX_QUADRANTn, GFX_xHALF and
* GFX_WHOLE constants and OR them together if required. Radius equal to
* zero gives a single pixel.
*
* \note This function only supports quadrants while gfx_draw_circle()
* supports octants. This is to improve performance on drawing
* filled circles.
*
* \param[in] x X coordinate of center.
* \param[in] y Y coordinate of center.
* \param[in] radius Circle radius in pixels.
* \param[in] color Pixel operation.
* \param[in] quadrant_mask Bitmask indicating which quadrants to draw.
*/
/** @} */
/** @} */
/**
* \page asfdoc_common2_gfx_mono_quickstart Quick Start Guide for the mono graphics service
*
* This is the quick start guide for the \ref asfdoc_common2_gfx_mono "Monochrome Graphics service",
* with step-by-step instructions on how to configure and use it for a specific
* use case.
*
* \section asfdoc_common2_gfx_mono_quickstart_basic Basic usage of the graphics service
* This use case will demonstrate initializing the mono graphics service and
* then draw a black line on the screen from coordinates X=10, Y=10 to X=20,
* Y=20.
*
* \section asfdoc_common2_gfx_mono_basic_usage Usage steps
* \subsection asfdoc_common2_gfx_mono_basic_usage_code Example code
* Add to, e.g., the main function in the application C-file:
* \code
system_init();
gfx_mono_init();
gfx_mono_draw_line(10, 10, 20, 20, GFX_PIXEL_SET);
\endcode
*
* \subsection gfx_mono_basic_usage_workflow Workflow
* -# Initialize system:
* - \code system_init(); \endcode
* -# Initialize monochrome graphics service
* - \code gfx_mono_init(); \endcode
* - \note This will call the init function for the low level display
* controller driver and intialize the screen to a cleared background.
* -# Draw a line from 10,10 to 20,20:
* - \code gfx_mono_draw_line(10, 10, 20, 20, GFX_PIXEL_SET); \endcode
* - \note This uses GFX_PIXEL_SET to set the display pixels on the line;
* other options can be found in \ref gfx_mono_color.
*/
/**
* \page asfdoc_common2_gfx_mono_exqsg Examples for GFX Mono Library
*
* This is a list of the available Quick Start guides (QSGs) and example applications
* for \ref asfdoc_common2_gfx_mono. QSGs are simple examples with step-by-step instructions
* to configure and use this driver in a selection of use cases. Note that QSGs can be compiled as
* a standalone application or be added to the user application.
* - \subpage asfdoc_common2_gfx_mono_quickstart
* - \subpage asfdoc_common2_gfx_mono_font_quickstart
* - \subpage asfdoc_common2_gfx_mono_sysfont_example
* - \subpage asfdoc_common2_gfx_mono_spinner_example
*
*/
#endif /* GFX_MONO_H */
|