libpynq (release 5EWC0-2023 version 0.2.3 of 2023-10-06 18:15)
Loading...
Searching...
No Matches
Display library

Data Structures

struct  display_t
 

Macros

#define DISPLAY_HEIGHT   240
 
#define DISPLAY_WIDTH   240
 

Enumerations

enum  colors {
  RGB_RED = 0xf800 , RGB_GREEN = 0x07e0 , RGB_BLUE = 0x001f , RGB_BLACK = 0x0000 ,
  RGB_WHITE = 0xffff , RGB_GRAY = 0x8c51 , RGB_YELLOW = 0xFFE0 , RGB_CYAN = 0x07FF ,
  RGB_PURPLE = 0xF81F
}
 
enum  directions {
  TEXT_DIRECTION0 = 0 , TEXT_DIRECTION90 = 1 , TEXT_DIRECTION180 = 2 , TEXT_DIRECTION270 = 3 ,
  NUM_TEXT_DIRECTIONS
}
 

Functions

void display_init (display_t *display)
 
void display_destroy (display_t *display)
 
void displayDrawPixel (display_t *display, uint16_t x, uint16_t y, uint16_t color)
 
void displayDrawFillRect (display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void displayFillScreen (display_t *display, uint16_t color)
 
void displayDrawLine (display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void displayDrawRect (display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 
void displayDrawRectAngle (display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
 
void displayDrawTriangleCenter (display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
 
void displayDrawCircle (display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
 
void displayDrawFillCircle (display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
 
void displayDrawRoundRect (display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color)
 
uint16_t rgb_conv (uint16_t r, uint16_t g, uint16_t b)
 
int displayDrawChar (display_t *display, FontxFile *fx, uint16_t x, uint16_t y, uint8_t ascii, uint16_t color)
 
int displayDrawString (display_t *display, FontxFile *fx, uint16_t x, uint16_t y, uint8_t *ascii, uint16_t color)
 
void displaySetFontDirection (display_t *display, uint16_t dir)
 
void displaySetFontFill (display_t *display, uint16_t color)
 
void displayUnsetFontFill (display_t *display)
 
void displaySetFontUnderLine (display_t *display, uint16_t color)
 
void displayUnsetFontUnderLine (display_t *display)
 
void displayDisplayOff (display_t *display)
 
void displayDisplayOn (display_t *display)
 
void displayBacklightOff (display_t *display)
 
void displayBacklightOn (display_t *display)
 
void displayInversionOff (display_t *display)
 
void displayInversionOn (display_t *display)
 
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)
 
void display_set_flip (display_t *display, bool xflip, bool yflip)
 

Detailed Description

Wrappers to simplify the use of the TFT LCD display.

Define a display_t display (called the display "handle"), initialise it, and pass this as the first parameter to all functions.

Warning
All functions fail with program exit if any pixel of the shape that is drawn is outside the display dimensions.

An example of how to use this library.

#include <libpynq.h>
int main (void)
{
// initialise all I/O
display_t display;
display_init(&display);
// drawing is simple
displayDrawPixel(&display, 50, 50, RGB_YELLOW);
displayDrawFillRect(&display, 10, 100, 110, 200, RGB_RED);
displayDrawCircle(&display, 60, 40, 15, RGB_RED);
// text is more involved
FontxFile fx16G[2];
// the font file must be reachable from the directory
// from which the executable is run -- see InitFontx
InitFontx(fx16G, "../../fonts/ILGH16XB.FNT", "");
GetFontx(fx16G, 0, buffer_fx16G, &fontWidth_fx16G, &fontHeight_fx16G);
uint8_t text[] = "hello";
displayDrawString(&display, fx16G, 15, fontHeight_fx16G * 6, text1,
// clean up after use
display_destroy(&display);
return EXIT_SUCCESS;
}
void display_destroy(display_t *display __attribute__((unused)))
Definition display.c:306
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:951
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:361
void displaySetFontDirection(display_t *display, uint16_t dir)
Changes the direction the characters will be printed.
Definition display.c:982
void display_init(display_t *display)
Initialize the display display.
Definition display.c:301
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:621
void displayFillScreen(display_t *display, uint16_t color)
Fill entire display with a single color using the ldcDrawFillRect function.
Definition display.c:417
void displayDrawPixel(display_t *display, uint16_t x, uint16_t y, uint16_t color)
Draw a single pixel to the display.
Definition display.c:317
@ TEXT_DIRECTION0
Definition display.h:105
@ RGB_YELLOW
Definition display.h:96
@ RGB_RED
Definition display.h:90
@ RGB_WHITE
Definition display.h:94
void InitFontx(FontxFile *fxs, const char *f0, const char *f1)
Initializes the given FontxFile structure with the specified font files.
Definition fontx.c:17
bool GetFontx(FontxFile *fxs, uint8_t ascii, uint8_t *pGlyph, uint8_t *pw, uint8_t *ph)
Gets the glyph data for the specified ASCII character.
Definition fontx.c:98
void pynq_init(void)
Initialise the switchbox and GPIO of the PYNQ.
Definition libpynq.c:24
void pynq_destroy(void)
Reset and destroy the switchbox and GPIO of the PYNQ.
Definition libpynq.c:35
Struct representing a font file.
Definition fontx.h:28
Internal type, do not use. Type of display that stores parameters for usage in different functions.
Definition display.h:116

Macro Definition Documentation

◆ DISPLAY_HEIGHT

#define DISPLAY_HEIGHT   240

Definition at line 83 of file display.h.

◆ DISPLAY_WIDTH

#define DISPLAY_WIDTH   240

Definition at line 84 of file display.h.

Enumeration Type Documentation

◆ colors

enum colors

Colors that can be used with the display.

Enumerator
RGB_RED 
RGB_GREEN 
RGB_BLUE 
RGB_BLACK 
RGB_WHITE 
RGB_GRAY 
RGB_YELLOW 
RGB_CYAN 
RGB_PURPLE 

Definition at line 89 of file display.h.

◆ directions

enum directions

Enum of directions the text can be printed on on the display.

Enumerator
TEXT_DIRECTION0 
TEXT_DIRECTION90 
TEXT_DIRECTION180 
TEXT_DIRECTION270 
NUM_TEXT_DIRECTIONS 

Definition at line 104 of file display.h.

Function Documentation

◆ display_destroy()

void display_destroy ( display_t display)

Stop using the display.

Parameters
displayHandle to display.

◆ display_init()

void display_init ( display_t display)

Initialize the display display.

Parameters
displayHandle to display.

Definition at line 301 of file display.c.

Here is the call graph for this function:

◆ display_set_flip()

void display_set_flip ( display_t display,
bool  xflip,
bool  yflip 
)

Flip the drawing off the screen.

Parameters
displayHandle to display
xflipFlip in the X direction
yflipFlip in the Y direction

Definition at line 279 of file display.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayBacklightOff()

void displayBacklightOff ( display_t display)

Turn off the display backlight.

Parameters
displayHandle to display.

Definition at line 1014 of file display.c.

Here is the call graph for this function:

◆ displayBacklightOn()

void displayBacklightOn ( display_t display)

Turn on the display backlight.

Parameters
displayHandle to display.

Definition at line 1023 of file display.c.

Here is the call graph for this function:

◆ displayDisplayOff()

void displayDisplayOff ( display_t display)

Turn off the display.

Parameters
displayHandle to display.

Definition at line 403 of file display.c.

Here is the call graph for this function:

◆ displayDisplayOn()

void displayDisplayOn ( display_t display)

Initialize DISPLAY screen.

Parameters
displayHandle to display.
widthWidth of screen in pixels.
heightHeight of screen in pixels.
offsetxHorizontal offset.
offsetyVertical offset.

Definition at line 410 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
fxPointer to font-file that is used for drawing the text.
xThe x-coordinate of the text on the display.
yThe y-coordinate of the text on the display.
asciiThe ascii character to draw.
colorThe 16-bit color value to write.
Returns
The x-value of the next character to be printed on the display.
Warning
The font-file path must be valid from the directory in which the executable is called, otherwise the error message "cannot get font from font file" will be thrown. Absolute paths (starting with /) are safe. See documentation for InitFontx.

Definition at line 782 of file display.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
displayHandle to display.
x_centerX-coordinate of the center of the circle.
y_centerY-coordinate of the center of the circle.
rThe radius of the circle in pixels.
colorThe 16-bit color value to write.

Definition at line 621 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
x_centerX-coordinate of the center of the circle.
y_centerY-coordinate of the center of the circle.
rThe radius of the circle in pixels.
colorThe 16-bit color value to write.

Definition at line 662 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
x1The X coordinate of the top-left corner of the rectangle.
y1The Y coordinate of the top-left corner of the rectangle.
x2The X coordinate of the bottom-right corner of the rectangle.
y2The Y coordinate of the bottom-right corner of the rectangle.
colorThe 16-bit color value to write.

Definition at line 361 of file display.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
displayHandle to display.
x1Starting x-coordinate of line.
y1Starting y-coordinate of line.
x2Ending x-coordinate of line.
y2Ending y-coordinate of line.
colorThe 16-bit color value to write.

Definition at line 425 of file display.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayDrawPixel()

void displayDrawPixel ( display_t display,
uint16_t  x,
uint16_t  y,
uint16_t  color 
)

Draw a single pixel to the display.

Parameters
displayHandle to display.
xThe X coordinate of the pixel.
yThe Y coordinate of the pixel.
colorThe 16-bit color value to write.

Definition at line 317 of file display.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
displayHandle to display.
x1Top-left x-coordinate of rectangle.
y1Top-left y-coordinate of rectangle.
x2Bottom-right x-coordinate of rectangle.
y2Bottom-right y-coordinate of rectangle.
colorThe 16-bit color value to write.

Definition at line 478 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
xcX-coordinate of the center of the rectangle.
ycY-coordinate of the center of the rectangle.
wWidth of the rectangle.
hHeight of the rectangle.
angleAngle of rotation in degrees.
colorThe 16-bit color value to write.

Definition at line 496 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
x1Top-left x-coordinate of rectangle.
y1Top-left y-coordinate of rectangle.
x2Bottom-right x-coordinate of rectangle.
y2Bottom-right y-coordinate of rectangle.
rThe radius of the circle that is used for the edges.
colorThe 16-bit color value to write.

Definition at line 708 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
fxPointer to font-file that is used for drawing the text.
xThe x-coordinate of the text on the display.
yThe y-coordinate of the text on the display.
asciiThe ascii characters to draw.
colorThe 16-bit color value to write.
Returns
The x or y coordinate of the next character, depending on the orientation of the display.
Warning
The font-file path must be valid from the directory in which the executable is called, otherwise the error message "cannot get font from font file" will be thrown. Absolute paths (starting with /) are safe. See documentation for InitFontx.

Definition at line 951 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
x1The first X-coordinate of the triangle.
y1The first Y-coordinate of the triangle.
x2The second X-coordinate of the triangle.
y2The second Y-coordinate of the triangle.
x3The third X-coordinate of the triangle.
y3The third Y-coordinate of the triangle.
colorThe 16-bit color value to write.

Definition at line 553 of file display.c.

Here is the call graph for this function:

◆ 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.

Parameters
displayHandle to display.
xcX-coordinate of the center of the rectangle.
ycY-coordinate of the center of the rectangle.
wWidth of the rectangle.
hHeight of the rectangle.
angleAngle of rotation in degrees.
colorThe 16-bit color value to write.

Definition at line 580 of file display.c.

Here is the call graph for this function:

◆ displayFillScreen()

void displayFillScreen ( display_t display,
uint16_t  color 
)

Fill entire display with a single color using the ldcDrawFillRect function.

Parameters
displayHandle to display.
colorFill color in RGB format.

Definition at line 417 of file display.c.

Here is the call graph for this function:

◆ displayInversionOff()

void displayInversionOff ( display_t display)

Turn off inversion of the colors.

Parameters
displayHandle to display.

Definition at line 1032 of file display.c.

Here is the call graph for this function:

◆ displayInversionOn()

void displayInversionOn ( display_t display)

Turn on inversion of the colors.

Parameters
displayHandle to display.

Definition at line 1039 of file display.c.

Here is the call graph for this function:

◆ displaySetFontDirection()

void displaySetFontDirection ( display_t display,
uint16_t  dir 
)

Changes the direction the characters will be printed.

Parameters
displayHandle to display.
dirThe direction to set the font in the display handle.

Definition at line 982 of file display.c.

◆ displaySetFontFill()

void displaySetFontFill ( display_t display,
uint16_t  color 
)

Enables the _font_fill and sets the _font_fill_color in the display handle.

Parameters
displayHandle to display.
colorThe fill-color the font should have

Definition at line 989 of file display.c.

◆ 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 color.

Parameters
displayHandle to display.
colorThe 16-bit color value to write.

Definition at line 999 of file display.c.

◆ displayUnsetFontFill()

void displayUnsetFontFill ( display_t display)

Sets the _font_fill parameter to false in the display handle, turns off the font fill.

Parameters
displayHandle to display.

Definition at line 997 of file display.c.

◆ displayUnsetFontUnderLine()

void displayUnsetFontUnderLine ( display_t display)

Turns off _font_underline in the display handle.

Parameters
displayHandle to display.

Definition at line 1007 of file display.c.

◆ rgb_conv()

uint16_t rgb_conv ( uint16_t  r,
uint16_t  g,
uint16_t  b 
)

RGB conversion for generating a color.

Parameters
rRed value, 5 least significant bits.
gGreen value, 6 least significant bits.
bBlue value, 5 least significant bits.

Definition at line 778 of file display.c.