libpynq  (release 5EID0-2023 version 0.3.0 of 2024-04-25 09:42 )
display.h
Go to the documentation of this file.
1 /*
2 MIT License
3 
4 Copyright (c) 2020
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 
24 Modified by Eindhoven University of Technology 2023.
25 */
26 #ifndef SCREEN_H
27 #define SCREEN_H
28 
29 #include <fontx.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <string.h>
34 
83 #define DISPLAY_HEIGHT 240
84 #define DISPLAY_WIDTH 240
85 
89 enum colors {
90  RGB_RED = 0xf800,
91  RGB_GREEN = 0x07e0,
92  RGB_BLUE = 0x001f,
93  RGB_BLACK = 0x0000,
94  RGB_WHITE = 0xffff,
95  RGB_GRAY = 0x8c51,
96  RGB_YELLOW = 0xFFE0,
97  RGB_CYAN = 0x07FF,
98  RGB_PURPLE = 0xF81F
99 };
100 
110 };
111 
116 typedef struct {
117  uint16_t _width;
118  uint16_t _height;
119  uint16_t _offsetx;
120  uint16_t _offsety;
121  uint16_t _font_direction;
122  uint16_t _font_fill;
124  uint16_t _font_underline;
126  int16_t _dc;
127  int16_t _bl;
128 } display_t;
129 
134 extern void display_init(display_t *display);
135 
140 extern void display_destroy(display_t *display);
141 
149 extern void displayDrawPixel(display_t *display, uint16_t x, uint16_t y,
150  uint16_t color);
151 
161 extern void displayDrawFillRect(display_t *display, uint16_t x1, uint16_t y1,
162  uint16_t x2, uint16_t y2, uint16_t color);
163 
170 extern void displayFillScreen(display_t *display, uint16_t color);
171 
181 extern void displayDrawLine(display_t *display, uint16_t x1, uint16_t y1,
182  uint16_t x2, uint16_t y2, uint16_t color);
183 
193 extern void displayDrawRect(display_t *display, uint16_t x1, uint16_t y1,
194  uint16_t x2, uint16_t y2, uint16_t color);
195 
208 extern void displayDrawRectAngle(display_t *display, uint16_t xc, uint16_t yc,
209  uint16_t w, uint16_t h, uint16_t angle,
210  uint16_t color);
211 
222 extern void displayDrawTriangleCenter(display_t *display, uint16_t xc,
223  uint16_t yc, uint16_t w, uint16_t h,
224  uint16_t angle, uint16_t color);
225 
234 extern void displayDrawCircle(display_t *display, uint16_t x_center,
235  uint16_t y_center, uint16_t r, uint16_t color);
236 
245 extern void displayDrawFillCircle(display_t *display, uint16_t x_center,
246  uint16_t y_center, uint16_t r,
247  uint16_t color);
248 
259 extern void displayDrawRoundRect(display_t *display, uint16_t x1, uint16_t y1,
260  uint16_t x2, uint16_t y2, uint16_t r,
261  uint16_t color);
262 
269 extern uint16_t rgb_conv(uint16_t r, uint16_t g, uint16_t b);
270 
285 extern int displayDrawChar(display_t *display, FontxFile *fx, uint16_t x,
286  uint16_t y, uint8_t ascii, uint16_t color);
287 
303 extern int displayDrawString(display_t *display, FontxFile *fx, uint16_t x,
304  uint16_t y, uint8_t *ascii, uint16_t color);
305 
311 extern void displaySetFontDirection(display_t *display, uint16_t dir);
312 
319 extern void displaySetFontFill(display_t *display, uint16_t color);
320 
327 extern void displayUnsetFontFill(display_t *display);
328 
336 extern void displaySetFontUnderLine(display_t *display, uint16_t color);
337 
342 extern void displayUnsetFontUnderLine(display_t *display);
343 
348 extern void displayDisplayOff(display_t *display);
349 
358 extern void displayDisplayOn(display_t *display);
359 
364 extern void displayBacklightOff(display_t *display);
365 
370 extern void displayBacklightOn(display_t *display);
371 
376 extern void displayInversionOff(display_t *display);
377 
382 extern void displayInversionOn(display_t *display);
383 
397 extern void displayDrawTriangle(display_t *display, uint16_t x1, uint16_t y1,
398  uint16_t x2, uint16_t y2, uint16_t x3,
399  uint16_t y3, uint16_t color);
400 
407 void display_set_flip(display_t *display, bool xflip, bool yflip);
412 #endif /* MAIN_ST7789_H_ */
display_t
Internal type, do not use. Type of display that stores parameters for usage in different functions.
Definition: display.h:116
RGB_GREEN
@ RGB_GREEN
Definition: display.h:91
displayDisplayOn
void displayDisplayOn(display_t *display)
Initialize DISPLAY screen.
Definition: display.c:413
display_t::_height
uint16_t _height
Definition: display.h:118
displayBacklightOff
void displayBacklightOff(display_t *display)
Turn off the display backlight.
Definition: display.c:1017
RGB_CYAN
@ RGB_CYAN
Definition: display.h:97
displayInversionOn
void displayInversionOn(display_t *display)
Turn on inversion of the colors.
Definition: display.c:1042
RGB_YELLOW
@ RGB_YELLOW
Definition: display.h:96
displaySetFontFill
void displaySetFontFill(display_t *display, uint16_t color)
Enables the _font_fill and sets the _font_fill_color in the display handle.
Definition: display.c:992
display_t::_bl
int16_t _bl
Definition: display.h:127
display_destroy
void display_destroy(display_t *display)
Stop using the display.
Definition: display.c:3
displayDrawCircle
void displayDrawCircle(display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
Draw a circle without infill on the display.
Definition: display.c:624
display_t::_font_underline
uint16_t _font_underline
Definition: display.h:124
displaySetFontDirection
void displaySetFontDirection(display_t *display, uint16_t dir)
Changes the direction the characters will be printed.
Definition: display.c:985
displayDrawRectAngle
void displayDrawRectAngle(display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
Draws a rectangle with rounded corners at a specified angle on the display.
Definition: display.c:499
display_t::_offsetx
uint16_t _offsetx
Definition: display.h:119
displayUnsetFontFill
void displayUnsetFontFill(display_t *display)
Sets the _font_fill parameter to false in the display handle, turns off the font fill.
Definition: display.c:1000
RGB_WHITE
@ RGB_WHITE
Definition: display.h:94
displayUnsetFontUnderLine
void displayUnsetFontUnderLine(display_t *display)
Turns off _font_underline in the display handle.
Definition: display.c:1010
directions
directions
Enum of directions the text can be printed on on the display.
Definition: display.h:104
display_init
void display_init(display_t *display)
Initialize the display display.
Definition: display.c:301
display_t::_font_underline_color
uint16_t _font_underline_color
Definition: display.h:125
rgb_conv
uint16_t rgb_conv(uint16_t r, uint16_t g, uint16_t b)
RGB conversion for generating a color.
Definition: display.c:781
RGB_BLACK
@ RGB_BLACK
Definition: display.h:93
TEXT_DIRECTION180
@ TEXT_DIRECTION180
Definition: display.h:107
RGB_RED
@ RGB_RED
Definition: display.h:90
displayInversionOff
void displayInversionOff(display_t *display)
Turn off inversion of the colors.
Definition: display.c:1035
RGB_BLUE
@ RGB_BLUE
Definition: display.h:92
displayBacklightOn
void displayBacklightOn(display_t *display)
Turn on the display backlight.
Definition: display.c:1026
TEXT_DIRECTION0
@ TEXT_DIRECTION0
Definition: display.h:105
displayDrawRect
void displayDrawRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a filled rectangle.
Definition: display.c:481
displayDrawTriangleCenter
void displayDrawTriangleCenter(display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
Draws a triangle at a specified angle on the display.
Definition: display.c:583
display_t::_font_fill_color
uint16_t _font_fill_color
Definition: display.h:123
display_set_flip
void display_set_flip(display_t *display, bool xflip, bool yflip)
Flip the drawing off the screen.
Definition: display.c:279
display_t::_width
uint16_t _width
Definition: display.h:117
FontxFile
Struct representing a font file.
Definition: fontx.h:28
RGB_PURPLE
@ RGB_PURPLE
Definition: display.h:98
NUM_TEXT_DIRECTIONS
@ NUM_TEXT_DIRECTIONS
Definition: display.h:109
TEXT_DIRECTION90
@ TEXT_DIRECTION90
Definition: display.h:106
displayDrawLine
void displayDrawLine(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a line from two coordinates.
Definition: display.c:428
colors
colors
Colors that can be used with the display.
Definition: display.h:89
TEXT_DIRECTION270
@ TEXT_DIRECTION270
Definition: display.h:108
displayDisplayOff
void displayDisplayOff(display_t *display)
Turn off the display.
Definition: display.c:406
displayFillScreen
void displayFillScreen(display_t *display, uint16_t color)
Fill entire display with a single color using the ldcDrawFillRect function.
Definition: display.c:420
display_t::_font_direction
uint16_t _font_direction
Definition: display.h:121
displaySetFontUnderLine
void displaySetFontUnderLine(display_t *display, uint16_t color)
Turns on _font_underline in the display handle and sets the _font_underline_color to the specified co...
Definition: display.c:1002
RGB_GRAY
@ RGB_GRAY
Definition: display.h:95
fontx.h
displayDrawTriangle
void displayDrawTriangle(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color)
Draw a triangle without infill between the three given points in the given color.
Definition: display.c:556
displayDrawRoundRect
void displayDrawRoundRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color)
Draw a rectangle with rounded angles.
Definition: display.c:711
displayDrawFillRect
void displayDrawFillRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a filled rectangle to the display.
Definition: display.c:364
display_t::_font_fill
uint16_t _font_fill
Definition: display.h:122
displayDrawPixel
void displayDrawPixel(display_t *display, uint16_t x, uint16_t y, uint16_t color)
Draw a single pixel to the display.
Definition: display.c:320
display_t::_dc
int16_t _dc
Definition: display.h:126
displayDrawFillCircle
void displayDrawFillCircle(display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
Draw a circle with infill on the display.
Definition: display.c:665
display_t::_offsety
uint16_t _offsety
Definition: display.h:120
displayDrawChar
int displayDrawChar(display_t *display, FontxFile *fx, uint16_t x, uint16_t y, uint8_t ascii, uint16_t color)
Draws a character on the given coordinates of the display.
Definition: display.c:785
displayDrawString
int displayDrawString(display_t *display, FontxFile *fx, uint16_t x, uint16_t y, uint8_t *ascii, uint16_t color)
Function to draw a string on the display.
Definition: display.c:954