Graphic Display v1.0.0
Control any mochrome display, with any microcontroller, in any amount.
Loading...
Searching...
No Matches
GraphicDisplay.h
Go to the documentation of this file.
1
21#ifndef GRAPHICDISPLAY_H_
22#define GRAPHICDISPLAY_H_
23
24
25/*
26 * Includes
27 */
28
29#include <assert.h>
30#include <math.h>
31#include <stdint.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <stddef.h>
35#include <stdbool.h>
36#include <string.h>
37
40
41/*
42 * Check if gd_config.h exists, otherwise, we load a 'default' configuration
43 *
44 * NOTE: Some compilers can`t support this directive, but the following list can support.
45 * Clang
46 * GCC from 5.X
47 * Visual Studio from VS2015 Update 2
48 *
49 * If your compiler give an error in this line, insert the NO_SUPPORT_FOR_HAS_INCLUDED
50 * in the preprocessor of your compiler and you need to create the "gd_config.h" header file
51 */
52#ifndef NO_SUPPORT_FOR_HAS_INCLUDED
53 #if __has_include("gd_config.h")
54 #include "gd_config.h"
55 #else
56 #define GD_INCLUDE_FONT_6x8
57 #define GD_INCLUDE_FONT_7x10
58 #define GD_INCLUDE_FONT_11x18
59 #define GD_INCLUDE_FONT_16x26
60 #define GD_INCLUDE_FONT_16x24
61 #define GD_INCLUDE_FONT_16x15
62 #endif
63#else
64 #include "gd_config.h"
65#endif
66
67/*
68 * Macros
69 */
70
71/*
72 * Enumerates
73 */
74
80typedef enum{
84
94
95/*
96 * Structs
97 */
98
105typedef void (*fxnGd_mtxLock)(void);
106
112typedef void (*fxnGd_mtxUnlock)(void);
113
229typedef struct{
231 void* pHandle;
232
244 uint8_t (*fxnSetPixelColor)(void* handle, uint32_t x, uint32_t y, uint8_t color);
245
254 uint8_t (*fxnFillFrameBuffer)(void* handle, uint8_t color);
255
264 uint8_t (*fxnRefreshDisp)(void* handle);
265
274 uint8_t (*fxnSetOn)(void* handle, bool on);
275
286 uint8_t (*fxnSetContrast)(void* handle, uint8_t value);
287
289
300typedef struct {
302 const uint8_t width;
304 const uint8_t height;
306 const uint16_t *const data;
308 const uint8_t *const char_width;
309}gd_font_t;
310
318typedef struct{
320 uint32_t x;
322 uint32_t y;
324
332typedef struct{
334 uint32_t u32Height;
336 uint32_t u32Width;
337
346
350
351 struct t_intern{
354 uint32_t u32BufferLen;
357 uint32_t u32CurrX;
360 uint32_t u32CurrY;
367 }_intern;
368}gd_t;
369
418
419/*
420 * Externs
421 */
422
437/*
438 * Publics
439 */
440
455gd_error_e GD_Init(gd_t *Gd, gd_params_t *params);
456
466
475
486gd_error_e GD_DrawPixel(gd_t *Gd, uint32_t x, uint32_t y, gd_color_e color);
487
498gd_error_e GD_WriteChar(gd_t *Gd, char ch, const gd_font_t *Font, gd_color_e color);
499
510gd_error_e GD_WriteString(gd_t *Gd, char* str, const gd_font_t *Font, gd_color_e color);
511
521gd_error_e GD_SetCursor(gd_t *Gd, uint32_t x, uint32_t y);
522
535gd_error_e GD_Line(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_color_e color);
536
550gd_error_e GD_DrawArc(gd_t *Gd, uint32_t x, uint32_t y, uint32_t radius, uint16_t start_angle, uint16_t sweep, gd_color_e color);
551
565gd_error_e GD_DrawArcWithRadiusLine(gd_t *Gd, uint32_t x, uint32_t y, uint32_t radius, uint16_t start_angle, uint16_t sweep, gd_color_e color);
566
567
579gd_error_e GD_DrawCircle(gd_t *Gd, uint32_t par_x, uint32_t par_y, uint32_t par_r, gd_color_e color);
580
581
593gd_error_e GD_FillCircle(gd_t *Gd, uint32_t par_x,uint32_t par_y,uint32_t par_r,gd_color_e par_color);
594
607gd_error_e GD_Polyline(gd_t *Gd, gd_vertex_t *par_vertex, uint16_t par_size, gd_color_e color);
608
623gd_error_e GD_DrawRectangle(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_color_e color);
624
637gd_error_e GD_FillRectangle(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_error_e color);
638
658gd_error_e GD_DrawBitmap(gd_t *Gd, uint32_t x, uint32_t y, const unsigned char* bitmap, uint32_t w, uint32_t h, gd_color_e color);
659
669gd_error_e GD_SetContrast(gd_t *Gd, const uint8_t value);
670
679gd_error_e GD_SetDisplayOn(gd_t *Gd, bool on);
680
688bool GD_GetDisplayOn(gd_t *Gd);
689
694#endif /* GRAPHICDISPLAY_H_ */
void(* fxnGd_mtxUnlock)(void)
Unlock the mutex after use on threadsafe need operations.
Definition GraphicDisplay.h:112
gd_color_e
Defines the pixel color of the display we want to write.
Definition GraphicDisplay.h:90
@ GD_BLACK
Definition GraphicDisplay.h:91
@ GD_WHITE
Definition GraphicDisplay.h:92
gd_error_e
Errors that can be generated by library.
Definition GraphicDisplay.h:80
@ GD_OK
Definition GraphicDisplay.h:81
@ GD_FAIL
Definition GraphicDisplay.h:82
void(* fxnGd_mtxLock)(void)
Locks the mutex to prevent overrun and conflicts over threads in RTOS environments.
Definition GraphicDisplay.h:105
gd_driver_t * Gd_Driver_SSD1306
SSD1306 Display Driver pointer.
Definition GraphicDisplay.c:37
gd_driver_t * Gd_Driver_ST7920
ST7920 Display Driver poointer.
Definition GraphicDisplay.c:48
gd_error_e GD_SetContrast(gd_t *Gd, const uint8_t value)
Set the contrast of the display, if are supported. If display doesn't have this routine,...
Definition GraphicDisplay.c:574
gd_error_e GD_Init(gd_t *Gd, gd_params_t *params)
Initializes the Graphic Display module, configured with the parameters provided.
Definition GraphicDisplay.c:117
gd_error_e GD_SetDisplayOn(gd_t *Gd, bool on)
Set display On or Off, if the display implements this routine.
Definition GraphicDisplay.c:583
gd_error_e GD_DrawArc(gd_t *Gd, uint32_t x, uint32_t y, uint32_t radius, uint16_t start_angle, uint16_t sweep, gd_color_e color)
Draw an arc into the frame buffer with center, radius, start angle, and sweep.
Definition GraphicDisplay.c:334
gd_error_e GD_DrawCircle(gd_t *Gd, uint32_t par_x, uint32_t par_y, uint32_t par_r, gd_color_e color)
Draw a complete circle with defined radius.
Definition GraphicDisplay.c:440
gd_error_e GD_WriteChar(gd_t *Gd, char ch, const gd_font_t *Font, gd_color_e color)
Write a character into a Frame Buffer, with the lines with the desired color.
Definition GraphicDisplay.c:205
gd_error_e GD_Line(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_color_e color)
Write a line into the frame buffer between (x1,y1) (x2,y2).
Definition GraphicDisplay.c:281
gd_error_e GD_Polyline(gd_t *Gd, gd_vertex_t *par_vertex, uint16_t par_size, gd_color_e color)
Draw a polyline, composed by staigth lines connecting the points given by vertex array.
Definition GraphicDisplay.c:311
gd_error_e GD_Fill(gd_t *Gd, gd_color_e color)
Fill the Frame Buffer with the provided color.
Definition GraphicDisplay.c:148
gd_error_e GD_DrawBitmap(gd_t *Gd, uint32_t x, uint32_t y, const unsigned char *bitmap, uint32_t w, uint32_t h, gd_color_e color)
Draw a bitmap into the Frame Buffer. The bitmap is an array with the pixels on/off.
Definition GraphicDisplay.c:542
gd_error_e GD_SetCursor(gd_t *Gd, uint32_t x, uint32_t y)
Set the cursor to the position X,Y.
Definition GraphicDisplay.c:264
gd_error_e GD_DrawRectangle(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_color_e color)
Draw a Rectangle between the position (x1,y1) and (x2,y2). The rectangle is not filled,...
Definition GraphicDisplay.c:509
gd_error_e GD_DrawArcWithRadiusLine(gd_t *Gd, uint32_t x, uint32_t y, uint32_t radius, uint16_t start_angle, uint16_t sweep, gd_color_e color)
Draw an arc into frame buffer with lines in the radius line.
Definition GraphicDisplay.c:382
bool GD_GetDisplayOn(gd_t *Gd)
Gets the display On/Off state.
Definition GraphicDisplay.c:593
gd_error_e GD_FillRectangle(gd_t *Gd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, gd_error_e color)
Draw a filled rectangle between the pointes (x1,y1) and (x2,y2).
Definition GraphicDisplay.c:522
gd_error_e GD_UpdateScreen(gd_t *Gd)
Update and refresh the update screen with the data into Frame Buffer.
Definition GraphicDisplay.c:160
gd_error_e GD_DrawPixel(gd_t *Gd, uint32_t x, uint32_t y, gd_color_e color)
Write a color into the desired pixel in the frame buffer.
Definition GraphicDisplay.c:177
gd_error_e GD_FillCircle(gd_t *Gd, uint32_t par_x, uint32_t par_y, uint32_t par_r, gd_color_e par_color)
Draw a circle filled with the provided color.
Definition GraphicDisplay.c:474
gd_error_e GD_WriteString(gd_t *Gd, char *str, const gd_font_t *Font, gd_color_e color)
Write a string into frame buffer, with the character lines with the desired color.
Definition GraphicDisplay.c:249
Driver for ST7920 display driver. This library needs you to implement interface control,...
Struct that creates a driver for the display, holding the handle and functions that are private of th...
Definition GraphicDisplay.h:229
void * pHandle
Handle of the display. The variable that holds all data of device.
Definition GraphicDisplay.h:231
Structure to holds Fonts. The default fonts are defined in GraphicDisplay_Fonts.h....
Definition GraphicDisplay.h:300
const uint8_t *const char_width
Definition GraphicDisplay.h:308
const uint8_t width
Font width in pixels.
Definition GraphicDisplay.h:302
const uint16_t *const data
Proportional character width in pixels (NULL for monospaced)
Definition GraphicDisplay.h:306
const uint8_t height
Pointer to font data array.
Definition GraphicDisplay.h:304
Parameters to initialize the Graphic Display Handler.
Definition GraphicDisplay.h:375
uint32_t u32Height
The Heigth of the display, in lines.
Definition GraphicDisplay.h:401
gd_driver_t * DisplayDriver
Driver for the display. External Drivers Already Implemented.
Definition GraphicDisplay.h:396
fxnGd_mtxLock mtxLock
mutex lock function pointer.
Definition GraphicDisplay.h:411
uint32_t u32Width
The Width of the display, in columns.
Definition GraphicDisplay.h:406
void * DisplayHandle
Handle of the display, provide the pointer of this handler. Example fort ssd1306 display:
Definition GraphicDisplay.h:392
fxnGd_mtxUnlock mtxUnlock
mutex unlock function pointer.
Definition GraphicDisplay.h:416
Definition GraphicDisplay.h:338
fxnGd_mtxLock mtxLock
mutex lock function pointer.
Definition GraphicDisplay.h:341
fxnGd_mtxUnlock mtxUnlock
mutex unlock function pointer.
Definition GraphicDisplay.h:344
Definition GraphicDisplay.h:351
bool bDisplayOn
Boolean to save display state.
Definition GraphicDisplay.h:363
uint32_t u32BufferLen
Size of the Frame Buffer display.
Definition GraphicDisplay.h:354
bool bInitialized
Boolean to tell if Graphic Display handler is initialized.
Definition GraphicDisplay.h:366
uint32_t u32CurrX
Current X display position.
Definition GraphicDisplay.h:357
uint32_t u32CurrY
Current Y display position.
Definition GraphicDisplay.h:360
Handler of Graphic Display. Each display must need your own handler. Yes, this library supports multi...
Definition GraphicDisplay.h:332
gd_driver_t * disp
Display driver, that contains the Handler and routines.
Definition GraphicDisplay.h:349
uint32_t u32Width
Display width in columns. Must be the same of display device.
Definition GraphicDisplay.h:336
uint32_t u32Height
Display height in Lines. Must be the same of display device.
Definition GraphicDisplay.h:334
Structure used to support the creation of polylines. In normal use, this is declared as an array,...
Definition GraphicDisplay.h:318
uint32_t y
point in Y axis
Definition GraphicDisplay.h:322
uint32_t x
point in X axis
Definition GraphicDisplay.h:320