busdisplay
displaysys.busdisplay ¶
displaysys.busdisplay
Classes¶
BusDisplay ¶
BusDisplay(display_bus, init_sequence=None, *, width=0, height=0, colstart=0, rowstart=0, rotation=0, mirrored=False, color_depth=16, bgr=False, invert=False, reverse_bytes_in_word=False, brightness=1.0, backlight_pin=None, backlight_on_high=True, reset_pin=None, reset_high=True, power_pin=None, power_on_high=True, set_column_command=_CASET, set_row_command=_RASET, write_ram_command=_RAMWR, brightness_command=None, data_as_commands=False, single_byte_bounds=False)
Base class for displays connected via a bus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_bus
|
(SPIBus, I80Bus)
|
The bus the display is connected to. |
required |
init_sequence
|
(bytes, list)
|
The initialization sequence for the display. |
None
|
width
|
int
|
The width of the display in pixels. |
0
|
height
|
int
|
The height of the display in pixels. |
0
|
colstart
|
int
|
The column start address for the display. |
0
|
rowstart
|
int
|
The row start address for the display. |
0
|
rotation
|
int
|
The rotation of the display in degrees. |
0
|
mirrored
|
bool
|
If True, the display is mirrored. |
False
|
color_depth
|
int
|
The color depth of the display in bits. |
16
|
bgr
|
bool
|
If True, the display uses BGR color order. |
False
|
invert
|
bool
|
If True, the display colors are inverted. |
False
|
reverse_bytes_in_word
|
bool
|
If True, the bytes in 16-bit colors are reversed. |
False
|
brightness
|
float
|
The brightness of the display as a float between 0.0 and 1.0. |
1.0
|
backlight_pin
|
(int, Pin)
|
The pin the display backlight is connected to. |
None
|
backlight_on_high
|
bool
|
If True, the backlight is on when the pin is high. |
True
|
reset_pin
|
(int, Pin)
|
The pin the display reset is connected to. |
None
|
reset_high
|
bool
|
If True, the reset pin is high. |
True
|
power_pin
|
(int, Pin)
|
The pin the display power is connected to. |
None
|
power_on_high
|
bool
|
If True, the power pin is high. |
True
|
set_column_command
|
int
|
The command to set the column address. |
_CASET
|
set_row_command
|
int
|
The command to set the row address. |
_RASET
|
write_ram_command
|
int
|
The command to write to the display RAM. |
_RAMWR
|
brightness_command
|
int
|
The command to set the display brightness. |
None
|
data_as_commands
|
bool
|
If True, data is sent as commands. |
False
|
single_byte_bounds
|
bool
|
If True, single byte bounds are used. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
display_bus |
(SPIBus, I80Bus)
|
The bus the display is connected to. |
color_depth |
int
|
The color depth of the display in bits. |
bgr |
bool
|
If True, the display uses BGR color order. |
rotation_table |
tuple
|
The rotation table for the display. |
Attributes¶
power
property
writable
¶
power
The power state of the display.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
The power state of the display. |
vscroll
property
writable
¶
vscroll
The vertical scroll position relative to the top fixed area.
Returns:
| Type | Description |
|---|---|
int
|
The vertical scroll position. |
tfa
property
¶
tfa
The top fixed area set by set_vscroll or vscrdef.
Returns:
| Type | Description |
|---|---|
int
|
The top fixed area. |
vsa
property
¶
vsa
The vertical scroll area set by set_vscroll or vscrdef.
Returns:
| Type | Description |
|---|---|
int
|
The vertical scroll area. |
bfa
property
¶
bfa
The bottom fixed area set by set_vscroll or vscrdef.
Returns:
| Type | Description |
|---|---|
int
|
The bottom fixed area. |
tfa_area
property
¶
tfa_area
Top fixed area for vertical scrolling.
Returns:
| Type | Description |
|---|---|
|
tuple[int, int, int, int]: |
vsa_area
property
¶
vsa_area
The vertical scroll area as an Area object.
Returns:
| Type | Description |
|---|---|
tuple
|
The vertical scroll area. |
bfa_area
property
¶
bfa_area
The bottom fixed area as an Area object.
Returns:
| Type | Description |
|---|---|
tuple
|
The bottom fixed area. |
Methods:¶
init ¶
init()
Post initialization tasks.
This method may be overridden by subclasses to perform any post initialization. If it is overridden, it must call super().init() or set self._initialized = True.
blit_rect ¶
blit_rect(buf, x, y, w, h)
Blit a buffer to the display.
This method takes a buffer of pixel data and writes it to a specified rectangular area of the display. The top-left corner of the rectangle is specified by the x and y parameters, and the size of the rectangle is specified by the width and height parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
memoryview
|
The buffer containing the pixel data. |
required |
x
|
int
|
The x-coordinate of the top-left corner of the rectangle. |
required |
y
|
int
|
The y-coordinate of the top-left corner of the rectangle. |
required |
w
|
int
|
The width of the rectangle in pixels. |
required |
h
|
int
|
The height of the rectangle in pixels. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing the x, y, width, and height of the rectangle. |
fill_rect ¶
fill_rect(x, y, w, h, c)
Draw a rectangle at the given location, size and filled with color.
This method draws a filled rectangle on the display. The top-left corner of the rectangle is specified by the x and y parameters, and the size of the rectangle is specified by the width and height parameters. The rectangle is filled with the specified color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The x-coordinate of the top-left corner of the rectangle. |
required |
y
|
int
|
The y-coordinate of the top-left corner of the rectangle. |
required |
w
|
int
|
The width of the rectangle in pixels. |
required |
h
|
int
|
The height of the rectangle in pixels. |
required |
c
|
int
|
The color of the rectangle. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing the x, y, width, and height of the rectangle. |
pixel ¶
pixel(x, y, c)
Set a pixel on the display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The x-coordinate of the pixel. |
required |
y
|
int
|
The y-coordinate of the pixel. |
required |
c
|
int
|
The color of the pixel. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing the x, y, width, and height of the pixel. |
vscrdef ¶
vscrdef(tfa, vsa, bfa)
Set Vertical Scrolling Definition.
To scroll a 135x240 display these values should be 40, 240, 40. There are 40 lines above the display that are not shown followed by 240 lines that are shown followed by 40 more lines that are not shown. You could write to these areas off display and scroll them into view by changing the TFA, VSA and BFA values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tfa
|
int
|
Top Fixed Area. |
required |
vsa
|
int
|
Vertical Scrolling Area. |
required |
bfa
|
int
|
Bottom Fixed Area. |
required |
vscsad ¶
vscsad(vssa=None)
Set the vertical scroll start address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vssa
|
(int, None)
|
The vertical scroll start address. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The vertical scroll start address. |
invert_colors ¶
invert_colors(value)
Invert the colors of the display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
If True, invert the colors of the display. |
required |
reset ¶
reset()
Reset display.
This method resets the display. If the display has a reset pin, it is reset using the reset pin. Otherwise, the display is reset using the software reset command.
sleep_mode ¶
sleep_mode(value)
Enable or disable display sleep mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
If True, enable sleep mode. If False, disable sleep mode. |
required |
fill ¶
fill(color)
Fill the display with a color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
int
|
The color to fill the display with. |
required |
scroll ¶
scroll(dx, dy)
Scroll the display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dx
|
int
|
The number of pixels to scroll horizontally. |
required |
dy
|
int
|
The number of pixels to scroll vertically. |
required |
disable_auto_byteswap ¶
disable_auto_byteswap(value)
Disable byte swapping in the display driver.
If self.requires_byteswap and the guest application is capable of byte swapping color data check to see if byte swapping can be disabled. If so, disable it.
Usage
# If byte swapping is required and the display driver is capable of having byte swapping disabled,
# disable it and set a flag so we can swap the color bytes as they are created.
if display_drv.requires_byteswap:
needs_swap = display_drv.disable_auto_byteswap(True)
else:
needs_swap = False
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Whether to disable byte swapping. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether byte swapping was disabled successfully. |
blit_transparent ¶
blit_transparent(buf, x, y, w, h, key)
Blit a buffer with transparency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
memoryview
|
The buffer to blit. |
required |
x
|
int
|
The x coordinate to blit to. |
required |
y
|
int
|
The y coordinate to blit to. |
required |
w
|
int
|
The width to blit. |
required |
h
|
int
|
The height to blit. |
required |
key
|
int
|
The color key to use for transparency. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
The x, y, w, h coordinates of the blitted area. |
set_vscroll ¶
set_vscroll(tfa=0, bfa=0)
Set the vertical scroll definition and move the vertical scroll to the top.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tfa
|
int
|
The top fixed area. |
0
|
bfa
|
int
|
The bottom fixed area. |
0
|
translate_point ¶
translate_point(point)
Translate a point from real coordinates to scrolled coordinates.
Useful for touch events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
tuple
|
The x and y coordinates to translate. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
The translated x and y coordinates. |
deinit ¶
deinit()
Deinitialize the display. Stops the auto-refresh timer so it can't fire
after resources are released. Idempotent. Subclasses that override
this should call super().deinit().
quit ¶
quit(code=0)
Release resources and terminate the program.
Called by eventsys.devices.Broker.quit() on a window-close (QUIT)
event. The base implementation deinitializes the display and raises
SystemExit, which is correct for front ends that poll on the main
thread. Drivers needing a platform-specific exit (e.g. SDLDisplay,
where SystemExit raised from the LVGL scheduled task handler is
swallowed on the unix port) should override this.
show ¶
show(*args, **kwargs)
Show the display. Base class method does nothing. May be overridden by subclasses.