EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
glib.h
Go to the documentation of this file.
1  /*************************************************************************/
16 #ifndef __GLIB_H
17 #define __GLIB_H
18 
19 /***************************************************************************/
168 /* C-header files */
169 #include <stdint.h>
170 #include <stdbool.h>
171 #include <stdlib.h>
172 
173 /* GLIB header files */
174 #include "glib_color.h"
175 
176 /* Display Driver header files */
177 #include "dmd/dmd.h"
178 
179 #include "em_types.h"
180 
181 #ifdef __cplusplus
182 extern "C" {
183 #endif
184 
186 #define ECODE_GLIB_BASE 0x00000000
187 
188 /* Error codes */
190 #define GLIB_OK 0x00000000
191 
192 #define GLIB_ERROR_NOTHING_TO_DRAW (ECODE_GLIB_BASE | 0x0001)
193 
194 #define GLIB_ERROR_INVALID_CHAR (ECODE_GLIB_BASE | 0x0002)
195 
196 #define GLIB_OUT_OF_BOUNDS (ECODE_GLIB_BASE | 0x0003)
197 
198 #define GLIB_ERROR_INVALID_CLIPPINGREGION (ECODE_GLIB_BASE | 0x0004)
199 
200 #define GLIB_ERROR_INVALID_ARGUMENT (ECODE_GLIB_BASE | 0x0005)
201 
202 #define GLIB_ERROR_OUT_OF_MEMORY (ECODE_GLIB_BASE | 0x0006)
203 
204 #define GLIB_ERROR_FILE_NOT_SUPPORTED (ECODE_GLIB_BASE | 0x0007)
205 
206 #define GLIB_ERROR_IO (ECODE_GLIB_BASE | 0x0008)
207 
208 #define GLIB_ERROR_INVALID_FILE (ECODE_GLIB_BASE | 0x0009)
209 
210 
213 typedef enum __GLIB_Font_Class
214 {
219 
220 
223 typedef struct __GLIB_Font_t
224 {
226  void *pFontPixMap;
227 
230 
233 
235  uint8_t fontRowOffset;
236 
238  uint8_t fontWidth;
239 
241  uint8_t fontHeight;
242 
244  uint8_t lineSpacing;
245 
247  uint8_t charSpacing;
248 
252 } GLIB_Font_t;
253 
254 
257 typedef struct __GLIB_Rectangle_t
258 {
260  int32_t xMin;
262  int32_t yMin;
264  int32_t xMax;
266  int32_t yMax;
268 
269 
273 typedef struct __GLIB_Context_t
274 {
276  const DMD_DisplayGeometry *pDisplayGeometry;
277 
279  uint32_t backgroundColor;
280 
282  uint32_t foregroundColor;
283 
286 
289 
291 
292 
293 /* Prototypes for graphics library functions */
294 EMSTATUS GLIB_contextInit(GLIB_Context_t *pContext);
295 
296 EMSTATUS GLIB_displayWakeUp(void);
297 
298 EMSTATUS GLIB_displaySleep(void);
299 
300 EMSTATUS GLIB_clear(GLIB_Context_t *pContext);
301 
302 EMSTATUS GLIB_clearRegion(const GLIB_Context_t *pContext);
303 
305 
306 EMSTATUS GLIB_resetClippingRegion(GLIB_Context_t *pContext);
307 
308 EMSTATUS GLIB_applyClippingRegion(const GLIB_Context_t *pContext);
309 
310 void GLIB_colorTranslate24bpp(uint32_t color, uint8_t *red, uint8_t *green, uint8_t *blue);
311 
312 uint32_t GLIB_rgbColor(uint8_t red, uint8_t green, uint8_t blue);
313 
314 bool GLIB_rectContainsPoint(const GLIB_Rectangle_t *pRect, int32_t xCenter, int32_t yCenter);
315 
317 
318 EMSTATUS GLIB_setClippingRegion(GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect);
319 
320 EMSTATUS GLIB_drawCircle(GLIB_Context_t *pContext, int32_t x, int32_t y,
321  uint32_t radius);
322 
323 EMSTATUS GLIB_drawCircleFilled(GLIB_Context_t *pContext, int32_t x, int32_t y,
324  uint32_t radius);
325 
326 EMSTATUS GLIB_drawPartialCircle(GLIB_Context_t *pContext, int32_t xCenter,
327  int32_t yCenter, uint32_t radius, uint8_t bitMask);
328 
329 EMSTATUS GLIB_setFont(GLIB_Context_t *pContext, GLIB_Font_t *pFont);
330 
331 EMSTATUS GLIB_drawString(GLIB_Context_t *pContext, const char* pString, uint32_t sLength,
332  int32_t x0, int32_t y0, bool opaque);
333 
334 EMSTATUS GLIB_drawChar(GLIB_Context_t *pContext, char myChar, int32_t x,
335  int32_t y, bool opaque);
336 
337 EMSTATUS GLIB_drawBitmap(GLIB_Context_t* pContext, int32_t x, int32_t y,
338  uint32_t width, uint32_t height, const uint8_t *picData);
339 
340 EMSTATUS GLIB_drawLine(GLIB_Context_t *pContext, int32_t x1, int32_t y1,
341  int32_t x2, int32_t y2);
342 
343 EMSTATUS GLIB_drawLineH(GLIB_Context_t *pContext, int32_t x1, int32_t y1,
344  int32_t x2);
345 
346 EMSTATUS GLIB_drawLineV(GLIB_Context_t *pContext, int32_t x1, int32_t y1,
347  int32_t y2);
348 
349 EMSTATUS GLIB_drawRect(GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect);
350 
351 EMSTATUS GLIB_drawRectFilled(GLIB_Context_t *pContext,
352  const GLIB_Rectangle_t *pRect);
353 
354 EMSTATUS GLIB_drawPolygon(GLIB_Context_t *pContext,
355  uint32_t numPoints, const int32_t *polyPoints);
356 
357 EMSTATUS GLIB_drawPixelRGB(GLIB_Context_t *pContext, int32_t x, int32_t y,
358  uint8_t red, uint8_t green, uint8_t blue);
359 
360 EMSTATUS GLIB_drawPixel(GLIB_Context_t *pContext, int32_t x, int32_t y);
361 
362 EMSTATUS GLIB_drawPixelColor(GLIB_Context_t *pContext, int32_t x, int32_t y,
363  uint32_t color);
364 
365 /* Fonts included in the library */
366 extern const GLIB_Font_t GLIB_FontNormal8x8; /* Default */
367 extern const GLIB_Font_t GLIB_FontNarrow6x8;
368 extern const GLIB_Font_t GLIB_FontNumber16x20;
369 
372 #ifdef __cplusplus
373 }
374 #endif
375 
376 #endif
EMSTATUS GLIB_drawPolygon(GLIB_Context_t *pContext, uint32_t numPoints, const int32_t *polyPoints)
Draws a polygon using Bresnham's Midpoint Line Algorithm.
Definition: glib_polygon.c:46
EMSTATUS GLIB_drawCircle(GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t radius)
Draws a circle with center at x, y, and a radius.
Definition: glib_circle.c:51
int32_t yMax
Definition: glib.h:266
int32_t yMin
Definition: glib.h:262
EMSTATUS GLIB_drawLineV(GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t y2)
Draws a vertical line from x1, y1 to x1, y2.
Definition: glib_line.c:113
EMSTATUS GLIB_drawRect(GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
Draws a rectangle outline defined by the passed in rectangle.
Font definition structure.
Definition: glib.h:223
const DMD_DisplayGeometry * pDisplayGeometry
Definition: glib.h:276
EMSTATUS GLIB_resetDisplayClippingArea(GLIB_Context_t *pContext)
Reset the display driver clipping area to the whole display.
Definition: glib.c:236
Rectangle structure.
Definition: glib.h:257
EMSTATUS GLIB_drawRectFilled(GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
Draws a filled rectangle defined by the passed in rectangle. The filled rectangle is drawn from (xMin...
const GLIB_Font_t GLIB_FontNarrow6x8
Narrow 6x8 pixels font containing characters and numbers.
EMSTATUS GLIB_drawPartialCircle(GLIB_Context_t *pContext, int32_t xCenter, int32_t yCenter, uint32_t radius, uint8_t bitMask)
Draws a partial circle with center at x, y, and a radius.
Definition: glib_circle.c:84
void * pFontPixMap
Definition: glib.h:226
struct __GLIB_Rectangle_t GLIB_Rectangle_t
Rectangle structure.
EMSTATUS GLIB_drawPixelRGB(GLIB_Context_t *pContext, int32_t x, int32_t y, uint8_t red, uint8_t green, uint8_t blue)
Draws a pixel at x, y with color defined by red, green and blue 1 byte per channel.
Definition: glib.c:421
Definition: glib.h:216
uint16_t cntOfMapElements
Definition: glib.h:229
EMSTATUS GLIB_drawString(GLIB_Context_t *pContext, const char *pString, uint32_t sLength, int32_t x0, int32_t y0, bool opaque)
Draws a string using the font supplied with the library.
Definition: glib_string.c:166
EMSTATUS GLIB_displayWakeUp(void)
Returns the display from sleep mode.
Definition: glib.c:97
uint32_t foregroundColor
Definition: glib.h:282
uint8_t fontHeight
Definition: glib.h:241
enum __GLIB_Font_Class GLIB_Font_Class
Font classes.
EMSTATUS GLIB_clear(GLIB_Context_t *pContext)
Clears the display with the background color of the GLIB_Context_t.
Definition: glib.c:163
uint32_t GLIB_rgbColor(uint8_t red, uint8_t green, uint8_t blue)
Convert 3 uint8_t color components into a 24-bit color.
Definition: glib.c:331
void GLIB_colorTranslate24bpp(uint32_t color, uint8_t *red, uint8_t *green, uint8_t *blue)
Extracts the color components from the 32-bit color passed and puts them in the passed in 8-bits ints...
Definition: glib.c:309
uint8_t fontRowOffset
Definition: glib.h:235
EMSTATUS GLIB_drawCircleFilled(GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t radius)
Draws a filled circle with center at x, y, and a radius.
Definition: glib_circle.c:142
GLIB_Font_t font
Definition: glib.h:288
uint8_t fontWidth
Definition: glib.h:238
EMSTATUS GLIB_drawLineH(GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2)
Draws a horizontal line from x1, y1 to x2, y2.
Definition: glib_line.c:49
EMSTATUS GLIB_contextInit(GLIB_Context_t *pContext)
Initialize the GLIB_Context_t.
Definition: glib.c:59
EMSTATUS GLIB_applyClippingRegion(const GLIB_Context_t *pContext)
Apply the clipping region from the GLIB_Context_t in the DMD driver.
Definition: glib.c:278
struct __GLIB_Font_t GLIB_Font_t
Font definition structure.
void GLIB_normalizeRect(GLIB_Rectangle_t *pRect)
Normalize the rectangle that is passed in. Sets yMin to the minimum value of yMin and yMax...
bool GLIB_rectContainsPoint(const GLIB_Rectangle_t *pRect, int32_t xCenter, int32_t yCenter)
Checks if the point passed in is in the interior of the rectangle passed in.
uint8_t sizeOfMapElement
Definition: glib.h:232
struct __GLIB_Context_t GLIB_Context_t
GLIB Drawing Context (Multiple instances of GLIB_Context_t can exist)
__GLIB_Font_Class
Font classes.
Definition: glib.h:213
const GLIB_Font_t GLIB_FontNumber16x20
Large 16x20 pixels font containing only numbers.
EMSTATUS GLIB_drawPixelColor(GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t color)
Draws a pixel at x, y using the color parameter.
Definition: glib.c:381
EMSTATUS GLIB_resetClippingRegion(GLIB_Context_t *pContext)
Reset the GLIB_Context_t clipping region to the whole display.
Definition: glib.c:255
EMSTATUS GLIB_drawPixel(GLIB_Context_t *pContext, int32_t x, int32_t y)
Draws a pixel at x, y using foregroundColor defined in the GLIB_Context_t.
Definition: glib.c:350
Silicon Labs Graphics Library: Color Defines.
EMSTATUS GLIB_setFont(GLIB_Context_t *pContext, GLIB_Font_t *pFont)
Set new font for the library. Note that GLIB defines a default font in glib.c. Redefine GLIB_DEFAULT_...
Definition: glib_string.c:223
int32_t xMax
Definition: glib.h:264
EMSTATUS GLIB_clearRegion(const GLIB_Context_t *pContext)
Clears the clipping region by filling it with the background color of the GLIB_Context_t.
Definition: glib.c:199
EMSTATUS GLIB_drawBitmap(GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t width, uint32_t height, const uint8_t *picData)
Draws a bitmap.
Definition: glib_bitmap.c:51
EMSTATUS GLIB_setClippingRegion(GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
Sets the clippingRegion of the passed in GLIB_Context_t.
Definition: glib.c:131
EMSTATUS GLIB_displaySleep(void)
Sets the display in sleep mode.
Definition: glib.c:110
EMSTATUS GLIB_drawLine(GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
Draws a line from x1,y1 to x2, y2.
Definition: glib_line.c:303
GLIB_Rectangle_t clippingRegion
Definition: glib.h:285
int32_t xMin
Definition: glib.h:260
const GLIB_Font_t GLIB_FontNormal8x8
Normal 8x8 pixels font containing characters and numbers.
uint32_t backgroundColor
Definition: glib.h:279
EMSTATUS GLIB_drawChar(GLIB_Context_t *pContext, char myChar, int32_t x, int32_t y, bool opaque)
Draws a char using the font supplied with the library.
Definition: glib_string.c:51
uint8_t charSpacing
Definition: glib.h:247
uint8_t lineSpacing
Definition: glib.h:244
GLIB Drawing Context (Multiple instances of GLIB_Context_t can exist)
Definition: glib.h:273