BT81x library¶
This module exports classes and functions to handle Bridgetek BT81x family of Embedded Video Engines.
-
class
DisplayConf
(width, height, hcycle, hoffset, hsync0, hsync1, vcycle, voffset, vsync0, vsync1, pclk, swizzle, pclkpol, cspread, dither, description)¶ Class to store a display configuration. List of attributes:
DisplayConf.width
display width in pixelsDisplayConf.height
display height in pixelsDisplayConf.hcycle
number of total PCLK cycles per horizontal line scanDisplayConf.hoffset
number of PCLK cycle before pixels are scanned outDisplayConf.hsync0
how many PCLK cycles for HSYNC0 during start of lineDisplayConf.hsync1
how many PCLK cycles for HSYNC1 during start of lineDisplayConf.vcycle
how many lines in one frameDisplayConf.voffset
how many lines taken after the start of a new frameDisplayConf.vsync0
how many lines of signal VSYNC0 takes at start of a new frameDisplayConf.vsync1
how many lines of signal VSYNC1 takes at start of a new frameDisplayConf.pclk
main clock divider for PCLK, if 0 there is no PCLK outputDisplayConf.swizzle
controls the arrangement of output RGB pins to support different LCD panelsDisplayConf.pclkpol
0
for PCLK polarity on the rising edge, 1 for falling edgeDisplayConf.cspread
controls the transition of RGB signals with PCLK active clock edgeDisplayConf.dither
1
or0
to respectively enable or disable ditherDisplayConf.description
a string describing the display
display_conf
module global variable is automatically set with aDisplayConf
instance when importing a display module from a display vendor:from riverdi.displays.bt81x import ctp50 from bridgetek.bt81x import bt81x
-
init
(spi, cs, pd, int, dc=None, spi_speed=3000000)¶ Parameters: - spi – spi driver (
SPI0
,SPI1
,...
) - cs – chip select pin
- pd – pd pin
- int – interrupt pin
- dc – display configuration as a
DisplayConf
instance - spi_speed – spi speed in Hertz
Initializes the chip.
When
dc
parameter is not specifieddisplay_conf
global variable is used.- spi – spi driver (
-
class
Palette
(font, foreground, background)¶ Class to store a color palette for font, foreground and background. List of attributes:
font
tuple of rgb values(r,g,b)
foreground
tuple of rgb values(r,g,b)
background
tuple of rgb values(r,g,b)
-
class
Text
(x, y, font, options, text, palette=None)¶ Class to store a text element configuration. List of attributes:
x
x-coordinate top-left, in pixelsy
y-coordinate top-left, in pixelsfont
font to use0-31
options
one ofOPT_CENTERX
,OPT_CENTERY
,OPT_CENTER
,OPT_RIGHTX
,OPT_FORMAT
,OPT_FILL
text
text stringpalette
Palette
object instance to set colors
-
class
Button
(x, y, width, height, font, options, text, palette=None)¶ Class to store a text element configuration. Inherits all
Text
attributes and adds:width
button width in pixelsheight
button height in pixels
Co-Processor Commands¶
List of available options for the options
command parameter:
OPT_3D
3D effectOPT_CENTER
horizontally and vertically centered styleOPT_CENTERX
horizontally-centered styleOPT_CENTERY
vertically-centered styleOPT_FILL
breaks the text at spaces into multiple linesOPT_FLASH
fetch the data from flash memoryOPT_FLAT
no 3D effectOPT_FORMAT
flag of string formattingOPT_FULLSCREEN
zoom the media to fill as much of the screen as possibleOPT_MEDIAFIFO
source data from the defined media FIFOOPT_MONO
decodes the source JPEG image to L8 format, i.e., monochromeOPT_NOBACK
no background drawnOPT_NODL
no display list commands generatedOPT_NOHANDS
no handsOPT_NOHM
no hour and minute handsOPT_NOPOINTER
no pointerOPT_NOSECS
no second handsOPT_NOTEAR
sync video updates to the display blanking interval, avoiding horizontal tearing artifactsOPT_NOTICKS
no ticksOPT_OVERLAY
append the video bitmap to an existing display listOPT_RGB565
decodes the source image to RGB565 formatOPT_RIGHTX
right justified styleOPT_SIGNED
the number is treated as a 32 bit signed integerOPT_SOUND
decode the audio data
Options can be combined using a bitwise OR.
-
dl_start
()¶ Starts a new display list.
-
set_font_color
(r, g, b)¶ Parameters: - r – red
0-255
- g – green
0-255
- b – blue
0-255
Sets current font color.
- r – red
-
set_foreground
(r, g, b)¶ Parameters: - r – red
0-255
- g – green
0-255
- b – blue
0-255
Sets current foreground color.
- r – red
-
set_background
(r, g, b)¶ Parameters: - r – red
0-255
- g – green
0-255
- b – blue
0-255
Sets current background color.
- r – red
-
add_text
(txt)¶ Parameters: txt – Text
object instanceAdds a text element to the screen.
A call to
set_font_color()
is performed if theText.palette
attribute is set.
Parameters: btn – Button
object instanceAdds a button element to the screen.
Calls to
set_background()
,set_foreground()
andset_font_color()
are performed if theText.palette.font
attribute is set.
-
add_keys
(x, y, w, h, font, options, s)¶ Parameters: - x – x-coordinate top-left, in pixels
- y – y-coordinate top-left, in pixels
- w – width of the keys
- h – height of the keys
- font – font used in key label
0-31
- options – one of
OPT_3D
(default),OPT_FLAT
,OPT_CENTER
or an ASCII code - s – key labels, one character per key.
Adds a row of keys to the screen. If an ASCII code is specified as option, that key is drawn as pressed (in background color with any 3D effect removed).
The
TAG
value is set to the ASCII value of each key, so that key presses can be detected with a callback on that value.
-
add_clock
(x, y, r, options, h, m, s, ms)¶ Parameters: - x – x-coordinate top-left, in pixels
- y – y-coordinate top-left, in pixels
- r – clock radius
- options – one of
OPT_3D
(default),OPT_FLAT
,OPT_NOBACK
,OPT_NOTICKS
,OPT_NOSECS
,OPT_NOHANDS
,OPT_NOHM
- h – hours
- m – minutes
- s – seconds
- ms – milliseconds
Adds a clock to the screen.
-
clear
(color, stencil, tag)¶ Parameters: - color – clear color
0-1
- stencil – clear stencil
0-1
- tag – clear tag
0-1
Clears buffers to default values.
- color – clear color
-
clear_color
(rgb=None, a=None)¶ Parameters: - rgb – tuple for red, green and blue values (
0-255
,0-255
,0-255
) - a – alpha
0-255
Sets the default color when colors are cleared. The initial value is
((0, 0, 0), 0)
.- rgb – tuple for red, green and blue values (
-
clear_tag
(default_tag)¶ Parameters: default_tag – default tag Sets the default tag when tag buffer is cleared. The initial value is
0
.
-
spinner
(x, y, style, scale)¶ Parameters: - x – x-coordinate top-left, in pixels
- y – y-coordinate top-left, in pixels
- style – spinner style, one of
SPINNER_CIRCLE
,SPINNER_LINE
,SPINNER_CLOCK
,SPINNER_ORBITING
Draws a spinner with a chosen style.
-
calibrate
()¶ Starts the calibration procedure (needed by Resistive Displays).
-
inflate
(ram_ptr, resource)¶ Parameters: - ram_ptr – address in RAM_G to inflate the resource to
- resource – name of the resource to inflate
Inflates a Zerynth resource to RAM_G (General purpose graphics RAM, bt81x main memory) for later use. The resource should be a valid bt81x image (zlib-compressed)
Raises: - PeripheralError – if an error occurs while inflating
- TimeoutError – if the process takes longer than set timeout (
set_timeout()
)
-
load_image
(ram_ptr, options, resource)¶ Parameters: - ram_ptr – address in RAM_G to load the resource to
- options – load options
- resource – name of the resource to inflate
Inflates a Zerynth resource consisting of a PNG image to RAM_G (General purpose graphics RAM, bt81x main memory) for later use.
Raises: - PeripheralError – if an error occurs while loading
- TimeoutError – if the process takes longer than set timeout (
set_timeout()
)
-
vertex_format
(fmt)¶ Parameters: fmt – format frac value, one of 0
,1
,2
,3
,4
Selects a vertex format for subsequent draw operations.
Vertex format are useful to specify pixel coordinates beyond the
0-511
range.
-
class
Bitmap
(handle, source, layout, size)¶ Parameters: - handle – a user-defined handle to refer to the bitmap
- source – bitmap source in RAM_G
- layout – a tuple of
(bitmap_format, linestride)
- size – a tuple of
(filtering_mode, x_wrap_mode, y_wrap_mode, bitmap_width, bitmap_height)
Class to store a bitmap element and to allow subsequent bitmap draw operations.
linestride
value represents the amount of memory used for each line of bitmap pixels. It depends on selected format and can be usually calculated with the following formula:linestride = width * byte/pixel
Allowed values for
bitmap_format
and number of bits/pixel for that format:L1
1
L2
2
L4
4
L8
8
ARGB2
8
RGB332
8
ARGB4
16
ARGB1555
16
RGB565
16
PALETTED8
8
PALETTED4444
8
PALETTED565
8
BARGRAPH
TEXT8X8
Allowed values for
filtering_mode
are:NEAREST
BILINEAR
Allowed values for
x_wrap_mode
andy_wrap_mode
are:BORDER
REPEAT
-
draw
(vertex, vertex_fmt=None)¶ Draws prepared image on screen. Can be called multiple times after a single
prepare_draw()
.If
vertex
tuple has 2 elements the vertex format is set according tovertex_fmt
parameter (vertex_format()
) andvertex
elements are assumed to be the imagex
andy
top-left coordinates.If
vertex
tuple has 4 elementsvertex_fmt
parameter is ignored andvertex
elements are assumed to be the imagex
andy
top-left coordinates, image handle and cell.
-
end
()¶ Ends drawing a graphics primitive.
-
display
()¶ Ends a display list.
-
swap_and_empty
()¶ Swaps current display list and waits until all commands are executed.
Raises: - PeripheralError – if an error occurs while executing commands
- TimeoutError – if the process takes longer than set timeout (
set_timeout()
)
-
set_timeout
(timeout_millis)¶ Parameters: timeout_millis – timeout in milliseconds Sets a timeout for Co-Processor commands. Default timeout value is
4000
.
-
tag
(n)¶ Parameters: n – tag value 1-255
Attaches the tag value to all the following graphics objects drawn on the screen, unless
tag_mask()
is used to disable it. When the graphics objects attached with the tag value are touched, if calls totrack()
andtouch_loop()
have been previously issued, a callback function is called.The initial tag value is specified by function
clear_tag()
and takes effect calling functionclear()
.
-
tag_mask
(mask)¶ Parameters: mask – mask value 0-1
If called with value
0
the default value of the tag buffer is used for current display list.
-
tag_mask
(mask) Parameters: mask – mask value 0-1
If called with value
0
the default value of the tag buffer is used for current display list.
-
touch_loop
(cbks)¶ Parameters: - cbks – tuple of tuples of callback and tag value for the callback to be activated on
((tag_value1, cbk1), (tag_value2, cbk2), ...)
- touch_points – number of multiple touch points (to be supported by used display)
Starts the touch loop to call set callbacks when touches are detected. Each callback function is called passing tag value, tracked value and touch point.
If a tag value of
-1
is specified for a certain callback, that callback is called for every detected tag value.- cbks – tuple of tuples of callback and tag value for the callback to be activated on