-
-
Notifications
You must be signed in to change notification settings - Fork 24
display
This class includes full support for TFT display modules used on Sipeed MAIX boards.
Before using the display, the display module must be imported and the instance of the TFT class has to be created:
import display
tft = display.TFT()
TFT module can draw to the display directly or using the framebuffer.
If frame buffer is used, no changes on the display will be visible until the tft.show()
command is executed.
After initialization, the framebuffer is used and tft.useFB()
command can be used to change the mode.
Color values are given as 16 bit integer numbers, coded as 5-6-5 RGB values.
For example: 0xF800 represents the RED color.
Color values can also be given as a tuple of RGB values, for example (255, 0, 0)
(red collor).
The following color constants are defined and can be used as color arguments:
BLACK
, NAVY
, DARKGREEN
, DARKCYAN
, MAROON
, PURPLE
OLIVE
, LIGHTGREY
, DARKGREY
, BLUE
, GREEN
, CYAN
, RED
MAGENTA
, YELLOW
, WHITE
, ORANGE
, GREENYELLOW
, PINK
All drawings coordinates are relative to the display window.
Initialy, the display window is set to full screen, and there are methods to set the window to the part of the full screen.
9 bit-mapped fonts and one vector 7-segment font are included. Unlimited number of fonts from file can also be used.
The following font constants are defined and can be used as font arguments:
FONT_Default
, FONT_DefaultSmall
, FONT_DejaVu18
, FONT_Dejavu24
FONT_Ubuntu
, FONT_Comic
, FONT_Minya
, FONT_Tooney
, FONT_Small
FONT_7seg
External fonts (from file) can be used.
Web application Font creator is provided to convert any TTF or OpenType font to binary.fon
file suitable for use with this module.
Create the desired font, download it and copy to the internal file system. You can select it usingtft.font()
method.
Touch panels are not supported at the moment, but the support will be added later.
Initialize the SPI interface and set the warious operational modes.
All arguments are optional and of KW argument type and must be entered as arg=value
.
Argument | Description |
---|---|
type | optional, sets the display controler type, for now this argument is ignored. |
width | optional, default=240, display phisical width in pixels (display's smaller dimension). |
height | optional, default=320, display phisical height in pixels (display's larger dimension). |
speed | optional, default=5000000, SPI speed for display comunication in Hz. Maximal usable speed depends on display type and the wiring length |
rot | optional, default=LANDSCAPE ; Set the initial display orientation |
bgr |
optional, default=True, set to True if the display panel has BGR matrix. If you get inverted RED and BLUE colors, try to change this argument |
splash | optional, default=True; If set to False do not display "MicroPython" string in RGB colors atfter initialization |
De initialize the used spi device(s), free all used resources.
Not used at the moment.
Draw the pixel at position (x,y).
If color is not given, current foreground color is used.
Draw the line from point (x,y) to point (x1,y1)
If color is not given, current foreground color is used.
Draw the line from point (x,y) with length lenght starting st distance start from center.
If color is not given, current foreground color is used.
The angle is given in degrees (0~359).
Draw the triangel between points (x,y), (x1,y1) and (x2,y2).
If color is not given, current foreground color is used.
If fillcolor is given, filled triangle will be drawn.
Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
If fillcolor is given, filled circle will be drawn.
Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
*opt argument defines the ellipse segment to be drawn, default id 15, all ellipse segments.
Multiple segments can drawn, combine (logical or) the values.
- 1 - upper left segment
- 2 - upper right segment
- 4 - lower left segment
- 8 - lower right segment
If fillcolor is given, filled elipse will be drawn.
Draw the arc with center at (x,y) and radius r, starting at angle start and ending at angle end
The thicknes of the arc outline is set by the thick argument
If fillcolor is given, filled arc will be drawn.
Draw the polygon with center at (x,y) and radius r, with number of sides sides
The thicknes of the polygon outline is set by the thick argument
If fillcolor is given, filled polygon will be drawn.
If rotate is given, the polygon is rotated by the given angle (0~359)
Draw the rectangle from the upper left point at (x,y) and width width and height height
If fillcolor is given, filled rectangle will be drawn.
Draw the rectangle with rounded corners from the upper left point at (x,y) and width width and height height
Corner radius is given by r argument.
If fillcolor is given, filled rectangle will be drawn.
Clear the screen with default background color or specific color if given.
Clear the current display window with default background color or specific color if given.
Set the display orientation.
Use one of predifined constants:
tft.PORTRAIT, tft.LANDSCAPE, tft.PORTRAIT_FLIP, tft.LANDSCAPE_FLIP
Set the active font and its characteristics.
Argument | Description |
---|---|
font | required, use font name constant or font file name |
rotate | optional, set font rotation angle (0~360) |
transparent | only draw font's foreground pixels |
fixedwidth | draw proportional font with fixed character width, max character width from the font is used |
dist | only for 7-seg font, the distance between bars |
width | only for 7-seg font, the width of the bar |
outline | only for 7-seg font, draw the outline |
color | font color, if not given the current foreground color is used |
Set characteristics of the 7-segment font
Argument | Description |
---|---|
dist | the distance between bars |
width | the width of the bar |
outline | outline color |
color | fill color |
Return width and height of the active font
Display the string text
at possition (x
,y
).
If color
is not given, current foreground color is used.
-
x
: horizontal position of the upper left point in pixels, special values can be given:-
CENTER
, centers the text -
RIGHT
, right justifies the text -
LASTX
, continues from last X position; offset can be used:LASTX+n
-
-
y
: vertical position of the upper left point in pixels, special values can be given:-
CENTER
, centers the text -
BOTTOM
, bottom justifies the text -
LASTY
, continues from last Y position; offset can be used:LASTY+n
-
-
text
: string to be displayed. Two special characters are allowed in strings:-
\r
CR (0x0D), clears the display to EOL -
\n
LF (ox0A), continues to the new line, x=0
-
Return the width of the string text using the active font fontSize
Clear the the screen area used by string text at possition (x,y) using the bacckground color color.
If color is not given, current background color is used.
Display the image from the file file on position (x,y)
-
JPG images are supported.
Baseline only. Progressive and Lossless JPEG format are not supported.
Image size: Up to 65520 x 65520 pixels
Color space: YCbCr three components only. Gray scale image is not supported.
Sampling factor: 4:4:4, 4:2:2 or 4:2:0. -
BMP images are supported.
Only uncompressed RGB 24-bit with no color space information BMP images can be displayed. -
RAW image format is supported.
Only fool screen images are supported for now, e.g. the saved framebuffer. - Constants tft.CENTER, tft.BOTTOM, tft.RIGHT can be used for x&y
- x and y values can be negative
scale (jpg): image scale factor: 0 to 3; if scale>0, image is scaled by factor 1/(2^scale) (1/2, 1/4 or 1/8)
scale (bmp): image scale factor: 0 to 7; if scale>0, image is scaled by factor 1/(scale+1)
type: optional, set the image type, constants tft.JPG
, tft.BMP
or tft.RAW
can be used. If not set, file extension and/or file content will be used to determine the image type.
Set active display window to screen rectangle (x,y) - (x1,y1)
Reset active display window to full screen size.
Save active display window dimensions.
Restore active display window dimensions previously saved wint savewin().
Return the display size, (width, height)
Return the active display window size, (width, height)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
Returns 16-bit integer value suitable to be used as color argument
Arguments
- hue: float: any number, the floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.
- saturation: float; 0 ~ 1.0
- brightness: float; 0 ~ 1.0
Converts the RGB components of a color given as a tuple (R, G, B)
to the 16-bit RGB565 value used by TFT.
Returns 16-bit integer value suitable to be used as color argument.
Get the default background color
Get the default foreground color
Set the default background color
Set the default foreground color
Set the display's SPI speed in Hz
Speeds form 1000000 to 16000000 Hz can be set.
Show (send to display) the current content of the frame buffer
Only executes if the current operating mode is framebuffer mode
Set the current operating mode to framebuffer mode or direct mode
Save the current content of the framebuffer to file.
- Maix-M1 schematic
- Maix-Bit schematic
- Maix-Go schematic
- Kendryte K210 datasheet
- RISC-V ISA Design
- RISC-V ISA Manual
- Forum
- MicroPython documentation
If you find this project useful, you can contribute by making a donation